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

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: Convert to using only profile prefs. 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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/environment.h" 14 #include "base/environment.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/metrics/stats_counters.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/prefs/json_pref_store.h" 20 #include "base/prefs/json_pref_store.h"
20 #include "base/prefs/scoped_user_pref_update.h" 21 #include "base/prefs/scoped_user_pref_update.h"
21 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
25 #include "base/synchronization/waitable_event.h" 26 #include "base/synchronization/waitable_event.h"
26 #include "base/threading/sequenced_worker_pool.h" 27 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/version.h" 28 #include "base/version.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "chrome/browser/profiles/profile_metrics.h" 67 #include "chrome/browser/profiles/profile_metrics.h"
67 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 68 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
68 #include "chrome/browser/services/gcm/gcm_profile_service.h" 69 #include "chrome/browser/services/gcm/gcm_profile_service.h"
69 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 70 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
70 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" 71 #include "chrome/browser/services/gcm/push_messaging_service_impl.h"
71 #include "chrome/browser/sessions/session_service_factory.h" 72 #include "chrome/browser/sessions/session_service_factory.h"
72 #include "chrome/browser/signin/signin_ui_util.h" 73 #include "chrome/browser/signin/signin_ui_util.h"
73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" 74 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
74 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" 75 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
75 #include "chrome/browser/ui/startup/startup_browser_creator.h" 76 #include "chrome/browser/ui/startup/startup_browser_creator.h"
77 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
76 #include "chrome/common/chrome_constants.h" 78 #include "chrome/common/chrome_constants.h"
77 #include "chrome/common/chrome_paths_internal.h" 79 #include "chrome/common/chrome_paths_internal.h"
78 #include "chrome/common/chrome_switches.h" 80 #include "chrome/common/chrome_switches.h"
79 #include "chrome/common/chrome_version_info.h" 81 #include "chrome/common/chrome_version_info.h"
80 #include "chrome/common/pref_names.h" 82 #include "chrome/common/pref_names.h"
81 #include "chrome/common/url_constants.h" 83 #include "chrome/common/url_constants.h"
82 #include "chrome/grit/chromium_strings.h" 84 #include "chrome/grit/chromium_strings.h"
83 #include "components/bookmarks/browser/bookmark_model.h" 85 #include "components/bookmarks/browser/bookmark_model.h"
84 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" 86 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
85 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" 87 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h"
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 PrefService* prefs = GetPrefs(); 512 PrefService* prefs = GetPrefs();
511 pref_change_registrar_.Init(prefs); 513 pref_change_registrar_.Init(prefs);
512 pref_change_registrar_.Add( 514 pref_change_registrar_.Add(
513 prefs::kGoogleServicesUsername, 515 prefs::kGoogleServicesUsername,
514 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, 516 base::Bind(&ProfileImpl::UpdateProfileUserNameCache,
515 base::Unretained(this))); 517 base::Unretained(this)));
516 pref_change_registrar_.Add( 518 pref_change_registrar_.Add(
517 prefs::kSupervisedUserId, 519 prefs::kSupervisedUserId,
518 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, 520 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache,
519 base::Unretained(this))); 521 base::Unretained(this)));
520 pref_change_registrar_.Add(
521 prefs::kDefaultZoomLevel,
522 base::Bind(&ProfileImpl::OnDefaultZoomLevelChanged,
523 base::Unretained(this)));
524 522
525 // Changes in the profile avatar. 523 // Changes in the profile avatar.
526 pref_change_registrar_.Add( 524 pref_change_registrar_.Add(
527 prefs::kProfileAvatarIndex, 525 prefs::kProfileAvatarIndex,
528 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 526 base::Bind(&ProfileImpl::UpdateProfileAvatarCache,
529 base::Unretained(this))); 527 base::Unretained(this)));
530 pref_change_registrar_.Add( 528 pref_change_registrar_.Add(
531 prefs::kProfileUsingDefaultAvatar, 529 prefs::kProfileUsingDefaultAvatar,
532 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 530 base::Bind(&ProfileImpl::UpdateProfileAvatarCache,
533 base::Unretained(this))); 531 base::Unretained(this)));
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 740
743 gcm::PushMessagingServiceImpl::InitializeForProfile(this); 741 gcm::PushMessagingServiceImpl::InitializeForProfile(this);
744 742
745 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) 743 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS)
746 signin_ui_util::InitializePrefsForProfile(this); 744 signin_ui_util::InitializePrefsForProfile(this);
747 #endif 745 #endif
748 } 746 }
749 747
750 void ProfileImpl::InitHostZoomMap() { 748 void ProfileImpl::InitHostZoomMap() {
751 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); 749 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this);
752 host_zoom_map->SetDefaultZoomLevel( 750 // As part of the migration from per-profile to per-partition HostZoomMaps,
753 prefs_->GetDouble(prefs::kDefaultZoomLevel)); 751 // we need to detect if an existing per-profile set of preferences exist, and
752 // if so convert them to be per-partition. We migrate any per-profile zoom
753 // level prefs via zoom_level_prefs_store_.
754 // Code that updates zoom prefs in the profile prefs store has been removed,
755 // so once we clear these values here, they should never get set again.
756 // TODO(wjmaclean): Remove this migration machinery several milestones after
757 // it goes stable. This means removing this entire function.
758 DCHECK(!zoom_level_prefs_store_);
759 zoom_level_prefs_store_.reset(
760 new chrome::ChromeZoomLevelPrefs(prefs_.get(), GetPath()));
761 zoom_level_prefs_store_->InitPrefsAndCopyToHostZoomMap(GetPath(),
762 host_zoom_map);
763
764 // Only migrate the default zoom level if it is not equal to the registered
765 // default for the preference.
766 double default_default_zoom_level = 0.0;
767 prefs_->GetDefaultPrefValue(prefs::kProfileDefaultZoomLevel)
768 ->GetAsDouble(&default_default_zoom_level);
769 double per_profile_default_zoom_level =
770 prefs_->GetDouble(prefs::kProfileDefaultZoomLevel);
771 if (per_profile_default_zoom_level != default_default_zoom_level) {
772 // We cannot un-register this pref name, but we can reset it to a
773 // default sentinel value.
774 prefs_->SetDouble(prefs::kProfileDefaultZoomLevel,
775 default_default_zoom_level);
776 zoom_level_prefs_store_->SetDefaultZoomLevel(
777 per_profile_default_zoom_level);
778 }
754 779
755 const base::DictionaryValue* host_zoom_dictionary = 780 const base::DictionaryValue* host_zoom_dictionary =
756 prefs_->GetDictionary(prefs::kPerHostZoomLevels); 781 prefs_->GetDictionary(prefs::kProfilePerHostZoomLevels);
757 // Careful: The returned value could be NULL if the pref has never been set. 782 // Careful: The returned value could be NULL if the pref has never been set.
758 if (host_zoom_dictionary != NULL) { 783 if (host_zoom_dictionary != NULL) {
759 std::vector<std::string> keys_to_remove; 784 // Collect stats on frequency with which migrations are occuring.
785 if (!host_zoom_dictionary->empty()) {
786 base::StatsCounter zoom_level_preferences_migration_counter(
Bernhard Bauer 2014/10/01 15:09:14 Any reason why you're doing this instead of base::
wjmaclean 2014/10/01 20:33:00 When I looked at UserAction() it seemed to be abou
787 "Chrome.ZoomLevelPreferencesMigration");
788 zoom_level_preferences_migration_counter.Increment();
789 }
790
760 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); 791 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd();
761 i.Advance()) { 792 i.Advance()) {
762 const std::string& host(i.key()); 793 const std::string& host(i.key());
763 double zoom_level = 0; 794 double zoom_level = 0;
764 795
765 bool success = i.value().GetAsDouble(&zoom_level); 796 bool success = i.value().GetAsDouble(&zoom_level);
766 DCHECK(success); 797 DCHECK(success);
767 798
768 // Filter out A) the empty host, B) zoom levels equal to the default; and 799 // Filter out A) the empty host, B) zoom levels equal to the default; and
769 // remember them, so that we can later erase them from Prefs. 800 // remember them, so that we can later erase them from Prefs.
770 // Values of type A and B could have been stored due to crbug.com/364399. 801 // Values of type A and B could have been stored due to crbug.com/364399.
771 // Values of type B could further have been stored before the default zoom 802 // Values of type B could further have been stored before the default zoom
772 // level was set to its current value. In either case, SetZoomLevelForHost 803 // level was set to its current value. In either case, SetZoomLevelForHost
773 // will ignore type B values, thus, to have consistency with HostZoomMap's 804 // will ignore type B values, thus, to have consistency with HostZoomMap's
774 // internal state, these values must also be removed from Prefs. 805 // internal state, these values must also be removed from Prefs.
775 if (host.empty() || 806 if (host.empty() ||
776 content::ZoomValuesEqual(zoom_level, 807 content::ZoomValuesEqual(zoom_level,
777 host_zoom_map->GetDefaultZoomLevel())) { 808 host_zoom_map->GetDefaultZoomLevel())) {
778 keys_to_remove.push_back(host);
779 continue; 809 continue;
780 } 810 }
781 811
812 // We push the profile per-host levels in through the HostZoomMap
813 // directly, which will update the zoom_level_prefs_store_ indirectly
814 // through the subsequent ZoomLevelChanged events.
782 host_zoom_map->SetZoomLevelForHost(host, zoom_level); 815 host_zoom_map->SetZoomLevelForHost(host, zoom_level);
783 } 816 }
784 817
785 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); 818 // We're done migrating the profile per-host zoom level values, so we clear
786 base::DictionaryValue* host_zoom_dictionary = update.Get(); 819 // them all.
787 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); 820 DictionaryPrefUpdate update(prefs_.get(), prefs::kProfilePerHostZoomLevels);
788 it != keys_to_remove.end(); ++it) { 821 base::DictionaryValue* host_zoom_dictionary_update = update.Get();
789 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); 822 host_zoom_dictionary_update->Clear();
790 }
791 } 823 }
792
793 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback(
794 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this)));
795 } 824 }
796 825
797 base::FilePath ProfileImpl::last_selected_directory() { 826 base::FilePath ProfileImpl::last_selected_directory() {
798 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); 827 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
799 } 828 }
800 829
801 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { 830 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) {
802 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); 831 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
803 } 832 }
804 833
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 // it to be set by asking for the prefs. 1034 // it to be set by asking for the prefs.
1006 GetPrefs(); 1035 GetPrefs();
1007 return last_session_exit_type_; 1036 return last_session_exit_type_;
1008 } 1037 }
1009 1038
1010 PrefService* ProfileImpl::GetPrefs() { 1039 PrefService* ProfileImpl::GetPrefs() {
1011 DCHECK(prefs_); // Should explicitly be initialized. 1040 DCHECK(prefs_); // Should explicitly be initialized.
1012 return prefs_.get(); 1041 return prefs_.get();
1013 } 1042 }
1014 1043
1044 chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() {
1045 return zoom_level_prefs_store_.get();
1046 }
1047
1015 PrefService* ProfileImpl::GetOffTheRecordPrefs() { 1048 PrefService* ProfileImpl::GetOffTheRecordPrefs() {
1016 DCHECK(prefs_); 1049 DCHECK(prefs_);
1017 if (!otr_prefs_) { 1050 if (!otr_prefs_) {
1018 // The new ExtensionPrefStore is ref_counted and the new PrefService 1051 // The new ExtensionPrefStore is ref_counted and the new PrefService
1019 // stores a reference so that we do not leak memory here. 1052 // stores a reference so that we do not leak memory here.
1020 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( 1053 otr_prefs_.reset(prefs_->CreateIncognitoPrefService(
1021 CreateExtensionPrefStore(this, true))); 1054 CreateExtensionPrefStore(this, true)));
1022 } 1055 }
1023 return otr_prefs_.get(); 1056 return otr_prefs_.get();
1024 } 1057 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 top_sites_ = history::TopSites::Create( 1186 top_sites_ = history::TopSites::Create(
1154 this, GetPath().Append(chrome::kTopSitesFilename)); 1187 this, GetPath().Append(chrome::kTopSitesFilename));
1155 } 1188 }
1156 return top_sites_.get(); 1189 return top_sites_.get();
1157 } 1190 }
1158 1191
1159 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 1192 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
1160 return top_sites_.get(); 1193 return top_sites_.get();
1161 } 1194 }
1162 1195
1163 void ProfileImpl::OnDefaultZoomLevelChanged() {
1164 HostZoomMap::GetDefaultForBrowserContext(this)->SetDefaultZoomLevel(
1165 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel));
1166 }
1167
1168 void ProfileImpl::OnZoomLevelChanged(
1169 const HostZoomMap::ZoomLevelChange& change) {
1170
1171 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST)
1172 return;
1173 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this);
1174 double level = change.zoom_level;
1175 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
1176 base::DictionaryValue* host_zoom_dictionary = update.Get();
1177 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel()))
1178 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL);
1179 else
1180 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level);
1181 }
1182
1183 #if defined(ENABLE_SESSION_SERVICE) 1196 #if defined(ENABLE_SESSION_SERVICE)
1184 void ProfileImpl::StopCreateSessionServiceTimer() { 1197 void ProfileImpl::StopCreateSessionServiceTimer() {
1185 create_session_service_timer_.Stop(); 1198 create_session_service_timer_.Stop();
1186 } 1199 }
1187 1200
1188 void ProfileImpl::EnsureSessionServiceCreated() { 1201 void ProfileImpl::EnsureSessionServiceCreated() {
1189 SessionServiceFactory::GetForProfile(this); 1202 SessionServiceFactory::GetForProfile(this);
1190 } 1203 }
1191 #endif 1204 #endif
1192 1205
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> 1444 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1432 GetForBrowserContext(this); 1445 GetForBrowserContext(this);
1433 if (!service) 1446 if (!service)
1434 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); 1447 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>();
1435 1448
1436 return service->CreateMonitor( 1449 return service->CreateMonitor(
1437 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), 1450 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
1438 local_state, 1451 local_state,
1439 prefs::kMetricsReportingEnabled); 1452 prefs::kMetricsReportingEnabled);
1440 } 1453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698