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-partiion HostZoomMaps, |
sky
2014/09/04 21:52:24
partition
| |
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. | |
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. |
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 |
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 // it to be set by asking for the prefs. | 1055 // it to be set by asking for the prefs. |
1030 GetPrefs(); | 1056 GetPrefs(); |
1031 return last_session_exit_type_; | 1057 return last_session_exit_type_; |
1032 } | 1058 } |
1033 | 1059 |
1034 PrefService* ProfileImpl::GetPrefs() { | 1060 PrefService* ProfileImpl::GetPrefs() { |
1035 DCHECK(prefs_); // Should explicitly be initialized. | 1061 DCHECK(prefs_); // Should explicitly be initialized. |
1036 return prefs_.get(); | 1062 return prefs_.get(); |
1037 } | 1063 } |
1038 | 1064 |
1065 PrefService* ProfileImpl::GetZoomLevelPrefs() { | |
1066 return zoom_level_prefs_store_ ? zoom_level_prefs_store_->GetPrefs() : NULL; | |
1067 } | |
1068 | |
1039 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 1069 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
1040 DCHECK(prefs_); | 1070 DCHECK(prefs_); |
1041 if (!otr_prefs_) { | 1071 if (!otr_prefs_) { |
1042 // The new ExtensionPrefStore is ref_counted and the new PrefService | 1072 // The new ExtensionPrefStore is ref_counted and the new PrefService |
1043 // stores a reference so that we do not leak memory here. | 1073 // stores a reference so that we do not leak memory here. |
1044 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( | 1074 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
1045 CreateExtensionPrefStore(this, true))); | 1075 CreateExtensionPrefStore(this, true))); |
1046 } | 1076 } |
1047 return otr_prefs_.get(); | 1077 return otr_prefs_.get(); |
1048 } | 1078 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 top_sites_ = history::TopSites::Create( | 1207 top_sites_ = history::TopSites::Create( |
1178 this, GetPath().Append(chrome::kTopSitesFilename)); | 1208 this, GetPath().Append(chrome::kTopSitesFilename)); |
1179 } | 1209 } |
1180 return top_sites_.get(); | 1210 return top_sites_.get(); |
1181 } | 1211 } |
1182 | 1212 |
1183 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1213 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
1184 return top_sites_.get(); | 1214 return top_sites_.get(); |
1185 } | 1215 } |
1186 | 1216 |
1187 void ProfileImpl::OnDefaultZoomLevelChanged() { | |
1188 HostZoomMap::GetDefaultForBrowserContext(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::GetDefaultForBrowserContext(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) | 1217 #if defined(ENABLE_SESSION_SERVICE) |
1208 void ProfileImpl::StopCreateSessionServiceTimer() { | 1218 void ProfileImpl::StopCreateSessionServiceTimer() { |
1209 create_session_service_timer_.Stop(); | 1219 create_session_service_timer_.Stop(); |
1210 } | 1220 } |
1211 | 1221 |
1212 void ProfileImpl::EnsureSessionServiceCreated() { | 1222 void ProfileImpl::EnsureSessionServiceCreated() { |
1213 SessionServiceFactory::GetForProfile(this); | 1223 SessionServiceFactory::GetForProfile(this); |
1214 } | 1224 } |
1215 #endif | 1225 #endif |
1216 | 1226 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1455 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1465 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
1456 GetForBrowserContext(this); | 1466 GetForBrowserContext(this); |
1457 if (!service) | 1467 if (!service) |
1458 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1468 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
1459 | 1469 |
1460 return service->CreateMonitor( | 1470 return service->CreateMonitor( |
1461 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1471 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
1462 local_state, | 1472 local_state, |
1463 prefs::kMetricsReportingEnabled); | 1473 prefs::kMetricsReportingEnabled); |
1464 } | 1474 } |
OLD | NEW |