Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 541103002: Introduce ChromeZoomLevelPref, make zoom level prefs independent of profile prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Experiment: Windows hash function test. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 // 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(),
765 host_zoom_map);
766
767 // Only migrate the default zoom level if it is not equal to the registered
768 // default for the preference.
769 double default_default_zoom_level = 0.0;
770 prefs_->GetDefaultPrefValue(prefs::kProfileDefaultZoomLevel)
771 ->GetAsDouble(&default_default_zoom_level);
772 double per_profile_default_zoom_level =
773 prefs_->GetDouble(prefs::kProfileDefaultZoomLevel);
774 if (per_profile_default_zoom_level != default_default_zoom_level) {
775 // We cannot un-register this pref name, but we can reset it to a
776 // default sentinel value.
777 prefs_->SetDouble(prefs::kProfileDefaultZoomLevel,
778 default_default_zoom_level);
779 zoom_level_prefs_->SetDefaultZoomLevelPref(
780 per_profile_default_zoom_level);
781 }
758 782
759 const base::DictionaryValue* host_zoom_dictionary = 783 const base::DictionaryValue* host_zoom_dictionary =
760 prefs_->GetDictionary(prefs::kPerHostZoomLevels); 784 prefs_->GetDictionary(prefs::kProfilePerHostZoomLevels);
761 // Careful: The returned value could be NULL if the pref has never been set. 785 // Careful: The returned value could be NULL if the pref has never been set.
762 if (host_zoom_dictionary != NULL) { 786 if (host_zoom_dictionary != NULL) {
763 std::vector<std::string> keys_to_remove; 787 // Collect stats on frequency with which migrations are occuring.
788 if (!host_zoom_dictionary->empty()) {
789 content::RecordAction(
790 UserMetricsAction("Chrome_ZoomLevelPreferencesMigration"));
Alexei Svitkine (slow) 2014/10/02 20:40:20 I'm not convinced a user action is the best way to
wjmaclean 2014/10/03 18:53:23 Done.
wjmaclean 2014/10/03 18:53:23 Done.
791 }
792
764 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); 793 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd();
765 i.Advance()) { 794 i.Advance()) {
766 const std::string& host(i.key()); 795 const std::string& host(i.key());
767 double zoom_level = 0; 796 double zoom_level = 0;
768 797
769 bool success = i.value().GetAsDouble(&zoom_level); 798 bool success = i.value().GetAsDouble(&zoom_level);
770 DCHECK(success); 799 DCHECK(success);
771 800
772 // Filter out A) the empty host, B) zoom levels equal to the default; and 801 // 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. 802 // 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. 803 // 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 804 // 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 805 // level was set to its current value. In either case, SetZoomLevelForHost
777 // will ignore type B values, thus, to have consistency with HostZoomMap's 806 // will ignore type B values, thus, to have consistency with HostZoomMap's
778 // internal state, these values must also be removed from Prefs. 807 // internal state, these values must also be removed from Prefs.
779 if (host.empty() || 808 if (host.empty() ||
780 content::ZoomValuesEqual(zoom_level, 809 content::ZoomValuesEqual(zoom_level,
781 host_zoom_map->GetDefaultZoomLevel())) { 810 host_zoom_map->GetDefaultZoomLevel())) {
782 keys_to_remove.push_back(host);
783 continue; 811 continue;
784 } 812 }
785 813
814 // We push the profile per-host levels in through the HostZoomMap
815 // directly, which will update the zoom_level_prefs_ indirectly
816 // through the subsequent ZoomLevelChanged events.
786 host_zoom_map->SetZoomLevelForHost(host, zoom_level); 817 host_zoom_map->SetZoomLevelForHost(host, zoom_level);
787 } 818 }
788 819
789 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); 820 // We're done migrating the profile per-host zoom level values, so we clear
790 base::DictionaryValue* host_zoom_dictionary = update.Get(); 821 // them all.
791 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); 822 DictionaryPrefUpdate update(prefs_.get(), prefs::kProfilePerHostZoomLevels);
792 it != keys_to_remove.end(); ++it) { 823 base::DictionaryValue* host_zoom_dictionary_update = update.Get();
793 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); 824 host_zoom_dictionary_update->Clear();
794 }
795 } 825 }
796
797 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback(
798 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this)));
799 } 826 }
800 827
801 base::FilePath ProfileImpl::last_selected_directory() { 828 base::FilePath ProfileImpl::last_selected_directory() {
802 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); 829 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
803 } 830 }
804 831
805 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { 832 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) {
806 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); 833 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
807 } 834 }
808 835
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 // it to be set by asking for the prefs. 1036 // it to be set by asking for the prefs.
1010 GetPrefs(); 1037 GetPrefs();
1011 return last_session_exit_type_; 1038 return last_session_exit_type_;
1012 } 1039 }
1013 1040
1014 PrefService* ProfileImpl::GetPrefs() { 1041 PrefService* ProfileImpl::GetPrefs() {
1015 DCHECK(prefs_); // Should explicitly be initialized. 1042 DCHECK(prefs_); // Should explicitly be initialized.
1016 return prefs_.get(); 1043 return prefs_.get();
1017 } 1044 }
1018 1045
1046 chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() {
1047 return zoom_level_prefs_.get();
1048 }
1049
1019 PrefService* ProfileImpl::GetOffTheRecordPrefs() { 1050 PrefService* ProfileImpl::GetOffTheRecordPrefs() {
1020 DCHECK(prefs_); 1051 DCHECK(prefs_);
1021 if (!otr_prefs_) { 1052 if (!otr_prefs_) {
1022 // The new ExtensionPrefStore is ref_counted and the new PrefService 1053 // The new ExtensionPrefStore is ref_counted and the new PrefService
1023 // stores a reference so that we do not leak memory here. 1054 // stores a reference so that we do not leak memory here.
1024 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( 1055 otr_prefs_.reset(prefs_->CreateIncognitoPrefService(
1025 CreateExtensionPrefStore(this, true))); 1056 CreateExtensionPrefStore(this, true)));
1026 } 1057 }
1027 return otr_prefs_.get(); 1058 return otr_prefs_.get();
1028 } 1059 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 top_sites_ = history::TopSites::Create( 1188 top_sites_ = history::TopSites::Create(
1158 this, GetPath().Append(chrome::kTopSitesFilename)); 1189 this, GetPath().Append(chrome::kTopSitesFilename));
1159 } 1190 }
1160 return top_sites_.get(); 1191 return top_sites_.get();
1161 } 1192 }
1162 1193
1163 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 1194 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
1164 return top_sites_.get(); 1195 return top_sites_.get();
1165 } 1196 }
1166 1197
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) 1198 #if defined(ENABLE_SESSION_SERVICE)
1188 void ProfileImpl::StopCreateSessionServiceTimer() { 1199 void ProfileImpl::StopCreateSessionServiceTimer() {
1189 create_session_service_timer_.Stop(); 1200 create_session_service_timer_.Stop();
1190 } 1201 }
1191 1202
1192 void ProfileImpl::EnsureSessionServiceCreated() { 1203 void ProfileImpl::EnsureSessionServiceCreated() {
1193 SessionServiceFactory::GetForProfile(this); 1204 SessionServiceFactory::GetForProfile(this);
1194 } 1205 }
1195 #endif 1206 #endif
1196 1207
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> 1446 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1436 GetForBrowserContext(this); 1447 GetForBrowserContext(this);
1437 if (!service) 1448 if (!service)
1438 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); 1449 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>();
1439 1450
1440 return service->CreateMonitor( 1451 return service->CreateMonitor(
1441 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), 1452 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
1442 local_state, 1453 local_state,
1443 prefs::kMetricsReportingEnabled); 1454 prefs::kMetricsReportingEnabled);
1444 } 1455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698