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/incognito_user_pref_store.h" |
| 28 #include "chrome/browser/prefs/per_tab_user_pref_store.h" | |
| 28 #include "chrome/browser/prefs/pref_model_associator.h" | 29 #include "chrome/browser/prefs/pref_model_associator.h" |
| 29 #include "chrome/browser/prefs/pref_notifier_impl.h" | 30 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 30 #include "chrome/browser/prefs/pref_value_store.h" | 31 #include "chrome/browser/prefs/pref_value_store.h" |
| 31 #include "chrome/browser/ui/profile_error_dialog.h" | 32 #include "chrome/browser/ui/profile_error_dialog.h" |
| 32 #include "chrome/common/json_pref_store.h" | 33 #include "chrome/common/json_pref_store.h" |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 34 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
| 35 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 | 38 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 ConfigurationPolicyPrefStore* managed_cloud = NULL; | 146 ConfigurationPolicyPrefStore* managed_cloud = NULL; |
| 146 ConfigurationPolicyPrefStore* recommended_platform = NULL; | 147 ConfigurationPolicyPrefStore* recommended_platform = NULL; |
| 147 ConfigurationPolicyPrefStore* recommended_cloud = NULL; | 148 ConfigurationPolicyPrefStore* recommended_cloud = NULL; |
| 148 #endif // ENABLE_CONFIGURATION_POLICY | 149 #endif // ENABLE_CONFIGURATION_POLICY |
| 149 | 150 |
| 150 CommandLinePrefStore* command_line = | 151 CommandLinePrefStore* command_line = |
| 151 new CommandLinePrefStore(CommandLine::ForCurrentProcess()); | 152 new CommandLinePrefStore(CommandLine::ForCurrentProcess()); |
| 152 JsonPrefStore* user = new JsonPrefStore( | 153 JsonPrefStore* user = new JsonPrefStore( |
| 153 pref_filename, | 154 pref_filename, |
| 154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 155 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| 155 DefaultPrefStore* default_pref_store = new DefaultPrefStore(); | 156 |
| 156 | 157 |
| 157 return new PrefService( | 158 return new PrefService( |
| 158 managed_platform, managed_cloud, extension_prefs, | 159 new PrefValueStore(managed_platform, |
| 159 command_line, user, recommended_platform, | 160 managed_cloud, |
| 160 recommended_cloud, default_pref_store, async); | 161 extension_prefs, |
| 162 command_line, | |
| 163 user, | |
| 164 recommended_platform, | |
| 165 recommended_cloud, | |
| 166 new DefaultPrefStore(), | |
| 167 new PrefModelAssociator(), | |
| 168 new PrefNotifierImpl()), | |
| 169 async); | |
| 161 } | 170 } |
| 162 | 171 |
| 163 PrefService* PrefService::CreateIncognitoPrefService( | 172 PrefService* PrefService::CreateIncognitoPrefService( |
| 164 PrefStore* incognito_extension_prefs) { | 173 PrefStore* incognito_extension_prefs) { |
| 165 return new PrefService(*this, incognito_extension_prefs); | 174 return new PrefService( |
| 175 pref_value_store_->CloneAndSpecialize( | |
| 176 NULL, // managed_platform_prefs | |
| 177 NULL, // managed_cloud_prefs | |
| 178 incognito_extension_prefs, | |
| 179 NULL, // command_line_prefs | |
| 180 new IncognitoUserPrefStore(user_pref_store_.get()), | |
| 181 NULL, // recommended_platform_prefs | |
| 182 NULL, // recommended_cloud_prefs | |
| 183 default_store_.get(), | |
| 184 // Incognito mode doesn't sync, so no need to create | |
| 185 // PrefModelAssociator. | |
| 186 NULL, // pref_sync_associator | |
| 187 // TODO(mnissler,mnaganov): This PrefNotifier needs to listen for | |
| 188 // notifications from the original |pref_notifier_| and forward | |
| 189 // notifications. We need to implement a wrapper that does this. | |
|
Mattias Nissler (ping if slow)
2011/11/16 12:08:04
I originally thought this would be a problem, but
mnaganov (inactive)
2011/11/17 16:50:58
Done.
| |
| 190 new PrefNotifierImpl()), | |
| 191 false); | |
| 166 } | 192 } |
| 167 | 193 |
| 168 PrefService::PrefService(PrefStore* managed_platform_prefs, | 194 PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { |
| 169 PrefStore* managed_cloud_prefs, | 195 return new PrefService( |
| 170 PrefStore* extension_prefs, | 196 pref_value_store_->CloneAndSpecialize( |
| 171 PrefStore* command_line_prefs, | 197 NULL, // managed_platform_prefs |
| 172 PersistentPrefStore* user_prefs, | 198 NULL, // managed_cloud_prefs |
| 173 PrefStore* recommended_platform_prefs, | 199 NULL, // extension_prefs |
| 174 PrefStore* recommended_cloud_prefs, | 200 NULL, // command_line_prefs |
| 175 DefaultPrefStore* default_store, | 201 new PerTabUserPrefStore(user_pref_store_.get()), |
| 176 bool async) | 202 NULL, // recommended_platform_prefs |
| 177 : user_pref_store_(user_prefs), | 203 NULL, // recommended_cloud_prefs |
| 178 default_store_(default_store) { | 204 new DefaultPrefStore(), |
| 179 pref_sync_associator_.reset(new PrefModelAssociator(this)); | 205 NULL, // pref_sync_associator |
| 180 pref_notifier_.reset(new PrefNotifierImpl(this)); | 206 new PrefNotifierImpl()), |
| 181 pref_value_store_.reset( | 207 false); |
| 182 new PrefValueStore(managed_platform_prefs, | |
| 183 managed_cloud_prefs, | |
| 184 extension_prefs, | |
| 185 command_line_prefs, | |
| 186 user_pref_store_, | |
| 187 recommended_platform_prefs, | |
| 188 recommended_cloud_prefs, | |
| 189 default_store, | |
| 190 pref_sync_associator_.get(), | |
| 191 pref_notifier_.get())); | |
| 192 InitFromStorage(async); | |
| 193 } | 208 } |
| 194 | 209 |
| 195 PrefService::PrefService(const PrefService& original, | 210 PrefService::PrefService(PrefValueStore* pref_value_store, |
| 196 PrefStore* incognito_extension_prefs) | 211 bool async) |
| 197 : user_pref_store_( | 212 : pref_value_store_(pref_value_store), |
| 198 new IncognitoUserPrefStore(original.user_pref_store_.get())), | 213 pref_notifier_(reinterpret_cast<PrefNotifierImpl*>( |
| 199 default_store_(original.default_store_.get()) { | 214 pref_value_store_->pref_notifier_)), |
|
Mattias Nissler (ping if slow)
2011/11/16 12:08:04
Suggestion: To avoid this cast, maybe it's better
mnaganov (inactive)
2011/11/17 16:50:58
I've reconsidered the approach to PrefService init
| |
| 200 // Incognito mode doesn't sync, so no need to create PrefModelAssociator. | 215 user_pref_store_(reinterpret_cast<PersistentPrefStore*>( |
| 201 pref_notifier_.reset(new PrefNotifierImpl(this)); | 216 pref_value_store_->GetPrefStore(PrefValueStore::USER_STORE))), |
|
Mattias Nissler (ping if slow)
2011/11/16 12:08:04
These casts suck. Can we just pass on the properly
mnaganov (inactive)
2011/11/17 16:50:58
Fixed.
| |
| 202 pref_value_store_.reset(original.pref_value_store_->CloneAndSpecialize( | 217 default_store_(reinterpret_cast<DefaultPrefStore*>( |
| 203 NULL, // managed_platform_prefs | 218 pref_value_store_->GetPrefStore(PrefValueStore::DEFAULT_STORE))), |
| 204 NULL, // managed_cloud_prefs | 219 pref_sync_associator_(pref_value_store_->pref_sync_associator_) { |
|
Mattias Nissler (ping if slow)
2011/11/16 12:08:04
This seems weird. Pass it in a parameter?
mnaganov (inactive)
2011/11/17 16:50:58
Fixed.
| |
| 205 incognito_extension_prefs, | 220 pref_notifier_->SetPrefService(this); |
| 206 NULL, // command_line_prefs | 221 if (pref_sync_associator_.get()) |
| 207 user_pref_store_.get(), | 222 pref_sync_associator_->SetPrefService(this); |
| 208 NULL, // recommended_platform_prefs | 223 pref_notifier_->SetPrefModelAssociator(pref_sync_associator_.get()); |
| 209 NULL, // recommended_cloud_prefs | 224 InitFromStorage(async); |
| 210 default_store_.get(), | |
| 211 NULL, // pref_sync_associator_ | |
| 212 pref_notifier_.get())); | |
| 213 } | 225 } |
| 214 | 226 |
| 215 PrefService::~PrefService() { | 227 PrefService::~PrefService() { |
| 216 DCHECK(CalledOnValidThread()); | 228 DCHECK(CalledOnValidThread()); |
| 217 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); | 229 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); |
| 218 prefs_.clear(); | 230 prefs_.clear(); |
| 219 | 231 |
| 220 // Reset pointers so accesses after destruction reliably crash. | 232 // Reset pointers so accesses after destruction reliably crash. |
| 221 pref_value_store_.reset(); | 233 pref_value_store_.reset(); |
| 222 user_pref_store_ = NULL; | 234 user_pref_store_ = NULL; |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 909 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 898 } | 910 } |
| 899 | 911 |
| 900 bool PrefService::Preference::IsUserModifiable() const { | 912 bool PrefService::Preference::IsUserModifiable() const { |
| 901 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 913 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 902 } | 914 } |
| 903 | 915 |
| 904 bool PrefService::Preference::IsExtensionModifiable() const { | 916 bool PrefService::Preference::IsExtensionModifiable() const { |
| 905 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 917 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 906 } | 918 } |
| OLD | NEW |