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

Side by Side Diff: components/sync_driver/device_info_service.h

Issue 1408123003: [Sync] Initial USS service implementation for DeviceInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated for Stan's comments. Created 5 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
« no previous file with comments | « components/sync_driver/device_info.cc ('k') | components/sync_driver/device_info_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_
6 #define COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_
7
8 #include <string>
9
10 #include "base/containers/scoped_ptr_map.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/observer_list.h"
15 #include "components/sync_driver/device_info_tracker.h"
16 #include "components/sync_driver/local_device_info_provider.h"
17 #include "sync/api/model_type_service.h"
18
19 namespace syncer {
20 class SyncError;
21 } // namespace syncer
22
23 namespace syncer_v2 {
24 class ModelTypeChangeProcessor;
25 } // namespace syncer_v2
26
27 namespace sync_pb {
28 class DeviceInfoSpecifics;
29 } // namespace sync_pb
30
31 namespace sync_driver_v2 {
32
33 class ModelTypeChangeProcessor;
34
35 // USS service implementation for DEVICE_INFO model type. Handles storage of
36 // device info and associated sync metadata, applying/merging foreign changes,
37 // and allows public read access.
38 class DeviceInfoService : public syncer_v2::ModelTypeService,
39 public sync_driver::DeviceInfoTracker {
40 public:
41 explicit DeviceInfoService(
42 sync_driver::LocalDeviceInfoProvider* local_device_info_provider);
43 ~DeviceInfoService() override;
44
45 // TODO(skym): Update once these are added to ModelTypeService interface.
46 // ModelTypeService implementation.
47 syncer::SyncError ApplySyncChanges();
48 syncer::SyncError LoadMetadata();
49 syncer::SyncError UpdateMetadata();
50 syncer::SyncError GetData();
51 syncer::SyncError GetAllData();
52 syncer::SyncError ClearMetadata();
53 // TODO(skym): See crbug/547087, do we need all these accessors?
54 syncer_v2::ModelTypeChangeProcessor* get_change_processor();
55 void set_change_processor(
56 scoped_ptr<syncer_v2::ModelTypeChangeProcessor> change_processor);
57 void clear_change_processor();
58
59 // DeviceInfoTracker implementation.
60 bool IsSyncing() const override;
61 scoped_ptr<sync_driver::DeviceInfo> GetDeviceInfo(
62 const std::string& client_id) const override;
63 ScopedVector<sync_driver::DeviceInfo> GetAllDeviceInfo() const override;
64 void AddObserver(Observer* observer) override;
65 void RemoveObserver(Observer* observer) override;
66
67 // Called to update local device backup time.
68 void UpdateLocalDeviceBackupTime(base::Time backup_time);
69 // Gets the most recently set local device backup time.
70 base::Time GetLocalDeviceBackupTime() const;
71
72 private:
73 friend class DeviceInfoServiceTest;
74
75 scoped_ptr<sync_pb::DeviceInfoSpecifics> CreateLocalSpecifics();
76 static scoped_ptr<sync_pb::DeviceInfoSpecifics> CreateSpecifics(
77 const sync_driver::DeviceInfo& info);
78
79 // Allocate new DeviceInfo from SyncData.
80 static scoped_ptr<sync_driver::DeviceInfo> CreateDeviceInfo(
81 const sync_pb::DeviceInfoSpecifics& specifics);
82
83 // Store SyncData in the cache.
84 void StoreSpecifics(scoped_ptr<sync_pb::DeviceInfoSpecifics> specifics);
85 // Delete SyncData from the cache.
86 void DeleteSpecifics(const std::string& client_id);
87 // Notify all registered observers.
88 void NotifyObservers();
89
90 void OnProviderInitialized();
91
92 // |local_device_backup_time_| accessors.
93 int64 local_device_backup_time() const { return local_device_backup_time_; }
94 bool has_local_device_backup_time() const {
95 return local_device_backup_time_ >= 0;
96 }
97 void set_local_device_backup_time(int64 value) {
98 local_device_backup_time_ = value;
99 }
100 void clear_local_device_backup_time() { local_device_backup_time_ = -1; }
101
102 // TODO(skym): Remove once we remove local provider.
103 // Local device last set backup time (in proto format).
104 // -1 if the value hasn't been specified
105 int64 local_device_backup_time_;
106
107 // |local_device_info_provider_| isn't owned.
108 const sync_driver::LocalDeviceInfoProvider* const local_device_info_provider_;
109
110 // Recieves ownership in set_change_processor(...).
111 scoped_ptr<syncer_v2::ModelTypeChangeProcessor> change_processor_;
112
113 // TODO(skym): Switch to use client tag hash instead of cache guid as key.
114 // Cache of all syncable and local data, stored by device cache guid.
115 typedef base::ScopedPtrMap<std::string,
116 scoped_ptr<sync_pb::DeviceInfoSpecifics>>
117 ClientIdToSpecifics;
118 ClientIdToSpecifics all_data_;
119
120 // Registered observers, not owned.
121 base::ObserverList<Observer, true> observers_;
122
123 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> subscription_;
124
125 DISALLOW_COPY_AND_ASSIGN(DeviceInfoService);
126 };
127
128 } // namespace sync_driver_v2
129
130 #endif // COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_
OLDNEW
« no previous file with comments | « components/sync_driver/device_info.cc ('k') | components/sync_driver/device_info_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698