OLD | NEW |
---|---|
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 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service.h" | 5 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 const syncer::SyncDataList& initial_sync_data, | 194 const syncer::SyncDataList& initial_sync_data, |
195 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 195 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
196 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 196 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
197 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); | 197 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); |
198 sync_processor_ = std::move(sync_processor); | 198 sync_processor_ = std::move(sync_processor); |
199 error_handler_ = std::move(error_handler); | 199 error_handler_ = std::move(error_handler); |
200 | 200 |
201 // We keep a map from MU ID to the set of keys that we have seen in the | 201 // We keep a map from MU ID to the set of keys that we have seen in the |
202 // initial sync data. | 202 // initial sync data. |
203 std::map<std::string, std::set<std::string> > seen_keys; | 203 std::map<std::string, std::set<std::string> > seen_keys; |
204 | 204 int num_added = 0; |
205 int num_modified = 0; | |
205 // Iterate over all initial sync data, and update it locally. This means that | 206 // Iterate over all initial sync data, and update it locally. This means that |
206 // the value from the server always wins over a local value. | 207 // the value from the server always wins over a local value. |
207 for (const SyncData& sync_data : initial_sync_data) { | 208 for (const SyncData& sync_data : initial_sync_data) { |
208 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType()); | 209 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType()); |
209 const ::sync_pb::ManagedUserSharedSettingSpecifics& | 210 const ::sync_pb::ManagedUserSharedSettingSpecifics& |
210 supervised_user_shared_setting = | 211 supervised_user_shared_setting = |
211 sync_data.GetSpecifics().managed_user_shared_setting(); | 212 sync_data.GetSpecifics().managed_user_shared_setting(); |
212 scoped_ptr<Value> value = | 213 scoped_ptr<Value> value = |
213 base::JSONReader::Read(supervised_user_shared_setting.value()); | 214 base::JSONReader::Read(supervised_user_shared_setting.value()); |
214 const std::string& su_id = supervised_user_shared_setting.mu_id(); | 215 const std::string& su_id = supervised_user_shared_setting.mu_id(); |
215 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); | 216 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); |
216 const std::string& key = supervised_user_shared_setting.key(); | 217 const std::string& key = supervised_user_shared_setting.key(); |
217 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key); | 218 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key); |
218 dict->SetWithoutPathExpansion(kValue, value.release()); | 219 dict->SetWithoutPathExpansion(kValue, value.release()); |
219 | 220 |
220 // Every setting we get from the server should have the acknowledged flag | 221 // Every setting we get from the server should have the acknowledged flag |
221 // set. | 222 // set. |
222 DCHECK(supervised_user_shared_setting.acknowledged()); | 223 DCHECK(supervised_user_shared_setting.acknowledged()); |
223 dict->SetBooleanWithoutPathExpansion( | 224 dict->SetBooleanWithoutPathExpansion( |
224 kAcknowledged, supervised_user_shared_setting.acknowledged()); | 225 kAcknowledged, supervised_user_shared_setting.acknowledged()); |
225 callbacks_.Notify(su_id, key); | 226 callbacks_.Notify(su_id, key); |
226 | 227 |
228 if (seen_keys.find(su_id) == seen_keys.end()) | |
229 num_added++; | |
230 else | |
231 num_modified++; | |
227 seen_keys[su_id].insert(key); | 232 seen_keys[su_id].insert(key); |
228 } | 233 } |
229 | 234 |
230 // Iterate over all settings that we have locally, which includes settings | 235 // Iterate over all settings that we have locally, which includes settings |
231 // that were just synced down. We filter those out using |seen_keys|. | 236 // that were just synced down. We filter those out using |seen_keys|. |
232 SyncChangeList change_list; | 237 SyncChangeList change_list; |
233 const DictionaryValue* all_settings = | 238 const DictionaryValue* all_settings = |
234 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); | 239 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); |
235 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd(); | 240 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd(); |
236 it.Advance()) { | 241 it.Advance()) { |
(...skipping 15 matching lines...) Expand all Loading... | |
252 } | 257 } |
253 } | 258 } |
254 | 259 |
255 SyncMergeResult result(SUPERVISED_USER_SHARED_SETTINGS); | 260 SyncMergeResult result(SUPERVISED_USER_SHARED_SETTINGS); |
256 // Process all the accumulated changes. | 261 // Process all the accumulated changes. |
257 if (change_list.size() > 0) { | 262 if (change_list.size() > 0) { |
258 result.set_error( | 263 result.set_error( |
259 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); | 264 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); |
260 } | 265 } |
261 | 266 |
262 // TODO(bauerb): Statistics? | 267 result.set_num_items_added(num_added); |
268 result.set_num_items_modified(num_modified); | |
Bernhard Bauer
2016/01/05 14:10:54
Add the number of items before and after associati
Deepak
2016/01/06 05:26:30
Done.
| |
263 return result; | 269 return result; |
264 } | 270 } |
265 | 271 |
266 void SupervisedUserSharedSettingsService::StopSyncing(syncer::ModelType type) { | 272 void SupervisedUserSharedSettingsService::StopSyncing(syncer::ModelType type) { |
267 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); | 273 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); |
268 sync_processor_.reset(); | 274 sync_processor_.reset(); |
269 error_handler_.reset(); | 275 error_handler_.reset(); |
270 } | 276 } |
271 | 277 |
272 syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData( | 278 syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 NOTREACHED(); | 343 NOTREACHED(); |
338 break; | 344 break; |
339 } | 345 } |
340 } | 346 } |
341 callbacks_.Notify(su_id, key); | 347 callbacks_.Notify(su_id, key); |
342 } | 348 } |
343 | 349 |
344 SyncError error; | 350 SyncError error; |
345 return error; | 351 return error; |
346 } | 352 } |
OLD | NEW |