| OLD | NEW |
| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/download/download_service.h" | 32 #include "chrome/browser/download/download_service.h" |
| 33 #include "chrome/browser/download/download_service_factory.h" | 33 #include "chrome/browser/download/download_service_factory.h" |
| 34 #include "chrome/browser/extensions/component_loader.h" | 34 #include "chrome/browser/extensions/component_loader.h" |
| 35 #include "chrome/browser/extensions/extension_devtools_manager.h" | 35 #include "chrome/browser/extensions/extension_devtools_manager.h" |
| 36 #include "chrome/browser/extensions/extension_error_reporter.h" | 36 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 37 #include "chrome/browser/extensions/extension_event_router.h" | 37 #include "chrome/browser/extensions/extension_event_router.h" |
| 38 #include "chrome/browser/extensions/extension_info_map.h" | 38 #include "chrome/browser/extensions/extension_info_map.h" |
| 39 #include "chrome/browser/extensions/extension_message_service.h" | 39 #include "chrome/browser/extensions/extension_message_service.h" |
| 40 #include "chrome/browser/extensions/extension_navigation_observer.h" | 40 #include "chrome/browser/extensions/extension_navigation_observer.h" |
| 41 #include "chrome/browser/extensions/extension_pref_store.h" | 41 #include "chrome/browser/extensions/extension_pref_store.h" |
| 42 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 43 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" |
| 42 #include "chrome/browser/extensions/extension_process_manager.h" | 44 #include "chrome/browser/extensions/extension_process_manager.h" |
| 43 #include "chrome/browser/extensions/extension_service.h" | 45 #include "chrome/browser/extensions/extension_service.h" |
| 44 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 46 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 45 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 47 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 46 #include "chrome/browser/extensions/unpacked_installer.h" | 48 #include "chrome/browser/extensions/unpacked_installer.h" |
| 47 #include "chrome/browser/extensions/user_script_master.h" | 49 #include "chrome/browser/extensions/user_script_master.h" |
| 48 #include "chrome/browser/favicon/favicon_service.h" | 50 #include "chrome/browser/favicon/favicon_service.h" |
| 49 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 51 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
| 50 #include "chrome/browser/history/history.h" | 52 #include "chrome/browser/history/history.h" |
| 51 #include "chrome/browser/history/shortcuts_backend.h" | 53 #include "chrome/browser/history/shortcuts_backend.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 268 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 267 predictor_ = chrome_browser_net::Predictor::CreatePredictor( | 269 predictor_ = chrome_browser_net::Predictor::CreatePredictor( |
| 268 !command_line->HasSwitch(switches::kDisablePreconnect), | 270 !command_line->HasSwitch(switches::kDisablePreconnect), |
| 269 g_browser_process->profile_manager() == NULL); | 271 g_browser_process->profile_manager() == NULL); |
| 270 | 272 |
| 271 session_restore_enabled_ = | 273 session_restore_enabled_ = |
| 272 !command_line->HasSwitch(switches::kDisableRestoreSessionState); | 274 !command_line->HasSwitch(switches::kDisableRestoreSessionState); |
| 273 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { | 275 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| 274 prefs_.reset(PrefService::CreatePrefService( | 276 prefs_.reset(PrefService::CreatePrefService( |
| 275 GetPrefFilePath(), | 277 GetPrefFilePath(), |
| 276 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 278 new ExtensionPrefStore( |
| 279 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 277 true)); | 280 true)); |
| 278 // Wait for the notification that prefs has been loaded (successfully or | 281 // Wait for the notification that prefs has been loaded (successfully or |
| 279 // not). | 282 // not). |
| 280 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | 283 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, |
| 281 content::Source<PrefService>(prefs_.get())); | 284 content::Source<PrefService>(prefs_.get())); |
| 282 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { | 285 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
| 283 // Load prefs synchronously. | 286 // Load prefs synchronously. |
| 284 prefs_.reset(PrefService::CreatePrefService( | 287 prefs_.reset(PrefService::CreatePrefService( |
| 285 GetPrefFilePath(), | 288 GetPrefFilePath(), |
| 286 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 289 new ExtensionPrefStore( |
| 290 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 287 false)); | 291 false)); |
| 288 OnPrefsLoaded(true); | 292 OnPrefsLoaded(true); |
| 289 } else { | 293 } else { |
| 290 NOTREACHED(); | 294 NOTREACHED(); |
| 291 } | 295 } |
| 292 } | 296 } |
| 293 | 297 |
| 294 void ProfileImpl::DoFinalInit(bool is_new_profile) { | 298 void ProfileImpl::DoFinalInit(bool is_new_profile) { |
| 295 PrefService* prefs = GetPrefs(); | 299 PrefService* prefs = GetPrefs(); |
| 296 pref_change_registrar_.Init(prefs); | 300 pref_change_registrar_.Init(prefs); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 content::NotificationService::current()->Notify( | 673 content::NotificationService::current()->Notify( |
| 670 chrome::NOTIFICATION_PROFILE_CREATED, | 674 chrome::NOTIFICATION_PROFILE_CREATED, |
| 671 content::Source<Profile>(off_the_record_profile_.get()), | 675 content::Source<Profile>(off_the_record_profile_.get()), |
| 672 content::NotificationService::NoDetails()); | 676 content::NotificationService::NoDetails()); |
| 673 } | 677 } |
| 674 return off_the_record_profile_.get(); | 678 return off_the_record_profile_.get(); |
| 675 } | 679 } |
| 676 | 680 |
| 677 void ProfileImpl::DestroyOffTheRecordProfile() { | 681 void ProfileImpl::DestroyOffTheRecordProfile() { |
| 678 off_the_record_profile_.reset(); | 682 off_the_record_profile_.reset(); |
| 679 extension_pref_value_map_->ClearAllIncognitoSessionOnlyPreferences(); | 683 ExtensionPrefValueMapFactory::GetForProfile(this)-> |
| 684 ClearAllIncognitoSessionOnlyPreferences(); |
| 680 } | 685 } |
| 681 | 686 |
| 682 bool ProfileImpl::HasOffTheRecordProfile() { | 687 bool ProfileImpl::HasOffTheRecordProfile() { |
| 683 return off_the_record_profile_.get() != NULL; | 688 return off_the_record_profile_.get() != NULL; |
| 684 } | 689 } |
| 685 | 690 |
| 686 Profile* ProfileImpl::GetOriginalProfile() { | 691 Profile* ProfileImpl::GetOriginalProfile() { |
| 687 return this; | 692 return this; |
| 688 } | 693 } |
| 689 | 694 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 prefs_->GetBoolean(prefs::kDisableExtensions) || | 769 prefs_->GetBoolean(prefs::kDisableExtensions) || |
| 765 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableExtensions); | 770 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableExtensions); |
| 766 | 771 |
| 767 ProfileDependencyManager::GetInstance()->CreateProfileServices(this, false); | 772 ProfileDependencyManager::GetInstance()->CreateProfileServices(this, false); |
| 768 | 773 |
| 769 // Ensure that preferences set by extensions are restored in the profile | 774 // Ensure that preferences set by extensions are restored in the profile |
| 770 // as early as possible. The constructor takes care of that. | 775 // as early as possible. The constructor takes care of that. |
| 771 extension_prefs_.reset(new ExtensionPrefs( | 776 extension_prefs_.reset(new ExtensionPrefs( |
| 772 prefs_.get(), | 777 prefs_.get(), |
| 773 GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), | 778 GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), |
| 774 GetExtensionPrefValueMap())); | 779 ExtensionPrefValueMapFactory::GetForProfile(this))); |
| 775 extension_prefs_->Init(extensions_disabled); | 780 extension_prefs_->Init(extensions_disabled); |
| 776 | 781 |
| 777 DCHECK(!net_pref_observer_.get()); | 782 DCHECK(!net_pref_observer_.get()); |
| 778 net_pref_observer_.reset(new NetPrefObserver( | 783 net_pref_observer_.reset(new NetPrefObserver( |
| 779 prefs_.get(), | 784 prefs_.get(), |
| 780 prerender::PrerenderManagerFactory::GetForProfile(this), | 785 prerender::PrerenderManagerFactory::GetForProfile(this), |
| 781 predictor_)); | 786 predictor_)); |
| 782 | 787 |
| 783 bool is_new_profile = prefs_->GetInitializationStatus() == | 788 bool is_new_profile = prefs_->GetInitializationStatus() == |
| 784 PrefService::INITIALIZATION_STATUS_CREATED_NEW_PROFILE; | 789 PrefService::INITIALIZATION_STATUS_CREATED_NEW_PROFILE; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 795 PrefService* ProfileImpl::GetPrefs() { | 800 PrefService* ProfileImpl::GetPrefs() { |
| 796 DCHECK(prefs_.get()); // Should explicitly be initialized. | 801 DCHECK(prefs_.get()); // Should explicitly be initialized. |
| 797 return prefs_.get(); | 802 return prefs_.get(); |
| 798 } | 803 } |
| 799 | 804 |
| 800 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 805 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
| 801 if (!otr_prefs_.get()) { | 806 if (!otr_prefs_.get()) { |
| 802 // The new ExtensionPrefStore is ref_counted and the new PrefService | 807 // The new ExtensionPrefStore is ref_counted and the new PrefService |
| 803 // stores a reference so that we do not leak memory here. | 808 // stores a reference so that we do not leak memory here. |
| 804 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService( | 809 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService( |
| 805 new ExtensionPrefStore(GetExtensionPrefValueMap(), true))); | 810 new ExtensionPrefStore( |
| 811 ExtensionPrefValueMapFactory::GetForProfile(this), true))); |
| 806 } | 812 } |
| 807 return otr_prefs_.get(); | 813 return otr_prefs_.get(); |
| 808 } | 814 } |
| 809 | 815 |
| 810 FilePath ProfileImpl::GetPrefFilePath() { | 816 FilePath ProfileImpl::GetPrefFilePath() { |
| 811 FilePath pref_file_path = path_; | 817 FilePath pref_file_path = path_; |
| 812 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); | 818 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); |
| 813 return pref_file_path; | 819 return pref_file_path; |
| 814 } | 820 } |
| 815 | 821 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 top_sites_ = new history::TopSites(this); | 1049 top_sites_ = new history::TopSites(this); |
| 1044 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); | 1050 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); |
| 1045 } | 1051 } |
| 1046 return top_sites_; | 1052 return top_sites_; |
| 1047 } | 1053 } |
| 1048 | 1054 |
| 1049 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1055 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
| 1050 return top_sites_; | 1056 return top_sites_; |
| 1051 } | 1057 } |
| 1052 | 1058 |
| 1053 ExtensionPrefValueMap* ProfileImpl::GetExtensionPrefValueMap() { | |
| 1054 if (!extension_pref_value_map_.get()) | |
| 1055 extension_pref_value_map_.reset(new ExtensionPrefValueMap); | |
| 1056 return extension_pref_value_map_.get(); | |
| 1057 } | |
| 1058 | |
| 1059 void ProfileImpl::MarkAsCleanShutdown() { | 1059 void ProfileImpl::MarkAsCleanShutdown() { |
| 1060 if (prefs_.get()) { | 1060 if (prefs_.get()) { |
| 1061 // The session cleanly exited, set kSessionExitedCleanly appropriately. | 1061 // The session cleanly exited, set kSessionExitedCleanly appropriately. |
| 1062 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); | 1062 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); |
| 1063 | 1063 |
| 1064 // NOTE: If you change what thread this writes on, be sure and update | 1064 // NOTE: If you change what thread this writes on, be sure and update |
| 1065 // ChromeFrame::EndSession(). | 1065 // ChromeFrame::EndSession(). |
| 1066 prefs_->CommitPendingWrite(); | 1066 prefs_->CommitPendingWrite(); |
| 1067 } | 1067 } |
| 1068 } | 1068 } |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 FilePath* cache_path, | 1355 FilePath* cache_path, |
| 1356 int* max_size) { | 1356 int* max_size) { |
| 1357 DCHECK(cache_path); | 1357 DCHECK(cache_path); |
| 1358 DCHECK(max_size); | 1358 DCHECK(max_size); |
| 1359 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1359 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
| 1360 if (!path.empty()) | 1360 if (!path.empty()) |
| 1361 *cache_path = path; | 1361 *cache_path = path; |
| 1362 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1362 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1363 prefs_->GetInteger(prefs::kDiskCacheSize); | 1363 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1364 } | 1364 } |
| OLD | NEW |