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 bool found = patterns_dict->GetDictionaryWithoutPathExpansion( |
70 expression, &expression_dict); | 70 expression, &expression_dict); |
71 if (!found) { | 71 if (!found) { |
72 expression_dict = new base::DictionaryValue; | 72 patterns_dict->SetWithoutPathExpansion( |
73 patterns_dict->SetWithoutPathExpansion(expression, expression_dict); | 73 expression, base::MakeUnique<base::DictionaryValue>()); |
| 74 patterns_dict->GetDictionaryWithoutPathExpansion(expression, |
| 75 &expression_dict); |
74 } | 76 } |
75 expression_dict->SetWithoutPathExpansion("setting", | 77 expression_dict->SetIntegerWithoutPathExpansion("setting", setting); |
76 new base::Value(setting)); | |
77 } | 78 } |
78 | 79 |
79 void SetPrefToEmpty(const std::string& pref_name) { | 80 void SetPrefToEmpty(const std::string& pref_name) { |
80 std::unique_ptr<base::Value> empty_value; | 81 std::unique_ptr<base::Value> empty_value; |
81 const PrefService::Preference* pref = | 82 const PrefService::Preference* pref = |
82 pref_service_->FindPreference(pref_name.c_str()); | 83 pref_service_->FindPreference(pref_name.c_str()); |
83 ASSERT_TRUE(pref); | 84 ASSERT_TRUE(pref); |
84 base::Value::Type type = pref->GetType(); | 85 base::Value::Type type = pref->GetType(); |
85 if (type == base::Value::Type::DICTIONARY) | 86 if (type == base::Value::Type::DICTIONARY) |
86 empty_value.reset(new base::DictionaryValue); | 87 empty_value.reset(new base::DictionaryValue); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 base::DictionaryValue server_patterns_; | 433 base::DictionaryValue server_patterns_; |
433 }; | 434 }; |
434 | 435 |
435 TEST_F(IndividualPreferenceMergeTest, ListPreference) { | 436 TEST_F(IndividualPreferenceMergeTest, ListPreference) { |
436 EXPECT_TRUE(MergeListPreference(kListPrefName)); | 437 EXPECT_TRUE(MergeListPreference(kListPrefName)); |
437 } | 438 } |
438 | 439 |
439 } // namespace | 440 } // namespace |
440 | 441 |
441 } // namespace sync_preferences | 442 } // namespace sync_preferences |
OLD | NEW |