Commit 053be24d authored by Jeffrey Cohen's avatar Jeffrey Cohen Committed by Commit Bot

[SendTabToSelf] add pref storage of previous device cache_guids

Send Tab To Self shares a url with a specific syncing machine, in order
to determine if the shared tab is meant for the local device, there needs
to be some persistence in storing previously used cache guids locally.

So that a local machine will not "miss" a tab sent to its previous guid.

Bug: 981850
Change-Id: Ibe99baae9d336a4e737935f4e7ce874496e604a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1694147
Commit-Queue: Jeffrey Cohen <jeffreycohen@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680215}
parent ba8870a3
...@@ -131,6 +131,7 @@ ...@@ -131,6 +131,7 @@
#include "components/startup_metric_utils/browser/startup_metric_utils.h" #include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "components/subresource_filter/content/browser/ruleset_service.h" #include "components/subresource_filter/content/browser/ruleset_service.h"
#include "components/sync/base/sync_prefs.h" #include "components/sync/base/sync_prefs.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_sessions/session_sync_prefs.h" #include "components/sync_sessions/session_sync_prefs.h"
#include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/browser/translate_prefs.h"
...@@ -743,6 +744,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, ...@@ -743,6 +744,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
SessionStartupPref::RegisterProfilePrefs(registry); SessionStartupPref::RegisterProfilePrefs(registry);
SharingSyncPreference::RegisterProfilePrefs(registry); SharingSyncPreference::RegisterProfilePrefs(registry);
sync_sessions::SessionSyncPrefs::RegisterProfilePrefs(registry); sync_sessions::SessionSyncPrefs::RegisterProfilePrefs(registry);
syncer::DeviceInfoPrefs::RegisterProfilePrefs(registry);
syncer::SyncPrefs::RegisterProfilePrefs(registry); syncer::SyncPrefs::RegisterProfilePrefs(registry);
syncer::PerUserTopicRegistrationManager::RegisterProfilePrefs(registry); syncer::PerUserTopicRegistrationManager::RegisterProfilePrefs(registry);
syncer::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry); syncer::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/send_tab_to_self/features.h" #include "components/send_tab_to_self/features.h"
#include "components/sync/base/sync_prefs.h" #include "components/sync/base/sync_prefs.h"
#include "components/sync/model/model_type_store_service.h" #include "components/sync/model/model_type_store_service.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/device_info_sync_service_impl.h" #include "components/sync_device_info/device_info_sync_service_impl.h"
#include "components/sync_device_info/local_device_info_provider_impl.h" #include "components/sync_device_info/local_device_info_provider_impl.h"
...@@ -101,7 +102,11 @@ KeyedService* DeviceInfoSyncServiceFactory::BuildServiceInstanceFor( ...@@ -101,7 +102,11 @@ KeyedService* DeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
chrome::GetChannel(), chrome::GetVersionString(), chrome::GetChannel(), chrome::GetVersionString(),
signin_scoped_device_id_callback, signin_scoped_device_id_callback,
send_tab_to_self_receiving_enabled_callback); send_tab_to_self_receiving_enabled_callback);
auto device_prefs =
std::make_unique<syncer::DeviceInfoPrefs>(profile->GetPrefs());
return new syncer::DeviceInfoSyncServiceImpl( return new syncer::DeviceInfoSyncServiceImpl(
ModelTypeStoreServiceFactory::GetForProfile(profile)->GetStoreFactory(), ModelTypeStoreServiceFactory::GetForProfile(profile)->GetStoreFactory(),
std::move(local_device_info_provider)); std::move(local_device_info_provider), std::move(device_prefs));
} }
...@@ -553,16 +553,17 @@ void SendTabToSelfBridge::NotifyRemoteSendTabToSelfEntryAdded( ...@@ -553,16 +553,17 @@ void SendTabToSelfBridge::NotifyRemoteSendTabToSelfEntryAdded(
if (base::FeatureList::IsEnabled(kSendTabToSelfBroadcast)) { if (base::FeatureList::IsEnabled(kSendTabToSelfBroadcast)) {
new_local_entries = new_entries; new_local_entries = new_entries;
} else { } else {
// Only pass along entries that are targeted at this device, and not // Only pass along entries that are not dismissed or opened, and are
// dismissed or opened. // 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()); DCHECK(!change_processor()->TrackedCacheGuid().empty());
for (const SendTabToSelfEntry* entry : new_entries) { for (const SendTabToSelfEntry* entry : new_entries) {
if (entry->GetTargetDeviceSyncCacheGuid() == if (device_info_tracker_->IsRecentLocalCacheGuid(
change_processor()->TrackedCacheGuid() && entry->GetTargetDeviceSyncCacheGuid()) &&
!entry->GetNotificationDismissed() && !entry->IsOpened()) { !entry->GetNotificationDismissed() && !entry->IsOpened()) {
new_local_entries.push_back(entry); new_local_entries.push_back(entry);
LogLocalDeviceNotified(UMANotifyLocalDevice::LOCAL); LogLocalDeviceNotified(UMANotifyLocalDevice::LOCAL);
} else { } else {
LogLocalDeviceNotified(UMANotifyLocalDevice::REMOTE); LogLocalDeviceNotified(UMANotifyLocalDevice::REMOTE);
} }
......
...@@ -94,6 +94,12 @@ class SendTabToSelfBridgeTest : public testing::Test { ...@@ -94,6 +94,12 @@ class SendTabToSelfBridgeTest : public testing::Test {
: store_(syncer::ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()) { : store_(syncer::ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()) {
scoped_feature_list_.InitAndEnableFeature(kSendTabToSelfShowSendingUI); scoped_feature_list_.InitAndEnableFeature(kSendTabToSelfShowSendingUI);
SetLocalDeviceCacheGuid(kLocalDeviceCacheGuid); 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 // Initialized the bridge based on the current local device and store. Can
...@@ -203,6 +209,8 @@ class SendTabToSelfBridgeTest : public testing::Test { ...@@ -203,6 +209,8 @@ class SendTabToSelfBridgeTest : public testing::Test {
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<syncer::DeviceInfo> local_device_;
DISALLOW_COPY_AND_ASSIGN(SendTabToSelfBridgeTest); DISALLOW_COPY_AND_ASSIGN(SendTabToSelfBridgeTest);
}; };
...@@ -253,6 +261,7 @@ TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesAddTwoSpecifics) { ...@@ -253,6 +261,7 @@ TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesAddTwoSpecifics) {
TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneAdd) { TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneAdd) {
InitializeBridge(); InitializeBridge();
SendTabToSelfEntry entry("guid1", GURL("http://www.example.com/"), "title", SendTabToSelfEntry entry("guid1", GURL("http://www.example.com/"), "title",
AdvanceAndGetTime(), AdvanceAndGetTime(), "device", AdvanceAndGetTime(), AdvanceAndGetTime(), "device",
kLocalDeviceCacheGuid); kLocalDeviceCacheGuid);
...@@ -273,6 +282,7 @@ TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneAdd) { ...@@ -273,6 +282,7 @@ TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneAdd) {
// Tests that the send tab to self entry is correctly removed. // Tests that the send tab to self entry is correctly removed.
TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneDeletion) { TEST_F(SendTabToSelfBridgeTest, ApplySyncChangesOneDeletion) {
InitializeBridge(); InitializeBridge();
SendTabToSelfEntry entry("guid1", GURL("http://www.example.com/"), "title", SendTabToSelfEntry entry("guid1", GURL("http://www.example.com/"), "title",
AdvanceAndGetTime(), AdvanceAndGetTime(), "device", AdvanceAndGetTime(), AdvanceAndGetTime(), "device",
kLocalDeviceCacheGuid); kLocalDeviceCacheGuid);
...@@ -565,17 +575,17 @@ TEST_F(SendTabToSelfBridgeTest, ...@@ -565,17 +575,17 @@ TEST_F(SendTabToSelfBridgeTest,
/*enabled_features=*/{kSendTabToSelfShowSendingUI}, /*enabled_features=*/{kSendTabToSelfShowSendingUI},
/*disabled_features=*/{kSendTabToSelfBroadcast}); /*disabled_features=*/{kSendTabToSelfBroadcast});
const std::string kRemoteGuid = "RemoteDevice";
InitializeBridge(); InitializeBridge();
SetLocalDeviceCacheGuid("Device1");
// Add on entry targeting this device and another targeting another device. // Add on entry targeting this device and another targeting another device.
syncer::EntityChangeList remote_input; syncer::EntityChangeList remote_input;
SendTabToSelfEntry entry1("guid1", GURL("http://www.example.com/"), "title", SendTabToSelfEntry entry1("guid1", GURL("http://www.example.com/"), "title",
AdvanceAndGetTime(), AdvanceAndGetTime(), "device", AdvanceAndGetTime(), AdvanceAndGetTime(), "device",
"Device1"); kLocalDeviceCacheGuid);
SendTabToSelfEntry entry2("guid2", GURL("http://www.example.com/"), "title", SendTabToSelfEntry entry2("guid2", GURL("http://www.example.com/"), "title",
AdvanceAndGetTime(), AdvanceAndGetTime(), "device", AdvanceAndGetTime(), AdvanceAndGetTime(), "device",
"Device2"); kRemoteGuid);
remote_input.push_back( remote_input.push_back(
syncer::EntityChange::CreateAdd("guid1", MakeEntityData(entry1))); syncer::EntityChange::CreateAdd("guid1", MakeEntityData(entry1)));
remote_input.push_back( remote_input.push_back(
......
...@@ -12,6 +12,8 @@ jumbo_static_library("sync_device_info") { ...@@ -12,6 +12,8 @@ jumbo_static_library("sync_device_info") {
"device_count_metrics_provider.h", "device_count_metrics_provider.h",
"device_info.cc", "device_info.cc",
"device_info.h", "device_info.h",
"device_info_prefs.cc",
"device_info_prefs.h",
"device_info_sync_bridge.cc", "device_info_sync_bridge.cc",
"device_info_sync_bridge.h", "device_info_sync_bridge.h",
"device_info_sync_service.cc", "device_info_sync_service.cc",
...@@ -43,6 +45,7 @@ jumbo_static_library("sync_device_info") { ...@@ -43,6 +45,7 @@ jumbo_static_library("sync_device_info") {
deps = [ deps = [
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/metrics", "//components/metrics",
"//components/prefs",
"//components/version_info", "//components/version_info",
"//ui/base", "//ui/base",
] ]
...@@ -91,6 +94,7 @@ source_set("unit_tests") { ...@@ -91,6 +94,7 @@ source_set("unit_tests") {
":test_support", ":test_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/prefs:test_support",
"//components/sync:test_support", "//components/sync:test_support",
"//components/version_info:version_string", "//components/version_info:version_string",
"//testing/gmock", "//testing/gmock",
......
...@@ -2,6 +2,7 @@ include_rules = [ ...@@ -2,6 +2,7 @@ include_rules = [
"+chromeos", "+chromeos",
"+components/keyed_service", "+components/keyed_service",
"+components/metrics", "+components/metrics",
"+components/prefs",
"+components/sync/base", "+components/sync/base",
"+components/sync/driver", "+components/sync/driver",
"+components/sync/model", "+components/sync/model",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sync_device_info/device_info_prefs.h"
#include <algorithm>
#include <vector>
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
namespace syncer {
namespace {
// The GUID device info will use to to remember the most recently used past
// cache GUIDs in order starting with the current cache GUID.
const char kDeviceInfoRecentGUIDs[] = "sync.local_device_guids";
// The max number of local device most recent cached GUIDSs that will be stored.
const int kMaxLocalCacheGuidsStored = 30;
} // namespace
// static
void DeviceInfoPrefs::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterListPref(kDeviceInfoRecentGUIDs);
}
DeviceInfoPrefs::DeviceInfoPrefs(PrefService* pref_service)
: pref_service_(pref_service) {
DCHECK(pref_service);
}
DeviceInfoPrefs::~DeviceInfoPrefs() {}
bool DeviceInfoPrefs::IsRecentLocalCacheGuid(
const std::string& cache_guid) const {
const base::Value::ListStorage& recent_local_cache_guids =
pref_service_->GetList(kDeviceInfoRecentGUIDs)->GetList();
return std::find(recent_local_cache_guids.begin(),
recent_local_cache_guids.end(),
base::Value(cache_guid)) != recent_local_cache_guids.end();
}
void DeviceInfoPrefs::AddLocalCacheGuid(const std::string& cache_guid) {
ListPrefUpdate update(pref_service_, kDeviceInfoRecentGUIDs);
base::ListValue* pref_data = update.Get();
base::Value::ListStorage* recent_local_cache_guids = &pref_data->GetList();
if (std::find(recent_local_cache_guids->begin(),
recent_local_cache_guids->end(),
base::Value(cache_guid)) != recent_local_cache_guids->end()) {
// Local cache GUID already known.
return;
}
recent_local_cache_guids->emplace(recent_local_cache_guids->begin(),
base::Value(cache_guid));
if (recent_local_cache_guids->size() > kMaxLocalCacheGuidsStored) {
recent_local_cache_guids->pop_back();
}
}
} // namespace syncer
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_PREFS_H_
#define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_PREFS_H_
#include <string>
#include <vector>
#include "base/macros.h"
class PrefService;
class PrefRegistrySimple;
namespace syncer {
// Use this for determining if a cache guid was recently used by this device.
class DeviceInfoPrefs {
public:
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
explicit DeviceInfoPrefs(PrefService* pref_service);
~DeviceInfoPrefs();
bool IsRecentLocalCacheGuid(const std::string& cache_guid) const;
void AddLocalCacheGuid(const std::string& cache_guid);
private:
PrefService* const pref_service_;
DISALLOW_COPY_AND_ASSIGN(DeviceInfoPrefs);
};
} // namespace syncer
#endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_PREFS_H_
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/sync/model/mutable_data_batch.h" #include "components/sync/model/mutable_data_batch.h"
#include "components/sync/protocol/model_type_state.pb.h" #include "components/sync/protocol/model_type_state.pb.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/device_info_util.h" #include "components/sync_device_info/device_info_util.h"
#include "components/sync_device_info/local_device_info_util.h" #include "components/sync_device_info/local_device_info_util.h"
...@@ -127,10 +128,13 @@ base::Optional<ModelError> ParseSpecificsOnBackendSequence( ...@@ -127,10 +128,13 @@ base::Optional<ModelError> ParseSpecificsOnBackendSequence(
DeviceInfoSyncBridge::DeviceInfoSyncBridge( DeviceInfoSyncBridge::DeviceInfoSyncBridge(
std::unique_ptr<MutableLocalDeviceInfoProvider> local_device_info_provider, std::unique_ptr<MutableLocalDeviceInfoProvider> local_device_info_provider,
OnceModelTypeStoreFactory store_factory, OnceModelTypeStoreFactory store_factory,
std::unique_ptr<ModelTypeChangeProcessor> change_processor) std::unique_ptr<ModelTypeChangeProcessor> change_processor,
std::unique_ptr<DeviceInfoPrefs> device_info_prefs)
: ModelTypeSyncBridge(std::move(change_processor)), : ModelTypeSyncBridge(std::move(change_processor)),
local_device_info_provider_(std::move(local_device_info_provider)) { local_device_info_provider_(std::move(local_device_info_provider)),
device_info_prefs_(std::move(device_info_prefs)) {
DCHECK(local_device_info_provider_); DCHECK(local_device_info_provider_);
DCHECK(device_info_prefs_);
// Provider must not be initialized, the bridge takes care. // Provider must not be initialized, the bridge takes care.
DCHECK(!local_device_info_provider_->GetLocalDeviceInfo()); DCHECK(!local_device_info_provider_->GetLocalDeviceInfo());
...@@ -150,6 +154,8 @@ void DeviceInfoSyncBridge::OnSyncStarting( ...@@ -150,6 +154,8 @@ void DeviceInfoSyncBridge::OnSyncStarting(
const DataTypeActivationRequest& request) { const DataTypeActivationRequest& request) {
// Store the cache GUID, mainly in case MergeSyncData() is executed later. // Store the cache GUID, mainly in case MergeSyncData() is executed later.
local_cache_guid_ = request.cache_guid; local_cache_guid_ = request.cache_guid;
// Add the cache guid to the local prefs.
device_info_prefs_->AddLocalCacheGuid(local_cache_guid_);
} }
std::unique_ptr<MetadataChangeList> std::unique_ptr<MetadataChangeList>
...@@ -174,8 +180,8 @@ base::Optional<ModelError> DeviceInfoSyncBridge::MergeSyncData( ...@@ -174,8 +180,8 @@ base::Optional<ModelError> DeviceInfoSyncBridge::MergeSyncData(
DCHECK_EQ(change->storage_key(), specifics.cache_guid()); DCHECK_EQ(change->storage_key(), specifics.cache_guid());
// Each device is the authoritative source for itself, ignore any remote // Each device is the authoritative source for itself, ignore any remote
// changes that have our local cache guid. // changes that have a cache guid that is or was this local device.
if (change->storage_key() == local_cache_guid_) { if (device_info_prefs_->IsRecentLocalCacheGuid(change->storage_key())) {
continue; continue;
} }
...@@ -197,8 +203,8 @@ base::Optional<ModelError> DeviceInfoSyncBridge::ApplySyncChanges( ...@@ -197,8 +203,8 @@ base::Optional<ModelError> DeviceInfoSyncBridge::ApplySyncChanges(
for (const std::unique_ptr<EntityChange>& change : entity_changes) { for (const std::unique_ptr<EntityChange>& change : entity_changes) {
const std::string guid = change->storage_key(); const std::string guid = change->storage_key();
// Each device is the authoritative source for itself, ignore any remote // Each device is the authoritative source for itself, ignore any remote
// changes that have our local cache guid. // changes that have a cache guid that is or was this local device.
if (guid == local_cache_guid_) { if (device_info_prefs_->IsRecentLocalCacheGuid(guid)) {
continue; continue;
} }
...@@ -305,6 +311,11 @@ int DeviceInfoSyncBridge::CountActiveDevices() const { ...@@ -305,6 +311,11 @@ int DeviceInfoSyncBridge::CountActiveDevices() const {
return CountActiveDevices(Time::Now()); return CountActiveDevices(Time::Now());
} }
bool DeviceInfoSyncBridge::IsRecentLocalCacheGuid(
const std::string& cache_guid) const {
return device_info_prefs_->IsRecentLocalCacheGuid(cache_guid);
}
bool DeviceInfoSyncBridge::IsPulseTimerRunningForTest() const { bool DeviceInfoSyncBridge::IsPulseTimerRunningForTest() const {
return pulse_timer_.IsRunning(); return pulse_timer_.IsRunning();
} }
...@@ -429,6 +440,10 @@ void DeviceInfoSyncBridge::OnReadAllMetadata( ...@@ -429,6 +440,10 @@ void DeviceInfoSyncBridge::OnReadAllMetadata(
local_cache_guid_ = local_cache_guid_in_metadata; local_cache_guid_ = local_cache_guid_in_metadata;
local_device_info_provider_->Initialize(local_cache_guid_, local_device_info_provider_->Initialize(local_cache_guid_,
local_session_name_); local_session_name_);
// This probably isn't strictly needed, but in case the cache_guid has changed
// we save the new one to prefs.
device_info_prefs_->AddLocalCacheGuid(local_cache_guid_);
ReconcileLocalAndStored(); ReconcileLocalAndStored();
} }
......
...@@ -28,6 +28,8 @@ class DeviceInfoSpecifics; ...@@ -28,6 +28,8 @@ class DeviceInfoSpecifics;
namespace syncer { namespace syncer {
class DeviceInfoPrefs;
// Sync bridge implementation for DEVICE_INFO model type. Handles storage of // Sync bridge implementation for DEVICE_INFO model type. Handles storage of
// device info and associated sync metadata, applying/merging foreign changes, // device info and associated sync metadata, applying/merging foreign changes,
// and allows public read access. // and allows public read access.
...@@ -38,7 +40,8 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge, ...@@ -38,7 +40,8 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
std::unique_ptr<MutableLocalDeviceInfoProvider> std::unique_ptr<MutableLocalDeviceInfoProvider>
local_device_info_provider, local_device_info_provider,
OnceModelTypeStoreFactory store_factory, OnceModelTypeStoreFactory store_factory,
std::unique_ptr<ModelTypeChangeProcessor> change_processor); std::unique_ptr<ModelTypeChangeProcessor> change_processor,
std::unique_ptr<DeviceInfoPrefs> device_info_prefs);
~DeviceInfoSyncBridge() override; ~DeviceInfoSyncBridge() override;
LocalDeviceInfoProvider* GetLocalDeviceInfoProvider(); LocalDeviceInfoProvider* GetLocalDeviceInfoProvider();
...@@ -67,6 +70,7 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge, ...@@ -67,6 +70,7 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
void AddObserver(Observer* observer) override; void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override; void RemoveObserver(Observer* observer) override;
int CountActiveDevices() const override; int CountActiveDevices() const override;
bool IsRecentLocalCacheGuid(const std::string& cache_guid) const override;
// For testing only. // For testing only.
bool IsPulseTimerRunningForTest() const; bool IsPulseTimerRunningForTest() const;
...@@ -139,6 +143,8 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge, ...@@ -139,6 +143,8 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
// Used to update our local device info once every pulse interval. // Used to update our local device info once every pulse interval.
base::OneShotTimer pulse_timer_; base::OneShotTimer pulse_timer_;
const std::unique_ptr<DeviceInfoPrefs> device_info_prefs_;
base::WeakPtrFactory<DeviceInfoSyncBridge> weak_ptr_factory_{this}; base::WeakPtrFactory<DeviceInfoSyncBridge> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncBridge); DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncBridge);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync/base/time.h" #include "components/sync/base/time.h"
#include "components/sync/model/data_batch.h" #include "components/sync/model/data_batch.h"
#include "components/sync/model/data_type_activation_request.h" #include "components/sync/model/data_type_activation_request.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "components/sync/model/model_type_store_test_util.h" #include "components/sync/model/model_type_store_test_util.h"
#include "components/sync/protocol/model_type_state.pb.h" #include "components/sync/protocol/model_type_state.pb.h"
#include "components/sync/test/test_matchers.h" #include "components/sync/test/test_matchers.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace syncer { namespace syncer {
...@@ -220,6 +222,7 @@ class DeviceInfoSyncBridgeTest : public testing::Test, ...@@ -220,6 +222,7 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
protected: protected:
DeviceInfoSyncBridgeTest() DeviceInfoSyncBridgeTest()
: store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()) { : store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()) {
DeviceInfoPrefs::RegisterProfilePrefs(pref_service_.registry());
ON_CALL(*processor(), IsTrackingMetadata()).WillByDefault(Return(true)); ON_CALL(*processor(), IsTrackingMetadata()).WillByDefault(Return(true));
} }
...@@ -239,7 +242,8 @@ class DeviceInfoSyncBridgeTest : public testing::Test, ...@@ -239,7 +242,8 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
bridge_ = std::make_unique<DeviceInfoSyncBridge>( bridge_ = std::make_unique<DeviceInfoSyncBridge>(
std::make_unique<TestLocalDeviceInfoProvider>(), std::make_unique<TestLocalDeviceInfoProvider>(),
ModelTypeStoreTestUtil::FactoryForForwardingStore(store_.get()), ModelTypeStoreTestUtil::FactoryForForwardingStore(store_.get()),
mock_processor_.CreateForwardingProcessor()); mock_processor_.CreateForwardingProcessor(),
std::make_unique<DeviceInfoPrefs>(&pref_service_));
bridge_->AddObserver(this); bridge_->AddObserver(this);
} }
...@@ -402,6 +406,7 @@ class DeviceInfoSyncBridgeTest : public testing::Test, ...@@ -402,6 +406,7 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
// Holds the store. // Holds the store.
const std::unique_ptr<ModelTypeStore> store_; const std::unique_ptr<ModelTypeStore> store_;
TestingPrefServiceSimple pref_service_;
// Not initialized immediately (upon test's constructor). This allows each // Not initialized immediately (upon test's constructor). This allows each
// test case to modify the dependencies the bridge will be constructed with. // test case to modify the dependencies the bridge will be constructed with.
std::unique_ptr<DeviceInfoSyncBridge> bridge_; std::unique_ptr<DeviceInfoSyncBridge> bridge_;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "components/sync/base/report_unrecoverable_error.h" #include "components/sync/base/report_unrecoverable_error.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h" #include "components/sync/model_impl/client_tag_based_model_type_processor.h"
#include "components/sync_device_info/device_info.h" #include "components/sync_device_info/device_info.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/device_info_sync_bridge.h" #include "components/sync_device_info/device_info_sync_bridge.h"
#include "components/sync_device_info/device_info_tracker.h" #include "components/sync_device_info/device_info_tracker.h"
#include "components/sync_device_info/local_device_info_provider.h" #include "components/sync_device_info/local_device_info_provider.h"
...@@ -18,9 +19,10 @@ namespace syncer { ...@@ -18,9 +19,10 @@ namespace syncer {
DeviceInfoSyncServiceImpl::DeviceInfoSyncServiceImpl( DeviceInfoSyncServiceImpl::DeviceInfoSyncServiceImpl(
OnceModelTypeStoreFactory model_type_store_factory, OnceModelTypeStoreFactory model_type_store_factory,
std::unique_ptr<MutableLocalDeviceInfoProvider> std::unique_ptr<MutableLocalDeviceInfoProvider> local_device_info_provider,
local_device_info_provider) { std::unique_ptr<DeviceInfoPrefs> device_info_prefs) {
DCHECK(local_device_info_provider); DCHECK(local_device_info_provider);
DCHECK(device_info_prefs);
// Make a copy of the channel to avoid relying on argument evaluation order. // Make a copy of the channel to avoid relying on argument evaluation order.
const version_info::Channel channel = const version_info::Channel channel =
...@@ -32,7 +34,8 @@ DeviceInfoSyncServiceImpl::DeviceInfoSyncServiceImpl( ...@@ -32,7 +34,8 @@ DeviceInfoSyncServiceImpl::DeviceInfoSyncServiceImpl(
std::make_unique<ClientTagBasedModelTypeProcessor>( std::make_unique<ClientTagBasedModelTypeProcessor>(
DEVICE_INFO, DEVICE_INFO,
/*dump_stack=*/base::BindRepeating(&ReportUnrecoverableError, /*dump_stack=*/base::BindRepeating(&ReportUnrecoverableError,
channel))); channel)),
std::move(device_info_prefs));
} }
DeviceInfoSyncServiceImpl::~DeviceInfoSyncServiceImpl() {} DeviceInfoSyncServiceImpl::~DeviceInfoSyncServiceImpl() {}
......
...@@ -13,15 +13,18 @@ ...@@ -13,15 +13,18 @@
namespace syncer { namespace syncer {
class DeviceInfoPrefs;
class DeviceInfoSyncBridge; class DeviceInfoSyncBridge;
class MutableLocalDeviceInfoProvider; class MutableLocalDeviceInfoProvider;
class DeviceInfoSyncServiceImpl : public DeviceInfoSyncService { class DeviceInfoSyncServiceImpl : public DeviceInfoSyncService {
public: public:
// |local_device_info_provider| must not be null. // |local_device_info_provider| must not be null.
// |device_info_prefs| must not be null.
DeviceInfoSyncServiceImpl(OnceModelTypeStoreFactory model_type_store_factory, DeviceInfoSyncServiceImpl(OnceModelTypeStoreFactory model_type_store_factory,
std::unique_ptr<MutableLocalDeviceInfoProvider> std::unique_ptr<MutableLocalDeviceInfoProvider>
local_device_info_provider); local_device_info_provider,
std::unique_ptr<DeviceInfoPrefs> device_info_prefs);
~DeviceInfoSyncServiceImpl() override; ~DeviceInfoSyncServiceImpl() override;
// DeviceInfoSyncService implementation. // DeviceInfoSyncService implementation.
......
...@@ -44,6 +44,9 @@ class DeviceInfoTracker { ...@@ -44,6 +44,9 @@ class DeviceInfoTracker {
// A temporary function to to allow tests to ensure active devices. // A temporary function to to allow tests to ensure active devices.
// TODO(crbug/948784) remove this function after architecture work. // TODO(crbug/948784) remove this function after architecture work.
virtual void ForcePulseForTest() = 0; virtual void ForcePulseForTest() = 0;
// Returns if the provided |cache_guid| is the current device cache_guid for
// the current device or was of the recently used.
virtual bool IsRecentLocalCacheGuid(const std::string& cache_guid) const = 0;
}; };
} // namespace syncer } // namespace syncer
......
...@@ -64,6 +64,16 @@ void FakeDeviceInfoTracker::ForcePulseForTest() { ...@@ -64,6 +64,16 @@ void FakeDeviceInfoTracker::ForcePulseForTest() {
NOTREACHED(); NOTREACHED();
} }
bool FakeDeviceInfoTracker::IsRecentLocalCacheGuid(
const std::string& cache_guid) const {
for (const DeviceInfo* device : devices_) {
if (device->guid() == cache_guid) {
return true;
}
}
return false;
}
void FakeDeviceInfoTracker::Add(const DeviceInfo* device) { void FakeDeviceInfoTracker::Add(const DeviceInfo* device) {
devices_.push_back(device); devices_.push_back(device);
} }
......
...@@ -32,6 +32,7 @@ class FakeDeviceInfoTracker : public DeviceInfoTracker { ...@@ -32,6 +32,7 @@ class FakeDeviceInfoTracker : public DeviceInfoTracker {
void RemoveObserver(Observer* observer) override; void RemoveObserver(Observer* observer) override;
int CountActiveDevices() const override; int CountActiveDevices() const override;
void ForcePulseForTest() override; void ForcePulseForTest() override;
bool IsRecentLocalCacheGuid(const std::string& cache_guid) const override;
// Adds a new DeviceInfo entry to |devices_|. // Adds a new DeviceInfo entry to |devices_|.
void Add(const DeviceInfo* device); void Add(const DeviceInfo* device);
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "components/strings/grit/components_locale_settings.h" #include "components/strings/grit/components_locale_settings.h"
#include "components/sync/base/sync_prefs.h" #include "components/sync/base/sync_prefs.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_sessions/session_sync_prefs.h" #include "components/sync_sessions/session_sync_prefs.h"
#include "components/translate/core/browser/translate_pref_names.h" #include "components/translate/core/browser/translate_pref_names.h"
#include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/browser/translate_prefs.h"
...@@ -131,6 +132,7 @@ void RegisterBrowserStatePrefs(user_prefs::PrefRegistrySyncable* registry) { ...@@ -131,6 +132,7 @@ void RegisterBrowserStatePrefs(user_prefs::PrefRegistrySyncable* registry) {
PrefProxyConfigTrackerImpl::RegisterProfilePrefs(registry); PrefProxyConfigTrackerImpl::RegisterProfilePrefs(registry);
RegisterVoiceSearchBrowserStatePrefs(registry); RegisterVoiceSearchBrowserStatePrefs(registry);
sync_sessions::SessionSyncPrefs::RegisterProfilePrefs(registry); sync_sessions::SessionSyncPrefs::RegisterProfilePrefs(registry);
syncer::DeviceInfoPrefs::RegisterProfilePrefs(registry);
syncer::SyncPrefs::RegisterProfilePrefs(registry); syncer::SyncPrefs::RegisterProfilePrefs(registry);
syncer::PerUserTopicRegistrationManager::RegisterProfilePrefs(registry); syncer::PerUserTopicRegistrationManager::RegisterProfilePrefs(registry);
syncer::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry); syncer::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "components/send_tab_to_self/features.h" #include "components/send_tab_to_self/features.h"
#include "components/signin/public/base/device_id_helper.h" #include "components/signin/public/base/device_id_helper.h"
#include "components/sync/model/model_type_store_service.h" #include "components/sync/model/model_type_store_service.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/device_info_sync_service_impl.h" #include "components/sync_device_info/device_info_sync_service_impl.h"
#include "components/sync_device_info/local_device_info_provider_impl.h" #include "components/sync_device_info/local_device_info_provider_impl.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
...@@ -83,9 +84,11 @@ DeviceInfoSyncServiceFactory::BuildServiceInstanceFor( ...@@ -83,9 +84,11 @@ DeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
base::BindRepeating( base::BindRepeating(
&send_tab_to_self::IsReceivingEnabledByUserOnThisDevice, &send_tab_to_self::IsReceivingEnabledByUserOnThisDevice,
browser_state->GetPrefs())); browser_state->GetPrefs()));
auto device_prefs =
std::make_unique<syncer::DeviceInfoPrefs>(browser_state->GetPrefs());
return std::make_unique<syncer::DeviceInfoSyncServiceImpl>( return std::make_unique<syncer::DeviceInfoSyncServiceImpl>(
ModelTypeStoreServiceFactory::GetForBrowserState(browser_state) ModelTypeStoreServiceFactory::GetForBrowserState(browser_state)
->GetStoreFactory(), ->GetStoreFactory(),
std::move(local_device_info_provider)); std::move(local_device_info_provider), std::move(device_prefs));
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/keyed_service/ios/browser_state_dependency_manager.h" #include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/signin/public/base/device_id_helper.h" #include "components/signin/public/base/device_id_helper.h"
#include "components/sync/model/model_type_store_service.h" #include "components/sync/model/model_type_store_service.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/device_info_sync_service_impl.h" #include "components/sync_device_info/device_info_sync_service_impl.h"
#include "components/sync_device_info/local_device_info_provider_impl.h" #include "components/sync_device_info/local_device_info_provider_impl.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
...@@ -60,10 +61,13 @@ WebViewDeviceInfoSyncServiceFactory::BuildServiceInstanceFor( ...@@ -60,10 +61,13 @@ WebViewDeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
/*send_tab_to_self_receiving_enabled_callback=*/ /*send_tab_to_self_receiving_enabled_callback=*/
base::BindRepeating([]() { return false; })); base::BindRepeating([]() { return false; }));
auto device_prefs =
std::make_unique<syncer::DeviceInfoPrefs>(browser_state->GetPrefs());
return std::make_unique<syncer::DeviceInfoSyncServiceImpl>( return std::make_unique<syncer::DeviceInfoSyncServiceImpl>(
WebViewModelTypeStoreServiceFactory::GetForBrowserState(browser_state) WebViewModelTypeStoreServiceFactory::GetForBrowserState(browser_state)
->GetStoreFactory(), ->GetStoreFactory(),
std::move(local_device_info_provider)); std::move(local_device_info_provider), std::move(device_prefs));
} }
} // namespace ios_web_view } // namespace ios_web_view
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