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

Side by Side Diff: chrome/browser/prefs/pref_value_store.cc

Issue 11636018: Remove PrefValueStore's dependency on PrefModelAssociator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DEPS Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/prefs/pref_value_store.h" 5 #include "chrome/browser/prefs/pref_value_store.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_notifier.h" 8 #include "base/prefs/pref_notifier.h"
9 #include "chrome/browser/prefs/pref_model_associator.h" 9 #include "base/prefs/pref_observer.h"
10 10
11 PrefValueStore::PrefStoreKeeper::PrefStoreKeeper() 11 PrefValueStore::PrefStoreKeeper::PrefStoreKeeper()
12 : pref_value_store_(NULL), 12 : pref_value_store_(NULL),
13 type_(PrefValueStore::INVALID_STORE) { 13 type_(PrefValueStore::INVALID_STORE) {
14 } 14 }
15 15
16 PrefValueStore::PrefStoreKeeper::~PrefStoreKeeper() { 16 PrefValueStore::PrefStoreKeeper::~PrefStoreKeeper() {
17 if (pref_store_.get()) { 17 if (pref_store_.get()) {
18 pref_store_->RemoveObserver(this); 18 pref_store_->RemoveObserver(this);
19 pref_store_ = NULL; 19 pref_store_ = NULL;
(...skipping 26 matching lines...) Expand all
46 pref_value_store_->OnInitializationCompleted(type_, succeeded); 46 pref_value_store_->OnInitializationCompleted(type_, succeeded);
47 } 47 }
48 48
49 PrefValueStore::PrefValueStore(PrefStore* managed_prefs, 49 PrefValueStore::PrefValueStore(PrefStore* managed_prefs,
50 PrefStore* extension_prefs, 50 PrefStore* extension_prefs,
51 PrefStore* command_line_prefs, 51 PrefStore* command_line_prefs,
52 PrefStore* user_prefs, 52 PrefStore* user_prefs,
53 PrefStore* recommended_prefs, 53 PrefStore* recommended_prefs,
54 PrefStore* default_prefs, 54 PrefStore* default_prefs,
55 PrefNotifier* pref_notifier) 55 PrefNotifier* pref_notifier)
56 : pref_sync_associator_(NULL), 56 : pref_notifier_(pref_notifier),
57 pref_notifier_(pref_notifier),
58 initialization_failed_(false) { 57 initialization_failed_(false) {
59 InitPrefStore(MANAGED_STORE, managed_prefs); 58 InitPrefStore(MANAGED_STORE, managed_prefs);
60 InitPrefStore(EXTENSION_STORE, extension_prefs); 59 InitPrefStore(EXTENSION_STORE, extension_prefs);
61 InitPrefStore(COMMAND_LINE_STORE, command_line_prefs); 60 InitPrefStore(COMMAND_LINE_STORE, command_line_prefs);
62 InitPrefStore(USER_STORE, user_prefs); 61 InitPrefStore(USER_STORE, user_prefs);
63 InitPrefStore(RECOMMENDED_STORE, recommended_prefs); 62 InitPrefStore(RECOMMENDED_STORE, recommended_prefs);
64 InitPrefStore(DEFAULT_STORE, default_prefs); 63 InitPrefStore(DEFAULT_STORE, default_prefs);
65 64
66 CheckInitializationCompleted(); 65 CheckInitializationCompleted();
67 } 66 }
(...skipping 20 matching lines...) Expand all
88 if (!recommended_prefs) 87 if (!recommended_prefs)
89 recommended_prefs = GetPrefStore(RECOMMENDED_STORE); 88 recommended_prefs = GetPrefStore(RECOMMENDED_STORE);
90 if (!default_prefs) 89 if (!default_prefs)
91 default_prefs = GetPrefStore(DEFAULT_STORE); 90 default_prefs = GetPrefStore(DEFAULT_STORE);
92 91
93 return new PrefValueStore( 92 return new PrefValueStore(
94 managed_prefs, extension_prefs, command_line_prefs, user_prefs, 93 managed_prefs, extension_prefs, command_line_prefs, user_prefs,
95 recommended_prefs, default_prefs, pref_notifier); 94 recommended_prefs, default_prefs, pref_notifier);
96 } 95 }
97 96
98 void PrefValueStore::set_sync_associator(PrefModelAssociator* sync_associator) { 97 void PrefValueStore::set_callback(const PrefChangedCallback& callback) {
99 pref_sync_associator_ = sync_associator; 98 pref_changed_callback_ = callback;
100 } 99 }
101 100
102 bool PrefValueStore::GetValue(const std::string& name, 101 bool PrefValueStore::GetValue(const std::string& name,
103 base::Value::Type type, 102 base::Value::Type type,
104 const Value** out_value) const { 103 const Value** out_value) const {
105 // Check the |PrefStore|s in order of their priority from highest to lowest, 104 // Check the |PrefStore|s in order of their priority from highest to lowest,
106 // looking for the first preference value with the given |name| and |type|. 105 // looking for the first preference value with the given |name| and |type|.
107 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 106 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
108 if (GetValueFromStoreWithType(name.c_str(), type, 107 if (GetValueFromStoreWithType(name.c_str(), type,
109 static_cast<PrefStoreType>(i), out_value)) 108 static_cast<PrefStoreType>(i), out_value))
(...skipping 10 matching lines...) Expand all
120 } 119 }
121 120
122 void PrefValueStore::NotifyPrefChanged( 121 void PrefValueStore::NotifyPrefChanged(
123 const char* path, 122 const char* path,
124 PrefValueStore::PrefStoreType new_store) { 123 PrefValueStore::PrefStoreType new_store) {
125 DCHECK(new_store != INVALID_STORE); 124 DCHECK(new_store != INVALID_STORE);
126 // A notification is sent when the pref value in any store changes. If this 125 // A notification is sent when the pref value in any store changes. If this
127 // store is currently being overridden by a higher-priority store, the 126 // store is currently being overridden by a higher-priority store, the
128 // effective value of the pref will not have changed. 127 // effective value of the pref will not have changed.
129 pref_notifier_->OnPreferenceChanged(path); 128 pref_notifier_->OnPreferenceChanged(path);
130 if (pref_sync_associator_) 129 if (!pref_changed_callback_.is_null())
131 pref_sync_associator_->ProcessPrefChange(path); 130 pref_changed_callback_.Run(path);
132 } 131 }
133 132
134 bool PrefValueStore::PrefValueInManagedStore(const char* name) const { 133 bool PrefValueStore::PrefValueInManagedStore(const char* name) const {
135 return PrefValueInStore(name, MANAGED_STORE); 134 return PrefValueInStore(name, MANAGED_STORE);
136 } 135 }
137 136
138 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const { 137 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const {
139 return PrefValueInStore(name, EXTENSION_STORE); 138 return PrefValueInStore(name, EXTENSION_STORE);
140 } 139 }
141 140
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (initialization_failed_) 267 if (initialization_failed_)
269 return; 268 return;
270 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 269 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
271 scoped_refptr<PrefStore> store = 270 scoped_refptr<PrefStore> store =
272 GetPrefStore(static_cast<PrefStoreType>(i)); 271 GetPrefStore(static_cast<PrefStoreType>(i));
273 if (store && !store->IsInitializationComplete()) 272 if (store && !store->IsInitializationComplete())
274 return; 273 return;
275 } 274 }
276 pref_notifier_->OnInitializationCompleted(true); 275 pref_notifier_->OnInitializationCompleted(true);
277 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_value_store.h ('k') | chrome/browser/prefs/pref_value_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698