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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 model->AddObserver(new BookmarkModelLoadedObserver(this)); | 741 model->AddObserver(new BookmarkModelLoadedObserver(this)); |
745 #endif | 742 #endif |
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() { |
battre
2014/10/08 11:27:10
What do you think of moving the migration code to
wjmaclean
2014/10/10 14:40:29
Done.
I didn't realize there was similar code els
| |
755 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 752 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
756 host_zoom_map->SetDefaultZoomLevel( | 753 // As part of the migration from per-profile to per-partition HostZoomMaps, |
757 prefs_->GetDouble(prefs::kDefaultZoomLevel)); | 754 // we need to detect if an existing per-profile set of preferences exist, and |
755 // if so convert them to be per-partition. We migrate any per-profile zoom | |
756 // level prefs via zoom_level_prefs_. | |
757 // Code that updates zoom prefs in the profile prefs store has been removed, | |
758 // so once we clear these values here, they should never get set again. | |
759 // TODO(wjmaclean): Remove this migration machinery several milestones after | |
760 // it goes stable. This means removing this entire function. | |
761 DCHECK(!zoom_level_prefs_); | |
762 zoom_level_prefs_.reset( | |
763 new chrome::ChromeZoomLevelPrefs(prefs_.get(), GetPath())); | |
764 zoom_level_prefs_->InitPrefsAndCopyToHostZoomMap(GetPath(), host_zoom_map); | |
765 | |
766 bool migrated = false; | |
767 // Only migrate the default zoom level if it is not equal to the registered | |
768 // default for the preference. | |
769 const base::Value* per_profile_default_zoom_level_value = | |
770 prefs_->GetUserPrefValue(prefs::kDefaultZoomLevelDeprecated); | |
771 if (per_profile_default_zoom_level_value) { | |
772 DCHECK(per_profile_default_zoom_level_value->GetType() == | |
773 base::Value::TYPE_DOUBLE); | |
774 double per_profile_default_zoom_level; | |
battre
2014/10/08 11:27:10
nit: = 0.0;
wjmaclean
2014/10/10 14:40:29
Done.
| |
775 per_profile_default_zoom_level_value->GetAsDouble( | |
776 &per_profile_default_zoom_level); | |
777 zoom_level_prefs_->SetDefaultZoomLevelPref(per_profile_default_zoom_level); | |
778 prefs_->ClearPref(prefs::kDefaultZoomLevelDeprecated); | |
779 migrated = true; | |
780 } | |
758 | 781 |
759 const base::DictionaryValue* host_zoom_dictionary = | 782 const base::DictionaryValue* host_zoom_dictionary = |
760 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | 783 prefs_->GetDictionary(prefs::kPerHostZoomLevelsDeprecated); |
761 // Careful: The returned value could be NULL if the pref has never been set. | 784 // Collect stats on frequency with which migrations are occuring. This measure |
762 if (host_zoom_dictionary != NULL) { | 785 // is not perfect, since it will consider an un-migrated user with only |
763 std::vector<std::string> keys_to_remove; | 786 // default value as being already migrated, but it will catch all non-trivial |
764 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | 787 // migrations. |
765 i.Advance()) { | 788 migrated |= !host_zoom_dictionary->empty(); |
766 const std::string& host(i.key()); | 789 UMA_HISTOGRAM_BOOLEAN("Settings.ZoomLevelPreferencesMigrated", migrated); |
767 double zoom_level = 0; | |
768 | 790 |
769 bool success = i.value().GetAsDouble(&zoom_level); | 791 for (base::DictionaryValue::Iterator it(*host_zoom_dictionary); !it.IsAtEnd(); |
770 DCHECK(success); | 792 it.Advance()) { |
793 const std::string& host(it.key()); | |
794 double zoom_level = 0; | |
771 | 795 |
772 // Filter out A) the empty host, B) zoom levels equal to the default; and | 796 bool success = it.value().GetAsDouble(&zoom_level); |
773 // remember them, so that we can later erase them from Prefs. | 797 DCHECK(success); |
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 | 798 |
786 host_zoom_map->SetZoomLevelForHost(host, zoom_level); | 799 // Filter out A) the empty host, B) zoom levels equal to the default; and |
800 // remember them, so that we can later erase them from Prefs. | |
801 // Values of type A and B could have been stored due to crbug.com/364399. | |
802 // Values of type B could further have been stored before the default zoom | |
803 // level was set to its current value. In either case, SetZoomLevelForHost | |
804 // will ignore type B values, thus, to have consistency with HostZoomMap's | |
805 // internal state, these values must also be removed from Prefs. | |
806 if (host.empty() || | |
807 content::ZoomValuesEqual(zoom_level, | |
808 host_zoom_map->GetDefaultZoomLevel())) { | |
809 continue; | |
787 } | 810 } |
788 | 811 |
789 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 812 // We push the profile per-host levels in through the HostZoomMap |
790 base::DictionaryValue* host_zoom_dictionary = update.Get(); | 813 // directly, which will update the zoom_level_prefs_ indirectly |
791 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | 814 // through the subsequent ZoomLevelChanged events. |
792 it != keys_to_remove.end(); ++it) { | 815 host_zoom_map->SetZoomLevelForHost(host, zoom_level); |
793 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | |
794 } | |
795 } | 816 } |
796 | 817 |
797 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | 818 // We're done migrating the profile per-host zoom level values, so we clear |
798 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | 819 // them all. |
820 DictionaryPrefUpdate host_zoom_dictionary_update( | |
821 prefs_.get(), prefs::kPerHostZoomLevelsDeprecated); | |
822 host_zoom_dictionary_update->Clear(); | |
799 } | 823 } |
800 | 824 |
801 base::FilePath ProfileImpl::last_selected_directory() { | 825 base::FilePath ProfileImpl::last_selected_directory() { |
802 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 826 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
803 } | 827 } |
804 | 828 |
805 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 829 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
806 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 830 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
807 } | 831 } |
808 | 832 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1009 // it to be set by asking for the prefs. | 1033 // it to be set by asking for the prefs. |
1010 GetPrefs(); | 1034 GetPrefs(); |
1011 return last_session_exit_type_; | 1035 return last_session_exit_type_; |
1012 } | 1036 } |
1013 | 1037 |
1014 PrefService* ProfileImpl::GetPrefs() { | 1038 PrefService* ProfileImpl::GetPrefs() { |
1015 DCHECK(prefs_); // Should explicitly be initialized. | 1039 DCHECK(prefs_); // Should explicitly be initialized. |
1016 return prefs_.get(); | 1040 return prefs_.get(); |
1017 } | 1041 } |
1018 | 1042 |
1043 chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { | |
1044 return zoom_level_prefs_.get(); | |
1045 } | |
1046 | |
1019 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 1047 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
1020 DCHECK(prefs_); | 1048 DCHECK(prefs_); |
1021 if (!otr_prefs_) { | 1049 if (!otr_prefs_) { |
1022 // The new ExtensionPrefStore is ref_counted and the new PrefService | 1050 // The new ExtensionPrefStore is ref_counted and the new PrefService |
1023 // stores a reference so that we do not leak memory here. | 1051 // stores a reference so that we do not leak memory here. |
1024 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( | 1052 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
1025 CreateExtensionPrefStore(this, true))); | 1053 CreateExtensionPrefStore(this, true))); |
1026 } | 1054 } |
1027 return otr_prefs_.get(); | 1055 return otr_prefs_.get(); |
1028 } | 1056 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1157 top_sites_ = history::TopSites::Create( | 1185 top_sites_ = history::TopSites::Create( |
1158 this, GetPath().Append(chrome::kTopSitesFilename)); | 1186 this, GetPath().Append(chrome::kTopSitesFilename)); |
1159 } | 1187 } |
1160 return top_sites_.get(); | 1188 return top_sites_.get(); |
1161 } | 1189 } |
1162 | 1190 |
1163 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1191 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
1164 return top_sites_.get(); | 1192 return top_sites_.get(); |
1165 } | 1193 } |
1166 | 1194 |
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) | 1195 #if defined(ENABLE_SESSION_SERVICE) |
1188 void ProfileImpl::StopCreateSessionServiceTimer() { | 1196 void ProfileImpl::StopCreateSessionServiceTimer() { |
1189 create_session_service_timer_.Stop(); | 1197 create_session_service_timer_.Stop(); |
1190 } | 1198 } |
1191 | 1199 |
1192 void ProfileImpl::EnsureSessionServiceCreated() { | 1200 void ProfileImpl::EnsureSessionServiceCreated() { |
1193 SessionServiceFactory::GetForProfile(this); | 1201 SessionServiceFactory::GetForProfile(this); |
1194 } | 1202 } |
1195 #endif | 1203 #endif |
1196 | 1204 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1435 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1443 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
1436 GetForBrowserContext(this); | 1444 GetForBrowserContext(this); |
1437 if (!service) | 1445 if (!service) |
1438 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1446 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
1439 | 1447 |
1440 return service->CreateMonitor( | 1448 return service->CreateMonitor( |
1441 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1449 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
1442 local_state, | 1450 local_state, |
1443 prefs::kMetricsReportingEnabled); | 1451 prefs::kMetricsReportingEnabled); |
1444 } | 1452 } |
OLD | NEW |