Commit 8c2bc960 authored by Paula Vidas's avatar Paula Vidas Committed by Commit Bot

[SyncInvalidations] Send device info when invalidations info changes.

This CL makes DeviceInfoSyncService an observer for FCM token and
interested data types, so that it can send updated device info when they
change.

Bug: 1102336
Change-Id: I3fe00cbef6eb57fd7ccff35c047fa74053e4fcd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2397578
Commit-Queue: Paula Vidas <paulavidas@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804906}
parent f9fdbac7
......@@ -24,7 +24,6 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/send_tab_to_self/features.h"
#include "components/sync/base/sync_prefs.h"
#include "components/sync/invalidations/switches.h"
#include "components/sync/invalidations/sync_invalidations_service.h"
#include "components/sync/model/model_type_store_service.h"
#include "components/sync_device_info/device_info_prefs.h"
......@@ -152,5 +151,6 @@ KeyedService* DeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
return new syncer::DeviceInfoSyncServiceImpl(
ModelTypeStoreServiceFactory::GetForProfile(profile)->GetStoreFactory(),
std::move(local_device_info_provider), std::move(device_prefs),
std::move(device_info_sync_client));
std::move(device_info_sync_client),
SyncInvalidationsServiceFactory::GetForProfile(profile));
}
......@@ -8,6 +8,7 @@
#include "base/bind_helpers.h"
#include "components/sync/base/report_unrecoverable_error.h"
#include "components/sync/invalidations/sync_invalidations_service.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_prefs.h"
......@@ -22,8 +23,10 @@ DeviceInfoSyncServiceImpl::DeviceInfoSyncServiceImpl(
OnceModelTypeStoreFactory model_type_store_factory,
std::unique_ptr<MutableLocalDeviceInfoProvider> local_device_info_provider,
std::unique_ptr<DeviceInfoPrefs> device_info_prefs,
std::unique_ptr<DeviceInfoSyncClient> device_info_sync_client)
: device_info_sync_client_(std::move(device_info_sync_client)) {
std::unique_ptr<DeviceInfoSyncClient> device_info_sync_client,
SyncInvalidationsService* sync_invalidations_service)
: device_info_sync_client_(std::move(device_info_sync_client)),
sync_invalidations_service_(sync_invalidations_service) {
DCHECK(local_device_info_provider);
DCHECK(device_info_prefs);
DCHECK(device_info_sync_client_);
......@@ -40,6 +43,11 @@ DeviceInfoSyncServiceImpl::DeviceInfoSyncServiceImpl(
/*dump_stack=*/base::BindRepeating(&ReportUnrecoverableError,
channel)),
std::move(device_info_prefs));
if (sync_invalidations_service_) {
sync_invalidations_service_->AddTokenObserver(this);
sync_invalidations_service_->AddInterestedDataTypesObserver(this);
}
}
DeviceInfoSyncServiceImpl::~DeviceInfoSyncServiceImpl() {}
......@@ -62,4 +70,19 @@ void DeviceInfoSyncServiceImpl::RefreshLocalDeviceInfo() {
bridge_->RefreshLocalDeviceInfo();
}
void DeviceInfoSyncServiceImpl::OnFCMRegistrationTokenChanged() {
RefreshLocalDeviceInfo();
}
void DeviceInfoSyncServiceImpl::OnInterestedDataTypesChanged() {
RefreshLocalDeviceInfo();
}
void DeviceInfoSyncServiceImpl::Shutdown() {
if (sync_invalidations_service_) {
sync_invalidations_service_->RemoveTokenObserver(this);
sync_invalidations_service_->RemoveInterestedDataTypesObserver(this);
}
}
} // namespace syncer
......@@ -8,6 +8,8 @@
#include <memory>
#include <string>
#include "components/sync/invalidations/fcm_registration_token_observer.h"
#include "components/sync/invalidations/interested_data_types_observer.h"
#include "components/sync/model/model_type_store.h"
#include "components/sync_device_info/device_info_sync_service.h"
......@@ -17,18 +19,24 @@ class DeviceInfoPrefs;
class DeviceInfoSyncClient;
class DeviceInfoSyncBridge;
class MutableLocalDeviceInfoProvider;
class SyncInvalidationsService;
class DeviceInfoSyncServiceImpl : public DeviceInfoSyncService {
class DeviceInfoSyncServiceImpl : public DeviceInfoSyncService,
public FCMRegistrationTokenObserver,
public InterestedDataTypesObserver {
public:
// |local_device_info_provider| must not be null.
// |device_info_prefs| must not be null.
// |device_info_sync_client| must not be null and must outlive this object.
// |sync_invalidations_service| can be null if sync invalidations are
// disabled.
DeviceInfoSyncServiceImpl(
OnceModelTypeStoreFactory model_type_store_factory,
std::unique_ptr<MutableLocalDeviceInfoProvider>
local_device_info_provider,
std::unique_ptr<DeviceInfoPrefs> device_info_prefs,
std::unique_ptr<DeviceInfoSyncClient> device_info_sync_client);
std::unique_ptr<DeviceInfoSyncClient> device_info_sync_client,
SyncInvalidationsService* sync_invalidations_service);
~DeviceInfoSyncServiceImpl() override;
// DeviceInfoSyncService implementation.
......@@ -37,10 +45,21 @@ class DeviceInfoSyncServiceImpl : public DeviceInfoSyncService {
base::WeakPtr<ModelTypeControllerDelegate> GetControllerDelegate() override;
void RefreshLocalDeviceInfo() override;
// FCMRegistrationTokenObserver implementation.
void OnFCMRegistrationTokenChanged() override;
// InterestedDataTypesObserver implementation.
void OnInterestedDataTypesChanged() override;
// KeyedService overrides.
void Shutdown() override;
private:
std::unique_ptr<DeviceInfoSyncClient> device_info_sync_client_;
std::unique_ptr<DeviceInfoSyncBridge> bridge_;
SyncInvalidationsService* sync_invalidations_service_;
DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncServiceImpl);
};
......
......@@ -125,5 +125,6 @@ DeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
ModelTypeStoreServiceFactory::GetForBrowserState(browser_state)
->GetStoreFactory(),
std::move(local_device_info_provider), std::move(device_prefs),
std::move(device_info_sync_client));
std::move(device_info_sync_client),
/*sync_invalidations_service=*/nullptr);
}
......@@ -103,7 +103,8 @@ WebViewDeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
WebViewModelTypeStoreServiceFactory::GetForBrowserState(browser_state)
->GetStoreFactory(),
std::move(local_device_info_provider), std::move(device_prefs),
std::move(device_info_sync_client));
std::move(device_info_sync_client),
/*sync_invalidations_service=*/nullptr);
}
} // 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