Chromium Code Reviews| 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 PrefService* prefs = GetPrefs(); | 511 PrefService* prefs = GetPrefs(); |
| 511 pref_change_registrar_.Init(prefs); | 512 pref_change_registrar_.Init(prefs); |
| 512 pref_change_registrar_.Add( | 513 pref_change_registrar_.Add( |
| 513 prefs::kGoogleServicesUsername, | 514 prefs::kGoogleServicesUsername, |
| 514 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, | 515 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, |
| 515 base::Unretained(this))); | 516 base::Unretained(this))); |
| 516 pref_change_registrar_.Add( | 517 pref_change_registrar_.Add( |
| 517 prefs::kSupervisedUserId, | 518 prefs::kSupervisedUserId, |
| 518 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, | 519 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, |
| 519 base::Unretained(this))); | 520 base::Unretained(this))); |
| 520 pref_change_registrar_.Add( | |
| 521 prefs::kDefaultZoomLevel, | |
| 522 base::Bind(&ProfileImpl::OnDefaultZoomLevelChanged, | |
| 523 base::Unretained(this))); | |
| 524 | 521 |
| 525 // Changes in the profile avatar. | 522 // Changes in the profile avatar. |
| 526 pref_change_registrar_.Add( | 523 pref_change_registrar_.Add( |
| 527 prefs::kProfileAvatarIndex, | 524 prefs::kProfileAvatarIndex, |
| 528 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 525 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
| 529 base::Unretained(this))); | 526 base::Unretained(this))); |
| 530 pref_change_registrar_.Add( | 527 pref_change_registrar_.Add( |
| 531 prefs::kProfileUsingDefaultAvatar, | 528 prefs::kProfileUsingDefaultAvatar, |
| 532 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 529 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
| 533 base::Unretained(this))); | 530 base::Unretained(this))); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 | 739 |
| 743 gcm::PushMessagingServiceImpl::InitializeForProfile(this); | 740 gcm::PushMessagingServiceImpl::InitializeForProfile(this); |
| 744 | 741 |
| 745 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) | 742 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) |
| 746 signin_ui_util::InitializePrefsForProfile(this); | 743 signin_ui_util::InitializePrefsForProfile(this); |
| 747 #endif | 744 #endif |
| 748 } | 745 } |
| 749 | 746 |
| 750 void ProfileImpl::InitHostZoomMap() { | 747 void ProfileImpl::InitHostZoomMap() { |
| 751 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 748 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
| 752 host_zoom_map->SetDefaultZoomLevel( | 749 // As part of the migration from per-profile to per-partition HostZoomMaps, |
| 753 prefs_->GetDouble(prefs::kDefaultZoomLevel)); | 750 // we need to detect if an existing per-profile set of preferences exist, and |
| 751 // if so convert them to be per-partition. We migrate any per-profile zoom | |
| 752 // level prefs via zoom_level_prefs_. | |
| 753 // Code that updates zoom prefs in the profile prefs store has been removed, | |
| 754 // so once we clear these values here, they should never get set again. | |
| 755 // TODO(wjmaclean): Remove this migration machinery several milestones after | |
| 756 // it goes stable. This means removing this entire function. | |
| 757 DCHECK(!zoom_level_prefs_); | |
| 758 zoom_level_prefs_.reset( | |
| 759 new chrome::ChromeZoomLevelPrefs(prefs_.get(), GetPath())); | |
| 760 zoom_level_prefs_->InitPrefsAndCopyToHostZoomMap(GetPath(), | |
| 761 host_zoom_map); | |
|
gab
2014/10/02 20:58:42
nit: indent
wjmaclean
2014/10/03 18:53:22
Done.
| |
| 762 | |
| 763 // Only migrate the default zoom level if it is not equal to the registered | |
| 764 // default for the preference. | |
| 765 double default_default_zoom_level = 0.0; | |
| 766 prefs_->GetDefaultPrefValue(prefs::kProfileDefaultZoomLevel) | |
| 767 ->GetAsDouble(&default_default_zoom_level); | |
| 768 double per_profile_default_zoom_level = | |
| 769 prefs_->GetDouble(prefs::kProfileDefaultZoomLevel); | |
| 770 if (per_profile_default_zoom_level != default_default_zoom_level) { | |
|
gab
2014/10/02 20:58:43
Use prefs_->GetUserPrefValue() instead which will
wjmaclean
2014/10/03 18:53:22
Thanks, that makes this code a lot better.
Done.
| |
| 771 // We cannot un-register this pref name, but we can reset it to a | |
| 772 // default sentinel value. | |
| 773 prefs_->SetDouble(prefs::kProfileDefaultZoomLevel, | |
| 774 default_default_zoom_level); | |
|
gab
2014/10/02 20:58:43
prefs_->ClearPref(prefs::kProfileDefaultZoomLevel)
wjmaclean
2014/10/03 18:53:22
Done.
| |
| 775 zoom_level_prefs_->SetDefaultZoomLevelPref( | |
| 776 per_profile_default_zoom_level); | |
| 777 } | |
| 754 | 778 |
| 755 const base::DictionaryValue* host_zoom_dictionary = | 779 const base::DictionaryValue* host_zoom_dictionary = |
| 756 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | 780 prefs_->GetDictionary(prefs::kProfilePerHostZoomLevels); |
| 757 // Careful: The returned value could be NULL if the pref has never been set. | 781 // Careful: The returned value could be NULL if the pref has never been set. |
|
gab
2014/10/02 20:58:43
Incorrect, PrefService will return the default val
wjmaclean
2014/10/03 18:53:22
This was actually in the legacy version of the cod
| |
| 758 if (host_zoom_dictionary != NULL) { | 782 if (host_zoom_dictionary != NULL) { |
| 759 std::vector<std::string> keys_to_remove; | 783 // Collect stats on frequency with which migrations are occuring. |
| 784 if (!host_zoom_dictionary->empty()) { | |
| 785 content::RecordAction( | |
| 786 UserMetricsAction("Chrome_ZoomLevelPreferencesMigration")); | |
|
gab
2014/10/02 20:58:43
Typically I use BooleanHit histograms [1] rather t
wjmaclean
2014/10/03 18:53:22
Done.
| |
| 787 } | |
| 788 | |
| 760 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | 789 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); |
|
gab
2014/10/02 20:58:43
s/i/it
is more common/better for iterators IMO
wjmaclean
2014/10/03 18:53:22
Done.
| |
| 761 i.Advance()) { | 790 i.Advance()) { |
| 762 const std::string& host(i.key()); | 791 const std::string& host(i.key()); |
| 763 double zoom_level = 0; | 792 double zoom_level = 0; |
| 764 | 793 |
| 765 bool success = i.value().GetAsDouble(&zoom_level); | 794 bool success = i.value().GetAsDouble(&zoom_level); |
| 766 DCHECK(success); | 795 DCHECK(success); |
| 767 | 796 |
| 768 // Filter out A) the empty host, B) zoom levels equal to the default; and | 797 // 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. | 798 // 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. | 799 // 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 | 800 // 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 | 801 // level was set to its current value. In either case, SetZoomLevelForHost |
| 773 // will ignore type B values, thus, to have consistency with HostZoomMap's | 802 // will ignore type B values, thus, to have consistency with HostZoomMap's |
| 774 // internal state, these values must also be removed from Prefs. | 803 // internal state, these values must also be removed from Prefs. |
| 775 if (host.empty() || | 804 if (host.empty() || |
| 776 content::ZoomValuesEqual(zoom_level, | 805 content::ZoomValuesEqual(zoom_level, |
| 777 host_zoom_map->GetDefaultZoomLevel())) { | 806 host_zoom_map->GetDefaultZoomLevel())) { |
| 778 keys_to_remove.push_back(host); | |
| 779 continue; | 807 continue; |
| 780 } | 808 } |
| 781 | 809 |
| 810 // We push the profile per-host levels in through the HostZoomMap | |
| 811 // directly, which will update the zoom_level_prefs_ indirectly | |
| 812 // through the subsequent ZoomLevelChanged events. | |
| 782 host_zoom_map->SetZoomLevelForHost(host, zoom_level); | 813 host_zoom_map->SetZoomLevelForHost(host, zoom_level); |
| 783 } | 814 } |
| 784 | 815 |
| 785 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 816 // We're done migrating the profile per-host zoom level values, so we clear |
| 786 base::DictionaryValue* host_zoom_dictionary = update.Get(); | 817 // them all. |
| 787 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | 818 DictionaryPrefUpdate update(prefs_.get(), prefs::kProfilePerHostZoomLevels); |
| 788 it != keys_to_remove.end(); ++it) { | 819 base::DictionaryValue* host_zoom_dictionary_update = update.Get(); |
| 789 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | 820 host_zoom_dictionary_update->Clear(); |
|
gab
2014/10/02 20:58:43
The above 2 lines can be replaced by
update->Clea
wjmaclean
2014/10/03 18:53:22
Done.
| |
| 790 } | |
| 791 } | 821 } |
| 792 | |
| 793 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | |
| 794 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | |
| 795 } | 822 } |
| 796 | 823 |
| 797 base::FilePath ProfileImpl::last_selected_directory() { | 824 base::FilePath ProfileImpl::last_selected_directory() { |
| 798 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 825 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
| 799 } | 826 } |
| 800 | 827 |
| 801 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 828 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
| 802 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 829 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 803 } | 830 } |
| 804 | 831 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 // it to be set by asking for the prefs. | 1032 // it to be set by asking for the prefs. |
| 1006 GetPrefs(); | 1033 GetPrefs(); |
| 1007 return last_session_exit_type_; | 1034 return last_session_exit_type_; |
| 1008 } | 1035 } |
| 1009 | 1036 |
| 1010 PrefService* ProfileImpl::GetPrefs() { | 1037 PrefService* ProfileImpl::GetPrefs() { |
| 1011 DCHECK(prefs_); // Should explicitly be initialized. | 1038 DCHECK(prefs_); // Should explicitly be initialized. |
| 1012 return prefs_.get(); | 1039 return prefs_.get(); |
| 1013 } | 1040 } |
| 1014 | 1041 |
| 1042 chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { | |
| 1043 return zoom_level_prefs_.get(); | |
| 1044 } | |
| 1045 | |
| 1015 PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 1046 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
| 1016 DCHECK(prefs_); | 1047 DCHECK(prefs_); |
| 1017 if (!otr_prefs_) { | 1048 if (!otr_prefs_) { |
| 1018 // The new ExtensionPrefStore is ref_counted and the new PrefService | 1049 // The new ExtensionPrefStore is ref_counted and the new PrefService |
| 1019 // stores a reference so that we do not leak memory here. | 1050 // stores a reference so that we do not leak memory here. |
| 1020 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( | 1051 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
| 1021 CreateExtensionPrefStore(this, true))); | 1052 CreateExtensionPrefStore(this, true))); |
| 1022 } | 1053 } |
| 1023 return otr_prefs_.get(); | 1054 return otr_prefs_.get(); |
| 1024 } | 1055 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 top_sites_ = history::TopSites::Create( | 1184 top_sites_ = history::TopSites::Create( |
| 1154 this, GetPath().Append(chrome::kTopSitesFilename)); | 1185 this, GetPath().Append(chrome::kTopSitesFilename)); |
| 1155 } | 1186 } |
| 1156 return top_sites_.get(); | 1187 return top_sites_.get(); |
| 1157 } | 1188 } |
| 1158 | 1189 |
| 1159 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1190 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
| 1160 return top_sites_.get(); | 1191 return top_sites_.get(); |
| 1161 } | 1192 } |
| 1162 | 1193 |
| 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) | 1194 #if defined(ENABLE_SESSION_SERVICE) |
| 1184 void ProfileImpl::StopCreateSessionServiceTimer() { | 1195 void ProfileImpl::StopCreateSessionServiceTimer() { |
| 1185 create_session_service_timer_.Stop(); | 1196 create_session_service_timer_.Stop(); |
| 1186 } | 1197 } |
| 1187 | 1198 |
| 1188 void ProfileImpl::EnsureSessionServiceCreated() { | 1199 void ProfileImpl::EnsureSessionServiceCreated() { |
| 1189 SessionServiceFactory::GetForProfile(this); | 1200 SessionServiceFactory::GetForProfile(this); |
| 1190 } | 1201 } |
| 1191 #endif | 1202 #endif |
| 1192 | 1203 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1431 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1442 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
| 1432 GetForBrowserContext(this); | 1443 GetForBrowserContext(this); |
| 1433 if (!service) | 1444 if (!service) |
| 1434 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1445 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
| 1435 | 1446 |
| 1436 return service->CreateMonitor( | 1447 return service->CreateMonitor( |
| 1437 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1448 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 1438 local_state, | 1449 local_state, |
| 1439 prefs::kMetricsReportingEnabled); | 1450 prefs::kMetricsReportingEnabled); |
| 1440 } | 1451 } |
| OLD | NEW |