Commit 73bc2de6 authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Reland "[SendTabToSelf] Use new cache guid method to assert that local device...

Reland "[SendTabToSelf] Use new cache guid method to assert that local device is not listed as a target"

This is a reland of 38392a67

In this reland, the old logic remains unchanged as a fallback mechanism
in case the GUID-based detection fails (as the reports suggest).

Original change's description:
> [SendTabToSelf] Use new cache guid method to assert that local device is not listed as a target
>
> Bug: 966413
> Change-Id: I29fe887806b07a51d7490603aaf81415a5a349cb
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1721379
> Commit-Queue: Jeffrey Cohen <jeffreycohen@chromium.org>
> Reviewed-by: Mikel Astiz <mastiz@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#682341}

Bug: 966413
Change-Id: I85ae3c33c83f29f9a59cb8f3c2219e22e31a2bad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1828817
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarRamya Nagarajan <ramyan@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701073}
parent 1479245b
...@@ -712,6 +712,12 @@ bool SendTabToSelfBridge::ShouldUpdateTargetDeviceInfoList() const { ...@@ -712,6 +712,12 @@ bool SendTabToSelfBridge::ShouldUpdateTargetDeviceInfoList() const {
} }
void SendTabToSelfBridge::SetTargetDeviceInfoList() { void SendTabToSelfBridge::SetTargetDeviceInfoList() {
// Verify that the current TrackedCacheGuid() is the local GUID without
// enforcing that tracked cache GUID is set.
DCHECK(device_info_tracker_->IsRecentLocalCacheGuid(
change_processor()->TrackedCacheGuid()) ||
change_processor()->TrackedCacheGuid().empty());
std::vector<std::unique_ptr<syncer::DeviceInfo>> all_devices = std::vector<std::unique_ptr<syncer::DeviceInfo>> all_devices =
device_info_tracker_->GetAllDeviceInfo(); device_info_tracker_->GetAllDeviceInfo();
number_of_devices_ = all_devices.size(); number_of_devices_ = all_devices.size();
...@@ -734,10 +740,17 @@ void SendTabToSelfBridge::SetTargetDeviceInfoList() { ...@@ -734,10 +740,17 @@ void SendTabToSelfBridge::SetTargetDeviceInfoList() {
break; break;
} }
// TODO(crbug.com/966413): Implement a better way to dedupe local devices in // Don't include this device if it is the local device.
// case the user has other devices with the same name. if (device_info_tracker_->IsRecentLocalCacheGuid(device->guid())) {
continue;
}
// Don't include this device. Also compare the name as the device can have // 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). // different cache guids (e.g. after stopping and re-starting sync).
// TODO(crbug.com/991943): This shouldn't be required now that
// IsRecentLocalCacheGuid() is used above. However, issues have been
// observed on Android, as if IsRecentLocalCacheGuid() didn't get populated
// reliably.
if (device->guid() == change_processor()->TrackedCacheGuid() || if (device->guid() == change_processor()->TrackedCacheGuid() ||
device->client_name() == local_device_name_) { device->client_name() == local_device_name_) {
continue; continue;
......
...@@ -99,7 +99,7 @@ class SendTabToSelfBridgeTest : public testing::Test { ...@@ -99,7 +99,7 @@ class SendTabToSelfBridgeTest : public testing::Test {
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "scoped_is", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "scoped_is",
clock()->Now() - base::TimeDelta::FromDays(1), clock()->Now() - base::TimeDelta::FromDays(1),
/*send_tab_to_self_receiving_enabled=*/true); /*send_tab_to_self_receiving_enabled=*/true);
AddTestDevice(local_device_.get()); AddTestDevice(local_device_.get(), /*local=*/true);
} }
// Initialized the bridge based on the current local device and store. Can // Initialized the bridge based on the current local device and store. Can
...@@ -179,8 +179,11 @@ class SendTabToSelfBridgeTest : public testing::Test { ...@@ -179,8 +179,11 @@ class SendTabToSelfBridgeTest : public testing::Test {
.WillByDefault(Return(cache_guid)); .WillByDefault(Return(cache_guid));
} }
void AddTestDevice(const syncer::DeviceInfo* device) { void AddTestDevice(const syncer::DeviceInfo* device, bool local = false) {
device_info_tracker_.Add(device); device_info_tracker_.Add(device);
if (local) {
device_info_tracker_.SetLocalCacheGuid(device->guid());
}
} }
syncer::MockModelTypeChangeProcessor* processor() { return &mock_processor_; } syncer::MockModelTypeChangeProcessor* processor() { return &mock_processor_; }
......
...@@ -34,7 +34,11 @@ bool FakeDeviceInfoTracker::IsSyncing() const { ...@@ -34,7 +34,11 @@ bool FakeDeviceInfoTracker::IsSyncing() const {
std::unique_ptr<DeviceInfo> FakeDeviceInfoTracker::GetDeviceInfo( std::unique_ptr<DeviceInfo> FakeDeviceInfoTracker::GetDeviceInfo(
const std::string& client_id) const { const std::string& client_id) const {
NOTREACHED(); for (const DeviceInfo* device : devices_) {
if (device->guid() == client_id) {
return CloneDeviceInfo(*device);
}
}
return nullptr; return nullptr;
} }
...@@ -66,12 +70,7 @@ void FakeDeviceInfoTracker::ForcePulseForTest() { ...@@ -66,12 +70,7 @@ void FakeDeviceInfoTracker::ForcePulseForTest() {
bool FakeDeviceInfoTracker::IsRecentLocalCacheGuid( bool FakeDeviceInfoTracker::IsRecentLocalCacheGuid(
const std::string& cache_guid) const { const std::string& cache_guid) const {
for (const DeviceInfo* device : devices_) { return local_device_cache_guid_ == cache_guid;
if (device->guid() == cache_guid) {
return true;
}
}
return false;
} }
void FakeDeviceInfoTracker::Add(const DeviceInfo* device) { void FakeDeviceInfoTracker::Add(const DeviceInfo* device) {
...@@ -86,4 +85,10 @@ void FakeDeviceInfoTracker::OverrideActiveDeviceCount(int count) { ...@@ -86,4 +85,10 @@ void FakeDeviceInfoTracker::OverrideActiveDeviceCount(int count) {
observer.OnDeviceInfoChange(); observer.OnDeviceInfoChange();
} }
void FakeDeviceInfoTracker::SetLocalCacheGuid(const std::string& cache_guid) {
// ensure that this cache guid is present in the tracker.
DCHECK(GetDeviceInfo(cache_guid));
local_device_cache_guid_ = cache_guid;
}
} // namespace syncer } // namespace syncer
...@@ -42,9 +42,13 @@ class FakeDeviceInfoTracker : public DeviceInfoTracker { ...@@ -42,9 +42,13 @@ class FakeDeviceInfoTracker : public DeviceInfoTracker {
// actual number of devices in |devices_|. // actual number of devices in |devices_|.
void OverrideActiveDeviceCount(int count); void OverrideActiveDeviceCount(int count);
// Marks an existing DeviceInfo entry as being on the local device.
void SetLocalCacheGuid(const std::string& cache_guid);
private: private:
// DeviceInfo stored here are not owned. // DeviceInfo stored here are not owned.
std::vector<const DeviceInfo*> devices_; std::vector<const DeviceInfo*> devices_;
std::string local_device_cache_guid_;
base::Optional<int> active_device_count_; base::Optional<int> active_device_count_;
// Registered observers, not owned. // Registered observers, not owned.
base::ObserverList<Observer, true>::Unchecked observers_; base::ObserverList<Observer, true>::Unchecked observers_;
......
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