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

Side by Side Diff: chrome/browser/pref_service.cc

Issue 3046023: Create factories for policy pref stores. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: fix mac compile failure Created 10 years, 5 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
« no previous file with comments | « chrome/browser/configuration_policy_pref_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/path_service.h"
16 #include "base/stl_util-inl.h" 15 #include "base/stl_util-inl.h"
17 #include "base/string_util.h" 16 #include "base/string_util.h"
18 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
19 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
20 #include "build/build_config.h" 19 #include "build/build_config.h"
21 #include "chrome/browser/chrome_thread.h" 20 #include "chrome/browser/chrome_thread.h"
22
23 #if defined(OS_WIN)
24 #include "chrome/browser/configuration_policy_provider_win.h"
25 #elif defined(OS_MACOSX)
26 #include "chrome/browser/configuration_policy_provider_mac.h"
27 #elif defined(OS_POSIX)
28 #include "chrome/browser/config_dir_policy_provider.h"
29 #endif
30 #include "chrome/browser/dummy_configuration_policy_provider.h"
31
32 #include "chrome/browser/command_line_pref_store.h" 21 #include "chrome/browser/command_line_pref_store.h"
33 #include "chrome/browser/configuration_policy_pref_store.h" 22 #include "chrome/browser/configuration_policy_pref_store.h"
34 #include "chrome/browser/extensions/extension_pref_store.h" 23 #include "chrome/browser/extensions/extension_pref_store.h"
35 #include "chrome/common/chrome_paths.h"
36 #include "chrome/common/json_pref_store.h" 24 #include "chrome/common/json_pref_store.h"
37 #include "chrome/common/notification_service.h" 25 #include "chrome/common/notification_service.h"
38 #include "grit/chromium_strings.h" 26 #include "grit/chromium_strings.h"
39 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
40 28
41 namespace { 29 namespace {
42 30
43 // A helper function for RegisterLocalized*Pref that creates a Value* based on 31 // A helper function for RegisterLocalized*Pref that creates a Value* based on
44 // the string value in the locale dll. Because we control the values in a 32 // the string value in the locale dll. Because we control the values in a
45 // locale dll, this should always return a Value of the appropriate type. 33 // locale dll, this should always return a Value of the appropriate type.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 void NotifyReadError(PrefService* pref, int message_id) { 74 void NotifyReadError(PrefService* pref, int message_id) {
87 Source<PrefService> source(pref); 75 Source<PrefService> source(pref);
88 NotificationService::current()->Notify(NotificationType::PROFILE_ERROR, 76 NotificationService::current()->Notify(NotificationType::PROFILE_ERROR,
89 source, Details<int>(&message_id)); 77 source, Details<int>(&message_id));
90 } 78 }
91 79
92 } // namespace 80 } // namespace
93 81
94 // static 82 // static
95 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename) { 83 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename) {
96 PrefStore* managed_prefs = NULL;
97 // TODO(pamg): Reinstate extension pref store after Mstone6 branch, when its 84 // TODO(pamg): Reinstate extension pref store after Mstone6 branch, when its
98 // memory leaks are fixed and any extension API is using it. 85 // memory leaks are fixed and any extension API is using it.
99 // ExtensionPrefStore* extension_prefs = new ExtensionPrefStore(NULL); 86 // ExtensionPrefStore* extension_prefs = new ExtensionPrefStore(NULL);
100 ExtensionPrefStore* extension_prefs = NULL; 87 ExtensionPrefStore* extension_prefs = NULL;
101 CommandLinePrefStore* command_line_prefs = new CommandLinePrefStore( 88 CommandLinePrefStore* command_line_prefs = new CommandLinePrefStore(
102 CommandLine::ForCurrentProcess()); 89 CommandLine::ForCurrentProcess());
103 PrefStore* local_prefs = new JsonPrefStore( 90 PrefStore* local_prefs = new JsonPrefStore(
104 pref_filename, 91 pref_filename,
105 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); 92 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE));
106 PrefStore* recommended_prefs = NULL;
107
108 ConfigurationPolicyProvider* managed_prefs_provider = NULL;
109 ConfigurationPolicyProvider* recommended_prefs_provider = NULL;
110
111 #if defined(OS_WIN)
112 managed_prefs_provider = new ConfigurationPolicyProviderWin();
113 recommended_prefs_provider = new DummyConfigurationPolicyProvider();
114 #elif defined(OS_MACOSX)
115 managed_prefs_provider = new ConfigurationPolicyProviderMac();
116 recommended_prefs_provider = new DummyConfigurationPolicyProvider();
117 #elif defined(OS_POSIX)
118 FilePath config_dir_path;
119 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) {
120 managed_prefs_provider = new ConfigDirPolicyProvider(
121 config_dir_path.Append(FILE_PATH_LITERAL("managed")));
122 recommended_prefs_provider = new ConfigDirPolicyProvider(
123 config_dir_path.Append(FILE_PATH_LITERAL("recommended")));
124 } else {
125 managed_prefs_provider = new DummyConfigurationPolicyProvider();
126 recommended_prefs_provider = new DummyConfigurationPolicyProvider();
127 }
128 #endif
129
130 // The ConfigurationPolicyPrefStore takes ownership of the passed
131 // |provider|.
132 managed_prefs = new ConfigurationPolicyPrefStore(
133 CommandLine::ForCurrentProcess(),
134 managed_prefs_provider);
135 recommended_prefs = new ConfigurationPolicyPrefStore(
136 CommandLine::ForCurrentProcess(),
137 recommended_prefs_provider);
138 93
139 // The PrefValueStore takes ownership of the PrefStores. 94 // The PrefValueStore takes ownership of the PrefStores.
140 PrefValueStore* value_store = new PrefValueStore( 95 PrefValueStore* value_store = new PrefValueStore(
141 managed_prefs, 96 ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(),
142 extension_prefs, 97 extension_prefs,
143 command_line_prefs, 98 command_line_prefs,
144 local_prefs, 99 local_prefs,
145 recommended_prefs); 100 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore());
146 101
147 PrefService* pref_service = new PrefService(value_store); 102 PrefService* pref_service = new PrefService(value_store);
148 // TODO(pamg): Uncomment when ExtensionPrefStore is reinstated. 103 // TODO(pamg): Uncomment when ExtensionPrefStore is reinstated.
149 // extension_prefs->SetPrefService(pref_service); 104 // extension_prefs->SetPrefService(pref_service);
150 105
151 return pref_service; 106 return pref_service;
152 } 107 }
153 108
154 // static 109 // static
155 PrefService* PrefService::CreateUserPrefService( 110 PrefService* PrefService::CreateUserPrefService(
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 return pref_value_store_->PrefValueFromExtensionStore(name_.c_str()); 824 return pref_value_store_->PrefValueFromExtensionStore(name_.c_str());
870 } 825 }
871 826
872 bool PrefService::Preference::IsUserControlled() const { 827 bool PrefService::Preference::IsUserControlled() const {
873 return pref_value_store_->PrefValueFromUserStore(name_.c_str()); 828 return pref_value_store_->PrefValueFromUserStore(name_.c_str());
874 } 829 }
875 830
876 bool PrefService::Preference::IsUserModifiable() const { 831 bool PrefService::Preference::IsUserModifiable() const {
877 return pref_value_store_->PrefValueUserModifiable(name_.c_str()); 832 return pref_value_store_->PrefValueUserModifiable(name_.c_str());
878 } 833 }
OLDNEW
« no previous file with comments | « chrome/browser/configuration_policy_pref_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698