Chromium Code Reviews| Index: components/sync_driver/device_info_service.h |
| diff --git a/components/sync_driver/device_info_service.h b/components/sync_driver/device_info_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..773c484694178033e94b0fbd9d270519af90fe1b |
| --- /dev/null |
| +++ b/components/sync_driver/device_info_service.h |
| @@ -0,0 +1,130 @@ |
| +// Copyright 2015 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_DRIVER_DEVICE_INFO_SERVICE_H_ |
| +#define COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/containers/scoped_ptr_map.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/scoped_vector.h" |
| +#include "base/observer_list.h" |
| +#include "components/sync_driver/device_info_tracker.h" |
| +#include "components/sync_driver/local_device_info_provider.h" |
| +#include "sync/api/model_type_change_processor.h" |
| +#include "sync/api/model_type_service.h" |
| + |
| +namespace syncer { |
| +class SyncError; |
| +} // namespace syncer |
| + |
| +namespace syncer_v2 { |
| +class ModelTypeChangeProcessor; |
| +} // namespace syncer_v2 |
| + |
| +namespace sync_driver { |
|
stanisc
2015/10/22 20:16:53
Should this be in sync_driver_v2 namespace to avoi
skym
2015/10/23 20:29:49
Done.
|
| + |
| +class LocalDeviceInfoProvider; |
| + |
| +// USS service implementation for DEVICE_INFO model type. Handles storage of |
| +// device info and associated sync metadata, applying/merging foreign changes, |
| +// and allows public read access. |
| +class DeviceInfoService : public syncer_v2::ModelTypeService, |
| + public DeviceInfoTracker { |
| + public: |
| + explicit DeviceInfoService( |
| + LocalDeviceInfoProvider* local_device_info_provider); |
| + ~DeviceInfoService() override; |
| + |
| + // TODO(skym): Update once these are added to ModelTypeService interface. |
| + // ModelTypeService implementation. |
| + syncer::SyncError ApplySyncChanges(); |
| + syncer::SyncError LoadMetadata(); |
| + syncer::SyncError UpdateMetadata(); |
| + syncer::SyncError GetData(); |
| + syncer::SyncError GetAllData(); |
| + syncer::SyncError ClearMetadata(); |
| + // TODO(skym): Are all these processor assessors really needed? |
|
stanisc
2015/10/22 20:16:53
This should be one of the next things to design an
skym
2015/10/23 20:29:49
Done.
|
| + syncer_v2::ModelTypeChangeProcessor* get_change_processor(); |
|
stanisc
2015/10/22 20:16:53
Perhaps this should be returning weak pointer to t
skym
2015/10/23 20:29:49
My understanding was this get...() was only going
|
| + void set_change_processor( |
| + scoped_ptr<syncer_v2::ModelTypeChangeProcessor> change_processor); |
| + void clear_change_processor(); |
| + |
| + // DeviceInfoTracker implementation. |
| + bool IsSyncing() const override; |
| + scoped_ptr<DeviceInfo> GetDeviceInfo( |
| + const std::string& client_id) const override; |
| + ScopedVector<DeviceInfo> GetAllDeviceInfo() const override; |
| + void AddObserver(Observer* observer) override; |
| + void RemoveObserver(Observer* observer) override; |
| + |
| + // Called to update local device backup time. |
| + void UpdateLocalDeviceBackupTime(base::Time backup_time); |
| + // Gets the most recently set local device backup time. |
| + base::Time GetLocalDeviceBackupTime() const; |
| + |
| + private: |
| + friend class DeviceInfoServiceTest; |
| + |
| + scoped_ptr<sync_pb::DeviceInfoSpecifics> CreateLocalSpecifics(); |
| + static scoped_ptr<sync_pb::DeviceInfoSpecifics> CreateSpecifics( |
| + const DeviceInfo& info); |
| + |
| + // Allocate new DeviceInfo from SyncData. |
| + static scoped_ptr<DeviceInfo> CreateDeviceInfo( |
| + const sync_pb::DeviceInfoSpecifics& specifics); |
| + |
| + // Store SyncData in the cache. |
| + void StoreSpecifics(scoped_ptr<sync_pb::DeviceInfoSpecifics> specifics); |
| + // Delete SyncData from the cache. |
| + void DeleteSpecifics(const std::string& client_id); |
| + // Notify all registered observers. |
| + void NotifyObservers(); |
| + |
| + void OnProviderInitialized(); |
| + |
| + // |local_device_backup_time_| accessors. |
| + int64 local_device_backup_time() const { return local_device_backup_time_; } |
| + bool has_local_device_backup_time() const { |
| + return local_device_backup_time_ >= 0; |
| + } |
| + void set_local_device_backup_time(int64 value) { |
| + local_device_backup_time_ = value; |
| + } |
| + void clear_local_device_backup_time() { local_device_backup_time_ = -1; } |
| + |
| + // TODO(skym): Remove once we remove local provider. |
| + // Local device last set backup time (in proto format). |
| + // -1 if the value hasn't been specified |
| + int64 local_device_backup_time_; |
| + |
| + // TODO(skym): Replace with initialization branch, callback, and local id. |
| + // |local_device_info_provider_| isn't owned. |
| + const LocalDeviceInfoProvider* const local_device_info_provider_; |
|
stanisc
2015/10/22 20:16:53
Why do you want to remove the local provider?
skym
2015/10/23 20:29:49
I'll remove this comment, it's a little old, I thi
|
| + |
| + // Recieves ownership in set_change_processor(...). |
| + scoped_ptr<syncer_v2::ModelTypeChangeProcessor> change_processor_; |
| + |
| + // TODO(skym): Replace scoped_ptr<sync_pb::DeviceInfoSpecifics> with specifics |
| + // wrapping immutable referencing object. |
| + // Cache of all syncable and local data, stored by device cache guid. |
| + typedef base::ScopedPtrMap<std::string, |
| + scoped_ptr<sync_pb::DeviceInfoSpecifics>> |
|
stanisc
2015/10/22 20:16:53
It would make sense to store ProtoValuePtr<sync_pb
skym
2015/10/23 20:29:49
Team post-scrummed this issue, we decided that the
|
| + ClientIdToSpecifics; |
| + ClientIdToSpecifics all_data_; |
| + |
| + // Registered observers, not owned. |
| + base::ObserverList<Observer, true> observers_; |
| + |
| + scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DeviceInfoService); |
| +}; |
| + |
| +} // namespace sync_driver |
| + |
| +#endif // COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ |