OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 |
| 5 #ifndef CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ |
| 7 |
| 8 #include "base/observer_list.h" |
| 9 #include "chrome/browser/sync/glue/device_info_tracker.h" |
| 10 #include "sync/api/sync_change_processor.h" |
| 11 #include "sync/api/sync_data.h" |
| 12 #include "sync/api/sync_error_factory.h" |
| 13 #include "sync/api/syncable_service.h" |
| 14 |
| 15 namespace browser_sync { |
| 16 |
| 17 class LocalDeviceInfoProvider; |
| 18 |
| 19 // SyncableService implementation for DEVICE_INFO model type. |
| 20 class DeviceInfoSyncService : public syncer::SyncableService, |
| 21 public DeviceInfoTracker { |
| 22 public: |
| 23 explicit DeviceInfoSyncService( |
| 24 LocalDeviceInfoProvider* local_device_info_provider); |
| 25 virtual ~DeviceInfoSyncService(); |
| 26 |
| 27 // syncer::SyncableService implementation. |
| 28 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 29 syncer::ModelType type, |
| 30 const syncer::SyncDataList& initial_sync_data, |
| 31 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 32 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
| 33 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| 34 virtual syncer::SyncDataList GetAllSyncData( |
| 35 syncer::ModelType type) const OVERRIDE; |
| 36 virtual syncer::SyncError ProcessSyncChanges( |
| 37 const tracked_objects::Location& from_here, |
| 38 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 39 |
| 40 // DeviceInfoTracker implementation. |
| 41 virtual scoped_ptr<DeviceInfo> GetDeviceInfo( |
| 42 const std::string& client_id) const OVERRIDE; |
| 43 virtual ScopedVector<DeviceInfo> GetAllDeviceInfo() const OVERRIDE; |
| 44 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 45 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 46 |
| 47 private: |
| 48 // Create SyncData from local DeviceInfo. |
| 49 static syncer::SyncData CreateLocalData(const DeviceInfo* info); |
| 50 // Allocate new DeviceInfo from SyncData. |
| 51 static DeviceInfo* CreateDeviceInfo(const syncer::SyncData sync_data); |
| 52 // Store SyncData in the cache. |
| 53 void StoreSyncData(const std::string& client_id, |
| 54 const syncer::SyncData& sync_data); |
| 55 // Delete SyncData from the cache. |
| 56 void DeleteSyncData(const std::string& client_id); |
| 57 // Notify all registered observers. |
| 58 void NotifyObservers(); |
| 59 |
| 60 // |local_device_info_provider_| isn't owned. |
| 61 const LocalDeviceInfoProvider* const local_device_info_provider_; |
| 62 |
| 63 // Receives ownership of |sync_processor_| and |error_handler_| in |
| 64 // MergeDataAndStartSyncing() and destroy them in StopSyncing(). |
| 65 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 66 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
| 67 |
| 68 // Cache of all syncable and local data. |
| 69 typedef std::map<std::string, syncer::SyncData> SyncDataMap; |
| 70 SyncDataMap all_data_; |
| 71 |
| 72 // Registered observers, not owned. |
| 73 ObserverList<Observer, true> observers_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncService); |
| 76 }; |
| 77 |
| 78 } // namespace browser_sync |
| 79 |
| 80 #endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ |
OLD | NEW |