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

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

Issue 2461723002: [Sync] DeviceInfoService static method and error cleanup. (Closed)
Patch Set: removing stdint.h from device_info_service.h Created 4 years, 1 month 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 | « no previous file | components/sync/device_info/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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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_SERVICE_H_ 5 #ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SERVICE_H_
6 #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SERVICE_H_ 6 #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SERVICE_H_
7 7
8 #include <stdint.h>
9
10 #include <map> 8 #include <map>
11 #include <memory> 9 #include <memory>
12 #include <string> 10 #include <string>
13 #include <vector> 11 #include <vector>
14 12
15 #include "base/macros.h" 13 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 15 #include "base/observer_list.h"
18 #include "base/time/time.h" 16 #include "base/time/time.h"
19 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void RemoveObserver(Observer* observer) override; 66 void RemoveObserver(Observer* observer) override;
69 int CountActiveDevices() const override; 67 int CountActiveDevices() const override;
70 68
71 private: 69 private:
72 friend class DeviceInfoServiceTest; 70 friend class DeviceInfoServiceTest;
73 71
74 // Cache of all syncable and local data, stored by device cache guid. 72 // Cache of all syncable and local data, stored by device cache guid.
75 using ClientIdToSpecifics = 73 using ClientIdToSpecifics =
76 std::map<std::string, std::unique_ptr<sync_pb::DeviceInfoSpecifics>>; 74 std::map<std::string, std::unique_ptr<sync_pb::DeviceInfoSpecifics>>;
77 75
78 static std::unique_ptr<sync_pb::DeviceInfoSpecifics> CopyToSpecifics(
79 const DeviceInfo& info);
80
81 // Allocate new DeviceInfo from SyncData.
82 static std::unique_ptr<DeviceInfo> CopyToModel(
83 const sync_pb::DeviceInfoSpecifics& specifics);
84 // Conversion as we prepare to hand data to the processor.
85 static std::unique_ptr<EntityData> CopyToEntityData(
86 const sync_pb::DeviceInfoSpecifics& specifics);
87
88 // Store SyncData in the cache and durable storage. 76 // Store SyncData in the cache and durable storage.
89 void StoreSpecifics(std::unique_ptr<sync_pb::DeviceInfoSpecifics> specifics, 77 void StoreSpecifics(std::unique_ptr<sync_pb::DeviceInfoSpecifics> specifics,
90 ModelTypeStore::WriteBatch* batch); 78 ModelTypeStore::WriteBatch* batch);
91 // Delete SyncData from the cache and durable storage, returns true if there 79 // Delete SyncData from the cache and durable storage, returns true if there
92 // was actually anything at the given tag. 80 // was actually anything at the given tag.
93 bool DeleteSpecifics(const std::string& tag, 81 bool DeleteSpecifics(const std::string& tag,
94 ModelTypeStore::WriteBatch* batch); 82 ModelTypeStore::WriteBatch* batch);
95 83
96 // Notify all registered observers. 84 // Notify all registered observers.
97 void NotifyObservers(); 85 void NotifyObservers();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Counts the number of active devices relative to |now|. The activeness of a 120 // Counts the number of active devices relative to |now|. The activeness of a
133 // device depends on the amount of time since it was updated, which means 121 // device depends on the amount of time since it was updated, which means
134 // comparing it against the current time. |now| is passed into this method to 122 // comparing it against the current time. |now| is passed into this method to
135 // allow unit tests to control expected results. 123 // allow unit tests to control expected results.
136 int CountActiveDevices(const base::Time now) const; 124 int CountActiveDevices(const base::Time now) const;
137 125
138 // Report an error starting up to sync if it tries to connect to this 126 // Report an error starting up to sync if it tries to connect to this
139 // datatype, since these errors prevent us from knowing if sync is enabled. 127 // datatype, since these errors prevent us from knowing if sync is enabled.
140 void ReportStartupErrorToSync(const std::string& msg); 128 void ReportStartupErrorToSync(const std::string& msg);
141 129
142 // Find the timestamp for the last time this |device_info| was edited.
143 static base::Time GetLastUpdateTime(
144 const sync_pb::DeviceInfoSpecifics& specifics);
145
146 // |local_device_info_provider_| isn't owned. 130 // |local_device_info_provider_| isn't owned.
147 const LocalDeviceInfoProvider* const local_device_info_provider_; 131 const LocalDeviceInfoProvider* const local_device_info_provider_;
148 132
149 ClientIdToSpecifics all_data_; 133 ClientIdToSpecifics all_data_;
150 134
151 // Registered observers, not owned. 135 // Registered observers, not owned.
152 base::ObserverList<Observer, true> observers_; 136 base::ObserverList<Observer, true> observers_;
153 137
154 // Used to listen for provider initialization. If the provider is already 138 // Used to listen for provider initialization. If the provider is already
155 // initialized during our constructor then the subscription is never used. 139 // initialized during our constructor then the subscription is never used.
156 std::unique_ptr<LocalDeviceInfoProvider::Subscription> subscription_; 140 std::unique_ptr<LocalDeviceInfoProvider::Subscription> subscription_;
157 141
158 // In charge of actually persiting changes to disk, or loading previous data. 142 // In charge of actually persiting changes to disk, or loading previous data.
159 std::unique_ptr<ModelTypeStore> store_; 143 std::unique_ptr<ModelTypeStore> store_;
160 144
161 // If |local_device_info_provider_| has initialized. 145 // If |local_device_info_provider_| has initialized.
162 bool has_provider_initialized_ = false; 146 bool has_provider_initialized_ = false;
163 // If data has been loaded from the store. 147 // If data has been loaded from the store.
164 bool has_data_loaded_ = false; 148 bool has_data_loaded_ = false;
165 149
166 // Used to update our local device info once every pulse interval. 150 // Used to update our local device info once every pulse interval.
167 base::OneShotTimer pulse_timer_; 151 base::OneShotTimer pulse_timer_;
168 152
169 DISALLOW_COPY_AND_ASSIGN(DeviceInfoService); 153 DISALLOW_COPY_AND_ASSIGN(DeviceInfoService);
170 }; 154 };
171 155
172 } // namespace syncer 156 } // namespace syncer
173 157
174 #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SERVICE_H_ 158 #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | components/sync/device_info/device_info_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698