Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: components/sync/device_info/device_info_sync_service.h

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_SERVICE_H_ 5 #ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_SERVICE_H_
6 #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_SERVICE_H_ 6 #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_SERVICE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
18 #include "components/sync/api/sync_change.h" 18 #include "components/sync/api/sync_change.h"
19 #include "components/sync/api/sync_change_processor.h" 19 #include "components/sync/api/sync_change_processor.h"
20 #include "components/sync/api/sync_data.h" 20 #include "components/sync/api/sync_data.h"
21 #include "components/sync/api/sync_error_factory.h" 21 #include "components/sync/api/sync_error_factory.h"
22 #include "components/sync/api/syncable_service.h" 22 #include "components/sync/api/syncable_service.h"
23 #include "components/sync/device_info/device_info_tracker.h" 23 #include "components/sync/device_info/device_info_tracker.h"
24 24
25 namespace syncer { 25 namespace sync_driver {
26 26
27 class LocalDeviceInfoProvider; 27 class LocalDeviceInfoProvider;
28 28
29 // SyncableService implementation for DEVICE_INFO model type. 29 // SyncableService implementation for DEVICE_INFO model type.
30 class DeviceInfoSyncService : public SyncableService, public DeviceInfoTracker { 30 class DeviceInfoSyncService : public syncer::SyncableService,
31 public DeviceInfoTracker {
31 public: 32 public:
32 explicit DeviceInfoSyncService( 33 explicit DeviceInfoSyncService(
33 LocalDeviceInfoProvider* local_device_info_provider); 34 LocalDeviceInfoProvider* local_device_info_provider);
34 ~DeviceInfoSyncService() override; 35 ~DeviceInfoSyncService() override;
35 36
36 // SyncableService implementation. 37 // syncer::SyncableService implementation.
37 SyncMergeResult MergeDataAndStartSyncing( 38 syncer::SyncMergeResult MergeDataAndStartSyncing(
38 ModelType type, 39 syncer::ModelType type,
39 const SyncDataList& initial_sync_data, 40 const syncer::SyncDataList& initial_sync_data,
40 std::unique_ptr<SyncChangeProcessor> sync_processor, 41 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
41 std::unique_ptr<SyncErrorFactory> error_handler) override; 42 std::unique_ptr<syncer::SyncErrorFactory> error_handler) override;
42 void StopSyncing(ModelType type) override; 43 void StopSyncing(syncer::ModelType type) override;
43 SyncDataList GetAllSyncData(ModelType type) const override; 44 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
44 SyncError ProcessSyncChanges(const tracked_objects::Location& from_here, 45 syncer::SyncError ProcessSyncChanges(
45 const SyncChangeList& change_list) override; 46 const tracked_objects::Location& from_here,
47 const syncer::SyncChangeList& change_list) override;
46 48
47 // DeviceInfoTracker implementation. 49 // DeviceInfoTracker implementation.
48 bool IsSyncing() const override; 50 bool IsSyncing() const override;
49 std::unique_ptr<DeviceInfo> GetDeviceInfo( 51 std::unique_ptr<DeviceInfo> GetDeviceInfo(
50 const std::string& client_id) const override; 52 const std::string& client_id) const override;
51 std::vector<std::unique_ptr<DeviceInfo>> GetAllDeviceInfo() const override; 53 std::vector<std::unique_ptr<DeviceInfo>> GetAllDeviceInfo() const override;
52 void AddObserver(Observer* observer) override; 54 void AddObserver(Observer* observer) override;
53 void RemoveObserver(Observer* observer) override; 55 void RemoveObserver(Observer* observer) override;
54 int CountActiveDevices() const override; 56 int CountActiveDevices() const override;
55 57
56 private: 58 private:
57 friend class DeviceInfoSyncServiceTest; 59 friend class DeviceInfoSyncServiceTest;
58 60
59 // Create SyncData from local DeviceInfo. 61 // Create SyncData from local DeviceInfo.
60 SyncData CreateLocalData(const DeviceInfo* info); 62 syncer::SyncData CreateLocalData(const DeviceInfo* info);
61 // Create SyncData from EntitySpecifics. 63 // Create SyncData from EntitySpecifics.
62 static SyncData CreateLocalData(const sync_pb::EntitySpecifics& entity); 64 static syncer::SyncData CreateLocalData(
65 const sync_pb::EntitySpecifics& entity);
63 66
64 // Allocate new DeviceInfo from SyncData. 67 // Allocate new DeviceInfo from SyncData.
65 static DeviceInfo* CreateDeviceInfo(const SyncData& sync_data); 68 static DeviceInfo* CreateDeviceInfo(const syncer::SyncData& sync_data);
66 // Store SyncData in the cache. 69 // Store SyncData in the cache.
67 void StoreSyncData(const std::string& client_id, const SyncData& sync_data); 70 void StoreSyncData(const std::string& client_id,
71 const syncer::SyncData& sync_data);
68 // Delete SyncData from the cache. 72 // Delete SyncData from the cache.
69 void DeleteSyncData(const std::string& client_id); 73 void DeleteSyncData(const std::string& client_id);
70 // Notify all registered observers. 74 // Notify all registered observers.
71 void NotifyObservers(); 75 void NotifyObservers();
72 76
73 // Sends a copy of the current device's state to the processor/sync. 77 // Sends a copy of the current device's state to the processor/sync.
74 void SendLocalData(const SyncChange::SyncChangeType change_type); 78 void SendLocalData(const syncer::SyncChange::SyncChangeType change_type);
75 79
76 // Finds the number of active devices give the current time, which allows for 80 // Finds the number of active devices give the current time, which allows for
77 // better unit tests. 81 // better unit tests.
78 int CountActiveDevices(const base::Time now) const; 82 int CountActiveDevices(const base::Time now) const;
79 83
80 // Find the timestamp for the last time this |device_info| was edited. 84 // Find the timestamp for the last time this |device_info| was edited.
81 static base::Time GetLastUpdateTime(const SyncData& device_info); 85 static base::Time GetLastUpdateTime(const syncer::SyncData& device_info);
82 86
83 // |local_device_info_provider_| isn't owned. 87 // |local_device_info_provider_| isn't owned.
84 const LocalDeviceInfoProvider* const local_device_info_provider_; 88 const LocalDeviceInfoProvider* const local_device_info_provider_;
85 89
86 // Receives ownership of |sync_processor_| and |error_handler_| in 90 // Receives ownership of |sync_processor_| and |error_handler_| in
87 // MergeDataAndStartSyncing() and destroy them in StopSyncing(). 91 // MergeDataAndStartSyncing() and destroy them in StopSyncing().
88 std::unique_ptr<SyncChangeProcessor> sync_processor_; 92 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_;
89 std::unique_ptr<SyncErrorFactory> error_handler_; 93 std::unique_ptr<syncer::SyncErrorFactory> error_handler_;
90 94
91 // Cache of all syncable and local data. 95 // Cache of all syncable and local data.
92 typedef std::map<std::string, SyncData> SyncDataMap; 96 typedef std::map<std::string, syncer::SyncData> SyncDataMap;
93 SyncDataMap all_data_; 97 SyncDataMap all_data_;
94 98
95 // Registered observers, not owned. 99 // Registered observers, not owned.
96 base::ObserverList<Observer, true> observers_; 100 base::ObserverList<Observer, true> observers_;
97 101
98 // Used to update our local device info once every pulse interval. 102 // Used to update our local device info once every pulse interval.
99 base::OneShotTimer pulse_timer_; 103 base::OneShotTimer pulse_timer_;
100 104
101 DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncService); 105 DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncService);
102 }; 106 };
103 107
104 } // namespace syncer 108 } // namespace sync_driver
105 109
106 #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_SERVICE_H_ 110 #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_SERVICE_H_
OLDNEW
« no previous file with comments | « components/sync/device_info/device_info_service_unittest.cc ('k') | components/sync/device_info/device_info_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698