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

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 12079097: Introduce PrefRegistrySyncable, simplifying PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head again; base::File changes conflicted. Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "chrome/browser/net/chrome_url_request_context.h" 48 #include "chrome/browser/net/chrome_url_request_context.h"
49 #include "chrome/browser/net/net_pref_observer.h" 49 #include "chrome/browser/net/net_pref_observer.h"
50 #include "chrome/browser/net/predictor.h" 50 #include "chrome/browser/net/predictor.h"
51 #include "chrome/browser/net/proxy_service_factory.h" 51 #include "chrome/browser/net/proxy_service_factory.h"
52 #include "chrome/browser/net/ssl_config_service_manager.h" 52 #include "chrome/browser/net/ssl_config_service_manager.h"
53 #include "chrome/browser/net/url_fixer_upper.h" 53 #include "chrome/browser/net/url_fixer_upper.h"
54 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 54 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
55 #include "chrome/browser/plugins/plugin_prefs.h" 55 #include "chrome/browser/plugins/plugin_prefs.h"
56 #include "chrome/browser/prefs/browser_prefs.h" 56 #include "chrome/browser/prefs/browser_prefs.h"
57 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 57 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
58 #include "chrome/browser/prefs/pref_registry_syncable.h"
59 #include "chrome/browser/prefs/pref_service_syncable.h"
58 #include "chrome/browser/prefs/scoped_user_pref_update.h" 60 #include "chrome/browser/prefs/scoped_user_pref_update.h"
59 #include "chrome/browser/prerender/prerender_manager_factory.h" 61 #include "chrome/browser/prerender/prerender_manager_factory.h"
60 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" 62 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
61 #include "chrome/browser/profiles/chrome_version_service.h" 63 #include "chrome/browser/profiles/chrome_version_service.h"
62 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" 64 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
63 #include "chrome/browser/profiles/profile_dependency_manager.h" 65 #include "chrome/browser/profiles/profile_dependency_manager.h"
64 #include "chrome/browser/profiles/profile_destroyer.h" 66 #include "chrome/browser/profiles/profile_destroyer.h"
65 #include "chrome/browser/profiles/profile_info_cache.h" 67 #include "chrome/browser/profiles/profile_info_cache.h"
66 #include "chrome/browser/profiles/profile_manager.h" 68 #include "chrome/browser/profiles/profile_manager.h"
67 #include "chrome/browser/search_engines/template_url_fetcher.h" 69 #include "chrome/browser/search_engines/template_url_fetcher.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner); 265 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner);
264 } 266 }
265 267
266 // static 268 // static
267 int ProfileImpl::create_readme_delay_ms = 60000; 269 int ProfileImpl::create_readme_delay_ms = 60000;
268 270
269 // static 271 // static
270 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; 272 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal";
271 273
272 // static 274 // static
273 void ProfileImpl::RegisterUserPrefs(PrefServiceSyncable* prefs) { 275 void ProfileImpl::RegisterUserPrefs(PrefRegistrySyncable* registry) {
274 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, 276 registry->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled,
275 false, 277 false,
276 PrefServiceSyncable::UNSYNCABLE_PREF); 278 PrefRegistrySyncable::UNSYNCABLE_PREF);
277 prefs->RegisterBooleanPref(prefs::kForceSafeSearch, 279 registry->RegisterBooleanPref(prefs::kForceSafeSearch,
278 false, 280 false,
279 PrefServiceSyncable::UNSYNCABLE_PREF); 281 PrefRegistrySyncable::UNSYNCABLE_PREF);
280 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, 282 registry->RegisterIntegerPref(prefs::kProfileAvatarIndex,
281 -1, 283 -1,
282 PrefServiceSyncable::SYNCABLE_PREF); 284 PrefRegistrySyncable::SYNCABLE_PREF);
283 prefs->RegisterStringPref(prefs::kProfileName, 285 registry->RegisterStringPref(prefs::kProfileName,
284 "", 286 "",
285 PrefServiceSyncable::SYNCABLE_PREF); 287 PrefRegistrySyncable::SYNCABLE_PREF);
286 prefs->RegisterBooleanPref(prefs::kProfileIsManaged, 288 registry->RegisterBooleanPref(prefs::kProfileIsManaged,
287 false, 289 false,
288 PrefServiceSyncable::SYNCABLE_PREF); 290 PrefRegistrySyncable::SYNCABLE_PREF);
289 prefs->RegisterStringPref(prefs::kHomePage, 291 registry->RegisterStringPref(prefs::kHomePage,
290 std::string(), 292 std::string(),
291 PrefServiceSyncable::SYNCABLE_PREF); 293 PrefRegistrySyncable::SYNCABLE_PREF);
292 #if defined(ENABLE_PRINTING) 294 #if defined(ENABLE_PRINTING)
293 prefs->RegisterBooleanPref(prefs::kPrintingEnabled, 295 registry->RegisterBooleanPref(prefs::kPrintingEnabled,
294 true, 296 true,
295 PrefServiceSyncable::UNSYNCABLE_PREF); 297 PrefRegistrySyncable::UNSYNCABLE_PREF);
296 #endif 298 #endif
297 prefs->RegisterBooleanPref(prefs::kPrintPreviewDisabled, 299 registry->RegisterBooleanPref(prefs::kPrintPreviewDisabled,
298 #if defined(GOOGLE_CHROME_BUILD) 300 #if defined(GOOGLE_CHROME_BUILD)
299 false, 301 false,
300 #else 302 #else
301 true, 303 true,
302 #endif 304 #endif
303 PrefServiceSyncable::UNSYNCABLE_PREF); 305 PrefRegistrySyncable::UNSYNCABLE_PREF);
304 306
305 // Initialize the cache prefs. 307 // Initialize the cache prefs.
306 prefs->RegisterFilePathPref(prefs::kDiskCacheDir, 308 registry->RegisterFilePathPref(prefs::kDiskCacheDir,
307 base::FilePath(), 309 base::FilePath(),
308 PrefServiceSyncable::UNSYNCABLE_PREF); 310 PrefRegistrySyncable::UNSYNCABLE_PREF);
309 prefs->RegisterIntegerPref(prefs::kDiskCacheSize, 311 registry->RegisterIntegerPref(prefs::kDiskCacheSize,
310 0, 312 0,
311 PrefServiceSyncable::UNSYNCABLE_PREF); 313 PrefRegistrySyncable::UNSYNCABLE_PREF);
312 prefs->RegisterIntegerPref(prefs::kMediaCacheSize, 314 registry->RegisterIntegerPref(prefs::kMediaCacheSize,
313 0, 315 0,
314 PrefServiceSyncable::UNSYNCABLE_PREF); 316 PrefRegistrySyncable::UNSYNCABLE_PREF);
315 317
316 // Deprecated. Kept around for migration. 318 // Deprecated. Kept around for migration.
317 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, 319 registry->RegisterBooleanPref(prefs::kClearSiteDataOnExit,
318 false, 320 false,
319 PrefServiceSyncable::SYNCABLE_PREF); 321 PrefRegistrySyncable::SYNCABLE_PREF);
320 } 322 }
321 323
322 ProfileImpl::ProfileImpl( 324 ProfileImpl::ProfileImpl(
323 const base::FilePath& path, 325 const base::FilePath& path,
324 Delegate* delegate, 326 Delegate* delegate,
325 CreateMode create_mode, 327 CreateMode create_mode,
326 base::SequencedTaskRunner* sequenced_task_runner) 328 base::SequencedTaskRunner* sequenced_task_runner)
327 : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged, 329 : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged,
328 base::Unretained(this))), 330 base::Unretained(this))),
329 path_(path), 331 path_(path),
332 pref_registry_(new PrefRegistrySyncable),
330 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), 333 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
331 host_content_settings_map_(NULL), 334 host_content_settings_map_(NULL),
332 last_session_exit_type_(EXIT_NORMAL), 335 last_session_exit_type_(EXIT_NORMAL),
333 start_time_(Time::Now()), 336 start_time_(Time::Now()),
334 delegate_(delegate), 337 delegate_(delegate),
335 predictor_(NULL) { 338 predictor_(NULL) {
336 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 339 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
337 "profile files to the root directory!"; 340 "profile files to the root directory!";
338 341
339 #if defined(ENABLE_SESSION_SERVICE) 342 #if defined(ENABLE_SESSION_SERVICE)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 policy_service_ = 378 policy_service_ =
376 g_browser_process->browser_policy_connector()->CreatePolicyService(this); 379 g_browser_process->browser_policy_connector()->CreatePolicyService(this);
377 #else 380 #else
378 policy_service_.reset(new policy::PolicyServiceStub()); 381 policy_service_.reset(new policy::PolicyServiceStub());
379 #endif 382 #endif
380 383
381 DCHECK(create_mode == CREATE_MODE_ASYNCHRONOUS || 384 DCHECK(create_mode == CREATE_MODE_ASYNCHRONOUS ||
382 create_mode == CREATE_MODE_SYNCHRONOUS); 385 create_mode == CREATE_MODE_SYNCHRONOUS);
383 bool async_prefs = create_mode == CREATE_MODE_ASYNCHRONOUS; 386 bool async_prefs = create_mode == CREATE_MODE_ASYNCHRONOUS;
384 387
388 Profile::RegisterUserPrefs(pref_registry_);
389
385 { 390 {
386 // On startup, preference loading is always synchronous so a scoped timer 391 // On startup, preference loading is always synchronous so a scoped timer
387 // will work here. 392 // will work here.
388 startup_metric_utils::ScopedSlowStartupUMA 393 startup_metric_utils::ScopedSlowStartupUMA
389 scoped_timer("Startup.SlowStartupPreferenceLoading"); 394 scoped_timer("Startup.SlowStartupPreferenceLoading");
390 prefs_.reset(chrome_prefs::CreateProfilePrefs( 395 prefs_.reset(chrome_prefs::CreateProfilePrefs(
391 GetPrefFilePath(), 396 GetPrefFilePath(),
392 sequenced_task_runner, 397 sequenced_task_runner,
393 policy_service_.get(), 398 policy_service_.get(),
394 new ExtensionPrefStore( 399 new ExtensionPrefStore(
395 ExtensionPrefValueMapFactory::GetForProfile(this), false), 400 ExtensionPrefValueMapFactory::GetForProfile(this), false),
401 pref_registry_,
396 async_prefs)); 402 async_prefs));
397 } 403 }
398 404
399 startup_metric_utils::ScopedSlowStartupUMA 405 startup_metric_utils::ScopedSlowStartupUMA
400 scoped_timer("Startup.SlowStartupFinalProfileInit"); 406 scoped_timer("Startup.SlowStartupFinalProfileInit");
401 if (async_prefs) { 407 if (async_prefs) {
402 // Wait for the notification that prefs has been loaded 408 // Wait for the notification that prefs has been loaded
403 // (successfully or not). Note that we can use base::Unretained 409 // (successfully or not). Note that we can use base::Unretained
404 // because the PrefService is owned by this class and lives on 410 // because the PrefService is owned by this class and lives on
405 // the same thread. 411 // the same thread.
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 return extension_special_storage_policy_.get(); 699 return extension_special_storage_policy_.get();
694 } 700 }
695 701
696 void ProfileImpl::OnPrefsLoaded(bool success) { 702 void ProfileImpl::OnPrefsLoaded(bool success) {
697 if (!success) { 703 if (!success) {
698 if (delegate_) 704 if (delegate_)
699 delegate_->OnProfileCreated(this, false, false); 705 delegate_->OnProfileCreated(this, false, false);
700 return; 706 return;
701 } 707 }
702 708
703 // The Profile class and ProfileManager class may read some prefs so 709 // TODO(joi): Registration can move to the constructor once it
704 // register known prefs as soon as possible. 710 // doesn't need the PrefService parameter.
705 Profile::RegisterUserPrefs(prefs_.get()); 711 chrome::RegisterUserPrefs(prefs_.get(), pref_registry_);
706 chrome::RegisterUserPrefs(prefs_.get()); 712
707 // TODO(mirandac): remove migration code after 6 months (crbug.com/69995). 713 // TODO(mirandac): remove migration code after 6 months (crbug.com/69995).
708 if (g_browser_process->local_state()) 714 if (g_browser_process->local_state())
709 chrome::MigrateBrowserPrefs(this, g_browser_process->local_state()); 715 chrome::MigrateBrowserPrefs(this, g_browser_process->local_state());
710 // TODO(ivankr): remove cleanup code eventually (crbug.com/165672). 716 // TODO(ivankr): remove cleanup code eventually (crbug.com/165672).
711 chrome::MigrateUserPrefs(this); 717 chrome::MigrateUserPrefs(this);
712 718
713 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref 719 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref
714 // value is empty fallback to checking for |kSessionExitedCleanly|. 720 // value is empty fallback to checking for |kSessionExitedCleanly|.
715 const std::string exit_type_pref_value( 721 const std::string exit_type_pref_value(
716 prefs_->GetString(prefs::kSessionExitType)); 722 prefs_->GetString(prefs::kSessionExitType));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 #else 785 #else
780 return NULL; 786 return NULL;
781 #endif 787 #endif
782 } 788 }
783 789
784 policy::PolicyService* ProfileImpl::GetPolicyService() { 790 policy::PolicyService* ProfileImpl::GetPolicyService() {
785 DCHECK(policy_service_.get()); // Should explicitly be initialized. 791 DCHECK(policy_service_.get()); // Should explicitly be initialized.
786 return policy_service_.get(); 792 return policy_service_.get();
787 } 793 }
788 794
789 PrefServiceSyncable* ProfileImpl::GetPrefs() { 795 PrefService* ProfileImpl::GetPrefs() {
790 DCHECK(prefs_.get()); // Should explicitly be initialized. 796 DCHECK(prefs_.get()); // Should explicitly be initialized.
791 return prefs_.get(); 797 return prefs_.get();
792 } 798 }
793 799
794 PrefServiceSyncable* ProfileImpl::GetOffTheRecordPrefs() { 800 PrefService* ProfileImpl::GetOffTheRecordPrefs() {
801 DCHECK(prefs_.get());
795 if (!otr_prefs_.get()) { 802 if (!otr_prefs_.get()) {
796 // The new ExtensionPrefStore is ref_counted and the new PrefService 803 // The new ExtensionPrefStore is ref_counted and the new PrefService
797 // stores a reference so that we do not leak memory here. 804 // stores a reference so that we do not leak memory here.
798 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService( 805 otr_prefs_.reset(prefs_->CreateIncognitoPrefService(
799 new ExtensionPrefStore( 806 new ExtensionPrefStore(
800 ExtensionPrefValueMapFactory::GetForProfile(this), true))); 807 ExtensionPrefValueMapFactory::GetForProfile(this), true)));
801 } 808 }
802 return otr_prefs_.get(); 809 return otr_prefs_.get();
803 } 810 }
804 811
805 base::FilePath ProfileImpl::GetPrefFilePath() { 812 base::FilePath ProfileImpl::GetPrefFilePath() {
806 base::FilePath pref_file_path = path_; 813 base::FilePath pref_file_path = path_;
807 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); 814 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
808 return pref_file_path; 815 return pref_file_path;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 } 1084 }
1078 1085
1079 void ProfileImpl::SetupChromeOSEnterpriseExtensionObserver() { 1086 void ProfileImpl::SetupChromeOSEnterpriseExtensionObserver() {
1080 DCHECK(!chromeos_enterprise_extension_observer_.get()); 1087 DCHECK(!chromeos_enterprise_extension_observer_.get());
1081 chromeos_enterprise_extension_observer_.reset( 1088 chromeos_enterprise_extension_observer_.reset(
1082 new chromeos::EnterpriseExtensionObserver(this)); 1089 new chromeos::EnterpriseExtensionObserver(this));
1083 } 1090 }
1084 1091
1085 void ProfileImpl::InitChromeOSPreferences() { 1092 void ProfileImpl::InitChromeOSPreferences() {
1086 chromeos_preferences_.reset(new chromeos::Preferences()); 1093 chromeos_preferences_.reset(new chromeos::Preferences());
1087 chromeos_preferences_->Init(GetPrefs()); 1094 chromeos_preferences_->Init(PrefServiceSyncable::FromProfile(this));
1088 } 1095 }
1089 #endif // defined(OS_CHROMEOS) 1096 #endif // defined(OS_CHROMEOS)
1090 1097
1091 PrefProxyConfigTracker* ProfileImpl::GetProxyConfigTracker() { 1098 PrefProxyConfigTracker* ProfileImpl::GetProxyConfigTracker() {
1092 if (!pref_proxy_config_tracker_.get()) { 1099 if (!pref_proxy_config_tracker_.get()) {
1093 pref_proxy_config_tracker_.reset( 1100 pref_proxy_config_tracker_.reset(
1094 ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs())); 1101 ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs()));
1095 } 1102 }
1096 return pref_proxy_config_tracker_.get(); 1103 return pref_proxy_config_tracker_.get();
1097 } 1104 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 base::FilePath* cache_path, 1181 base::FilePath* cache_path,
1175 int* max_size) { 1182 int* max_size) {
1176 DCHECK(cache_path); 1183 DCHECK(cache_path);
1177 DCHECK(max_size); 1184 DCHECK(max_size);
1178 base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); 1185 base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1179 if (!path.empty()) 1186 if (!path.empty())
1180 *cache_path = path; 1187 *cache_path = path;
1181 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1188 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1182 prefs_->GetInteger(prefs::kDiskCacheSize); 1189 prefs_->GetInteger(prefs::kDiskCacheSize);
1183 } 1190 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/profiles/profile_keyed_base_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698