Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: services/preferences/public/cpp/pref_store_client_mixin.cc

Issue 2803023005: Switch base::Value typemapping to be by value instead of by unique_ptr.
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "services/preferences/public/cpp/pref_store_client_mixin.h" 5 #include "services/preferences/public/cpp/pref_store_client_mixin.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "services/preferences/public/cpp/pref_store_client.h" 10 #include "services/preferences/public/cpp/pref_store_client.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 DCHECK(initialized_); 52 DCHECK(initialized_);
53 DCHECK(cached_prefs_); 53 DCHECK(cached_prefs_);
54 return cached_prefs_->CreateDeepCopy(); 54 return cached_prefs_->CreateDeepCopy();
55 } 55 }
56 56
57 template <typename BasePrefStore> 57 template <typename BasePrefStore>
58 PrefStoreClientMixin<BasePrefStore>::~PrefStoreClientMixin() = default; 58 PrefStoreClientMixin<BasePrefStore>::~PrefStoreClientMixin() = default;
59 59
60 template <typename BasePrefStore> 60 template <typename BasePrefStore>
61 void PrefStoreClientMixin<BasePrefStore>::Init( 61 void PrefStoreClientMixin<BasePrefStore>::Init(
62 std::unique_ptr<base::DictionaryValue> initial_prefs, 62 const base::DictionaryValue* initial_prefs,
63 bool initialized, 63 bool initialized,
64 mojom::PrefStoreObserverRequest observer_request) { 64 mojom::PrefStoreObserverRequest observer_request) {
65 cached_prefs_ = std::move(initial_prefs); 65 if (initial_prefs)
66 cached_prefs_ = initial_prefs->CreateDeepCopy();
66 observer_binding_.Bind(std::move(observer_request)); 67 observer_binding_.Bind(std::move(observer_request));
67 if (initialized) 68 if (initialized)
68 OnInitializationCompleted(static_cast<bool>(cached_prefs_)); 69 OnInitializationCompleted(static_cast<bool>(cached_prefs_));
69 } 70 }
70 71
71 template <typename BasePrefStore> 72 template <typename BasePrefStore>
72 base::DictionaryValue& PrefStoreClientMixin<BasePrefStore>::GetMutableValues() { 73 base::DictionaryValue& PrefStoreClientMixin<BasePrefStore>::GetMutableValues() {
73 DCHECK(cached_prefs_); 74 DCHECK(cached_prefs_);
74 return *cached_prefs_; 75 return *cached_prefs_;
75 } 76 }
(...skipping 18 matching lines...) Expand all
94 if (!initialized_) { 95 if (!initialized_) {
95 initialized_ = true; 96 initialized_ = true;
96 for (auto& observer : observers_) 97 for (auto& observer : observers_)
97 observer.OnInitializationCompleted(succeeded); 98 observer.OnInitializationCompleted(succeeded);
98 } 99 }
99 } 100 }
100 101
101 template <typename BasePrefStore> 102 template <typename BasePrefStore>
102 void PrefStoreClientMixin<BasePrefStore>::OnPrefChanged( 103 void PrefStoreClientMixin<BasePrefStore>::OnPrefChanged(
103 const std::string& key, 104 const std::string& key,
104 std::unique_ptr<base::Value> value) { 105 base::Optional<base::Value> value) {
105 DCHECK(cached_prefs_); 106 DCHECK(cached_prefs_);
106 bool changed = false; 107 bool changed = false;
107 if (!value) { // Delete 108 if (!value) { // Delete
108 if (cached_prefs_->RemovePath(key, nullptr)) 109 if (cached_prefs_->RemovePath(key, nullptr))
109 changed = true; 110 changed = true;
110 } else { 111 } else {
111 const base::Value* prev; 112 const base::Value* prev;
112 if (cached_prefs_->Get(key, &prev)) { 113 if (cached_prefs_->Get(key, &prev)) {
113 if (!prev->Equals(value.get())) { 114 if (*prev != *value) {
114 cached_prefs_->Set(key, std::move(value)); 115 cached_prefs_->Set(key, value->CreateDeepCopy());
115 changed = true; 116 changed = true;
116 } 117 }
117 } else { 118 } else {
118 cached_prefs_->Set(key, std::move(value)); 119 cached_prefs_->Set(key, value->CreateDeepCopy());
119 changed = true; 120 changed = true;
120 } 121 }
121 } 122 }
122 if (changed && initialized_) 123 if (changed && initialized_)
123 ReportPrefValueChanged(key); 124 ReportPrefValueChanged(key);
124 } 125 }
125 126
126 template class PrefStoreClientMixin<::PrefStore>; 127 template class PrefStoreClientMixin<::PrefStore>;
127 template class PrefStoreClientMixin<::PersistentPrefStore>; 128 template class PrefStoreClientMixin<::PersistentPrefStore>;
128 129
129 } // namespace prefs 130 } // namespace prefs
OLDNEW
« no previous file with comments | « services/preferences/public/cpp/pref_store_client_mixin.h ('k') | services/preferences/public/cpp/pref_store_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698