OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/pref_value_store.h" | 5 #include "chrome/browser/pref_value_store.h" |
6 | |
7 #include "chrome/browser/chrome_thread.h" | |
8 #include "chrome/browser/command_line_pref_store.h" | |
9 #include "chrome/browser/configuration_policy_pref_store.h" | |
10 #include "chrome/browser/extensions/extension_pref_store.h" | |
11 #include "chrome/common/json_pref_store.h" | |
6 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
7 | 13 |
8 PrefValueStore::PrefValueStore(PrefStore* managed_prefs, | 14 // static |
9 PrefStore* extension_prefs, | 15 PrefValueStore* PrefValueStore::CreatePrefValueStore( |
10 PrefStore* command_line_prefs, | 16 const FilePath& pref_filename, |
11 PrefStore* user_prefs, | 17 Profile* profile, |
12 PrefStore* recommended_prefs) { | 18 bool user_only) { |
13 pref_stores_[MANAGED].reset(managed_prefs); | 19 ConfigurationPolicyPrefStore* managed = NULL; |
14 pref_stores_[EXTENSION].reset(extension_prefs); | 20 ExtensionPrefStore* extension = NULL; |
15 pref_stores_[COMMAND_LINE].reset(command_line_prefs); | 21 CommandLinePrefStore* command_line = NULL; |
16 pref_stores_[USER].reset(user_prefs); | 22 JsonPrefStore* user = NULL; |
17 pref_stores_[RECOMMENDED].reset(recommended_prefs); | 23 ConfigurationPolicyPrefStore* recommended = NULL; |
24 | |
25 if (!pref_filename.empty()) { | |
26 user = new JsonPrefStore( | |
27 pref_filename, | |
28 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); | |
29 } | |
30 | |
31 if (!user_only) { | |
32 managed = ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(); | |
33 extension = new ExtensionPrefStore(profile); | |
34 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); | |
35 recommended = | |
36 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); | |
37 } | |
38 return new PrefValueStore(managed, extension, command_line, user, | |
39 recommended); | |
18 } | 40 } |
19 | 41 |
20 PrefValueStore::~PrefValueStore() { } | 42 PrefValueStore::~PrefValueStore() {} |
21 | 43 |
22 bool PrefValueStore::GetValue(const std::wstring& name, | 44 bool PrefValueStore::GetValue(const std::wstring& name, |
23 Value** out_value) const { | 45 Value** out_value) const { |
24 // Check the |PrefStore|s in order of their priority from highest to lowest | 46 // Check the |PrefStore|s in order of their priority from highest to lowest |
25 // to find the value of the preference described by the given preference name. | 47 // to find the value of the preference described by the given preference name. |
26 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { | 48 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
27 if (pref_stores_[i].get() && | 49 if (pref_stores_[i].get() && |
28 pref_stores_[i]->prefs()->Get(name.c_str(), out_value)) { | 50 pref_stores_[i]->prefs()->Get(name.c_str(), out_value)) { |
29 return true; | 51 return true; |
30 } | 52 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 CHECK(ChromeThread::GetCurrentThreadIdentifier(¤t_thread_id)); | 226 CHECK(ChromeThread::GetCurrentThreadIdentifier(¤t_thread_id)); |
205 ChromeThread::PostTask( | 227 ChromeThread::PostTask( |
206 ChromeThread::FILE, FROM_HERE, | 228 ChromeThread::FILE, FROM_HERE, |
207 NewRunnableMethod(this, | 229 NewRunnableMethod(this, |
208 &PrefValueStore::RefreshPolicyPrefsOnFileThread, | 230 &PrefValueStore::RefreshPolicyPrefsOnFileThread, |
209 current_thread_id, | 231 current_thread_id, |
210 new_managed_pref_store, | 232 new_managed_pref_store, |
211 new_recommended_pref_store, | 233 new_recommended_pref_store, |
212 callback)); | 234 callback)); |
213 } | 235 } |
236 | |
237 PrefValueStore::PrefValueStore(PrefStore* managed_prefs, | |
238 PrefStore* extension_prefs, | |
239 PrefStore* command_line_prefs, | |
240 PrefStore* user_prefs, | |
241 PrefStore* recommended_prefs) { | |
242 pref_stores_[MANAGED].reset(managed_prefs); | |
243 pref_stores_[EXTENSION].reset(extension_prefs); | |
244 pref_stores_[COMMAND_LINE].reset(command_line_prefs); | |
245 pref_stores_[USER].reset(user_prefs); | |
246 pref_stores_[RECOMMENDED].reset(recommended_prefs); | |
247 } | |
Mattias Nissler (ping if slow)
2010/08/06 07:29:42
nit: Order of definitions doesn't correspond to or
| |
OLD | NEW |