diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 10:22:43 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:36:28 +0000 |
commit | 271a6c3487a14599023a9106329505597638d793 (patch) | |
tree | e040d58ffc86c1480b79ca8528020ca9ec919bf8 /chromium/components/send_tab_to_self | |
parent | 7b2ffa587235a47d4094787d72f38102089f402a (diff) | |
download | qtwebengine-chromium-271a6c3487a14599023a9106329505597638d793.tar.gz |
BASELINE: Update Chromium to 77.0.3865.59
Change-Id: I1e89a5f3b009a9519a6705102ad65c92fe736f21
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/send_tab_to_self')
13 files changed, 120 insertions, 178 deletions
diff --git a/chromium/components/send_tab_to_self/BUILD.gn b/chromium/components/send_tab_to_self/BUILD.gn index 907f11d80ae..145099077fe 100644 --- a/chromium/components/send_tab_to_self/BUILD.gn +++ b/chromium/components/send_tab_to_self/BUILD.gn @@ -73,7 +73,7 @@ source_set("unit_tests") { "//components/history/core/browser", "//components/send_tab_to_self/proto:send_tab_to_self_proto", "//components/sync:test_support", - "//components/sync_device_info", + "//components/sync_device_info:test_support", "//testing/gtest", "//url", ] diff --git a/chromium/components/send_tab_to_self/OWNERS b/chromium/components/send_tab_to_self/OWNERS index cbbc50e63a9..a49acc9eff2 100644 --- a/chromium/components/send_tab_to_self/OWNERS +++ b/chromium/components/send_tab_to_self/OWNERS @@ -1,5 +1,6 @@ hansberry@chromium.org jeffreycohen@chromium.org sebsg@chromium.org +tgupta@chromium.org # COMPONENT: UI>Browser>Sharing diff --git a/chromium/components/send_tab_to_self/features.cc b/chromium/components/send_tab_to_self/features.cc index 9ac7562d408..5c2ead8564f 100644 --- a/chromium/components/send_tab_to_self/features.cc +++ b/chromium/components/send_tab_to_self/features.cc @@ -16,9 +16,6 @@ const base::Feature kSendTabToSelfShowSendingUI{ const base::Feature kSendTabToSelfBroadcast{"SendTabToSelfBroadcast", base::FEATURE_DISABLED_BY_DEFAULT}; -const base::Feature kSendTabToSelfHistory{"SendTabToSelfHistory", - base::FEATURE_DISABLED_BY_DEFAULT}; - const base::Feature kSendTabToSelfWhenSignedIn{ "SendTabToSelfWhenSignedIn", base::FEATURE_DISABLED_BY_DEFAULT}; @@ -33,9 +30,4 @@ bool EnabledOnSignIn() { base::FeatureList::IsEnabled(kSendTabToSelfWhenSignedIn); } -bool HistoryViewEnabled() { - return base::FeatureList::IsEnabled(switches::kSyncSendTabToSelf) && - base::FeatureList::IsEnabled(kSendTabToSelfHistory); -} - } // namespace send_tab_to_self diff --git a/chromium/components/send_tab_to_self/features.h b/chromium/components/send_tab_to_self/features.h index 6e3b42b94fd..922edf01e3a 100644 --- a/chromium/components/send_tab_to_self/features.h +++ b/chromium/components/send_tab_to_self/features.h @@ -19,11 +19,6 @@ extern const base::Feature kSendTabToSelfShowSendingUI; // targeted to a specific device. This only affects the receiving side. extern const base::Feature kSendTabToSelfBroadcast; -// If this feature is enabled, the tabs will be accessible after they are shared -// in the history tab on desktop devices or in the recent tab page on mobile -// devices. -extern const base::Feature kSendTabToSelfHistory; - // If this feature is enabled, we will use signed-in, ephemeral data rather than // persistent sync data. Users who are signed in can use the feature regardless // of whether they have the sync feature enabled. @@ -39,10 +34,6 @@ bool IsReceivingEnabledByUserOnThisDevice(PrefService* prefs); // persistent sync data. Then the feature may be used by signed-in users, // regardless of whether they have full sync enabled. bool EnabledOnSignIn(); - -// Returns whether we should show the send tab to self history ui on desktop or -// the recent tab UI on mobile, in order to access previously sent tabs. -bool HistoryViewEnabled(); } // namespace send_tab_to_self #endif // COMPONENTS_SEND_TAB_TO_SELF_FEATURES_H_ diff --git a/chromium/components/send_tab_to_self/send_tab_to_self_bridge.cc b/chromium/components/send_tab_to_self/send_tab_to_self_bridge.cc index afa9f32e39d..e10dfefe82d 100644 --- a/chromium/components/send_tab_to_self/send_tab_to_self_bridge.cc +++ b/chromium/components/send_tab_to_self/send_tab_to_self_bridge.cc @@ -112,7 +112,7 @@ std::unique_ptr<syncer::EntityData> CopyToEntityData( const sync_pb::SendTabToSelfSpecifics& specifics) { auto entity_data = std::make_unique<syncer::EntityData>(); *entity_data->specifics.mutable_send_tab_to_self() = specifics; - entity_data->non_unique_name = specifics.url(); + entity_data->name = specifics.url(); entity_data->creation_time = ProtoTimeToTime(specifics.shared_time_usec()); return entity_data; } @@ -156,8 +156,7 @@ SendTabToSelfBridge::SendTabToSelfBridge( clock_(clock), history_service_(history_service), device_info_tracker_(device_info_tracker), - mru_entry_(nullptr), - weak_ptr_factory_(this) { + mru_entry_(nullptr) { DCHECK(clock_); DCHECK(device_info_tracker_); if (history_service) { @@ -513,16 +512,16 @@ bool SendTabToSelfBridge::IsReady() { } bool SendTabToSelfBridge::HasValidTargetDevice() { - if (ShouldUpdateTargetDeviceNameToCacheInfoMap()) { - SetTargetDeviceNameToCacheInfoMap(); + if (ShouldUpdateTargetDeviceInfoList()) { + SetTargetDeviceInfoList(); } return target_device_name_to_cache_info_.size() > 0; } -std::map<std::string, TargetDeviceInfo> -SendTabToSelfBridge::GetTargetDeviceNameToCacheInfoMap() { - if (ShouldUpdateTargetDeviceNameToCacheInfoMap()) { - SetTargetDeviceNameToCacheInfoMap(); +std::vector<TargetDeviceInfo> +SendTabToSelfBridge::GetTargetDeviceInfoSortedList() { + if (ShouldUpdateTargetDeviceInfoList()) { + SetTargetDeviceInfoList(); } return target_device_name_to_cache_info_; } @@ -534,8 +533,8 @@ SendTabToSelfBridge::DestroyAndStealStoreForTest( return std::move(bridge->store_); } -bool SendTabToSelfBridge::ShouldUpdateTargetDeviceNameToCacheInfoMapForTest() { - return ShouldUpdateTargetDeviceNameToCacheInfoMap(); +bool SendTabToSelfBridge::ShouldUpdateTargetDeviceInfoListForTest() { + return ShouldUpdateTargetDeviceInfoList(); } void SendTabToSelfBridge::SetLocalDeviceNameForTest( @@ -554,16 +553,17 @@ void SendTabToSelfBridge::NotifyRemoteSendTabToSelfEntryAdded( if (base::FeatureList::IsEnabled(kSendTabToSelfBroadcast)) { new_local_entries = new_entries; } else { - // Only pass along entries that are targeted at this device, and not - // dismissed or opened. + // Only pass along entries that are not dismissed or opened, and are + // targeted at this device, which is determined by comparing the cache guid + // associated with the entry to each device's local list of recently used + // cache_guids DCHECK(!change_processor()->TrackedCacheGuid().empty()); for (const SendTabToSelfEntry* entry : new_entries) { - if (entry->GetTargetDeviceSyncCacheGuid() == - change_processor()->TrackedCacheGuid() && + if (device_info_tracker_->IsRecentLocalCacheGuid( + entry->GetTargetDeviceSyncCacheGuid()) && !entry->GetNotificationDismissed() && !entry->IsOpened()) { new_local_entries.push_back(entry); LogLocalDeviceNotified(UMANotifyLocalDevice::LOCAL); - } else { LogLocalDeviceNotified(UMANotifyLocalDevice::REMOTE); } @@ -699,11 +699,11 @@ void SendTabToSelfBridge::DoGarbageCollection() { NotifyRemoteSendTabToSelfEntryDeleted(removed); } -bool SendTabToSelfBridge::ShouldUpdateTargetDeviceNameToCacheInfoMap() const { - // The map should be updated if any of these is true: - // * The map is empty. +bool SendTabToSelfBridge::ShouldUpdateTargetDeviceInfoList() const { + // The vector should be updated if any of these is true: + // * The vector is empty. // * The number of total devices changed. - // * The oldest non-expired entry in the map is now expired. + // * The oldest non-expired entry in the vector is now expired. return target_device_name_to_cache_info_.empty() || device_info_tracker_->GetAllDeviceInfo().size() != number_of_devices_ || @@ -711,7 +711,7 @@ bool SendTabToSelfBridge::ShouldUpdateTargetDeviceNameToCacheInfoMap() const { kDeviceExpiration; } -void SendTabToSelfBridge::SetTargetDeviceNameToCacheInfoMap() { +void SendTabToSelfBridge::SetTargetDeviceInfoList() { std::vector<std::unique_ptr<syncer::DeviceInfo>> all_devices = device_info_tracker_->GetAllDeviceInfo(); number_of_devices_ = all_devices.size(); @@ -725,6 +725,7 @@ void SendTabToSelfBridge::SetTargetDeviceNameToCacheInfoMap() { }); target_device_name_to_cache_info_.clear(); + std::set<std::string> unique_device_names; for (const auto& device : all_devices) { // If the current device is considered expired for our purposes, stop here // since the next devices in the vector are at least as expired than this @@ -750,11 +751,13 @@ void SendTabToSelfBridge::SetTargetDeviceNameToCacheInfoMap() { // Only keep one device per device name. We only keep the first occurrence // which is the most recent. - TargetDeviceInfo target_device_info(device->guid(), device->device_type(), - device->last_updated_timestamp()); - target_device_name_to_cache_info_.emplace(device->client_name(), - target_device_info); - oldest_non_expired_device_timestamp_ = device->last_updated_timestamp(); + if (unique_device_names.insert(device->client_name()).second) { + TargetDeviceInfo target_device_info(device->client_name(), device->guid(), + device->device_type(), + device->last_updated_timestamp()); + target_device_name_to_cache_info_.push_back(target_device_info); + oldest_non_expired_device_timestamp_ = device->last_updated_timestamp(); + } } } diff --git a/chromium/components/send_tab_to_self/send_tab_to_self_bridge.h b/chromium/components/send_tab_to_self/send_tab_to_self_bridge.h index d8b94b5e768..fdf2da6cd65 100644 --- a/chromium/components/send_tab_to_self/send_tab_to_self_bridge.h +++ b/chromium/components/send_tab_to_self/send_tab_to_self_bridge.h @@ -5,10 +5,8 @@ #ifndef COMPONENTS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_BRIDGE_H_ #define COMPONENTS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_BRIDGE_H_ -#include <map> #include <memory> #include <string> -#include <utility> #include <vector> #include "base/macros.h" @@ -85,8 +83,7 @@ class SendTabToSelfBridge : public syncer::ModelTypeSyncBridge, void MarkEntryOpened(const std::string& guid) override; bool IsReady() override; bool HasValidTargetDevice() override; - std::map<std::string, TargetDeviceInfo> GetTargetDeviceNameToCacheInfoMap() - override; + std::vector<TargetDeviceInfo> GetTargetDeviceInfoSortedList() override; // history::HistoryServiceObserver: void OnURLsDeleted(history::HistoryService* history_service, @@ -95,7 +92,7 @@ class SendTabToSelfBridge : public syncer::ModelTypeSyncBridge, // For testing only. static std::unique_ptr<syncer::ModelTypeStore> DestroyAndStealStoreForTest( std::unique_ptr<SendTabToSelfBridge> bridge); - bool ShouldUpdateTargetDeviceNameToCacheInfoMapForTest(); + bool ShouldUpdateTargetDeviceInfoListForTest(); void SetLocalDeviceNameForTest(const std::string& local_device_name); private: @@ -140,11 +137,11 @@ class SendTabToSelfBridge : public syncer::ModelTypeSyncBridge, // Delete expired entries. void DoGarbageCollection(); - // Returns whether the target device name to cache guid map should be updated. - bool ShouldUpdateTargetDeviceNameToCacheInfoMap() const; + // Returns whether the target device info list should be updated. + bool ShouldUpdateTargetDeviceInfoList() const; - // Sets the target device name to cache guid map. - void SetTargetDeviceNameToCacheInfoMap(); + // Sets the target device info list. + void SetTargetDeviceInfoList(); // Remove entry with |guid| from entries, but doesn't call Commit on provided // |batch|. This allows multiple for deletions without duplicate batch calls. @@ -175,15 +172,15 @@ class SendTabToSelfBridge : public syncer::ModelTypeSyncBridge, // A pointer to the most recently used entry used for deduplication. const SendTabToSelfEntry* mru_entry_; - // A map of target devices names to their associated cache information. - std::map<std::string, TargetDeviceInfo> target_device_name_to_cache_info_; + // A list of target devices and their associated cache information. + std::vector<TargetDeviceInfo> target_device_name_to_cache_info_; // The following two variables are used to determine whether we should update // the target device name to cache guid map. base::Time oldest_non_expired_device_timestamp_; size_t number_of_devices_ = 0; - base::WeakPtrFactory<SendTabToSelfBridge> weak_ptr_factory_; + base::WeakPtrFactory<SendTabToSelfBridge> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(SendTabToSelfBridge); }; diff --git a/chromium/components/send_tab_to_self/send_tab_to_self_bridge_unittest.cc b/chromium/components/send_tab_to_self/send_tab_to_self_bridge_unittest.cc index cacd462ff2a..3f3ffee618a 100644 --- a/chromium/components/send_tab_to_self/send_tab_to_self_bridge_unittest.cc +++ b/chromium/components/send_tab_to_self/send_tab_to_self_bridge_unittest.cc @@ -26,7 +26,7 @@ #include "components/sync/protocol/model_type_state.pb.h" #include "components/sync/test/test_matchers.h" #include "components/sync_device_info/device_info.h" -#include "components/sync_device_info/device_info_tracker.h" +#include "components/sync_device_info/fake_device_info_tracker.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -38,7 +38,6 @@ using testing::_; using testing::AllOf; using testing::ElementsAre; using testing::IsEmpty; -using testing::Pair; using testing::Return; using testing::SizeIs; using testing::UnorderedElementsAre; @@ -89,58 +88,18 @@ MATCHER_P(GuidIs, e, "") { return testing::ExplainMatchResult(e, arg->GetGUID(), result_listener); } -// TODO(crbug.com/958016): Extract into its own file. -// Mock DeviceInfoTracker class for setting device info. -class TestDeviceInfoTracker : public syncer::DeviceInfoTracker { - public: - TestDeviceInfoTracker() = default; - ~TestDeviceInfoTracker() override = default; - - static std::unique_ptr<syncer::DeviceInfo> CloneDeviceInfo( - const syncer::DeviceInfo& device_info) { - return std::make_unique<syncer::DeviceInfo>( - device_info.guid(), device_info.client_name(), - device_info.chrome_version(), device_info.sync_user_agent(), - device_info.device_type(), device_info.signin_scoped_device_id(), - device_info.last_updated_timestamp(), - device_info.send_tab_to_self_receiving_enabled()); - } - - void Add(const syncer::DeviceInfo* device) { devices_.push_back(device); } - - // DeviceInfoTracker implementation. - bool IsSyncing() const override { return false; } - std::unique_ptr<syncer::DeviceInfo> GetDeviceInfo( - const std::string& client_id) const override { - NOTIMPLEMENTED(); - return std::unique_ptr<syncer::DeviceInfo>(); - } - std::vector<std::unique_ptr<syncer::DeviceInfo>> GetAllDeviceInfo() - const override { - std::vector<std::unique_ptr<syncer::DeviceInfo>> devices; - for (const syncer::DeviceInfo* device : devices_) { - devices.push_back(CloneDeviceInfo(*device)); - } - return devices; - } - int CountActiveDevices() const override { return devices_.size(); } - void AddObserver(Observer* observer) override { NOTIMPLEMENTED(); } - void RemoveObserver(Observer* observer) override { NOTIMPLEMENTED(); } - void ForcePulseForTest() override { NOTIMPLEMENTED(); } - - private: - // DeviceInfo stored here are not owned. - std::vector<const syncer::DeviceInfo*> devices_; - - DISALLOW_COPY_AND_ASSIGN(TestDeviceInfoTracker); -}; - class SendTabToSelfBridgeTest : public testing::Test { protected: SendTabToSelfBridgeTest() : store_(syncer::ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()) { scoped_feature_list_.InitAndEnableFeature(kSendTabToSelfShowSendingUI); SetLocalDeviceCacheGuid(kLocalDeviceCacheGuid); + local_device_ = std::make_unique<syncer::DeviceInfo>( + kLocalDeviceCacheGuid, "device", "72", "agent", + sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "scoped_is", + clock()->Now() - base::TimeDelta::FromDays(1), + /*send_tab_to_self_receiving_enabled=*/true); + AddTestDevice(local_device_.get()); } // Initialized the bridge based on the current local device and store. Can @@ -180,7 +139,7 @@ class SendTabToSelfBridgeTest : public testing::Test { *(entity_data->specifics.mutable_send_tab_to_self()) = specifics.specifics(); - entity_data->non_unique_name = entry.GetURL().spec(); + entity_data->name = entry.GetURL().spec(); return entity_data; } @@ -194,7 +153,7 @@ class SendTabToSelfBridgeTest : public testing::Test { auto entity_data = std::make_unique<syncer::EntityData>(); *(entity_data->specifics.mutable_send_tab_to_self()) = specifics; - entity_data->non_unique_name = specifics.url(); + entity_data->name = specifics.url(); changes.push_back(syncer::EntityChange::CreateAdd( specifics.guid(), std::move(entity_data))); @@ -242,7 +201,7 @@ class SendTabToSelfBridgeTest : public testing::Test { testing::NiceMock<syncer::MockModelTypeChangeProcessor> mock_processor_; - TestDeviceInfoTracker device_info_tracker_; + syncer::FakeDeviceInfoTracker device_info_tracker_; std::unique_ptr<SendTabToSelfBridge> bridge_; @@ -250,6 +209,8 @@ class SendTabToSelfBridgeTest : public testing::Test { base::test::ScopedFeatureList scoped_feature_list_; + std::unique_ptr<syncer::DeviceInfo> local_device_; + DISALLOW_COPY_AND_ASSIGN(SendTabToSelfBridgeTest); }; @@ -300,6 +261,7 @@ TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesAddTwoSpecifics) { TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneAdd) { InitializeBridge(); + SendTabToSelfEntry entry("guid1", GURL("http://www.example.com/"), "title", AdvanceAndGetTime(), AdvanceAndGetTime(), "device", kLocalDeviceCacheGuid); @@ -320,6 +282,7 @@ TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneAdd) { // Tests that the send tab to self entry is correctly removed. TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneDeletion) { InitializeBridge(); + SendTabToSelfEntry entry("guid1", GURL("http://www.example.com/"), "title", AdvanceAndGetTime(), AdvanceAndGetTime(), "device", kLocalDeviceCacheGuid); @@ -612,17 +575,17 @@ TEST_F(SendTabToSelfBridgeTest, /*enabled_features=*/{kSendTabToSelfShowSendingUI}, /*disabled_features=*/{kSendTabToSelfBroadcast}); + const std::string kRemoteGuid = "RemoteDevice"; InitializeBridge(); - SetLocalDeviceCacheGuid("Device1"); // Add on entry targeting this device and another targeting another device. syncer::EntityChangeList remote_input; SendTabToSelfEntry entry1("guid1", GURL("http://www.example.com/"), "title", AdvanceAndGetTime(), AdvanceAndGetTime(), "device", - "Device1"); + kLocalDeviceCacheGuid); SendTabToSelfEntry entry2("guid2", GURL("http://www.example.com/"), "title", AdvanceAndGetTime(), AdvanceAndGetTime(), "device", - "Device2"); + kRemoteGuid); remote_input.push_back( syncer::EntityChange::CreateAdd("guid1", MakeEntityData(entry1))); remote_input.push_back( @@ -677,7 +640,7 @@ TEST_F(SendTabToSelfBridgeTest, // Tests that only the most recent device's guid is returned when multiple // devices have the same name. TEST_F(SendTabToSelfBridgeTest, - GetTargetDeviceNameToCacheInfoMap_OneDevicePerName) { + GetTargetDeviceInfoSortedList_OneDevicePerName) { const std::string kRecentGuid = "guid1"; const std::string kOldGuid = "guid2"; const std::string kOlderGuid = "guid3"; @@ -706,19 +669,18 @@ TEST_F(SendTabToSelfBridgeTest, /*send_tab_to_self_receiving_enabled=*/true); AddTestDevice(&older_device); - TargetDeviceInfo target_device_info(recent_device.guid(), - recent_device.device_type(), - recent_device.last_updated_timestamp()); + TargetDeviceInfo target_device_info( + recent_device.client_name(), recent_device.guid(), + recent_device.device_type(), recent_device.last_updated_timestamp()); - EXPECT_THAT( - bridge()->GetTargetDeviceNameToCacheInfoMap(), - ElementsAre(Pair(recent_device.client_name(), target_device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(target_device_info)); } // Tests that only devices that have the send tab to self receiving feature // enabled are returned. TEST_F(SendTabToSelfBridgeTest, - GetTargetDeviceNameToCacheInfoMap_OnlyReceivingEnabled) { + GetTargetDeviceInfoSortedList_OnlyReceivingEnabled) { InitializeBridge(); syncer::DeviceInfo enabled_device( @@ -735,18 +697,17 @@ TEST_F(SendTabToSelfBridgeTest, /*send_tab_to_self_receiving_enabled=*/false); AddTestDevice(&disabled_device); - TargetDeviceInfo target_device_info(enabled_device.guid(), - enabled_device.device_type(), - enabled_device.last_updated_timestamp()); + TargetDeviceInfo target_device_info( + enabled_device.client_name(), enabled_device.guid(), + enabled_device.device_type(), enabled_device.last_updated_timestamp()); - EXPECT_THAT( - bridge()->GetTargetDeviceNameToCacheInfoMap(), - ElementsAre(Pair(enabled_device.client_name(), target_device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(target_device_info)); } // Tests that only devices that are not expired are returned. TEST_F(SendTabToSelfBridgeTest, - GetTargetDeviceNameToCacheInfoMap_NoExpiredDevices) { + GetTargetDeviceInfoSortedList_NoExpiredDevices) { InitializeBridge(); syncer::DeviceInfo expired_device( @@ -763,18 +724,16 @@ TEST_F(SendTabToSelfBridgeTest, /*send_tab_to_self_receiving_enabled=*/true); AddTestDevice(&valid_device); - TargetDeviceInfo target_device_info(valid_device.guid(), - valid_device.device_type(), - valid_device.last_updated_timestamp()); + TargetDeviceInfo target_device_info( + valid_device.client_name(), valid_device.guid(), + valid_device.device_type(), valid_device.last_updated_timestamp()); - EXPECT_THAT( - bridge()->GetTargetDeviceNameToCacheInfoMap(), - ElementsAre(Pair(valid_device.client_name(), target_device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(target_device_info)); } // Tests that the local device is not returned. -TEST_F(SendTabToSelfBridgeTest, - GetTargetDeviceNameToCacheInfoMap_NoLocalDevice) { +TEST_F(SendTabToSelfBridgeTest, GetTargetDeviceInfoSortedList_NoLocalDevice) { InitializeBridge(); bridge()->SetLocalDeviceNameForTest(kLocalDeviceName); @@ -799,18 +758,17 @@ TEST_F(SendTabToSelfBridgeTest, /*send_tab_to_self_receiving_enabled=*/true); AddTestDevice(&other_device); - TargetDeviceInfo target_device_info(other_device.guid(), - other_device.device_type(), - other_device.last_updated_timestamp()); + TargetDeviceInfo target_device_info( + other_device.client_name(), other_device.guid(), + other_device.device_type(), other_device.last_updated_timestamp()); - EXPECT_THAT( - bridge()->GetTargetDeviceNameToCacheInfoMap(), - ElementsAre(Pair(other_device.client_name(), target_device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(target_device_info)); } // Tests that the local device is not returned. TEST_F(SendTabToSelfBridgeTest, - GetTargetDeviceNameToCacheInfoMap_Updated_DeviceExpired) { + GetTargetDeviceInfoSortedList_Updated_DeviceExpired) { InitializeBridge(); // Set a device that is about to expire and a more recent device. @@ -828,31 +786,28 @@ TEST_F(SendTabToSelfBridgeTest, /*send_tab_to_self_receiving_enabled=*/true); AddTestDevice(&recent_device); - TargetDeviceInfo older_device_info(older_device.guid(), - older_device.device_type(), - older_device.last_updated_timestamp()); - TargetDeviceInfo recent_device_info(recent_device.guid(), - recent_device.device_type(), - recent_device.last_updated_timestamp()); + TargetDeviceInfo older_device_info( + older_device.client_name(), older_device.guid(), + older_device.device_type(), older_device.last_updated_timestamp()); + TargetDeviceInfo recent_device_info( + recent_device.client_name(), recent_device.guid(), + recent_device.device_type(), recent_device.last_updated_timestamp()); // Set the map by calling it. Make sure it has the 2 devices. - EXPECT_THAT(bridge()->GetTargetDeviceNameToCacheInfoMap(), - UnorderedElementsAre( - Pair(older_device.client_name(), older_device_info), - Pair(recent_device.client_name(), recent_device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(recent_device_info, older_device_info)); // Advance the time so that the older device expires. clock()->Advance(base::TimeDelta::FromDays(5)); // Make sure only the recent device is in the map. - EXPECT_THAT( - bridge()->GetTargetDeviceNameToCacheInfoMap(), - ElementsAre(Pair(recent_device.client_name(), recent_device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(recent_device_info)); } // Tests that the local device is not returned. TEST_F(SendTabToSelfBridgeTest, - GetTargetDeviceNameToCacheInfoMap_Updated_NewEntries) { + GetTargetDeviceInfoSortedList_Updated_NewEntries) { InitializeBridge(); // Set a valid device. @@ -863,11 +818,12 @@ TEST_F(SendTabToSelfBridgeTest, AddTestDevice(&device); // Set the map by calling it. Make sure it has the device. - TargetDeviceInfo device_info(device.guid(), device.device_type(), + TargetDeviceInfo device_info(device.client_name(), device.guid(), + device.device_type(), device.last_updated_timestamp()); - EXPECT_THAT(bridge()->GetTargetDeviceNameToCacheInfoMap(), - ElementsAre(Pair(device.client_name(), device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(device_info)); // Add a new device. syncer::DeviceInfo new_device("new_guid", "new_name", "72", "agent", @@ -878,13 +834,12 @@ TEST_F(SendTabToSelfBridgeTest, AddTestDevice(&new_device); // Make sure both devices are in the map. - TargetDeviceInfo new_device_info(new_device.guid(), new_device.device_type(), + TargetDeviceInfo new_device_info(new_device.client_name(), new_device.guid(), + new_device.device_type(), new_device.last_updated_timestamp()); - EXPECT_THAT( - bridge()->GetTargetDeviceNameToCacheInfoMap(), - UnorderedElementsAre(Pair(device.client_name(), device_info), - Pair(new_device.client_name(), new_device_info))); + EXPECT_THAT(bridge()->GetTargetDeviceInfoSortedList(), + ElementsAre(device_info, new_device_info)); } TEST_F(SendTabToSelfBridgeTest, NotifyRemoteSendTabToSelfEntryOpened) { diff --git a/chromium/components/send_tab_to_self/send_tab_to_self_metrics.h b/chromium/components/send_tab_to_self/send_tab_to_self_metrics.h index 55a5cfd3d40..a8d0e86ef04 100644 --- a/chromium/components/send_tab_to_self/send_tab_to_self_metrics.h +++ b/chromium/components/send_tab_to_self/send_tab_to_self_metrics.h @@ -18,10 +18,10 @@ enum class SendTabToSelfNotification { kDismissed = 1, // A notification was shown from a remotely added entry. kShown = 2, - // A notification was dismissed remotely. - kDismissedRemotely = 3, + // 3 is once |kDismissedRemotely| and has been obsoleted. + // Numeric values should skip 3. // Update kMaxValue when new enums are added. - kMaxValue = kDismissedRemotely, + kMaxValue = kShown, }; void RecordNotificationHistogram(SendTabToSelfNotification status); diff --git a/chromium/components/send_tab_to_self/send_tab_to_self_model.h b/chromium/components/send_tab_to_self/send_tab_to_self_model.h index bae3766dcae..e484b13c518 100644 --- a/chromium/components/send_tab_to_self/send_tab_to_self_model.h +++ b/chromium/components/send_tab_to_self/send_tab_to_self_model.h @@ -75,11 +75,10 @@ class SendTabToSelfModel { // Returns true if the user has valid target device. virtual bool HasValidTargetDevice() = 0; - // Returns a map of the name of possible target devices for the send tab to - // self feature to their cache guid. This is a thin layer on top of - // DeviceInfoTracker. - virtual std::map<std::string, TargetDeviceInfo> - GetTargetDeviceNameToCacheInfoMap() = 0; + // Returns a vector of information about possible target devices, ordered by + // the last updated time stamp of the device with the most recently used + // device listed first. This is a thin layer on top of DeviceInfoTracker. + virtual std::vector<TargetDeviceInfo> GetTargetDeviceInfoSortedList() = 0; protected: // The observers. diff --git a/chromium/components/send_tab_to_self/target_device_info.cc b/chromium/components/send_tab_to_self/target_device_info.cc index 77b8f5fe2d6..5baffdce428 100644 --- a/chromium/components/send_tab_to_self/target_device_info.cc +++ b/chromium/components/send_tab_to_self/target_device_info.cc @@ -7,15 +7,18 @@ namespace send_tab_to_self { TargetDeviceInfo::TargetDeviceInfo( + const std::string& device_name, const std::string& cache_guid, const sync_pb::SyncEnums::DeviceType device_type, base::Time last_updated_timestamp) - : cache_guid(cache_guid), + : device_name(device_name), + cache_guid(cache_guid), device_type(device_type), last_updated_timestamp(last_updated_timestamp) {} bool TargetDeviceInfo::operator==(const TargetDeviceInfo& rhs) const { - return this->cache_guid == rhs.cache_guid && + return this->device_name == rhs.device_name && + this->cache_guid == rhs.cache_guid && this->device_type == rhs.device_type && this->last_updated_timestamp == rhs.last_updated_timestamp; } diff --git a/chromium/components/send_tab_to_self/target_device_info.h b/chromium/components/send_tab_to_self/target_device_info.h index 29504305e4c..872d2f8fdaa 100644 --- a/chromium/components/send_tab_to_self/target_device_info.h +++ b/chromium/components/send_tab_to_self/target_device_info.h @@ -14,7 +14,8 @@ namespace send_tab_to_self { // Device information for generating send tab to self UI. struct TargetDeviceInfo { public: - TargetDeviceInfo(const std::string& cache_guid, + TargetDeviceInfo(const std::string& device_name, + const std::string& cache_guid, const sync_pb::SyncEnums::DeviceType device_type, base::Time last_updated_timestamp); TargetDeviceInfo(const TargetDeviceInfo& other) = default; @@ -22,6 +23,8 @@ struct TargetDeviceInfo { bool operator==(const TargetDeviceInfo& rhs) const; + // Device name. + std::string device_name; // Device guid. std::string cache_guid; // Device type. diff --git a/chromium/components/send_tab_to_self/test_send_tab_to_self_model.cc b/chromium/components/send_tab_to_self/test_send_tab_to_self_model.cc index 6883553fffc..182c21638d7 100644 --- a/chromium/components/send_tab_to_self/test_send_tab_to_self_model.cc +++ b/chromium/components/send_tab_to_self/test_send_tab_to_self_model.cc @@ -39,8 +39,8 @@ bool TestSendTabToSelfModel::HasValidTargetDevice() { return false; } -std::map<std::string, TargetDeviceInfo> -TestSendTabToSelfModel::GetTargetDeviceNameToCacheInfoMap() { +std::vector<TargetDeviceInfo> +TestSendTabToSelfModel::GetTargetDeviceInfoSortedList() { return {}; } diff --git a/chromium/components/send_tab_to_self/test_send_tab_to_self_model.h b/chromium/components/send_tab_to_self/test_send_tab_to_self_model.h index bdc0e4f2246..0e8c69a52ad 100644 --- a/chromium/components/send_tab_to_self/test_send_tab_to_self_model.h +++ b/chromium/components/send_tab_to_self/test_send_tab_to_self_model.h @@ -5,7 +5,6 @@ #ifndef COMPONENTS_SEND_TAB_TO_SELF_TEST_SEND_TAB_TO_SELF_MODEL_H_ #define COMPONENTS_SEND_TAB_TO_SELF_TEST_SEND_TAB_TO_SELF_MODEL_H_ -#include <map> #include <string> #include <vector> @@ -37,8 +36,7 @@ class TestSendTabToSelfModel : public SendTabToSelfModel { bool IsReady() override; bool HasValidTargetDevice() override; - std::map<std::string, TargetDeviceInfo> GetTargetDeviceNameToCacheInfoMap() - override; + std::vector<TargetDeviceInfo> GetTargetDeviceInfoSortedList() override; }; } // namespace send_tab_to_self |