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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #include "chrome/browser/profiles/profile_metrics.h" | 66 #include "chrome/browser/profiles/profile_metrics.h" |
67 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 67 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
68 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 68 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
69 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 69 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
70 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" | 70 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" |
71 #include "chrome/browser/sessions/session_service_factory.h" | 71 #include "chrome/browser/sessions/session_service_factory.h" |
72 #include "chrome/browser/signin/signin_ui_util.h" | 72 #include "chrome/browser/signin/signin_ui_util.h" |
73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
74 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | 74 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" |
75 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 75 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 76 #include "chrome/browser/ui/zoom/zoom_level_prefs_store_impl.h" |
76 #include "chrome/common/chrome_constants.h" | 77 #include "chrome/common/chrome_constants.h" |
77 #include "chrome/common/chrome_paths_internal.h" | 78 #include "chrome/common/chrome_paths_internal.h" |
78 #include "chrome/common/chrome_switches.h" | 79 #include "chrome/common/chrome_switches.h" |
79 #include "chrome/common/chrome_version_info.h" | 80 #include "chrome/common/chrome_version_info.h" |
80 #include "chrome/common/pref_names.h" | 81 #include "chrome/common/pref_names.h" |
81 #include "chrome/common/url_constants.h" | 82 #include "chrome/common/url_constants.h" |
82 #include "chrome/grit/chromium_strings.h" | 83 #include "chrome/grit/chromium_strings.h" |
83 #include "components/bookmarks/browser/bookmark_model.h" | 84 #include "components/bookmarks/browser/bookmark_model.h" |
84 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" | 85 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" |
85 #include "components/dom_distiller/core/url_constants.h" | 86 #include "components/dom_distiller/core/url_constants.h" |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 PrefService* prefs = GetPrefs(); | 541 PrefService* prefs = GetPrefs(); |
541 pref_change_registrar_.Init(prefs); | 542 pref_change_registrar_.Init(prefs); |
542 pref_change_registrar_.Add( | 543 pref_change_registrar_.Add( |
543 prefs::kGoogleServicesUsername, | 544 prefs::kGoogleServicesUsername, |
544 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, | 545 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, |
545 base::Unretained(this))); | 546 base::Unretained(this))); |
546 pref_change_registrar_.Add( | 547 pref_change_registrar_.Add( |
547 prefs::kSupervisedUserId, | 548 prefs::kSupervisedUserId, |
548 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, | 549 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, |
549 base::Unretained(this))); | 550 base::Unretained(this))); |
550 pref_change_registrar_.Add( | |
551 prefs::kDefaultZoomLevel, | |
552 base::Bind(&ProfileImpl::OnDefaultZoomLevelChanged, | |
553 base::Unretained(this))); | |
554 | |
555 // Changes in the profile avatar. | 551 // Changes in the profile avatar. |
556 pref_change_registrar_.Add( | 552 pref_change_registrar_.Add( |
557 prefs::kProfileAvatarIndex, | 553 prefs::kProfileAvatarIndex, |
558 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 554 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
559 base::Unretained(this))); | 555 base::Unretained(this))); |
560 pref_change_registrar_.Add( | 556 pref_change_registrar_.Add( |
561 prefs::kProfileUsingDefaultAvatar, | 557 prefs::kProfileUsingDefaultAvatar, |
562 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 558 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
563 base::Unretained(this))); | 559 base::Unretained(this))); |
564 pref_change_registrar_.Add( | 560 pref_change_registrar_.Add( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 StartupBrowserCreator::GetSessionStartupPref( | 644 StartupBrowserCreator::GetSessionStartupPref( |
649 *CommandLine::ForCurrentProcess(), this).type; | 645 *CommandLine::ForCurrentProcess(), this).type; |
650 #endif | 646 #endif |
651 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = | 647 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = |
652 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; | 648 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; |
653 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || | 649 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || |
654 startup_pref_type == SessionStartupPref::LAST) { | 650 startup_pref_type == SessionStartupPref::LAST) { |
655 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; | 651 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; |
656 } | 652 } |
657 | 653 |
658 InitHostZoomMap(); | |
659 | |
660 base::Callback<void(bool)> data_reduction_proxy_unavailable; | 654 base::Callback<void(bool)> data_reduction_proxy_unavailable; |
661 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> | 655 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> |
662 data_reduction_proxy_params; | 656 data_reduction_proxy_params; |
663 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; | 657 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; |
| 658 |
664 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 659 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
665 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = | 660 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = |
666 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); | 661 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); |
667 data_reduction_proxy_params = | 662 data_reduction_proxy_params = |
668 data_reduction_proxy_chrome_settings->params()->Clone(); | 663 data_reduction_proxy_chrome_settings->params()->Clone(); |
669 data_reduction_proxy_unavailable = | 664 data_reduction_proxy_unavailable = |
670 base::Bind( | 665 base::Bind( |
671 &data_reduction_proxy::DataReductionProxySettings::SetUnreachable, | 666 &data_reduction_proxy::DataReductionProxySettings::SetUnreachable, |
672 base::Unretained(data_reduction_proxy_chrome_settings)); | 667 base::Unretained(data_reduction_proxy_chrome_settings)); |
673 // The configurator is used by DataReductionProxyChromeSettings and | 668 // The configurator is used by DataReductionProxyChromeSettings and |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 model->AddObserver(new BookmarkModelLoadedObserver(this)); | 756 model->AddObserver(new BookmarkModelLoadedObserver(this)); |
762 #endif | 757 #endif |
763 | 758 |
764 gcm::PushMessagingServiceImpl::InitializeForProfile(this); | 759 gcm::PushMessagingServiceImpl::InitializeForProfile(this); |
765 | 760 |
766 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) | 761 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) |
767 signin_ui_util::InitializePrefsForProfile(this); | 762 signin_ui_util::InitializePrefsForProfile(this); |
768 #endif | 763 #endif |
769 } | 764 } |
770 | 765 |
771 void ProfileImpl::InitHostZoomMap() { | |
772 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | |
773 host_zoom_map->SetDefaultZoomLevel( | |
774 prefs_->GetDouble(prefs::kDefaultZoomLevel)); | |
775 | |
776 const base::DictionaryValue* host_zoom_dictionary = | |
777 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | |
778 // Careful: The returned value could be NULL if the pref has never been set. | |
779 if (host_zoom_dictionary != NULL) { | |
780 std::vector<std::string> keys_to_remove; | |
781 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | |
782 i.Advance()) { | |
783 const std::string& host(i.key()); | |
784 double zoom_level = 0; | |
785 | |
786 bool success = i.value().GetAsDouble(&zoom_level); | |
787 DCHECK(success); | |
788 | |
789 // Filter out A) the empty host, B) zoom levels equal to the default; and | |
790 // remember them, so that we can later erase them from Prefs. | |
791 // Values of type A and B could have been stored due to crbug.com/364399. | |
792 // Values of type B could further have been stored before the default zoom | |
793 // level was set to its current value. In either case, SetZoomLevelForHost | |
794 // will ignore type B values, thus, to have consistency with HostZoomMap's | |
795 // internal state, these values must also be removed from Prefs. | |
796 if (host.empty() || | |
797 content::ZoomValuesEqual(zoom_level, | |
798 host_zoom_map->GetDefaultZoomLevel())) { | |
799 keys_to_remove.push_back(host); | |
800 continue; | |
801 } | |
802 | |
803 host_zoom_map->SetZoomLevelForHost(host, zoom_level); | |
804 } | |
805 | |
806 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
807 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
808 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | |
809 it != keys_to_remove.end(); ++it) { | |
810 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | |
811 } | |
812 } | |
813 | |
814 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | |
815 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | |
816 } | |
817 | |
818 base::FilePath ProfileImpl::last_selected_directory() { | 766 base::FilePath ProfileImpl::last_selected_directory() { |
819 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 767 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
820 } | 768 } |
821 | 769 |
822 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 770 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
823 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 771 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
824 } | 772 } |
825 | 773 |
826 ProfileImpl::~ProfileImpl() { | 774 ProfileImpl::~ProfileImpl() { |
827 MaybeSendDestroyedNotification(); | 775 MaybeSendDestroyedNotification(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 } | 818 } |
871 | 819 |
872 std::string ProfileImpl::GetProfileName() { | 820 std::string ProfileImpl::GetProfileName() { |
873 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 821 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
874 } | 822 } |
875 | 823 |
876 Profile::ProfileType ProfileImpl::GetProfileType() const { | 824 Profile::ProfileType ProfileImpl::GetProfileType() const { |
877 return REGULAR_PROFILE; | 825 return REGULAR_PROFILE; |
878 } | 826 } |
879 | 827 |
| 828 scoped_ptr<content::ZoomLevelPrefsStore> |
| 829 ProfileImpl::CreateZoomLevelPrefsStore() { |
| 830 return scoped_ptr<content::ZoomLevelPrefsStore>( |
| 831 new chrome::ZoomLevelPrefsStoreImpl); |
| 832 } |
| 833 |
880 base::FilePath ProfileImpl::GetPath() const { | 834 base::FilePath ProfileImpl::GetPath() const { |
881 return path_; | 835 return path_; |
882 } | 836 } |
883 | 837 |
884 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { | 838 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { |
885 return JsonPrefStore::GetTaskRunnerForFile( | 839 return JsonPrefStore::GetTaskRunnerForFile( |
886 GetPath(), BrowserThread::GetBlockingPool()); | 840 GetPath(), BrowserThread::GetBlockingPool()); |
887 } | 841 } |
888 | 842 |
889 bool ProfileImpl::IsOffTheRecord() const { | 843 bool ProfileImpl::IsOffTheRecord() const { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 top_sites_ = history::TopSites::Create( | 1131 top_sites_ = history::TopSites::Create( |
1178 this, GetPath().Append(chrome::kTopSitesFilename)); | 1132 this, GetPath().Append(chrome::kTopSitesFilename)); |
1179 } | 1133 } |
1180 return top_sites_.get(); | 1134 return top_sites_.get(); |
1181 } | 1135 } |
1182 | 1136 |
1183 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1137 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
1184 return top_sites_.get(); | 1138 return top_sites_.get(); |
1185 } | 1139 } |
1186 | 1140 |
1187 void ProfileImpl::OnDefaultZoomLevelChanged() { | |
1188 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | |
1189 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); | |
1190 } | |
1191 | |
1192 void ProfileImpl::OnZoomLevelChanged( | |
1193 const HostZoomMap::ZoomLevelChange& change) { | |
1194 | |
1195 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | |
1196 return; | |
1197 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | |
1198 double level = change.zoom_level; | |
1199 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
1200 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
1201 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) | |
1202 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | |
1203 else | |
1204 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); | |
1205 } | |
1206 | |
1207 #if defined(ENABLE_SESSION_SERVICE) | 1141 #if defined(ENABLE_SESSION_SERVICE) |
1208 void ProfileImpl::StopCreateSessionServiceTimer() { | 1142 void ProfileImpl::StopCreateSessionServiceTimer() { |
1209 create_session_service_timer_.Stop(); | 1143 create_session_service_timer_.Stop(); |
1210 } | 1144 } |
1211 | 1145 |
1212 void ProfileImpl::EnsureSessionServiceCreated() { | 1146 void ProfileImpl::EnsureSessionServiceCreated() { |
1213 SessionServiceFactory::GetForProfile(this); | 1147 SessionServiceFactory::GetForProfile(this); |
1214 } | 1148 } |
1215 #endif | 1149 #endif |
1216 | 1150 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 ProfileImpl::CreateDomainReliabilityMonitor() { | 1387 ProfileImpl::CreateDomainReliabilityMonitor() { |
1454 domain_reliability::DomainReliabilityService* service = | 1388 domain_reliability::DomainReliabilityService* service = |
1455 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1389 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
1456 GetForBrowserContext(this); | 1390 GetForBrowserContext(this); |
1457 if (!service) | 1391 if (!service) |
1458 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1392 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
1459 | 1393 |
1460 return service->CreateMonitor( | 1394 return service->CreateMonitor( |
1461 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1395 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
1462 } | 1396 } |
OLD | NEW |