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/chrome_zoom_level_prefs.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/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 85 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
85 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" | 86 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 PrefService* prefs = GetPrefs(); | 515 PrefService* prefs = GetPrefs(); |
515 pref_change_registrar_.Init(prefs); | 516 pref_change_registrar_.Init(prefs); |
516 pref_change_registrar_.Add( | 517 pref_change_registrar_.Add( |
517 prefs::kGoogleServicesUsername, | 518 prefs::kGoogleServicesUsername, |
518 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, | 519 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, |
519 base::Unretained(this))); | 520 base::Unretained(this))); |
520 pref_change_registrar_.Add( | 521 pref_change_registrar_.Add( |
521 prefs::kSupervisedUserId, | 522 prefs::kSupervisedUserId, |
522 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, | 523 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, |
523 base::Unretained(this))); | 524 base::Unretained(this))); |
524 pref_change_registrar_.Add( | |
525 prefs::kDefaultZoomLevel, | |
526 base::Bind(&ProfileImpl::OnDefaultZoomLevelChanged, | |
527 base::Unretained(this))); | |
528 | 525 |
529 // Changes in the profile avatar. | 526 // Changes in the profile avatar. |
530 pref_change_registrar_.Add( | 527 pref_change_registrar_.Add( |
531 prefs::kProfileAvatarIndex, | 528 prefs::kProfileAvatarIndex, |
532 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 529 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
533 base::Unretained(this))); | 530 base::Unretained(this))); |
534 pref_change_registrar_.Add( | 531 pref_change_registrar_.Add( |
535 prefs::kProfileUsingDefaultAvatar, | 532 prefs::kProfileUsingDefaultAvatar, |
536 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 533 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
537 base::Unretained(this))); | 534 base::Unretained(this))); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 | 743 |
747 gcm::PushMessagingServiceImpl::InitializeForProfile(this); | 744 gcm::PushMessagingServiceImpl::InitializeForProfile(this); |
748 | 745 |
749 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) | 746 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) |
750 signin_ui_util::InitializePrefsForProfile(this); | 747 signin_ui_util::InitializePrefsForProfile(this); |
751 #endif | 748 #endif |
752 } | 749 } |
753 | 750 |
754 void ProfileImpl::InitHostZoomMap() { | 751 void ProfileImpl::InitHostZoomMap() { |
755 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 752 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
756 host_zoom_map->SetDefaultZoomLevel( | 753 DCHECK(!zoom_level_prefs_); |
757 prefs_->GetDouble(prefs::kDefaultZoomLevel)); | 754 zoom_level_prefs_.reset( |
755 new chrome::ChromeZoomLevelPrefs(prefs_.get(), GetPath())); | |
756 zoom_level_prefs_->InitPrefsAndCopyToHostZoomMap(GetPath(), host_zoom_map); | |
758 | 757 |
759 const base::DictionaryValue* host_zoom_dictionary = | 758 // TODO(wjmaclean): Remove this. crbug.com/420643 |
760 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | 759 chrome::MigrateProfileZoomLevelPrefs(this); |
761 // Careful: The returned value could be NULL if the pref has never been set. | |
762 if (host_zoom_dictionary != NULL) { | |
763 std::vector<std::string> keys_to_remove; | |
764 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | |
765 i.Advance()) { | |
766 const std::string& host(i.key()); | |
767 double zoom_level = 0; | |
768 | |
769 bool success = i.value().GetAsDouble(&zoom_level); | |
770 DCHECK(success); | |
771 | |
772 // Filter out A) the empty host, B) zoom levels equal to the default; and | |
773 // remember them, so that we can later erase them from Prefs. | |
774 // Values of type A and B could have been stored due to crbug.com/364399. | |
775 // Values of type B could further have been stored before the default zoom | |
776 // level was set to its current value. In either case, SetZoomLevelForHost | |
777 // will ignore type B values, thus, to have consistency with HostZoomMap's | |
778 // internal state, these values must also be removed from Prefs. | |
779 if (host.empty() || | |
780 content::ZoomValuesEqual(zoom_level, | |
781 host_zoom_map->GetDefaultZoomLevel())) { | |
782 keys_to_remove.push_back(host); | |
783 continue; | |
784 } | |
785 | |
786 host_zoom_map->SetZoomLevelForHost(host, zoom_level); | |
787 } | |
788 | |
789 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
790 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
791 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | |
792 it != keys_to_remove.end(); ++it) { | |
793 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | |
794 } | |
795 } | |
796 | |
797 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | |
798 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | |
799 } | 760 } |
800 | 761 |
801 base::FilePath ProfileImpl::last_selected_directory() { | 762 base::FilePath ProfileImpl::last_selected_directory() { |
802 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 763 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
803 } | 764 } |
804 | 765 |
805 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 766 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
806 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 767 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
807 } | 768 } |
808 | 769 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1009 // it to be set by asking for the prefs. | 970 // it to be set by asking for the prefs. |
1010 GetPrefs(); | 971 GetPrefs(); |
1011 return last_session_exit_type_; | 972 return last_session_exit_type_; |
1012 } | 973 } |
1013 | 974 |
1014 PrefService* ProfileImpl::GetPrefs() { | 975 PrefService* ProfileImpl::GetPrefs() { |
1015 DCHECK(prefs_); // Should explicitly be initialized. | 976 DCHECK(prefs_); // Should explicitly be initialized. |
1016 return prefs_.get(); | 977 return prefs_.get(); |
1017 } | 978 } |
1018 | 979 |
980 chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { | |
Elliot Glaysher
2014/10/10 19:05:11
So, on what sort of timescale do you plan to remov
wjmaclean
2014/10/10 19:18:39
The timescale is intended to be "as quickly as pos
| |
981 return zoom_level_prefs_.get(); | |
982 } | |
983 | |
1019 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 984 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
1020 DCHECK(prefs_); | 985 DCHECK(prefs_); |
1021 if (!otr_prefs_) { | 986 if (!otr_prefs_) { |
1022 // The new ExtensionPrefStore is ref_counted and the new PrefService | 987 // The new ExtensionPrefStore is ref_counted and the new PrefService |
1023 // stores a reference so that we do not leak memory here. | 988 // stores a reference so that we do not leak memory here. |
1024 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( | 989 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
1025 CreateExtensionPrefStore(this, true))); | 990 CreateExtensionPrefStore(this, true))); |
1026 } | 991 } |
1027 return otr_prefs_.get(); | 992 return otr_prefs_.get(); |
1028 } | 993 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1157 top_sites_ = history::TopSites::Create( | 1122 top_sites_ = history::TopSites::Create( |
1158 this, GetPath().Append(chrome::kTopSitesFilename)); | 1123 this, GetPath().Append(chrome::kTopSitesFilename)); |
1159 } | 1124 } |
1160 return top_sites_.get(); | 1125 return top_sites_.get(); |
1161 } | 1126 } |
1162 | 1127 |
1163 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1128 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
1164 return top_sites_.get(); | 1129 return top_sites_.get(); |
1165 } | 1130 } |
1166 | 1131 |
1167 void ProfileImpl::OnDefaultZoomLevelChanged() { | |
1168 HostZoomMap::GetDefaultForBrowserContext(this)->SetDefaultZoomLevel( | |
1169 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); | |
1170 } | |
1171 | |
1172 void ProfileImpl::OnZoomLevelChanged( | |
1173 const HostZoomMap::ZoomLevelChange& change) { | |
1174 | |
1175 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | |
1176 return; | |
1177 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | |
1178 double level = change.zoom_level; | |
1179 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
1180 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
1181 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) | |
1182 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | |
1183 else | |
1184 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); | |
1185 } | |
1186 | |
1187 #if defined(ENABLE_SESSION_SERVICE) | 1132 #if defined(ENABLE_SESSION_SERVICE) |
1188 void ProfileImpl::StopCreateSessionServiceTimer() { | 1133 void ProfileImpl::StopCreateSessionServiceTimer() { |
1189 create_session_service_timer_.Stop(); | 1134 create_session_service_timer_.Stop(); |
1190 } | 1135 } |
1191 | 1136 |
1192 void ProfileImpl::EnsureSessionServiceCreated() { | 1137 void ProfileImpl::EnsureSessionServiceCreated() { |
1193 SessionServiceFactory::GetForProfile(this); | 1138 SessionServiceFactory::GetForProfile(this); |
1194 } | 1139 } |
1195 #endif | 1140 #endif |
1196 | 1141 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { | 1378 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { |
1434 domain_reliability::DomainReliabilityService* service = | 1379 domain_reliability::DomainReliabilityService* service = |
1435 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1380 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
1436 GetForBrowserContext(this); | 1381 GetForBrowserContext(this); |
1437 if (!service) | 1382 if (!service) |
1438 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1383 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
1439 | 1384 |
1440 return service->CreateMonitor( | 1385 return service->CreateMonitor( |
1441 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1386 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
1442 } | 1387 } |
OLD | NEW |