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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 base::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued")); | 166 base::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued")); |
167 dict = GetQueuedItems(); | 167 dict = GetQueuedItems(); |
168 } | 168 } |
169 dict->SetWithoutPathExpansion(key_suffix, std::move(value)); | 169 dict->SetWithoutPathExpansion(key_suffix, std::move(value)); |
170 } | 170 } |
171 | 171 |
172 void SupervisedUserSettingsService::SetLocalSetting( | 172 void SupervisedUserSettingsService::SetLocalSetting( |
173 const std::string& key, | 173 const std::string& key, |
174 std::unique_ptr<base::Value> value) { | 174 std::unique_ptr<base::Value> value) { |
175 if (value) | 175 if (value) |
176 local_settings_->SetWithoutPathExpansion(key, value.release()); | 176 local_settings_->SetWithoutPathExpansion(key, std::move(value)); |
177 else | 177 else |
178 local_settings_->RemoveWithoutPathExpansion(key, nullptr); | 178 local_settings_->RemoveWithoutPathExpansion(key, nullptr); |
179 | 179 |
180 InformSubscribers(); | 180 InformSubscribers(); |
181 } | 181 } |
182 | 182 |
183 // static | 183 // static |
184 SyncData SupervisedUserSettingsService::CreateSyncDataForSetting( | 184 SyncData SupervisedUserSettingsService::CreateSyncDataForSetting( |
185 const std::string& name, | 185 const std::string& name, |
186 const base::Value& value) { | 186 const base::Value& value) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 // SetWithoutPathExpansion below requires non-null values. | 245 // SetWithoutPathExpansion below requires non-null values. |
246 if (!value) { | 246 if (!value) { |
247 DLOG(ERROR) << "Invalid managed user setting value: " | 247 DLOG(ERROR) << "Invalid managed user setting value: " |
248 << supervised_user_setting.value() | 248 << supervised_user_setting.value() |
249 << ". Values must be JSON values."; | 249 << ". Values must be JSON values."; |
250 continue; | 250 continue; |
251 } | 251 } |
252 std::string name_suffix = supervised_user_setting.name(); | 252 std::string name_suffix = supervised_user_setting.name(); |
253 std::string name_key = name_suffix; | 253 std::string name_key = name_suffix; |
254 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); | 254 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); |
255 dict->SetWithoutPathExpansion(name_suffix, value.release()); | 255 dict->SetWithoutPathExpansion(name_suffix, std::move(value)); |
256 if (seen_keys.find(name_key) == seen_keys.end()) { | 256 if (seen_keys.find(name_key) == seen_keys.end()) { |
257 added_sync_keys.insert(name_key); | 257 added_sync_keys.insert(name_key); |
258 num_added++; | 258 num_added++; |
259 } else { | 259 } else { |
260 num_modified++; | 260 num_modified++; |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 num_deleted -= num_modified; | 264 num_deleted -= num_modified; |
265 | 265 |
266 store_->ReportValueChanged(kAtomicSettings, | 266 store_->ReportValueChanged(kAtomicSettings, |
267 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 267 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
268 store_->ReportValueChanged(kSplitSettings, | 268 store_->ReportValueChanged(kSplitSettings, |
269 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 269 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
270 InformSubscribers(); | 270 InformSubscribers(); |
271 | 271 |
272 // Upload all the queued up items (either with an ADD or an UPDATE action, | 272 // Upload all the queued up items (either with an ADD or an UPDATE action, |
273 // depending on whether they already exist) and move them to split settings. | 273 // depending on whether they already exist) and move them to split settings. |
274 SyncChangeList change_list; | 274 SyncChangeList change_list; |
275 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd(); | 275 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd(); |
276 it.Advance()) { | 276 it.Advance()) { |
277 std::string key_suffix = it.key(); | 277 std::string key_suffix = it.key(); |
278 std::string name_key = key_suffix; | 278 std::string name_key = key_suffix; |
279 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix); | 279 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix); |
280 SyncData data = CreateSyncDataForSetting(it.key(), it.value()); | 280 SyncData data = CreateSyncDataForSetting(it.key(), it.value()); |
281 SyncChange::SyncChangeType change_type = | 281 SyncChange::SyncChangeType change_type = |
282 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE | 282 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE |
283 : SyncChange::ACTION_ADD; | 283 : SyncChange::ACTION_ADD; |
284 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); | 284 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); |
285 dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy()); | 285 dict->SetWithoutPathExpansion(key_suffix, it.value().CreateDeepCopy()); |
vabr (Chromium)
2017/04/28 07:23:40
and here a copy constructor instead as well?
jdoerrie
2017/05/02 18:08:06
Done.
| |
286 if (added_sync_keys.find(name_key) != added_sync_keys.end()) { | 286 if (added_sync_keys.find(name_key) != added_sync_keys.end()) { |
287 num_added--; | 287 num_added--; |
288 } | 288 } |
289 } | 289 } |
290 queued_items->Clear(); | 290 queued_items->Clear(); |
291 | 291 |
292 SyncMergeResult result(SUPERVISED_USER_SETTINGS); | 292 SyncMergeResult result(SUPERVISED_USER_SETTINGS); |
293 // Process all the accumulated changes from the queued items. | 293 // Process all the accumulated changes from the queued items. |
294 if (change_list.size() > 0) { | 294 if (change_list.size() > 0) { |
295 store_->ReportValueChanged(kQueuedItems, | 295 store_->ReportValueChanged(kQueuedItems, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 case SyncChange::ACTION_UPDATE: { | 365 case SyncChange::ACTION_UPDATE: { |
366 std::unique_ptr<base::Value> value = | 366 std::unique_ptr<base::Value> value = |
367 JSONReader::Read(supervised_user_setting.value()); | 367 JSONReader::Read(supervised_user_setting.value()); |
368 if (dict->HasKey(key)) { | 368 if (dict->HasKey(key)) { |
369 DLOG_IF(WARNING, change_type == SyncChange::ACTION_ADD) | 369 DLOG_IF(WARNING, change_type == SyncChange::ACTION_ADD) |
370 << "Value for key " << key << " already exists"; | 370 << "Value for key " << key << " already exists"; |
371 } else { | 371 } else { |
372 DLOG_IF(WARNING, change_type == SyncChange::ACTION_UPDATE) | 372 DLOG_IF(WARNING, change_type == SyncChange::ACTION_UPDATE) |
373 << "Value for key " << key << " doesn't exist yet"; | 373 << "Value for key " << key << " doesn't exist yet"; |
374 } | 374 } |
375 dict->SetWithoutPathExpansion(key, value.release()); | 375 dict->SetWithoutPathExpansion(key, std::move(value)); |
376 break; | 376 break; |
377 } | 377 } |
378 case SyncChange::ACTION_DELETE: { | 378 case SyncChange::ACTION_DELETE: { |
379 DLOG_IF(WARNING, !dict->HasKey(key)) << "Trying to delete nonexistent " | 379 DLOG_IF(WARNING, !dict->HasKey(key)) << "Trying to delete nonexistent " |
380 << "key " << key; | 380 << "key " << key; |
381 dict->RemoveWithoutPathExpansion(key, nullptr); | 381 dict->RemoveWithoutPathExpansion(key, nullptr); |
382 break; | 382 break; |
383 } | 383 } |
384 case SyncChange::ACTION_INVALID: { | 384 case SyncChange::ACTION_INVALID: { |
385 NOTREACHED(); | 385 NOTREACHED(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 return settings; | 489 return settings; |
490 } | 490 } |
491 | 491 |
492 void SupervisedUserSettingsService::InformSubscribers() { | 492 void SupervisedUserSettingsService::InformSubscribers() { |
493 if (!IsReady()) | 493 if (!IsReady()) |
494 return; | 494 return; |
495 | 495 |
496 std::unique_ptr<base::DictionaryValue> settings = GetSettings(); | 496 std::unique_ptr<base::DictionaryValue> settings = GetSettings(); |
497 callback_list_.Notify(settings.get()); | 497 callback_list_.Notify(settings.get()); |
498 } | 498 } |
OLD | NEW |