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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 | 759 |
764 gcm::PushMessagingServiceImpl::InitializeForProfile(this); | 760 gcm::PushMessagingServiceImpl::InitializeForProfile(this); |
765 | 761 |
766 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) | 762 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) |
767 signin_ui_util::InitializePrefsForProfile(this); | 763 signin_ui_util::InitializePrefsForProfile(this); |
768 #endif | 764 #endif |
769 } | 765 } |
770 | 766 |
771 void ProfileImpl::InitHostZoomMap() { | 767 void ProfileImpl::InitHostZoomMap() { |
772 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 768 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
773 host_zoom_map->SetDefaultZoomLevel( | 769 // As part of the migration from per-profile to per-partition HostZoomMaps, |
774 prefs_->GetDouble(prefs::kDefaultZoomLevel)); | 770 // we need to detect if an existing per-profile set of preferences exist, and |
771 // if so convert them to be per-partition. We defer running this function | |
772 // until zoom_level_prefs_store_ has initialized, and then migrate any per- | |
773 // profile zoom level prefs via zoom_level_prefs_store_. | |
774 // Code that updates zoom prefs in the profile prefs store has been removed, | |
775 // so once we clear these values here, they should never get set again. | |
776 // TODO(wjmaclean): Remove this migration machinery one (?) milestone after | |
777 // it goes stable. This means removing this entire function. | |
Peter Kasting
2014/09/11 00:45:47
You're going to want to wait quite a bit longer th
wjmaclean
2014/09/11 21:00:51
Sure, I was wondering about that. Is there any acc
| |
778 if (!zoom_level_prefs_store_) { | |
779 chrome::ZoomLevelPrefsStoreImpl* zoom_level_prefs_store_impl = | |
780 new chrome::ZoomLevelPrefsStoreImpl; | |
781 zoom_level_prefs_store_impl->SetInitCallback( | |
782 base::Bind(&ProfileImpl::InitHostZoomMap, base::Unretained(this))); | |
783 zoom_level_prefs_store_.reset(zoom_level_prefs_store_impl); | |
784 zoom_level_prefs_store_->InitPrefsAndCopyToHostZoomMap(GetPath(), | |
785 host_zoom_map); | |
786 return; | |
787 } | |
788 | |
789 // Only migrate the default zoom level if it is not equal to the registered | |
790 // default for the preference. | |
791 double default_default_zoom_level = 0.0; | |
792 prefs_->GetDefaultPrefValue(prefs::kProfileDefaultZoomLevel) | |
793 ->GetAsDouble(&default_default_zoom_level); | |
794 double per_profile_default_zoom_level = | |
795 prefs_->GetDouble(prefs::kProfileDefaultZoomLevel); | |
796 if (per_profile_default_zoom_level != default_default_zoom_level) { | |
797 // We cannot un-register this pref name, but we can reset it to a | |
798 // default sentinel value. | |
799 prefs_->SetDouble(prefs::kProfileDefaultZoomLevel, | |
800 default_default_zoom_level); | |
801 zoom_level_prefs_store_->GetPrefs()->SetDouble( | |
802 prefs::kDefaultZoomLevel, per_profile_default_zoom_level); | |
803 } | |
775 | 804 |
776 const base::DictionaryValue* host_zoom_dictionary = | 805 const base::DictionaryValue* host_zoom_dictionary = |
777 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | 806 prefs_->GetDictionary(prefs::kProfilePerHostZoomLevels); |
778 // Careful: The returned value could be NULL if the pref has never been set. | 807 // Careful: The returned value could be NULL if the pref has never been set. |
779 if (host_zoom_dictionary != NULL) { | 808 if (host_zoom_dictionary != NULL) { |
780 std::vector<std::string> keys_to_remove; | |
781 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | 809 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); |
782 i.Advance()) { | 810 i.Advance()) { |
783 const std::string& host(i.key()); | 811 const std::string& host(i.key()); |
784 double zoom_level = 0; | 812 double zoom_level = 0; |
785 | 813 |
786 bool success = i.value().GetAsDouble(&zoom_level); | 814 bool success = i.value().GetAsDouble(&zoom_level); |
787 DCHECK(success); | 815 DCHECK(success); |
788 | 816 |
789 // Filter out A) the empty host, B) zoom levels equal to the default; and | 817 // 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. | 818 // remember them, so that we can later erase them from Prefs. |
Peter Kasting
2014/09/11 00:45:47
This comment seems out of date?
wjmaclean
2014/09/11 21:00:51
Done.
| |
791 // Values of type A and B could have been stored due to crbug.com/364399. | 819 // 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 | 820 // 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 | 821 // level was set to its current value. In either case, SetZoomLevelForHost |
794 // will ignore type B values, thus, to have consistency with HostZoomMap's | 822 // will ignore type B values, thus, to have consistency with HostZoomMap's |
795 // internal state, these values must also be removed from Prefs. | 823 // internal state, these values must also be removed from Prefs. |
796 if (host.empty() || | 824 if (host.empty() || |
797 content::ZoomValuesEqual(zoom_level, | 825 content::ZoomValuesEqual(zoom_level, |
798 host_zoom_map->GetDefaultZoomLevel())) { | 826 host_zoom_map->GetDefaultZoomLevel())) { |
799 keys_to_remove.push_back(host); | |
800 continue; | 827 continue; |
801 } | 828 } |
802 | 829 |
830 // We push the profile per-host levels in through the HostZoomMap | |
831 // directly, which will update the zoom_level_prefs_store_ indirectly | |
832 // through the subsequent ZoomLevelChanged events. | |
803 host_zoom_map->SetZoomLevelForHost(host, zoom_level); | 833 host_zoom_map->SetZoomLevelForHost(host, zoom_level); |
804 } | 834 } |
805 | 835 |
806 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 836 // We're done imigrating the profile per-host zoom level values, so we clear |
Peter Kasting
2014/09/11 00:45:47
Nit: Spelling. (I'd just say "migrating", that's
wjmaclean
2014/09/11 21:00:51
Ha ha ... the 'i' was from vi ... 'migrating was i
| |
807 base::DictionaryValue* host_zoom_dictionary = update.Get(); | 837 // them all. |
808 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | 838 DictionaryPrefUpdate update(prefs_.get(), prefs::kProfilePerHostZoomLevels); |
809 it != keys_to_remove.end(); ++it) { | 839 base::DictionaryValue* host_zoom_dictionary_update = update.Get(); |
810 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | 840 host_zoom_dictionary_update->Clear(); |
811 } | |
812 } | 841 } |
813 | |
814 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | |
815 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | |
816 } | 842 } |
817 | 843 |
818 base::FilePath ProfileImpl::last_selected_directory() { | 844 base::FilePath ProfileImpl::last_selected_directory() { |
819 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 845 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
820 } | 846 } |
821 | 847 |
822 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 848 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
823 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 849 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
824 } | 850 } |
825 | 851 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 // it to be set by asking for the prefs. | 1052 // it to be set by asking for the prefs. |
1027 GetPrefs(); | 1053 GetPrefs(); |
1028 return last_session_exit_type_; | 1054 return last_session_exit_type_; |
1029 } | 1055 } |
1030 | 1056 |
1031 PrefService* ProfileImpl::GetPrefs() { | 1057 PrefService* ProfileImpl::GetPrefs() { |
1032 DCHECK(prefs_); // Should explicitly be initialized. | 1058 DCHECK(prefs_); // Should explicitly be initialized. |
1033 return prefs_.get(); | 1059 return prefs_.get(); |
1034 } | 1060 } |
1035 | 1061 |
1062 PrefService* ProfileImpl::GetZoomLevelPrefs() { | |
1063 return zoom_level_prefs_store_ ? zoom_level_prefs_store_->GetPrefs() : NULL; | |
1064 } | |
1065 | |
1036 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 1066 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
1037 DCHECK(prefs_); | 1067 DCHECK(prefs_); |
1038 if (!otr_prefs_) { | 1068 if (!otr_prefs_) { |
1039 // The new ExtensionPrefStore is ref_counted and the new PrefService | 1069 // The new ExtensionPrefStore is ref_counted and the new PrefService |
1040 // stores a reference so that we do not leak memory here. | 1070 // stores a reference so that we do not leak memory here. |
1041 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( | 1071 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
1042 CreateExtensionPrefStore(this, true))); | 1072 CreateExtensionPrefStore(this, true))); |
1043 } | 1073 } |
1044 return otr_prefs_.get(); | 1074 return otr_prefs_.get(); |
1045 } | 1075 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 top_sites_ = history::TopSites::Create( | 1204 top_sites_ = history::TopSites::Create( |
1175 this, GetPath().Append(chrome::kTopSitesFilename)); | 1205 this, GetPath().Append(chrome::kTopSitesFilename)); |
1176 } | 1206 } |
1177 return top_sites_.get(); | 1207 return top_sites_.get(); |
1178 } | 1208 } |
1179 | 1209 |
1180 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1210 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
1181 return top_sites_.get(); | 1211 return top_sites_.get(); |
1182 } | 1212 } |
1183 | 1213 |
1184 void ProfileImpl::OnDefaultZoomLevelChanged() { | |
1185 HostZoomMap::GetDefaultForBrowserContext(this)->SetDefaultZoomLevel( | |
1186 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); | |
1187 } | |
1188 | |
1189 void ProfileImpl::OnZoomLevelChanged( | |
1190 const HostZoomMap::ZoomLevelChange& change) { | |
1191 | |
1192 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | |
1193 return; | |
1194 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | |
1195 double level = change.zoom_level; | |
1196 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
1197 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
1198 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) | |
1199 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | |
1200 else | |
1201 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); | |
1202 } | |
1203 | |
1204 #if defined(ENABLE_SESSION_SERVICE) | 1214 #if defined(ENABLE_SESSION_SERVICE) |
1205 void ProfileImpl::StopCreateSessionServiceTimer() { | 1215 void ProfileImpl::StopCreateSessionServiceTimer() { |
1206 create_session_service_timer_.Stop(); | 1216 create_session_service_timer_.Stop(); |
1207 } | 1217 } |
1208 | 1218 |
1209 void ProfileImpl::EnsureSessionServiceCreated() { | 1219 void ProfileImpl::EnsureSessionServiceCreated() { |
1210 SessionServiceFactory::GetForProfile(this); | 1220 SessionServiceFactory::GetForProfile(this); |
1211 } | 1221 } |
1212 #endif | 1222 #endif |
1213 | 1223 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1452 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1462 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
1453 GetForBrowserContext(this); | 1463 GetForBrowserContext(this); |
1454 if (!service) | 1464 if (!service) |
1455 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1465 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
1456 | 1466 |
1457 return service->CreateMonitor( | 1467 return service->CreateMonitor( |
1458 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1468 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
1459 local_state, | 1469 local_state, |
1460 prefs::kMetricsReportingEnabled); | 1470 prefs::kMetricsReportingEnabled); |
1461 } | 1471 } |
OLD | NEW |