| 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 |
| 86 void SegregatedPrefStore::SetValue(const std::string& key, | 100 void SegregatedPrefStore::SetValue(const std::string& key, |
| 87 std::unique_ptr<base::Value> value, | 101 std::unique_ptr<base::Value> value, |
| 88 uint32_t flags) { | 102 uint32_t flags) { |
| 89 StoreForKey(key)->SetValue(key, std::move(value), flags); | 103 StoreForKey(key)->SetValue(key, std::move(value), flags); |
| 90 } | 104 } |
| 91 | 105 |
| 92 void SegregatedPrefStore::RemoveValue(const std::string& key, uint32_t flags) { | 106 void SegregatedPrefStore::RemoveValue(const std::string& key, uint32_t flags) { |
| 93 StoreForKey(key)->RemoveValue(key, flags); | 107 StoreForKey(key)->RemoveValue(key, flags); |
| 94 } | 108 } |
| 95 | 109 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 .get(); | 185 .get(); |
| 172 } | 186 } |
| 173 | 187 |
| 174 const PersistentPrefStore* SegregatedPrefStore::StoreForKey( | 188 const PersistentPrefStore* SegregatedPrefStore::StoreForKey( |
| 175 const std::string& key) const { | 189 const std::string& key) const { |
| 176 return (base::ContainsKey(selected_preference_names_, key) | 190 return (base::ContainsKey(selected_preference_names_, key) |
| 177 ? selected_pref_store_ | 191 ? selected_pref_store_ |
| 178 : default_pref_store_) | 192 : default_pref_store_) |
| 179 .get(); | 193 .get(); |
| 180 } | 194 } |
| OLD | NEW |