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

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

Issue 2635093002: Switch Preferences to use Factory (Closed)
Patch Set: Missed test Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_observer_store.h" 5 #include "services/preferences/public/cpp/pref_observer_store.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "services/service_manager/public/cpp/connector.h" 9 #include "services/service_manager/public/cpp/connector.h"
10 10
11 namespace preferences { 11 namespace preferences {
12 12
13 PrefObserverStore::PrefObserverStore( 13 PrefObserverStore::PrefObserverStore(
14 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr) 14 prefs::mojom::PreferencesFactoryPtr pref_factory_ptr)
15 : prefs_binding_(this), 15 : prefs_binding_(this),
16 prefs_manager_ptr_(std::move(prefs_manager_ptr)), 16 pref_factory_ptr_(std::move(pref_factory_ptr)),
17 initialized_(false) {} 17 initialized_(false) {
18 pref_factory_ptr_->Create(prefs_binding_.CreateInterfacePtrAndBind(),
19 mojo::MakeRequest(&prefs_manager_ptr_));
20 }
18 21
19 void PrefObserverStore::Subscribe(const std::set<std::string>& keys) { 22 void PrefObserverStore::Subscribe(const std::set<std::string>& keys) {
20 if (keys_.empty())
21 prefs_manager_ptr_->AddObserver(prefs_binding_.CreateInterfacePtrAndBind());
22 keys_.insert(keys.begin(), keys.end()); 23 keys_.insert(keys.begin(), keys.end());
23 24
24 std::vector<std::string> pref_array; 25 std::vector<std::string> pref_array;
25 std::copy(keys_.begin(), keys_.end(), std::back_inserter(pref_array)); 26 std::copy(keys_.begin(), keys_.end(), std::back_inserter(pref_array));
26 prefs_manager_ptr_->Subscribe(pref_array); 27 prefs_manager_ptr_->Subscribe(pref_array);
27 } 28 }
28 29
29 bool PrefObserverStore::GetValue(const std::string& key, 30 bool PrefObserverStore::GetValue(const std::string& key,
30 const base::Value** value) const { 31 const base::Value** value) const {
31 DCHECK(initialized_); 32 DCHECK(initialized_);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 for (base::DictionaryValue::Iterator it(*preferences); !it.IsAtEnd(); 96 for (base::DictionaryValue::Iterator it(*preferences); !it.IsAtEnd();
96 it.Advance()) { 97 it.Advance()) {
97 if (keys_.find(it.key()) == keys_.end()) 98 if (keys_.find(it.key()) == keys_.end())
98 continue; 99 continue;
99 ValueMapPrefStore::SetValue(it.key(), it.value().CreateDeepCopy(), 0); 100 ValueMapPrefStore::SetValue(it.key(), it.value().CreateDeepCopy(), 0);
100 } 101 }
101 } 102 }
102 103
103 } // namespace preferences 104 } // namespace preferences
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698