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