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

Side by Side Diff: services/preferences/public/cpp/pref_store_impl.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_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 std::vector<mojom::PrefUpdatePtr> updates; 29 std::vector<mojom::PrefUpdatePtr> updates;
30 updates.push_back(mojom::PrefUpdate::New(key, value.CreateDeepCopy(), 0)); 30 updates.push_back(mojom::PrefUpdate::New(key, value, 0));
31 observer_->OnPrefsChanged(std::move(updates)); 31 observer_->OnPrefsChanged(std::move(updates));
32 } 32 }
33 33
34 void OnPrefRemoved(const std::string& key) const { 34 void OnPrefRemoved(const std::string& key) const {
35 if (!base::ContainsKey(prefs_, key)) 35 if (!base::ContainsKey(prefs_, key))
36 return; 36 return;
37 37
38 std::vector<mojom::PrefUpdatePtr> updates; 38 std::vector<mojom::PrefUpdatePtr> updates;
39 updates.push_back(mojom::PrefUpdate::New(key, nullptr, 0)); 39 updates.push_back(mojom::PrefUpdate::New(key, base::nullopt, 0));
40 observer_->OnPrefsChanged(std::move(updates)); 40 observer_->OnPrefsChanged(std::move(updates));
41 } 41 }
42 42
43 private: 43 private:
44 mojom::PrefStoreObserverPtr observer_; 44 mojom::PrefStoreObserverPtr observer_;
45 const std::unordered_set<std::string> prefs_; 45 const std::unordered_set<std::string> prefs_;
46 46
47 DISALLOW_COPY_AND_ASSIGN(Observer); 47 DISALLOW_COPY_AND_ASSIGN(Observer);
48 }; 48 };
49 49
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 void PrefStoreImpl::AddObserver( 99 void PrefStoreImpl::AddObserver(
100 const std::vector<std::string>& prefs_to_observe, 100 const std::vector<std::string>& prefs_to_observe,
101 const AddObserverCallback& callback) { 101 const AddObserverCallback& callback) {
102 mojom::PrefStoreObserverPtr observer_ptr; 102 mojom::PrefStoreObserverPtr observer_ptr;
103 auto request = mojo::MakeRequest(&observer_ptr); 103 auto request = mojo::MakeRequest(&observer_ptr);
104 observers_.push_back(base::MakeUnique<Observer>( 104 observers_.push_back(base::MakeUnique<Observer>(
105 std::move(observer_ptr), 105 std::move(observer_ptr),
106 std::unordered_set<std::string>(prefs_to_observe.begin(), 106 std::unordered_set<std::string>(prefs_to_observe.begin(),
107 prefs_to_observe.end()))); 107 prefs_to_observe.end())));
108 callback.Run(mojom::PrefStoreConnection::New( 108 callback.Run(mojom::PrefStoreConnection::New(
109 std::move(request), backing_pref_store_->GetValues(), 109 std::move(request), *backing_pref_store_->GetValues(),
110 backing_pref_store_->IsInitializationComplete())); 110 backing_pref_store_->IsInitializationComplete()));
111 } 111 }
112 112
113 } // namespace prefs 113 } // namespace prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698