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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_shared_settings_service.cc

Issue 615493005: c/b/supervised_user: Use range-based for where appropriate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix CrOS Created 6 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 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service .h" 5 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service .h"
6 6
7 #include <map>
8 #include <set>
9
7 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
9 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 13 #include "base/prefs/scoped_user_pref_update.h"
11 #include "base/values.h" 14 #include "base/values.h"
12 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
13 #include "components/pref_registry/pref_registry_syncable.h" 16 #include "components/pref_registry/pref_registry_syncable.h"
14 #include "sync/api/sync_change.h" 17 #include "sync/api/sync_change.h"
15 #include "sync/api/sync_data.h" 18 #include "sync/api/sync_data.h"
16 #include "sync/api/sync_error.h" 19 #include "sync/api/sync_error.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); 198 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type);
196 sync_processor_ = sync_processor.Pass(); 199 sync_processor_ = sync_processor.Pass();
197 error_handler_ = error_handler.Pass(); 200 error_handler_ = error_handler.Pass();
198 201
199 // We keep a map from MU ID to the set of keys that we have seen in the 202 // We keep a map from MU ID to the set of keys that we have seen in the
200 // initial sync data. 203 // initial sync data.
201 std::map<std::string, std::set<std::string> > seen_keys; 204 std::map<std::string, std::set<std::string> > seen_keys;
202 205
203 // 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
204 // the value from the server always wins over a local value. 207 // the value from the server always wins over a local value.
205 for (SyncDataList::const_iterator it = initial_sync_data.begin(); 208 for (const SyncData& sync_data : initial_sync_data) {
206 it != initial_sync_data.end(); 209 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType());
207 ++it) {
208 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, it->GetDataType());
209 const ::sync_pb::ManagedUserSharedSettingSpecifics& 210 const ::sync_pb::ManagedUserSharedSettingSpecifics&
210 supervised_user_shared_setting = 211 supervised_user_shared_setting =
211 it->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.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) { 284 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) {
284 data.push_back(CreateSyncDataForValue(it.key(), jt.key(), jt.value())); 285 data.push_back(CreateSyncDataForValue(it.key(), jt.key(), jt.value()));
285 } 286 }
286 } 287 }
287 return data; 288 return data;
288 } 289 }
289 290
290 syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges( 291 syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges(
291 const tracked_objects::Location& from_here, 292 const tracked_objects::Location& from_here,
292 const syncer::SyncChangeList& change_list) { 293 const syncer::SyncChangeList& change_list) {
293 for (SyncChangeList::const_iterator it = change_list.begin(); 294 for (const SyncChange& sync_change : change_list) {
294 it != change_list.end(); 295 SyncData data = sync_change.sync_data();
295 ++it) {
296 SyncData data = it->sync_data();
297 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType()); 296 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType());
298 const ::sync_pb::ManagedUserSharedSettingSpecifics& 297 const ::sync_pb::ManagedUserSharedSettingSpecifics&
299 supervised_user_shared_setting = 298 supervised_user_shared_setting =
300 data.GetSpecifics().managed_user_shared_setting(); 299 data.GetSpecifics().managed_user_shared_setting();
301 const std::string& key = supervised_user_shared_setting.key(); 300 const std::string& key = supervised_user_shared_setting.key();
302 const std::string& su_id = supervised_user_shared_setting.mu_id(); 301 const std::string& su_id = supervised_user_shared_setting.mu_id();
303 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); 302 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id);
304 DictionaryValue* update_dict = update.Get(); 303 DictionaryValue* update_dict = update.Get();
305 DictionaryValue* dict = NULL; 304 DictionaryValue* dict = NULL;
306 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict); 305 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict);
307 switch (it->change_type()) { 306 switch (sync_change.change_type()) {
308 case SyncChange::ACTION_ADD: 307 case SyncChange::ACTION_ADD:
309 case SyncChange::ACTION_UPDATE: { 308 case SyncChange::ACTION_UPDATE: {
310 // Every setting we get from the server should have the acknowledged 309 // Every setting we get from the server should have the acknowledged
311 // flag set. 310 // flag set.
312 DCHECK(supervised_user_shared_setting.acknowledged()); 311 DCHECK(supervised_user_shared_setting.acknowledged());
313 312
314 if (has_key) { 313 if (has_key) {
315 // If the supervised user already exists, it should be an update 314 // If the supervised user already exists, it should be an update
316 // action. 315 // action.
317 DCHECK_EQ(SyncChange::ACTION_UPDATE, it->change_type()); 316 DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type());
318 } else { 317 } else {
319 // Otherwise, it should be an add action. 318 // Otherwise, it should be an add action.
320 DCHECK_EQ(SyncChange::ACTION_ADD, it->change_type()); 319 DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type());
321 dict = new DictionaryValue; 320 dict = new DictionaryValue;
322 update_dict->SetWithoutPathExpansion(key, dict); 321 update_dict->SetWithoutPathExpansion(key, dict);
323 } 322 }
324 scoped_ptr<Value> value( 323 scoped_ptr<Value> value(
325 base::JSONReader::Read(supervised_user_shared_setting.value())); 324 base::JSONReader::Read(supervised_user_shared_setting.value()));
326 dict->SetWithoutPathExpansion(kValue, value.release()); 325 dict->SetWithoutPathExpansion(kValue, value.release());
327 dict->SetBooleanWithoutPathExpansion( 326 dict->SetBooleanWithoutPathExpansion(
328 kAcknowledged, supervised_user_shared_setting.acknowledged()); 327 kAcknowledged, supervised_user_shared_setting.acknowledged());
329 break; 328 break;
330 } 329 }
331 case SyncChange::ACTION_DELETE: { 330 case SyncChange::ACTION_DELETE: {
332 if (has_key) 331 if (has_key)
333 update_dict->RemoveWithoutPathExpansion(key, NULL); 332 update_dict->RemoveWithoutPathExpansion(key, NULL);
334 else 333 else
335 NOTREACHED() << "Trying to delete nonexistent key " << key; 334 NOTREACHED() << "Trying to delete nonexistent key " << key;
336 break; 335 break;
337 } 336 }
338 case SyncChange::ACTION_INVALID: { 337 case SyncChange::ACTION_INVALID: {
339 NOTREACHED(); 338 NOTREACHED();
340 break; 339 break;
341 } 340 }
342 } 341 }
343 callbacks_.Notify(su_id, key); 342 callbacks_.Notify(su_id, key);
344 } 343 }
345 344
346 SyncError error; 345 SyncError error;
347 return error; 346 return error;
348 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698