Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_service.h" | 5 #include "chrome/browser/prefs/pref_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/value_conversions.h" | 20 #include "base/value_conversions.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/extensions/extension_pref_store.h" | 23 #include "chrome/browser/extensions/extension_pref_store.h" |
| 24 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 24 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 25 #include "chrome/browser/prefs/command_line_pref_store.h" | 25 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 26 #include "chrome/browser/prefs/default_pref_store.h" | 26 #include "chrome/browser/prefs/default_pref_store.h" |
| 27 #include "chrome/browser/prefs/incognito_user_pref_store.h" | 27 #include "chrome/browser/prefs/overlay_user_pref_store.h" |
| 28 #include "chrome/browser/prefs/per_tab_user_pref_store.h" | |
| 29 #include "chrome/browser/prefs/pref_model_associator.h" | 28 #include "chrome/browser/prefs/pref_model_associator.h" |
| 30 #include "chrome/browser/prefs/pref_notifier_impl.h" | 29 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 31 #include "chrome/browser/prefs/pref_value_store.h" | 30 #include "chrome/browser/prefs/pref_value_store.h" |
| 32 #include "chrome/browser/ui/profile_error_dialog.h" | 31 #include "chrome/browser/ui/profile_error_dialog.h" |
| 33 #include "chrome/common/json_pref_store.h" | 32 #include "chrome/common/json_pref_store.h" |
| 33 #include "chrome/common/pref_names.h" | |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 38 | 38 |
| 39 using content::BrowserThread; | 39 using content::BrowserThread; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // A helper function for RegisterLocalized*Pref that creates a Value* based on | 43 // A helper function for RegisterLocalized*Pref that creates a Value* based on |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 if (message_id) { | 104 if (message_id) { |
| 105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 106 base::Bind(&NotifyReadError, message_id)); | 106 base::Bind(&NotifyReadError, message_id)); |
| 107 } | 107 } |
| 108 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, | 108 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
| 109 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | 109 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 static void InitIncognitoUserPrefStore(OverlayUserPrefStore* pref_store) { | |
|
Bernhard Bauer
2011/12/30 17:54:16
You could move this into browser_prefs.cc, where t
| |
| 115 // List of keys that cannot be changed in the user prefs file by the incognito | |
| 116 // profile. All preferences that store information about the browsing history | |
| 117 // or behavior of the user should have this property. | |
| 118 pref_store->RegisterOverlayPref(prefs::kBrowserWindowPlacement); | |
| 119 } | |
| 120 | |
| 121 static void InitPerTabUserPrefStore(OverlayUserPrefStore* pref_store) { | |
| 122 // List of keys that have per-tab and per-profile (Global) counterpart. | |
| 123 // Setting a per-profile preference affects all tabs sharing the profile, | |
| 124 // unless a tab has specified its own per-tab property value. Changing a | |
| 125 // per-profile preference on a per-tab pref store delegates to underlay | |
| 126 // per-profile pref store. | |
| 127 pref_store->RegisterOverlayPref( | |
| 128 prefs::kWebKitJavascriptEnabled, | |
| 129 prefs::kWebKitGlobalJavascriptEnabled); | |
| 130 pref_store->RegisterOverlayPref( | |
| 131 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, | |
| 132 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically); | |
| 133 pref_store->RegisterOverlayPref( | |
| 134 prefs::kWebKitLoadsImagesAutomatically, | |
| 135 prefs::kWebKitGlobalLoadsImagesAutomatically); | |
| 136 pref_store->RegisterOverlayPref( | |
| 137 prefs::kWebKitPluginsEnabled, | |
| 138 prefs::kWebKitGlobalPluginsEnabled); | |
| 139 pref_store->RegisterOverlayPref( | |
| 140 prefs::kDefaultCharset, | |
| 141 prefs::kGlobalDefaultCharset); | |
| 142 pref_store->RegisterOverlayPref( | |
| 143 prefs::kWebKitStandardFontFamily, | |
| 144 prefs::kWebKitGlobalStandardFontFamily); | |
| 145 pref_store->RegisterOverlayPref( | |
| 146 prefs::kWebKitFixedFontFamily, | |
| 147 prefs::kWebKitGlobalFixedFontFamily); | |
| 148 pref_store->RegisterOverlayPref( | |
| 149 prefs::kWebKitSerifFontFamily, | |
| 150 prefs::kWebKitGlobalSerifFontFamily); | |
| 151 pref_store->RegisterOverlayPref( | |
| 152 prefs::kWebKitSansSerifFontFamily, | |
| 153 prefs::kWebKitGlobalSansSerifFontFamily); | |
| 154 pref_store->RegisterOverlayPref( | |
| 155 prefs::kWebKitCursiveFontFamily, | |
| 156 prefs::kWebKitGlobalCursiveFontFamily); | |
| 157 pref_store->RegisterOverlayPref( | |
| 158 prefs::kWebKitFantasyFontFamily, | |
| 159 prefs::kWebKitGlobalFantasyFontFamily); | |
| 160 pref_store->RegisterOverlayPref( | |
| 161 prefs::kWebKitDefaultFontSize, | |
| 162 prefs::kWebKitGlobalDefaultFontSize); | |
| 163 pref_store->RegisterOverlayPref( | |
| 164 prefs::kWebKitDefaultFixedFontSize, | |
| 165 prefs::kWebKitGlobalDefaultFixedFontSize); | |
| 166 pref_store->RegisterOverlayPref( | |
| 167 prefs::kWebKitMinimumFontSize, | |
| 168 prefs::kWebKitGlobalMinimumFontSize); | |
| 169 pref_store->RegisterOverlayPref( | |
| 170 prefs::kWebKitMinimumLogicalFontSize, | |
| 171 prefs::kWebKitGlobalMinimumLogicalFontSize); | |
| 172 } | |
| 173 | |
| 114 } // namespace | 174 } // namespace |
| 115 | 175 |
| 116 // static | 176 // static |
| 117 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, | 177 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, |
| 118 PrefStore* extension_prefs, | 178 PrefStore* extension_prefs, |
| 119 bool async) { | 179 bool async) { |
| 120 using policy::ConfigurationPolicyPrefStore; | 180 using policy::ConfigurationPolicyPrefStore; |
| 121 | 181 |
| 122 #if defined(OS_LINUX) | 182 #if defined(OS_LINUX) |
| 123 // We'd like to see what fraction of our users have the preferences | 183 // We'd like to see what fraction of our users have the preferences |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 pref_notifier), | 233 pref_notifier), |
| 174 user, | 234 user, |
| 175 default_pref_store, | 235 default_pref_store, |
| 176 pref_sync_associator, | 236 pref_sync_associator, |
| 177 async); | 237 async); |
| 178 } | 238 } |
| 179 | 239 |
| 180 PrefService* PrefService::CreateIncognitoPrefService( | 240 PrefService* PrefService::CreateIncognitoPrefService( |
| 181 PrefStore* incognito_extension_prefs) { | 241 PrefStore* incognito_extension_prefs) { |
| 182 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); | 242 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 183 PersistentPrefStore* incognito_pref_store = | 243 OverlayUserPrefStore* incognito_pref_store = |
| 184 new IncognitoUserPrefStore(user_pref_store_.get()); | 244 new OverlayUserPrefStore(user_pref_store_.get()); |
| 245 InitIncognitoUserPrefStore(incognito_pref_store); | |
| 185 return new PrefService( | 246 return new PrefService( |
| 186 pref_notifier, | 247 pref_notifier, |
| 187 pref_value_store_->CloneAndSpecialize( | 248 pref_value_store_->CloneAndSpecialize( |
| 188 NULL, // managed_platform_prefs | 249 NULL, // managed_platform_prefs |
| 189 NULL, // managed_cloud_prefs | 250 NULL, // managed_cloud_prefs |
| 190 incognito_extension_prefs, | 251 incognito_extension_prefs, |
| 191 NULL, // command_line_prefs | 252 NULL, // command_line_prefs |
| 192 incognito_pref_store, | 253 incognito_pref_store, |
| 193 NULL, // recommended_platform_prefs | 254 NULL, // recommended_platform_prefs |
| 194 NULL, // recommended_cloud_prefs | 255 NULL, // recommended_cloud_prefs |
| 195 default_store_.get(), | 256 default_store_.get(), |
| 196 NULL, // pref_sync_associator | 257 NULL, // pref_sync_associator |
| 197 pref_notifier), | 258 pref_notifier), |
| 198 incognito_pref_store, | 259 incognito_pref_store, |
| 199 default_store_.get(), | 260 default_store_.get(), |
| 200 NULL, | 261 NULL, |
| 201 false); | 262 false); |
| 202 } | 263 } |
| 203 | 264 |
| 204 PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { | 265 PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { |
| 205 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); | 266 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 206 PersistentPrefStore* per_tab_pref_store = | 267 OverlayUserPrefStore* per_tab_pref_store = |
| 207 new PerTabUserPrefStore(user_pref_store_.get()); | 268 new OverlayUserPrefStore(user_pref_store_.get()); |
| 269 InitPerTabUserPrefStore(per_tab_pref_store); | |
| 208 DefaultPrefStore* default_store = new DefaultPrefStore(); | 270 DefaultPrefStore* default_store = new DefaultPrefStore(); |
| 209 return new PrefService( | 271 return new PrefService( |
| 210 pref_notifier, | 272 pref_notifier, |
| 211 pref_value_store_->CloneAndSpecialize( | 273 pref_value_store_->CloneAndSpecialize( |
| 212 NULL, // managed_platform_prefs | 274 NULL, // managed_platform_prefs |
| 213 NULL, // managed_cloud_prefs | 275 NULL, // managed_cloud_prefs |
| 214 NULL, // extension_prefs | 276 NULL, // extension_prefs |
| 215 NULL, // command_line_prefs | 277 NULL, // command_line_prefs |
| 216 per_tab_pref_store, | 278 per_tab_pref_store, |
| 217 NULL, // recommended_platform_prefs | 279 NULL, // recommended_platform_prefs |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 1002 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 941 } | 1003 } |
| 942 | 1004 |
| 943 bool PrefService::Preference::IsUserModifiable() const { | 1005 bool PrefService::Preference::IsUserModifiable() const { |
| 944 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 1006 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 945 } | 1007 } |
| 946 | 1008 |
| 947 bool PrefService::Preference::IsExtensionModifiable() const { | 1009 bool PrefService::Preference::IsExtensionModifiable() const { |
| 948 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 1010 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 949 } | 1011 } |
| OLD | NEW |