Chromium Code Reviews| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 #include "components/domain_reliability/monitor.h" | 88 #include "components/domain_reliability/monitor.h" |
| 89 #include "components/domain_reliability/service.h" | 89 #include "components/domain_reliability/service.h" |
| 90 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 90 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 91 #include "components/metrics/metrics_service.h" | 91 #include "components/metrics/metrics_service.h" |
| 92 #include "components/pref_registry/pref_registry_syncable.h" | 92 #include "components/pref_registry/pref_registry_syncable.h" |
| 93 #include "components/startup_metric_utils/startup_metric_utils.h" | 93 #include "components/startup_metric_utils/startup_metric_utils.h" |
| 94 #include "components/url_fixer/url_fixer.h" | 94 #include "components/url_fixer/url_fixer.h" |
| 95 #include "components/user_prefs/user_prefs.h" | 95 #include "components/user_prefs/user_prefs.h" |
| 96 #include "content/public/browser/browser_thread.h" | 96 #include "content/public/browser/browser_thread.h" |
| 97 #include "content/public/browser/dom_storage_context.h" | 97 #include "content/public/browser/dom_storage_context.h" |
| 98 #include "content/public/browser/host_zoom_map.h" | |
| 99 #include "content/public/browser/notification_service.h" | 98 #include "content/public/browser/notification_service.h" |
| 100 #include "content/public/browser/render_process_host.h" | 99 #include "content/public/browser/render_process_host.h" |
| 101 #include "content/public/browser/storage_partition.h" | 100 #include "content/public/browser/storage_partition.h" |
| 102 #include "content/public/browser/url_data_source.h" | 101 #include "content/public/browser/url_data_source.h" |
| 103 #include "content/public/browser/user_metrics.h" | 102 #include "content/public/browser/user_metrics.h" |
| 104 #include "content/public/common/content_constants.h" | 103 #include "content/public/common/content_constants.h" |
| 105 #include "content/public/common/page_zoom.h" | 104 #include "content/public/common/page_zoom.h" |
| 106 #include "ui/base/l10n/l10n_util.h" | 105 #include "ui/base/l10n/l10n_util.h" |
| 107 | 106 |
| 108 #if defined(OS_ANDROID) | 107 #if defined(OS_ANDROID) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 #if defined(ENABLE_MANAGED_USERS) | 148 #if defined(ENABLE_MANAGED_USERS) |
| 150 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 149 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 151 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" | 150 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" |
| 152 #endif | 151 #endif |
| 153 | 152 |
| 154 using base::Time; | 153 using base::Time; |
| 155 using base::TimeDelta; | 154 using base::TimeDelta; |
| 156 using base::UserMetricsAction; | 155 using base::UserMetricsAction; |
| 157 using content::BrowserThread; | 156 using content::BrowserThread; |
| 158 using content::DownloadManagerDelegate; | 157 using content::DownloadManagerDelegate; |
| 159 using content::HostZoomMap; | |
| 160 | 158 |
| 161 namespace { | 159 namespace { |
| 162 | 160 |
| 163 #if defined(ENABLE_SESSION_SERVICE) | 161 #if defined(ENABLE_SESSION_SERVICE) |
| 164 // Delay, in milliseconds, before we explicitly create the SessionService. | 162 // Delay, in milliseconds, before we explicitly create the SessionService. |
| 165 const int kCreateSessionServiceDelayMS = 500; | 163 const int kCreateSessionServiceDelayMS = 500; |
| 166 #endif | 164 #endif |
| 167 | 165 |
| 168 // Text content of README file created in each profile directory. Both %s | 166 // Text content of README file created in each profile directory. Both %s |
| 169 // placeholders must contain the product name. This is not localizable and hence | 167 // placeholders must contain the product name. This is not localizable and hence |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 StartupBrowserCreator::GetSessionStartupPref( | 623 StartupBrowserCreator::GetSessionStartupPref( |
| 626 *CommandLine::ForCurrentProcess(), this).type; | 624 *CommandLine::ForCurrentProcess(), this).type; |
| 627 #endif | 625 #endif |
| 628 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = | 626 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = |
| 629 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; | 627 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; |
| 630 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || | 628 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || |
| 631 startup_pref_type == SessionStartupPref::LAST) { | 629 startup_pref_type == SessionStartupPref::LAST) { |
| 632 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; | 630 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; |
| 633 } | 631 } |
| 634 | 632 |
| 635 InitHostZoomMap(); | |
| 636 | |
| 637 base::Callback<void(bool)> data_reduction_proxy_unavailable; | 633 base::Callback<void(bool)> data_reduction_proxy_unavailable; |
| 638 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> | 634 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> |
| 639 data_reduction_proxy_params; | 635 data_reduction_proxy_params; |
| 640 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; | 636 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; |
| 641 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> | 637 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> |
| 642 data_reduction_proxy_statistics_prefs; | 638 data_reduction_proxy_statistics_prefs; |
| 643 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = | 639 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = |
| 644 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); | 640 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); |
| 645 data_reduction_proxy_params = | 641 data_reduction_proxy_params = |
| 646 data_reduction_proxy_chrome_settings->params()->Clone(); | 642 data_reduction_proxy_chrome_settings->params()->Clone(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 // Delay README creation to not impact startup performance. | 705 // Delay README creation to not impact startup performance. |
| 710 BrowserThread::PostDelayedTask( | 706 BrowserThread::PostDelayedTask( |
| 711 BrowserThread::FILE, FROM_HERE, | 707 BrowserThread::FILE, FROM_HERE, |
| 712 base::Bind(&EnsureReadmeFile, GetPath()), | 708 base::Bind(&EnsureReadmeFile, GetPath()), |
| 713 base::TimeDelta::FromMilliseconds(create_readme_delay_ms)); | 709 base::TimeDelta::FromMilliseconds(create_readme_delay_ms)); |
| 714 | 710 |
| 715 TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk"); | 711 TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk"); |
| 716 content::BrowserContext::GetDefaultStoragePartition(this)-> | 712 content::BrowserContext::GetDefaultStoragePartition(this)-> |
| 717 GetDOMStorageContext()->SetSaveSessionStorageOnDisk(); | 713 GetDOMStorageContext()->SetSaveSessionStorageOnDisk(); |
| 718 | 714 |
| 715 // TODO(wjmaclean): Remove this. crbug.com/420643 | |
| 716 chrome::MigrateProfileZoomLevelPrefs(this); | |
| 717 | |
| 719 // The DomDistillerViewerSource is not a normal WebUI so it must be registered | 718 // The DomDistillerViewerSource is not a normal WebUI so it must be registered |
| 720 // as a URLDataSource early. | 719 // as a URLDataSource early. |
| 721 RegisterDomDistillerViewerSource(this); | 720 RegisterDomDistillerViewerSource(this); |
| 722 | 721 |
| 723 // Creation has been finished. | 722 // Creation has been finished. |
| 724 TRACE_EVENT_END1("browser", | 723 TRACE_EVENT_END1("browser", |
| 725 "Profile::CreateProfile", | 724 "Profile::CreateProfile", |
| 726 "profile_path", | 725 "profile_path", |
| 727 path_.value().c_str()); | 726 path_.value().c_str()); |
| 728 | 727 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 750 model->AddObserver(new BookmarkModelLoadedObserver(this)); | 749 model->AddObserver(new BookmarkModelLoadedObserver(this)); |
| 751 #endif | 750 #endif |
| 752 | 751 |
| 753 gcm::PushMessagingServiceImpl::InitializeForProfile(this); | 752 gcm::PushMessagingServiceImpl::InitializeForProfile(this); |
| 754 | 753 |
| 755 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) | 754 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) |
| 756 signin_ui_util::InitializePrefsForProfile(this); | 755 signin_ui_util::InitializePrefsForProfile(this); |
| 757 #endif | 756 #endif |
| 758 } | 757 } |
| 759 | 758 |
| 760 void ProfileImpl::InitHostZoomMap() { | |
| 761 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | |
| 762 DCHECK(!zoom_level_prefs_); | |
| 763 zoom_level_prefs_.reset( | |
| 764 new chrome::ChromeZoomLevelPrefs(prefs_.get(), GetPath())); | |
| 765 zoom_level_prefs_->InitPrefsAndCopyToHostZoomMap(GetPath(), host_zoom_map); | |
| 766 | |
| 767 // TODO(wjmaclean): Remove this. crbug.com/420643 | |
| 768 chrome::MigrateProfileZoomLevelPrefs(this); | |
| 769 } | |
| 770 | |
| 771 base::FilePath ProfileImpl::last_selected_directory() { | 759 base::FilePath ProfileImpl::last_selected_directory() { |
| 772 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 760 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
| 773 } | 761 } |
| 774 | 762 |
| 775 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 763 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
| 776 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 764 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 777 } | 765 } |
| 778 | 766 |
| 779 ProfileImpl::~ProfileImpl() { | 767 ProfileImpl::~ProfileImpl() { |
| 780 MaybeSendDestroyedNotification(); | 768 MaybeSendDestroyedNotification(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 } | 811 } |
| 824 | 812 |
| 825 std::string ProfileImpl::GetProfileName() { | 813 std::string ProfileImpl::GetProfileName() { |
| 826 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 814 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| 827 } | 815 } |
| 828 | 816 |
| 829 Profile::ProfileType ProfileImpl::GetProfileType() const { | 817 Profile::ProfileType ProfileImpl::GetProfileType() const { |
| 830 return REGULAR_PROFILE; | 818 return REGULAR_PROFILE; |
| 831 } | 819 } |
| 832 | 820 |
| 821 scoped_ptr<content::ZoomLevelDelegate> | |
| 822 ProfileImpl::CreateZoomLevelDelegate(const base::FilePath& partition_path) { | |
| 823 return scoped_ptr<content::ZoomLevelDelegate>( | |
|
Bernhard Bauer
2014/11/12 10:39:20
I think make_scoped_ptr() should work here.
wjmaclean
2014/11/12 15:12:55
Done.
| |
| 824 new chrome::ChromeZoomLevelPrefs(GetPrefs(), GetPath(), partition_path)); | |
| 825 } | |
| 826 | |
| 833 base::FilePath ProfileImpl::GetPath() const { | 827 base::FilePath ProfileImpl::GetPath() const { |
| 834 return path_; | 828 return path_; |
| 835 } | 829 } |
| 836 | 830 |
| 837 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { | 831 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { |
| 838 return JsonPrefStore::GetTaskRunnerForFile( | 832 return JsonPrefStore::GetTaskRunnerForFile( |
| 839 GetPath(), BrowserThread::GetBlockingPool()); | 833 GetPath(), BrowserThread::GetBlockingPool()); |
| 840 } | 834 } |
| 841 | 835 |
| 842 bool ProfileImpl::IsOffTheRecord() const { | 836 bool ProfileImpl::IsOffTheRecord() const { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 GetPrefs(); | 974 GetPrefs(); |
| 981 return last_session_exit_type_; | 975 return last_session_exit_type_; |
| 982 } | 976 } |
| 983 | 977 |
| 984 PrefService* ProfileImpl::GetPrefs() { | 978 PrefService* ProfileImpl::GetPrefs() { |
| 985 DCHECK(prefs_); // Should explicitly be initialized. | 979 DCHECK(prefs_); // Should explicitly be initialized. |
| 986 return prefs_.get(); | 980 return prefs_.get(); |
| 987 } | 981 } |
| 988 | 982 |
| 989 chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { | 983 chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { |
| 990 return zoom_level_prefs_.get(); | 984 return static_cast<chrome::ChromeZoomLevelPrefs*>( |
| 985 GetDefaultStoragePartition(this)->GetZoomLevelDelegate()); | |
| 991 } | 986 } |
| 992 | 987 |
| 993 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 988 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
| 994 DCHECK(prefs_); | 989 DCHECK(prefs_); |
| 995 if (!otr_prefs_) { | 990 if (!otr_prefs_) { |
| 996 // The new ExtensionPrefStore is ref_counted and the new PrefService | 991 // The new ExtensionPrefStore is ref_counted and the new PrefService |
| 997 // stores a reference so that we do not leak memory here. | 992 // stores a reference so that we do not leak memory here. |
| 998 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( | 993 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
| 999 CreateExtensionPrefStore(this, true))); | 994 CreateExtensionPrefStore(this, true))); |
| 1000 } | 995 } |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1388 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { | 1383 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { |
| 1389 domain_reliability::DomainReliabilityService* service = | 1384 domain_reliability::DomainReliabilityService* service = |
| 1390 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1385 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
| 1391 GetForBrowserContext(this); | 1386 GetForBrowserContext(this); |
| 1392 if (!service) | 1387 if (!service) |
| 1393 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1388 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
| 1394 | 1389 |
| 1395 return service->CreateMonitor( | 1390 return service->CreateMonitor( |
| 1396 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1391 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 1397 } | 1392 } |
| OLD | NEW |