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

Side by Side Diff: services/preferences/public/cpp/pref_store_impl.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_impl.h" 5 #include "services/preferences/public/cpp/pref_store_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 12
13 namespace prefs { 13 namespace prefs {
14 14
15 class PrefStoreImpl::Observer { 15 class PrefStoreImpl::Observer {
16 public: 16 public:
17 Observer(mojom::PrefStoreObserverPtr observer, 17 Observer(mojom::PrefStoreObserverPtr observer,
18 std::unordered_set<std::string> prefs) 18 std::unordered_set<std::string> prefs)
19 : observer_(std::move(observer)), prefs_(std::move(prefs)) {} 19 : observer_(std::move(observer)), prefs_(std::move(prefs)) {}
20 20
21 void OnInitializationCompleted(bool succeeded) { 21 void OnInitializationCompleted(bool succeeded) {
22 observer_->OnInitializationCompleted(succeeded); 22 observer_->OnInitializationCompleted(succeeded);
23 } 23 }
24 24
25 void OnPrefChanged(const std::string& key, const base::Value& value) const { 25 void OnPrefChanged(const std::string& key, const base::Value& value) const {
26 if (!base::ContainsKey(prefs_, key)) 26 if (!base::ContainsKey(prefs_, key))
27 return; 27 return;
28 28
29 observer_->OnPrefChanged(key, value.CreateDeepCopy()); 29 std::vector<mojom::PrefUpdatePtr> updates;
30 updates.push_back(mojom::PrefUpdate::New(key, value.CreateDeepCopy(), 0));
31 observer_->OnPrefsChanged(std::move(updates));
30 } 32 }
31 33
32 void OnPrefRemoved(const std::string& key) const { 34 void OnPrefRemoved(const std::string& key) const {
33 if (!base::ContainsKey(prefs_, key)) 35 if (!base::ContainsKey(prefs_, key))
34 return; 36 return;
35 37
36 observer_->OnPrefChanged(key, nullptr); 38 std::vector<mojom::PrefUpdatePtr> updates;
39 updates.push_back(mojom::PrefUpdate::New(key, nullptr, 0));
40 observer_->OnPrefsChanged(std::move(updates));
37 } 41 }
38 42
39 private: 43 private:
40 mojom::PrefStoreObserverPtr observer_; 44 mojom::PrefStoreObserverPtr observer_;
41 const std::unordered_set<std::string> prefs_; 45 const std::unordered_set<std::string> prefs_;
42 46
43 DISALLOW_COPY_AND_ASSIGN(Observer); 47 DISALLOW_COPY_AND_ASSIGN(Observer);
44 }; 48 };
45 49
46 PrefStoreImpl::PrefStoreImpl(scoped_refptr<::PrefStore> pref_store, 50 PrefStoreImpl::PrefStoreImpl(scoped_refptr<::PrefStore> pref_store,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 observers_.push_back(base::MakeUnique<Observer>( 104 observers_.push_back(base::MakeUnique<Observer>(
101 std::move(observer_ptr), 105 std::move(observer_ptr),
102 std::unordered_set<std::string>(prefs_to_observe.begin(), 106 std::unordered_set<std::string>(prefs_to_observe.begin(),
103 prefs_to_observe.end()))); 107 prefs_to_observe.end())));
104 callback.Run(mojom::PrefStoreConnection::New( 108 callback.Run(mojom::PrefStoreConnection::New(
105 std::move(request), backing_pref_store_->GetValues(), 109 std::move(request), backing_pref_store_->GetValues(),
106 backing_pref_store_->IsInitializationComplete())); 110 backing_pref_store_->IsInitializationComplete()));
107 } 111 }
108 112
109 } // namespace prefs 113 } // namespace prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698