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

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

Issue 2791893002: Pref service: Batch pref updates. (Closed)
Patch Set: rebase 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 template <typename BasePrefStore> 77 template <typename BasePrefStore>
78 void PrefStoreClientMixin<BasePrefStore>::ReportPrefValueChanged( 78 void PrefStoreClientMixin<BasePrefStore>::ReportPrefValueChanged(
79 const std::string& key) { 79 const std::string& key) {
80 for (auto& observer : observers_) 80 for (auto& observer : observers_)
81 observer.OnPrefValueChanged(key); 81 observer.OnPrefValueChanged(key);
82 } 82 }
83 83
84 template <typename BasePrefStore> 84 template <typename BasePrefStore>
85 void PrefStoreClientMixin<BasePrefStore>::OnPrefsChanged(
86 std::vector<mojom::PrefUpdatePtr> updates) {
87 for (const auto& update : updates)
88 OnPrefChanged(update->key, std::move(update->value));
89 }
90
91 template <typename BasePrefStore>
92 void PrefStoreClientMixin<BasePrefStore>::OnInitializationCompleted(
93 bool succeeded) {
94 if (!initialized_) {
95 initialized_ = true;
96 for (auto& observer : observers_)
97 observer.OnInitializationCompleted(succeeded);
98 }
99 }
100
101 template <typename BasePrefStore>
85 void PrefStoreClientMixin<BasePrefStore>::OnPrefChanged( 102 void PrefStoreClientMixin<BasePrefStore>::OnPrefChanged(
86 const std::string& key, 103 const std::string& key,
87 std::unique_ptr<base::Value> value) { 104 std::unique_ptr<base::Value> value) {
88 DCHECK(cached_prefs_); 105 DCHECK(cached_prefs_);
89 bool changed = false; 106 bool changed = false;
90 if (!value) { // Delete 107 if (!value) { // Delete
91 if (cached_prefs_->RemovePath(key, nullptr)) 108 if (cached_prefs_->RemovePath(key, nullptr))
92 changed = true; 109 changed = true;
93 } else { 110 } else {
94 const base::Value* prev; 111 const base::Value* prev;
95 if (cached_prefs_->Get(key, &prev)) { 112 if (cached_prefs_->Get(key, &prev)) {
96 if (!prev->Equals(value.get())) { 113 if (!prev->Equals(value.get())) {
97 cached_prefs_->Set(key, std::move(value)); 114 cached_prefs_->Set(key, std::move(value));
98 changed = true; 115 changed = true;
99 } 116 }
100 } else { 117 } else {
101 cached_prefs_->Set(key, std::move(value)); 118 cached_prefs_->Set(key, std::move(value));
102 changed = true; 119 changed = true;
103 } 120 }
104 } 121 }
105 if (changed && initialized_) 122 if (changed && initialized_)
106 ReportPrefValueChanged(key); 123 ReportPrefValueChanged(key);
107 } 124 }
108 125
109 template <typename BasePrefStore>
110 void PrefStoreClientMixin<BasePrefStore>::OnInitializationCompleted(
111 bool succeeded) {
112 if (!initialized_) {
113 initialized_ = true;
114 for (auto& observer : observers_)
115 observer.OnInitializationCompleted(succeeded);
116 }
117 }
118
119 template class PrefStoreClientMixin<::PrefStore>; 126 template class PrefStoreClientMixin<::PrefStore>;
120 template class PrefStoreClientMixin<::PersistentPrefStore>; 127 template class PrefStoreClientMixin<::PersistentPrefStore>;
121 128
122 } // namespace prefs 129 } // 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