| 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/supervised_user_settings_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/prefs/json_pref_store.h" | 10 #include "base/prefs/json_pref_store.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 ModelType type, | 166 ModelType type, |
| 167 const SyncDataList& initial_sync_data, | 167 const SyncDataList& initial_sync_data, |
| 168 scoped_ptr<SyncChangeProcessor> sync_processor, | 168 scoped_ptr<SyncChangeProcessor> sync_processor, |
| 169 scoped_ptr<SyncErrorFactory> error_handler) { | 169 scoped_ptr<SyncErrorFactory> error_handler) { |
| 170 DCHECK_EQ(SUPERVISED_USER_SETTINGS, type); | 170 DCHECK_EQ(SUPERVISED_USER_SETTINGS, type); |
| 171 sync_processor_ = sync_processor.Pass(); | 171 sync_processor_ = sync_processor.Pass(); |
| 172 error_handler_ = error_handler.Pass(); | 172 error_handler_ = error_handler.Pass(); |
| 173 | 173 |
| 174 // Clear all atomic and split settings, then recreate them from Sync data. | 174 // Clear all atomic and split settings, then recreate them from Sync data. |
| 175 Clear(); | 175 Clear(); |
| 176 for (SyncDataList::const_iterator it = initial_sync_data.begin(); | 176 for (const auto& sync_data : initial_sync_data) { |
| 177 it != initial_sync_data.end(); ++it) { | 177 DCHECK_EQ(SUPERVISED_USER_SETTINGS, sync_data.GetDataType()); |
| 178 DCHECK_EQ(SUPERVISED_USER_SETTINGS, it->GetDataType()); | |
| 179 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = | 178 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = |
| 180 it->GetSpecifics().managed_user_setting(); | 179 sync_data.GetSpecifics().managed_user_setting(); |
| 181 scoped_ptr<base::Value> value( | 180 scoped_ptr<base::Value> value( |
| 182 JSONReader::Read(supervised_user_setting.value())); | 181 JSONReader::Read(supervised_user_setting.value())); |
| 183 std::string name_suffix = supervised_user_setting.name(); | 182 std::string name_suffix = supervised_user_setting.name(); |
| 184 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); | 183 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); |
| 185 dict->SetWithoutPathExpansion(name_suffix, value.release()); | 184 dict->SetWithoutPathExpansion(name_suffix, value.release()); |
| 186 } | 185 } |
| 187 store_->ReportValueChanged(kAtomicSettings); | 186 store_->ReportValueChanged(kAtomicSettings); |
| 188 store_->ReportValueChanged(kSplitSettings); | 187 store_->ReportValueChanged(kSplitSettings); |
| 189 InformSubscribers(); | 188 InformSubscribers(); |
| 190 | 189 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 MakeSplitSettingKey(it.key(), jt.key()), jt.value())); | 240 MakeSplitSettingKey(it.key(), jt.key()), jt.value())); |
| 242 } | 241 } |
| 243 } | 242 } |
| 244 DCHECK_EQ(0u, GetQueuedItems()->size()); | 243 DCHECK_EQ(0u, GetQueuedItems()->size()); |
| 245 return data; | 244 return data; |
| 246 } | 245 } |
| 247 | 246 |
| 248 SyncError SupervisedUserSettingsService::ProcessSyncChanges( | 247 SyncError SupervisedUserSettingsService::ProcessSyncChanges( |
| 249 const tracked_objects::Location& from_here, | 248 const tracked_objects::Location& from_here, |
| 250 const SyncChangeList& change_list) { | 249 const SyncChangeList& change_list) { |
| 251 for (SyncChangeList::const_iterator it = change_list.begin(); | 250 for (const auto& sync_change : change_list) { |
| 252 it != change_list.end(); ++it) { | 251 SyncData data = sync_change.sync_data(); |
| 253 SyncData data = it->sync_data(); | |
| 254 DCHECK_EQ(SUPERVISED_USER_SETTINGS, data.GetDataType()); | 252 DCHECK_EQ(SUPERVISED_USER_SETTINGS, data.GetDataType()); |
| 255 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = | 253 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = |
| 256 data.GetSpecifics().managed_user_setting(); | 254 data.GetSpecifics().managed_user_setting(); |
| 257 std::string key = supervised_user_setting.name(); | 255 std::string key = supervised_user_setting.name(); |
| 258 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key); | 256 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key); |
| 259 switch (it->change_type()) { | 257 SyncChange::SyncChangeType change_type = sync_change.change_type(); |
| 258 switch (change_type) { |
| 260 case SyncChange::ACTION_ADD: | 259 case SyncChange::ACTION_ADD: |
| 261 case SyncChange::ACTION_UPDATE: { | 260 case SyncChange::ACTION_UPDATE: { |
| 262 scoped_ptr<base::Value> value( | 261 scoped_ptr<base::Value> value( |
| 263 JSONReader::Read(supervised_user_setting.value())); | 262 JSONReader::Read(supervised_user_setting.value())); |
| 264 if (dict->HasKey(key)) { | 263 if (dict->HasKey(key)) { |
| 265 DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_ADD) | 264 DLOG_IF(WARNING, change_type == SyncChange::ACTION_ADD) |
| 266 << "Value for key " << key << " already exists"; | 265 << "Value for key " << key << " already exists"; |
| 267 } else { | 266 } else { |
| 268 DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_UPDATE) | 267 DLOG_IF(WARNING, change_type == SyncChange::ACTION_UPDATE) |
| 269 << "Value for key " << key << " doesn't exist yet"; | 268 << "Value for key " << key << " doesn't exist yet"; |
| 270 } | 269 } |
| 271 dict->SetWithoutPathExpansion(key, value.release()); | 270 dict->SetWithoutPathExpansion(key, value.release()); |
| 272 break; | 271 break; |
| 273 } | 272 } |
| 274 case SyncChange::ACTION_DELETE: { | 273 case SyncChange::ACTION_DELETE: { |
| 275 DLOG_IF(WARNING, !dict->HasKey(key)) << "Trying to delete nonexistent " | 274 DLOG_IF(WARNING, !dict->HasKey(key)) << "Trying to delete nonexistent " |
| 276 << "key " << key; | 275 << "key " << key; |
| 277 dict->RemoveWithoutPathExpansion(key, NULL); | 276 dict->RemoveWithoutPathExpansion(key, NULL); |
| 278 break; | 277 break; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 371 } |
| 373 | 372 |
| 374 return settings.Pass(); | 373 return settings.Pass(); |
| 375 } | 374 } |
| 376 | 375 |
| 377 void SupervisedUserSettingsService::InformSubscribers() { | 376 void SupervisedUserSettingsService::InformSubscribers() { |
| 378 if (!IsReady()) | 377 if (!IsReady()) |
| 379 return; | 378 return; |
| 380 | 379 |
| 381 scoped_ptr<base::DictionaryValue> settings = GetSettings(); | 380 scoped_ptr<base::DictionaryValue> settings = GetSettings(); |
| 382 for (std::vector<SettingsCallback>::iterator it = subscribers_.begin(); | 381 for (const auto& callback : subscribers_) { |
| 383 it != subscribers_.end(); ++it) { | 382 callback.Run(settings.get()); |
| 384 it->Run(settings.get()); | |
| 385 } | 383 } |
| 386 } | 384 } |
| OLD | NEW |