| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "components/sync_preferences/pref_model_associator.h" | 5 #include "components/sync_preferences/pref_model_associator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 pref_registry->RegisterDictionaryPref( | 58 pref_registry->RegisterDictionaryPref( |
| 59 kDictionaryPrefName, user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 59 kDictionaryPrefName, user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 60 pref_service_ = factory.CreateSyncable(pref_registry.get()); | 60 pref_service_ = factory.CreateSyncable(pref_registry.get()); |
| 61 pref_sync_service_ = static_cast<PrefModelAssociator*>( | 61 pref_sync_service_ = static_cast<PrefModelAssociator*>( |
| 62 pref_service_->GetSyncableService(syncer::PREFERENCES)); | 62 pref_service_->GetSyncableService(syncer::PREFERENCES)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void SetContentPattern(base::DictionaryValue* patterns_dict, | 65 void SetContentPattern(base::DictionaryValue* patterns_dict, |
| 66 const std::string& expression, | 66 const std::string& expression, |
| 67 int setting) { | 67 int setting) { |
| 68 base::DictionaryValue* expression_dict; | 68 base::DictionaryValue* expression_dict = nullptr; |
| 69 bool found = patterns_dict->GetDictionaryWithoutPathExpansion( | 69 if (!patterns_dict->GetDictionaryWithoutPathExpansion(expression, |
| 70 expression, &expression_dict); | 70 &expression_dict)) { |
| 71 if (!found) { | 71 expression_dict = patterns_dict->SetDictionaryWithoutPathExpansion( |
| 72 expression_dict = new base::DictionaryValue; | 72 expression, base::MakeUnique<base::DictionaryValue>()); |
| 73 patterns_dict->SetWithoutPathExpansion(expression, expression_dict); | |
| 74 } | 73 } |
| 75 expression_dict->SetWithoutPathExpansion("setting", | 74 expression_dict->SetIntegerWithoutPathExpansion("setting", setting); |
| 76 new base::Value(setting)); | |
| 77 } | 75 } |
| 78 | 76 |
| 79 void SetPrefToEmpty(const std::string& pref_name) { | 77 void SetPrefToEmpty(const std::string& pref_name) { |
| 80 std::unique_ptr<base::Value> empty_value; | 78 std::unique_ptr<base::Value> empty_value; |
| 81 const PrefService::Preference* pref = | 79 const PrefService::Preference* pref = |
| 82 pref_service_->FindPreference(pref_name.c_str()); | 80 pref_service_->FindPreference(pref_name.c_str()); |
| 83 ASSERT_TRUE(pref); | 81 ASSERT_TRUE(pref); |
| 84 base::Value::Type type = pref->GetType(); | 82 base::Value::Type type = pref->GetType(); |
| 85 if (type == base::Value::Type::DICTIONARY) | 83 if (type == base::Value::Type::DICTIONARY) |
| 86 empty_value.reset(new base::DictionaryValue); | 84 empty_value.reset(new base::DictionaryValue); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 base::DictionaryValue server_patterns_; | 430 base::DictionaryValue server_patterns_; |
| 433 }; | 431 }; |
| 434 | 432 |
| 435 TEST_F(IndividualPreferenceMergeTest, ListPreference) { | 433 TEST_F(IndividualPreferenceMergeTest, ListPreference) { |
| 436 EXPECT_TRUE(MergeListPreference(kListPrefName)); | 434 EXPECT_TRUE(MergeListPreference(kListPrefName)); |
| 437 } | 435 } |
| 438 | 436 |
| 439 } // namespace | 437 } // namespace |
| 440 | 438 |
| 441 } // namespace sync_preferences | 439 } // namespace sync_preferences |
| OLD | NEW |