device_info_sync_service_impl.cc 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/sync_device_info/device_info_sync_service_impl.h"
  5. #include <utility>
  6. #include "base/callback.h"
  7. #include "components/sync/base/report_unrecoverable_error.h"
  8. #include "components/sync/invalidations/sync_invalidations_service.h"
  9. #include "components/sync/model/client_tag_based_model_type_processor.h"
  10. #include "components/sync_device_info/device_info.h"
  11. #include "components/sync_device_info/device_info_prefs.h"
  12. #include "components/sync_device_info/device_info_sync_bridge.h"
  13. #include "components/sync_device_info/device_info_sync_client.h"
  14. #include "components/sync_device_info/device_info_tracker.h"
  15. #include "components/sync_device_info/local_device_info_provider.h"
  16. namespace syncer {
  17. DeviceInfoSyncServiceImpl::DeviceInfoSyncServiceImpl(
  18. OnceModelTypeStoreFactory model_type_store_factory,
  19. std::unique_ptr<MutableLocalDeviceInfoProvider> local_device_info_provider,
  20. std::unique_ptr<DeviceInfoPrefs> device_info_prefs,
  21. std::unique_ptr<DeviceInfoSyncClient> device_info_sync_client,
  22. SyncInvalidationsService* sync_invalidations_service)
  23. : device_info_sync_client_(std::move(device_info_sync_client)),
  24. sync_invalidations_service_(sync_invalidations_service) {
  25. DCHECK(local_device_info_provider);
  26. DCHECK(device_info_prefs);
  27. DCHECK(device_info_sync_client_);
  28. // Make a copy of the channel to avoid relying on argument evaluation order.
  29. const version_info::Channel channel =
  30. local_device_info_provider->GetChannel();
  31. bridge_ = std::make_unique<DeviceInfoSyncBridge>(
  32. std::move(local_device_info_provider),
  33. std::move(model_type_store_factory),
  34. std::make_unique<ClientTagBasedModelTypeProcessor>(
  35. DEVICE_INFO,
  36. /*dump_stack=*/base::BindRepeating(&ReportUnrecoverableError,
  37. channel)),
  38. std::move(device_info_prefs));
  39. if (sync_invalidations_service_) {
  40. sync_invalidations_service_->AddTokenObserver(this);
  41. sync_invalidations_service_->SetInterestedDataTypesHandler(this);
  42. }
  43. }
  44. DeviceInfoSyncServiceImpl::~DeviceInfoSyncServiceImpl() = default;
  45. LocalDeviceInfoProvider*
  46. DeviceInfoSyncServiceImpl::GetLocalDeviceInfoProvider() {
  47. return bridge_->GetLocalDeviceInfoProvider();
  48. }
  49. void DeviceInfoSyncServiceImpl::
  50. SetCommittedAdditionalInterestedDataTypesCallback(
  51. base::RepeatingCallback<void(const ModelTypeSet&)> callback) {
  52. bridge_->SetCommittedAdditionalInterestedDataTypesCallback(
  53. std::move(callback));
  54. }
  55. DeviceInfoTracker* DeviceInfoSyncServiceImpl::GetDeviceInfoTracker() {
  56. return bridge_.get();
  57. }
  58. base::WeakPtr<ModelTypeControllerDelegate>
  59. DeviceInfoSyncServiceImpl::GetControllerDelegate() {
  60. return bridge_->change_processor()->GetControllerDelegate();
  61. }
  62. void DeviceInfoSyncServiceImpl::RefreshLocalDeviceInfo() {
  63. bridge_->RefreshLocalDeviceInfoIfNeeded();
  64. }
  65. void DeviceInfoSyncServiceImpl::OnFCMRegistrationTokenChanged() {
  66. RefreshLocalDeviceInfo();
  67. }
  68. void DeviceInfoSyncServiceImpl::OnInterestedDataTypesChanged() {
  69. RefreshLocalDeviceInfo();
  70. }
  71. void DeviceInfoSyncServiceImpl::Shutdown() {
  72. if (sync_invalidations_service_) {
  73. sync_invalidations_service_->RemoveTokenObserver(this);
  74. sync_invalidations_service_->SetInterestedDataTypesHandler(nullptr);
  75. }
  76. }
  77. } // namespace syncer