| 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 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_plugin_service_filter.h" | 25 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 26 #include "chrome/browser/content_settings/cookie_settings.h" | 26 #include "chrome/browser/content_settings/cookie_settings.h" |
| 27 #include "chrome/browser/content_settings/host_content_settings_map.h" | 27 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 29 #include "chrome/browser/download/download_service.h" | 29 #include "chrome/browser/download/download_service.h" |
| 30 #include "chrome/browser/download/download_service_factory.h" | 30 #include "chrome/browser/download/download_service_factory.h" |
| 31 #include "chrome/browser/extensions/extension_event_router.h" | 31 #include "chrome/browser/extensions/extension_event_router.h" |
| 32 #include "chrome/browser/extensions/extension_pref_store.h" | 32 #include "chrome/browser/extensions/extension_pref_store.h" |
| 33 #include "chrome/browser/extensions/extension_pref_value_map.h" | 33 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 34 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" |
| 34 #include "chrome/browser/extensions/extension_process_manager.h" | 35 #include "chrome/browser/extensions/extension_process_manager.h" |
| 35 #include "chrome/browser/extensions/extension_service.h" | 36 #include "chrome/browser/extensions/extension_service.h" |
| 36 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 37 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 37 #include "chrome/browser/extensions/extension_system.h" | 38 #include "chrome/browser/extensions/extension_system.h" |
| 38 #include "chrome/browser/extensions/user_script_master.h" | 39 #include "chrome/browser/extensions/user_script_master.h" |
| 39 #include "chrome/browser/favicon/favicon_service.h" | 40 #include "chrome/browser/favicon/favicon_service.h" |
| 40 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 41 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
| 41 #include "chrome/browser/history/history.h" | 42 #include "chrome/browser/history/history.h" |
| 42 #include "chrome/browser/history/shortcuts_backend.h" | 43 #include "chrome/browser/history/shortcuts_backend.h" |
| 43 #include "chrome/browser/history/top_sites.h" | 44 #include "chrome/browser/history/top_sites.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 246 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 246 predictor_ = chrome_browser_net::Predictor::CreatePredictor( | 247 predictor_ = chrome_browser_net::Predictor::CreatePredictor( |
| 247 !command_line->HasSwitch(switches::kDisablePreconnect), | 248 !command_line->HasSwitch(switches::kDisablePreconnect), |
| 248 g_browser_process->profile_manager() == NULL); | 249 g_browser_process->profile_manager() == NULL); |
| 249 | 250 |
| 250 session_restore_enabled_ = | 251 session_restore_enabled_ = |
| 251 !command_line->HasSwitch(switches::kDisableRestoreSessionState); | 252 !command_line->HasSwitch(switches::kDisableRestoreSessionState); |
| 252 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { | 253 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| 253 prefs_.reset(PrefService::CreatePrefService( | 254 prefs_.reset(PrefService::CreatePrefService( |
| 254 GetPrefFilePath(), | 255 GetPrefFilePath(), |
| 255 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 256 new ExtensionPrefStore( |
| 257 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 256 true)); | 258 true)); |
| 257 // Wait for the notification that prefs has been loaded (successfully or | 259 // Wait for the notification that prefs has been loaded (successfully or |
| 258 // not). | 260 // not). |
| 259 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | 261 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, |
| 260 content::Source<PrefService>(prefs_.get())); | 262 content::Source<PrefService>(prefs_.get())); |
| 261 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { | 263 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
| 262 // Load prefs synchronously. | 264 // Load prefs synchronously. |
| 263 prefs_.reset(PrefService::CreatePrefService( | 265 prefs_.reset(PrefService::CreatePrefService( |
| 264 GetPrefFilePath(), | 266 GetPrefFilePath(), |
| 265 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 267 new ExtensionPrefStore( |
| 268 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 266 false)); | 269 false)); |
| 267 OnPrefsLoaded(true); | 270 OnPrefsLoaded(true); |
| 268 } else { | 271 } else { |
| 269 NOTREACHED(); | 272 NOTREACHED(); |
| 270 } | 273 } |
| 271 } | 274 } |
| 272 | 275 |
| 273 void ProfileImpl::DoFinalInit(bool is_new_profile) { | 276 void ProfileImpl::DoFinalInit(bool is_new_profile) { |
| 274 PrefService* prefs = GetPrefs(); | 277 PrefService* prefs = GetPrefs(); |
| 275 pref_change_registrar_.Init(prefs); | 278 pref_change_registrar_.Init(prefs); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 content::NotificationService::current()->Notify( | 557 content::NotificationService::current()->Notify( |
| 555 chrome::NOTIFICATION_PROFILE_CREATED, | 558 chrome::NOTIFICATION_PROFILE_CREATED, |
| 556 content::Source<Profile>(off_the_record_profile_.get()), | 559 content::Source<Profile>(off_the_record_profile_.get()), |
| 557 content::NotificationService::NoDetails()); | 560 content::NotificationService::NoDetails()); |
| 558 } | 561 } |
| 559 return off_the_record_profile_.get(); | 562 return off_the_record_profile_.get(); |
| 560 } | 563 } |
| 561 | 564 |
| 562 void ProfileImpl::DestroyOffTheRecordProfile() { | 565 void ProfileImpl::DestroyOffTheRecordProfile() { |
| 563 off_the_record_profile_.reset(); | 566 off_the_record_profile_.reset(); |
| 564 extension_pref_value_map_->ClearAllIncognitoSessionOnlyPreferences(); | 567 ExtensionPrefValueMapFactory::GetForProfile(this)-> |
| 568 ClearAllIncognitoSessionOnlyPreferences(); |
| 565 } | 569 } |
| 566 | 570 |
| 567 bool ProfileImpl::HasOffTheRecordProfile() { | 571 bool ProfileImpl::HasOffTheRecordProfile() { |
| 568 return off_the_record_profile_.get() != NULL; | 572 return off_the_record_profile_.get() != NULL; |
| 569 } | 573 } |
| 570 | 574 |
| 571 Profile* ProfileImpl::GetOriginalProfile() { | 575 Profile* ProfileImpl::GetOriginalProfile() { |
| 572 return this; | 576 return this; |
| 573 } | 577 } |
| 574 | 578 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 PrefService* ProfileImpl::GetPrefs() { | 660 PrefService* ProfileImpl::GetPrefs() { |
| 657 DCHECK(prefs_.get()); // Should explicitly be initialized. | 661 DCHECK(prefs_.get()); // Should explicitly be initialized. |
| 658 return prefs_.get(); | 662 return prefs_.get(); |
| 659 } | 663 } |
| 660 | 664 |
| 661 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 665 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
| 662 if (!otr_prefs_.get()) { | 666 if (!otr_prefs_.get()) { |
| 663 // The new ExtensionPrefStore is ref_counted and the new PrefService | 667 // The new ExtensionPrefStore is ref_counted and the new PrefService |
| 664 // stores a reference so that we do not leak memory here. | 668 // stores a reference so that we do not leak memory here. |
| 665 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService( | 669 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService( |
| 666 new ExtensionPrefStore(GetExtensionPrefValueMap(), true))); | 670 new ExtensionPrefStore( |
| 671 ExtensionPrefValueMapFactory::GetForProfile(this), true))); |
| 667 } | 672 } |
| 668 return otr_prefs_.get(); | 673 return otr_prefs_.get(); |
| 669 } | 674 } |
| 670 | 675 |
| 671 FilePath ProfileImpl::GetPrefFilePath() { | 676 FilePath ProfileImpl::GetPrefFilePath() { |
| 672 FilePath pref_file_path = path_; | 677 FilePath pref_file_path = path_; |
| 673 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); | 678 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); |
| 674 return pref_file_path; | 679 return pref_file_path; |
| 675 } | 680 } |
| 676 | 681 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 top_sites_ = new history::TopSites(this); | 880 top_sites_ = new history::TopSites(this); |
| 876 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); | 881 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); |
| 877 } | 882 } |
| 878 return top_sites_; | 883 return top_sites_; |
| 879 } | 884 } |
| 880 | 885 |
| 881 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 886 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
| 882 return top_sites_; | 887 return top_sites_; |
| 883 } | 888 } |
| 884 | 889 |
| 885 ExtensionPrefValueMap* ProfileImpl::GetExtensionPrefValueMap() { | |
| 886 if (!extension_pref_value_map_.get()) | |
| 887 extension_pref_value_map_.reset(new ExtensionPrefValueMap); | |
| 888 return extension_pref_value_map_.get(); | |
| 889 } | |
| 890 | |
| 891 void ProfileImpl::MarkAsCleanShutdown() { | 890 void ProfileImpl::MarkAsCleanShutdown() { |
| 892 if (prefs_.get()) { | 891 if (prefs_.get()) { |
| 893 // The session cleanly exited, set kSessionExitedCleanly appropriately. | 892 // The session cleanly exited, set kSessionExitedCleanly appropriately. |
| 894 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); | 893 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); |
| 895 | 894 |
| 896 // NOTE: If you change what thread this writes on, be sure and update | 895 // NOTE: If you change what thread this writes on, be sure and update |
| 897 // ChromeFrame::EndSession(). | 896 // ChromeFrame::EndSession(). |
| 898 prefs_->CommitPendingWrite(); | 897 prefs_->CommitPendingWrite(); |
| 899 } | 898 } |
| 900 } | 899 } |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 FilePath* cache_path, | 1162 FilePath* cache_path, |
| 1164 int* max_size) { | 1163 int* max_size) { |
| 1165 DCHECK(cache_path); | 1164 DCHECK(cache_path); |
| 1166 DCHECK(max_size); | 1165 DCHECK(max_size); |
| 1167 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1166 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
| 1168 if (!path.empty()) | 1167 if (!path.empty()) |
| 1169 *cache_path = path; | 1168 *cache_path = path; |
| 1170 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1169 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1171 prefs_->GetInteger(prefs::kDiskCacheSize); | 1170 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1172 } | 1171 } |
| OLD | NEW |