| 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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 base::DictionaryValue* SupervisedUserSettingsService::GetDictionaryAndSplitKey( | 447 base::DictionaryValue* SupervisedUserSettingsService::GetDictionaryAndSplitKey( |
| 448 std::string* key) const { | 448 std::string* key) const { |
| 449 size_t pos = key->find_first_of(kSplitSettingKeySeparator); | 449 size_t pos = key->find_first_of(kSplitSettingKeySeparator); |
| 450 if (pos == std::string::npos) | 450 if (pos == std::string::npos) |
| 451 return GetAtomicSettings(); | 451 return GetAtomicSettings(); |
| 452 | 452 |
| 453 base::DictionaryValue* split_settings = GetSplitSettings(); | 453 base::DictionaryValue* split_settings = GetSplitSettings(); |
| 454 std::string prefix = key->substr(0, pos); | 454 std::string prefix = key->substr(0, pos); |
| 455 base::DictionaryValue* dict = nullptr; | 455 base::DictionaryValue* dict = nullptr; |
| 456 if (!split_settings->GetDictionary(prefix, &dict)) { | 456 if (!split_settings->GetDictionary(prefix, &dict)) { |
| 457 dict = new base::DictionaryValue; | |
| 458 DCHECK(!split_settings->HasKey(prefix)); | 457 DCHECK(!split_settings->HasKey(prefix)); |
| 459 split_settings->Set(prefix, dict); | 458 dict = split_settings->SetDictionary( |
| 459 prefix, base::MakeUnique<base::DictionaryValue>()); |
| 460 } | 460 } |
| 461 key->erase(0, pos + 1); | 461 key->erase(0, pos + 1); |
| 462 return dict; | 462 return dict; |
| 463 } | 463 } |
| 464 | 464 |
| 465 std::unique_ptr<base::DictionaryValue> | 465 std::unique_ptr<base::DictionaryValue> |
| 466 SupervisedUserSettingsService::GetSettings() { | 466 SupervisedUserSettingsService::GetSettings() { |
| 467 DCHECK(IsReady()); | 467 DCHECK(IsReady()); |
| 468 if (!active_ || initialization_failed_) | 468 if (!active_ || initialization_failed_) |
| 469 return std::unique_ptr<base::DictionaryValue>(); | 469 return std::unique_ptr<base::DictionaryValue>(); |
| 470 | 470 |
| 471 std::unique_ptr<base::DictionaryValue> settings(local_settings_->DeepCopy()); | 471 std::unique_ptr<base::DictionaryValue> settings(local_settings_->DeepCopy()); |
| 472 | 472 |
| 473 base::DictionaryValue* atomic_settings = GetAtomicSettings(); | 473 base::DictionaryValue* atomic_settings = GetAtomicSettings(); |
| 474 for (base::DictionaryValue::Iterator it(*atomic_settings); !it.IsAtEnd(); | 474 for (base::DictionaryValue::Iterator it(*atomic_settings); !it.IsAtEnd(); |
| 475 it.Advance()) { | 475 it.Advance()) { |
| 476 if (!SettingShouldApplyToPrefs(it.key())) | 476 if (!SettingShouldApplyToPrefs(it.key())) |
| 477 continue; | 477 continue; |
| 478 | 478 |
| 479 settings->Set(it.key(), it.value().DeepCopy()); | 479 settings->Set(it.key(), base::MakeUnique<base::Value>(it.value())); |
| 480 } | 480 } |
| 481 | 481 |
| 482 base::DictionaryValue* split_settings = GetSplitSettings(); | 482 base::DictionaryValue* split_settings = GetSplitSettings(); |
| 483 for (base::DictionaryValue::Iterator it(*split_settings); !it.IsAtEnd(); | 483 for (base::DictionaryValue::Iterator it(*split_settings); !it.IsAtEnd(); |
| 484 it.Advance()) { | 484 it.Advance()) { |
| 485 if (!SettingShouldApplyToPrefs(it.key())) | 485 if (!SettingShouldApplyToPrefs(it.key())) |
| 486 continue; | 486 continue; |
| 487 | 487 |
| 488 settings->Set(it.key(), it.value().DeepCopy()); | 488 settings->Set(it.key(), base::MakeUnique<base::Value>(it.value())); |
| 489 } | 489 } |
| 490 | 490 |
| 491 return settings; | 491 return settings; |
| 492 } | 492 } |
| 493 | 493 |
| 494 void SupervisedUserSettingsService::InformSubscribers() { | 494 void SupervisedUserSettingsService::InformSubscribers() { |
| 495 if (!IsReady()) | 495 if (!IsReady()) |
| 496 return; | 496 return; |
| 497 | 497 |
| 498 std::unique_ptr<base::DictionaryValue> settings = GetSettings(); | 498 std::unique_ptr<base::DictionaryValue> settings = GetSettings(); |
| 499 callback_list_.Notify(settings.get()); | 499 callback_list_.Notify(settings.get()); |
| 500 } | 500 } |
| OLD | NEW |