Chromium Code Reviews| Index: chrome/browser/sync/glue/device_info_sync_service.h |
| diff --git a/chrome/browser/sync/glue/device_info_sync_service.h b/chrome/browser/sync/glue/device_info_sync_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..986f3f6f558e47d65dd6cd42379512a99dca0725 |
| --- /dev/null |
| +++ b/chrome/browser/sync/glue/device_info_sync_service.h |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2014 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 CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ |
| +#define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ |
| + |
| +#include "chrome/browser/sync/glue/device_info_tracker.h" |
| +#include "sync/api/sync_change_processor.h" |
| +#include "sync/api/sync_data.h" |
| +#include "sync/api/sync_error_factory.h" |
| +#include "sync/api/syncable_service.h" |
| + |
| +namespace browser_sync { |
| + |
| +class LocalDeviceInfoProvider; |
| + |
| +// SyncableService implementation for DEVICE_INFO model type. |
| +class DeviceInfoSyncService : public syncer::SyncableService, |
| + public DeviceInfoTracker { |
| + public: |
| + explicit DeviceInfoSyncService( |
| + LocalDeviceInfoProvider* local_device_info_provider); |
| + virtual ~DeviceInfoSyncService(); |
| + |
| + // syncer::SyncableService implementation. |
| + virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| + syncer::ModelType type, |
| + const syncer::SyncDataList& initial_sync_data, |
| + scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| + scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
| + virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| + virtual syncer::SyncDataList GetAllSyncData( |
| + syncer::ModelType type) const OVERRIDE; |
| + virtual syncer::SyncError ProcessSyncChanges( |
| + const tracked_objects::Location& from_here, |
| + const syncer::SyncChangeList& change_list) OVERRIDE; |
| + |
| + // DeviceInfoTracker implementation. |
| + virtual scoped_ptr<DeviceInfo> GetDeviceInfo( |
| + const std::string& client_id) const OVERRIDE; |
| + virtual ScopedVector<DeviceInfo> GetAllDeviceInfo() const OVERRIDE; |
| + virtual scoped_ptr<Subscription> RegisterOnDeviceInfoChangedCallback( |
| + const base::Closure& callback) OVERRIDE; |
| + |
| + private: |
| + // Create SyncData from local DeviceInfo. |
|
rlarocque
2014/08/01 20:40:36
nit: I prefer to have a whitespace line before a c
|
| + static syncer::SyncData CreateLocalData(const DeviceInfo* info); |
| + // Allocate new DeviceInfo from SyncData. |
| + static DeviceInfo* CreateDeviceInfo(const syncer::SyncData sync_data); |
| + // Store SyncData in the cache. |
| + void StoreSyncData(const std::string& client_id, |
| + const syncer::SyncData& sync_data); |
| + // Delete SyncData from the cache. |
| + void DeleteSyncData(const std::string& client_id); |
| + |
| + // |local_device_info_provider_| isn't owned. |
| + const LocalDeviceInfoProvider* const local_device_info_provider_; |
| + |
| + // Receives ownership of |sync_processor_| and |error_handler_| in |
| + // MergeDataAndStartSyncing() and destroy them in StopSyncing(). |
| + scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| + scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
| + |
| + // Cache of all syncable and local data. |
| + typedef std::map<std::string, syncer::SyncData> SyncDataMap; |
| + SyncDataMap all_data_; |
|
rlarocque
2014/08/01 20:40:36
I think Pavel already pointed this out, but I'll m
stanisc
2014/08/01 21:37:42
Yeah, I've thought about using native DeviceInfo w
rlarocque
2014/08/01 23:03:23
SGTM for now. I see this as an experiment. Since
|
| + |
| + // Registered observer callbacks. |
| + base::CallbackList<void(void)> callback_list_; |
|
rlarocque
2014/08/01 20:40:36
Why not use base/observer_list.h?
stanisc
2014/08/01 21:37:42
I thought CallbackList was simpler and more elegan
stanisc
2014/08/01 22:55:50
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncService); |
| +}; |
| + |
| +} // namespace browser_sync |
| + |
| +#endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ |