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_service.h" | 5 #include "chrome/browser/pref_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/histogram.h" | 12 #include "base/histogram.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/sys_string_conversions.h" | 18 #include "base/sys_string_conversions.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "chrome/browser/chrome_thread.h" | 21 #include "chrome/browser/chrome_thread.h" |
| 22 #include "chrome/browser/configuration_policy_pref_store.h" |
22 #include "chrome/browser/profile.h" | 23 #include "chrome/browser/profile.h" |
23 #include "chrome/browser/command_line_pref_store.h" | |
24 #include "chrome/browser/configuration_policy_pref_store.h" | |
25 #include "chrome/browser/extensions/extension_pref_store.h" | |
26 #include "chrome/common/json_pref_store.h" | |
27 #include "chrome/common/notification_service.h" | 24 #include "chrome/common/notification_service.h" |
28 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
29 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
30 | 27 |
31 namespace { | 28 namespace { |
32 | 29 |
33 // A helper function for RegisterLocalized*Pref that creates a Value* based on | 30 // A helper function for RegisterLocalized*Pref that creates a Value* based on |
34 // the string value in the locale dll. Because we control the values in a | 31 // the string value in the locale dll. Because we control the values in a |
35 // locale dll, this should always return a Value of the appropriate type. | 32 // locale dll, this should always return a Value of the appropriate type. |
36 Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { | 33 Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 Source<PrefService> source(pref); | 73 Source<PrefService> source(pref); |
77 NotificationService::current()->Notify(NotificationType::PROFILE_ERROR, | 74 NotificationService::current()->Notify(NotificationType::PROFILE_ERROR, |
78 source, Details<int>(&message_id)); | 75 source, Details<int>(&message_id)); |
79 } | 76 } |
80 | 77 |
81 } // namespace | 78 } // namespace |
82 | 79 |
83 // static | 80 // static |
84 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, | 81 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, |
85 Profile* profile) { | 82 Profile* profile) { |
86 ExtensionPrefStore* extension_prefs = new ExtensionPrefStore(profile); | 83 return new PrefService( |
87 CommandLinePrefStore* command_line_prefs = new CommandLinePrefStore( | 84 PrefValueStore::CreatePrefValueStore(pref_filename, profile, false)); |
88 CommandLine::ForCurrentProcess()); | |
89 PrefStore* local_prefs = new JsonPrefStore( | |
90 pref_filename, | |
91 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); | |
92 | |
93 // The PrefValueStore takes ownership of the PrefStores. | |
94 PrefValueStore* value_store = new PrefValueStore( | |
95 ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(), | |
96 extension_prefs, | |
97 command_line_prefs, | |
98 local_prefs, | |
99 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore()); | |
100 | |
101 return new PrefService(value_store); | |
102 } | 85 } |
103 | 86 |
104 // static | 87 // static |
105 PrefService* PrefService::CreateUserPrefService( | 88 PrefService* PrefService::CreateUserPrefService(const FilePath& pref_filename) { |
106 const FilePath& pref_filename) { | 89 return new PrefService( |
107 PrefValueStore* value_store = new PrefValueStore( | 90 PrefValueStore::CreatePrefValueStore(pref_filename, NULL, true)); |
108 NULL, /* no enforced prefs */ | |
109 NULL, /* no extension prefs */ | |
110 NULL, /* no command-line prefs */ | |
111 new JsonPrefStore( | |
112 pref_filename, | |
113 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)), | |
114 /* user prefs */ | |
115 NULL /* no advised prefs */); | |
116 return new PrefService(value_store); | |
117 } | 91 } |
118 | 92 |
119 PrefService::PrefService(PrefValueStore* pref_value_store) | 93 PrefService::PrefService(PrefValueStore* pref_value_store) |
120 : pref_value_store_(pref_value_store) { | 94 : pref_value_store_(pref_value_store) { |
121 InitFromStorage(); | 95 InitFromStorage(); |
122 registrar_.Add(this, | 96 registrar_.Add(this, |
123 NotificationType(NotificationType::POLICY_CHANGED), | 97 NotificationType(NotificationType::POLICY_CHANGED), |
124 NotificationService::AllSources()); | 98 NotificationService::AllSources()); |
125 } | 99 } |
126 | 100 |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 ChromeThread::PostTask( | 831 ChromeThread::PostTask( |
858 ChromeThread::UI, FROM_HERE, | 832 ChromeThread::UI, FROM_HERE, |
859 NewRunnableMethod( | 833 NewRunnableMethod( |
860 pref_value_store_.get(), | 834 pref_value_store_.get(), |
861 &PrefValueStore::RefreshPolicyPrefs, | 835 &PrefValueStore::RefreshPolicyPrefs, |
862 ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(), | 836 ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(), |
863 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(), | 837 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(), |
864 callback)); | 838 callback)); |
865 } | 839 } |
866 } | 840 } |
OLD | NEW |