Commit f484e3ef authored by Sébastien Séguin-Gagnon's avatar Sébastien Séguin-Gagnon Committed by Commit Bot

[SendTabToSelf] Filter out devices with local device name from targets.

Filter out devices with the same name as the local device from the list
of target devices.

This is because there can be different device_info objects for the
local device that have different cache guids.

Bug: 957716
Change-Id: Idf279a9cb2298657c6d6cfa03f0dde62b0587473
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1625904
Commit-Queue: sebsg <sebsg@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarJeffrey Cohen <jeffreycohen@chromium.org>
Auto-Submit: sebsg <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663951}
parent 07659220
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/sync/test/integration/sync_test.h" #include "chrome/browser/sync/test/integration/sync_test.h"
#include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_service.h"
#include "components/send_tab_to_self/features.h" #include "components/send_tab_to_self/features.h"
#include "components/send_tab_to_self/send_tab_to_self_bridge.h"
#include "components/send_tab_to_self/send_tab_to_self_model.h" #include "components/send_tab_to_self/send_tab_to_self_model.h"
#include "components/send_tab_to_self/send_tab_to_self_sync_service.h" #include "components/send_tab_to_self/send_tab_to_self_sync_service.h"
#include "components/send_tab_to_self/target_device_info.h" #include "components/send_tab_to_self/target_device_info.h"
...@@ -206,6 +207,18 @@ IN_PROC_BROWSER_TEST_F(TwoClientSendTabToSelfSyncTest, ...@@ -206,6 +207,18 @@ IN_PROC_BROWSER_TEST_F(TwoClientSendTabToSelfSyncTest,
->GetDeviceInfoTracker()) ->GetDeviceInfoTracker())
.Wait()); .Wait());
// Explicitly set the two profiles to have different client names to simulate
// them being on different devices. Otherwise their device infos will get
// deduped.
static_cast<send_tab_to_self::SendTabToSelfBridge*>(
SendTabToSelfSyncServiceFactory::GetForProfile(GetProfile(0))
->GetSendTabToSelfModel())
->SetLocalDeviceNameForTest("device1");
static_cast<send_tab_to_self::SendTabToSelfBridge*>(
SendTabToSelfSyncServiceFactory::GetForProfile(GetProfile(1))
->GetSendTabToSelfModel())
->SetLocalDeviceNameForTest("device2");
std::map<std::string, send_tab_to_self::TargetDeviceInfo> std::map<std::string, send_tab_to_self::TargetDeviceInfo>
profile1_target_device_map = profile1_target_device_map =
SendTabToSelfSyncServiceFactory::GetForProfile(GetProfile(0)) SendTabToSelfSyncServiceFactory::GetForProfile(GetProfile(0))
......
...@@ -460,6 +460,11 @@ bool SendTabToSelfBridge::ShouldUpdateTargetDeviceNameToCacheInfoMapForTest() { ...@@ -460,6 +460,11 @@ bool SendTabToSelfBridge::ShouldUpdateTargetDeviceNameToCacheInfoMapForTest() {
return ShouldUpdateTargetDeviceNameToCacheInfoMap(); return ShouldUpdateTargetDeviceNameToCacheInfoMap();
} }
void SendTabToSelfBridge::SetLocalDeviceNameForTest(
const std::string& local_device_name) {
local_device_name_ = local_device_name;
}
void SendTabToSelfBridge::NotifyRemoteSendTabToSelfEntryAdded( void SendTabToSelfBridge::NotifyRemoteSendTabToSelfEntryAdded(
const std::vector<const SendTabToSelfEntry*>& new_entries) { const std::vector<const SendTabToSelfEntry*>& new_entries) {
std::vector<const SendTabToSelfEntry*> new_local_entries; std::vector<const SendTabToSelfEntry*> new_local_entries;
...@@ -633,9 +638,12 @@ void SendTabToSelfBridge::SetTargetDeviceNameToCacheInfoMap() { ...@@ -633,9 +638,12 @@ void SendTabToSelfBridge::SetTargetDeviceNameToCacheInfoMap() {
break; break;
} }
// TODO(crbug.com/957716): Dedupe older versions of this device as well. // TODO(crbug.com/966413): Implement a better way to dedupe local devices in
// Don't include this device. // case the user has other devices with the same name.
if (device->guid() == change_processor()->TrackedCacheGuid()) { // Don't include this device. Also compare the name as the device can have
// different cache guids (e.g. after stopping and re-starting sync).
if (device->guid() == change_processor()->TrackedCacheGuid() ||
device->client_name() == local_device_name_) {
continue; continue;
} }
......
...@@ -93,6 +93,7 @@ class SendTabToSelfBridge : public syncer::ModelTypeSyncBridge, ...@@ -93,6 +93,7 @@ class SendTabToSelfBridge : public syncer::ModelTypeSyncBridge,
static std::unique_ptr<syncer::ModelTypeStore> DestroyAndStealStoreForTest( static std::unique_ptr<syncer::ModelTypeStore> DestroyAndStealStoreForTest(
std::unique_ptr<SendTabToSelfBridge> bridge); std::unique_ptr<SendTabToSelfBridge> bridge);
bool ShouldUpdateTargetDeviceNameToCacheInfoMapForTest(); bool ShouldUpdateTargetDeviceNameToCacheInfoMapForTest();
void SetLocalDeviceNameForTest(const std::string& local_device_name);
private: private:
using SendTabToSelfEntries = using SendTabToSelfEntries =
......
...@@ -48,6 +48,7 @@ const char kURLFormat[] = "https://www.url%d.com/"; ...@@ -48,6 +48,7 @@ const char kURLFormat[] = "https://www.url%d.com/";
const char kTitleFormat[] = "title %d"; const char kTitleFormat[] = "title %d";
const char kDeviceFormat[] = "device %d"; const char kDeviceFormat[] = "device %d";
const char kLocalDeviceCacheGuid[] = "local_device_guid"; const char kLocalDeviceCacheGuid[] = "local_device_guid";
const char kLocalDeviceName[] = "local_device_name";
sync_pb::SendTabToSelfSpecifics CreateSpecifics( sync_pb::SendTabToSelfSpecifics CreateSpecifics(
int suffix, int suffix,
...@@ -775,9 +776,17 @@ TEST_F(SendTabToSelfBridgeTest, ...@@ -775,9 +776,17 @@ TEST_F(SendTabToSelfBridgeTest,
TEST_F(SendTabToSelfBridgeTest, TEST_F(SendTabToSelfBridgeTest,
GetTargetDeviceNameToCacheInfoMap_NoLocalDevice) { GetTargetDeviceNameToCacheInfoMap_NoLocalDevice) {
InitializeBridge(); InitializeBridge();
bridge()->SetLocalDeviceNameForTest(kLocalDeviceName);
syncer::DeviceInfo local_device( syncer::DeviceInfo local_device(
kLocalDeviceCacheGuid, "local_device_name", "72", "agent", kLocalDeviceCacheGuid, kLocalDeviceName, "72", "agent",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "scoped_is",
/*last_updated_timestamp=*/clock()->Now(),
/*send_tab_to_self_receiving_enabled=*/true);
AddTestDevice(&local_device);
syncer::DeviceInfo other_local_device(
"other_local_guid", kLocalDeviceName, "72", "agent",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "scoped_is", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "scoped_is",
/*last_updated_timestamp=*/clock()->Now(), /*last_updated_timestamp=*/clock()->Now(),
/*send_tab_to_self_receiving_enabled=*/true); /*send_tab_to_self_receiving_enabled=*/true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment