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

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

Issue 2461723002: [Sync] DeviceInfoService static method and error cleanup. (Closed)
Patch Set: Rebase 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> 8 #include <stdint.h>
maxbogue 2016/10/28 21:33:20 Is this still needed? I'm not actually sure what's
skym 2016/10/28 21:49:24 Good catch! Done. I actually just added it to the
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void RemoveObserver(Observer* observer) override; 68 void RemoveObserver(Observer* observer) override;
69 int CountActiveDevices() const override; 69 int CountActiveDevices() const override;
70 70
71 private: 71 private:
72 friend class DeviceInfoServiceTest; 72 friend class DeviceInfoServiceTest;
73 73
74 // Cache of all syncable and local data, stored by device cache guid. 74 // Cache of all syncable and local data, stored by device cache guid.
75 using ClientIdToSpecifics = 75 using ClientIdToSpecifics =
76 std::map<std::string, std::unique_ptr<sync_pb::DeviceInfoSpecifics>>; 76 std::map<std::string, std::unique_ptr<sync_pb::DeviceInfoSpecifics>>;
77 77
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. 78 // Store SyncData in the cache and durable storage.
89 void StoreSpecifics(std::unique_ptr<sync_pb::DeviceInfoSpecifics> specifics, 79 void StoreSpecifics(std::unique_ptr<sync_pb::DeviceInfoSpecifics> specifics,
90 ModelTypeStore::WriteBatch* batch); 80 ModelTypeStore::WriteBatch* batch);
91 // Delete SyncData from the cache and durable storage, returns true if there 81 // Delete SyncData from the cache and durable storage, returns true if there
92 // was actually anything at the given tag. 82 // was actually anything at the given tag.
93 bool DeleteSpecifics(const std::string& tag, 83 bool DeleteSpecifics(const std::string& tag,
94 ModelTypeStore::WriteBatch* batch); 84 ModelTypeStore::WriteBatch* batch);
95 85
96 // Notify all registered observers. 86 // Notify all registered observers.
97 void NotifyObservers(); 87 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 122 // 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 123 // 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 124 // comparing it against the current time. |now| is passed into this method to
135 // allow unit tests to control expected results. 125 // allow unit tests to control expected results.
136 int CountActiveDevices(const base::Time now) const; 126 int CountActiveDevices(const base::Time now) const;
137 127
138 // Report an error starting up to sync if it tries to connect to this 128 // 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. 129 // datatype, since these errors prevent us from knowing if sync is enabled.
140 void ReportStartupErrorToSync(const std::string& msg); 130 void ReportStartupErrorToSync(const std::string& msg);
141 131
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. 132 // |local_device_info_provider_| isn't owned.
147 const LocalDeviceInfoProvider* const local_device_info_provider_; 133 const LocalDeviceInfoProvider* const local_device_info_provider_;
148 134
149 ClientIdToSpecifics all_data_; 135 ClientIdToSpecifics all_data_;
150 136
151 // Registered observers, not owned. 137 // Registered observers, not owned.
152 base::ObserverList<Observer, true> observers_; 138 base::ObserverList<Observer, true> observers_;
153 139
154 // Used to listen for provider initialization. If the provider is already 140 // Used to listen for provider initialization. If the provider is already
155 // initialized during our constructor then the subscription is never used. 141 // initialized during our constructor then the subscription is never used.
156 std::unique_ptr<LocalDeviceInfoProvider::Subscription> subscription_; 142 std::unique_ptr<LocalDeviceInfoProvider::Subscription> subscription_;
157 143
158 // In charge of actually persiting changes to disk, or loading previous data. 144 // In charge of actually persiting changes to disk, or loading previous data.
159 std::unique_ptr<ModelTypeStore> store_; 145 std::unique_ptr<ModelTypeStore> store_;
160 146
161 // If |local_device_info_provider_| has initialized. 147 // If |local_device_info_provider_| has initialized.
162 bool has_provider_initialized_ = false; 148 bool has_provider_initialized_ = false;
163 // If data has been loaded from the store. 149 // If data has been loaded from the store.
164 bool has_data_loaded_ = false; 150 bool has_data_loaded_ = false;
165 151
166 // Used to update our local device info once every pulse interval. 152 // Used to update our local device info once every pulse interval.
167 base::OneShotTimer pulse_timer_; 153 base::OneShotTimer pulse_timer_;
168 154
169 DISALLOW_COPY_AND_ASSIGN(DeviceInfoService); 155 DISALLOW_COPY_AND_ASSIGN(DeviceInfoService);
170 }; 156 };
171 157
172 } // namespace syncer 158 } // namespace syncer
173 159
174 #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SERVICE_H_ 160 #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