| 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 "components/user_prefs/tracked/segregated_pref_store.h" | 5 #include "components/user_prefs/tracked/segregated_pref_store.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 bool SegregatedPrefStore::IsInitializationComplete() const { | 76 bool SegregatedPrefStore::IsInitializationComplete() const { |
| 77 return default_pref_store_->IsInitializationComplete() && | 77 return default_pref_store_->IsInitializationComplete() && |
| 78 selected_pref_store_->IsInitializationComplete(); | 78 selected_pref_store_->IsInitializationComplete(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool SegregatedPrefStore::GetValue(const std::string& key, | 81 bool SegregatedPrefStore::GetValue(const std::string& key, |
| 82 const base::Value** result) const { | 82 const base::Value** result) const { |
| 83 return StoreForKey(key)->GetValue(key, result); | 83 return StoreForKey(key)->GetValue(key, result); |
| 84 } | 84 } |
| 85 | 85 |
| 86 std::unique_ptr<base::DictionaryValue> SegregatedPrefStore::GetValues() const { | |
| 87 auto values = default_pref_store_->GetValues(); | |
| 88 auto selected_pref_store_values = selected_pref_store_->GetValues(); | |
| 89 for (const auto& key : selected_preference_names_) { | |
| 90 const base::Value* value = nullptr; | |
| 91 if (selected_pref_store_values->Get(key, &value)) { | |
| 92 values->Set(key, value->CreateDeepCopy()); | |
| 93 } else { | |
| 94 values->Remove(key, nullptr); | |
| 95 } | |
| 96 } | |
| 97 return values; | |
| 98 } | |
| 99 | |
| 100 void SegregatedPrefStore::SetValue(const std::string& key, | 86 void SegregatedPrefStore::SetValue(const std::string& key, |
| 101 std::unique_ptr<base::Value> value, | 87 std::unique_ptr<base::Value> value, |
| 102 uint32_t flags) { | 88 uint32_t flags) { |
| 103 StoreForKey(key)->SetValue(key, std::move(value), flags); | 89 StoreForKey(key)->SetValue(key, std::move(value), flags); |
| 104 } | 90 } |
| 105 | 91 |
| 106 void SegregatedPrefStore::RemoveValue(const std::string& key, uint32_t flags) { | 92 void SegregatedPrefStore::RemoveValue(const std::string& key, uint32_t flags) { |
| 107 StoreForKey(key)->RemoveValue(key, flags); | 93 StoreForKey(key)->RemoveValue(key, flags); |
| 108 } | 94 } |
| 109 | 95 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 .get(); | 171 .get(); |
| 186 } | 172 } |
| 187 | 173 |
| 188 const PersistentPrefStore* SegregatedPrefStore::StoreForKey( | 174 const PersistentPrefStore* SegregatedPrefStore::StoreForKey( |
| 189 const std::string& key) const { | 175 const std::string& key) const { |
| 190 return (base::ContainsKey(selected_preference_names_, key) | 176 return (base::ContainsKey(selected_preference_names_, key) |
| 191 ? selected_pref_store_ | 177 ? selected_pref_store_ |
| 192 : default_pref_store_) | 178 : default_pref_store_) |
| 193 .get(); | 179 .get(); |
| 194 } | 180 } |
| OLD | NEW |