Chromium Code Reviews| Index: chrome/browser/profiles/profile_impl.cc | 
| diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc | 
| index f770e233e61129210851721d7c3bb7e92333ee47..69b08d667466e434a80feda2f83692fd8dfa1d86 100644 | 
| --- a/chrome/browser/profiles/profile_impl.cc | 
| +++ b/chrome/browser/profiles/profile_impl.cc | 
| @@ -15,6 +15,7 @@ | 
| #include "base/files/file_path.h" | 
| #include "base/files/file_util.h" | 
| #include "base/memory/scoped_ptr.h" | 
| +#include "base/metrics/stats_counters.h" | 
| #include "base/path_service.h" | 
| #include "base/prefs/json_pref_store.h" | 
| #include "base/prefs/scoped_user_pref_update.h" | 
| @@ -73,6 +74,7 @@ | 
| #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 
| #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | 
| #include "chrome/browser/ui/startup/startup_browser_creator.h" | 
| +#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 
| #include "chrome/common/chrome_constants.h" | 
| #include "chrome/common/chrome_paths_internal.h" | 
| #include "chrome/common/chrome_switches.h" | 
| @@ -517,10 +519,6 @@ void ProfileImpl::DoFinalInit() { | 
| prefs::kSupervisedUserId, | 
| base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, | 
| base::Unretained(this))); | 
| - pref_change_registrar_.Add( | 
| - prefs::kDefaultZoomLevel, | 
| - base::Bind(&ProfileImpl::OnDefaultZoomLevelChanged, | 
| - base::Unretained(this))); | 
| // Changes in the profile avatar. | 
| pref_change_registrar_.Add( | 
| @@ -749,14 +747,47 @@ void ProfileImpl::DoFinalInit() { | 
| void ProfileImpl::InitHostZoomMap() { | 
| HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 
| - host_zoom_map->SetDefaultZoomLevel( | 
| - prefs_->GetDouble(prefs::kDefaultZoomLevel)); | 
| + // As part of the migration from per-profile to per-partition HostZoomMaps, | 
| + // we need to detect if an existing per-profile set of preferences exist, and | 
| + // if so convert them to be per-partition. We migrate any per-profile zoom | 
| + // level prefs via zoom_level_prefs_store_. | 
| + // Code that updates zoom prefs in the profile prefs store has been removed, | 
| + // so once we clear these values here, they should never get set again. | 
| + // TODO(wjmaclean): Remove this migration machinery several milestones after | 
| + // it goes stable. This means removing this entire function. | 
| + DCHECK(!zoom_level_prefs_store_); | 
| + zoom_level_prefs_store_.reset( | 
| + new chrome::ChromeZoomLevelPrefs(prefs_.get(), GetPath())); | 
| + zoom_level_prefs_store_->InitPrefsAndCopyToHostZoomMap(GetPath(), | 
| + host_zoom_map); | 
| + | 
| + // Only migrate the default zoom level if it is not equal to the registered | 
| + // default for the preference. | 
| + double default_default_zoom_level = 0.0; | 
| + prefs_->GetDefaultPrefValue(prefs::kProfileDefaultZoomLevel) | 
| + ->GetAsDouble(&default_default_zoom_level); | 
| + double per_profile_default_zoom_level = | 
| + prefs_->GetDouble(prefs::kProfileDefaultZoomLevel); | 
| + if (per_profile_default_zoom_level != default_default_zoom_level) { | 
| + // We cannot un-register this pref name, but we can reset it to a | 
| + // default sentinel value. | 
| + prefs_->SetDouble(prefs::kProfileDefaultZoomLevel, | 
| + default_default_zoom_level); | 
| + zoom_level_prefs_store_->SetDefaultZoomLevel( | 
| + per_profile_default_zoom_level); | 
| + } | 
| const base::DictionaryValue* host_zoom_dictionary = | 
| - prefs_->GetDictionary(prefs::kPerHostZoomLevels); | 
| + prefs_->GetDictionary(prefs::kProfilePerHostZoomLevels); | 
| // Careful: The returned value could be NULL if the pref has never been set. | 
| if (host_zoom_dictionary != NULL) { | 
| - std::vector<std::string> keys_to_remove; | 
| + // Collect stats on frequency with which migrations are occuring. | 
| + if (!host_zoom_dictionary->empty()) { | 
| + 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
 
 | 
| + "Chrome.ZoomLevelPreferencesMigration"); | 
| + zoom_level_preferences_migration_counter.Increment(); | 
| + } | 
| + | 
| for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | 
| i.Advance()) { | 
| const std::string& host(i.key()); | 
| @@ -775,23 +806,21 @@ void ProfileImpl::InitHostZoomMap() { | 
| if (host.empty() || | 
| content::ZoomValuesEqual(zoom_level, | 
| host_zoom_map->GetDefaultZoomLevel())) { | 
| - keys_to_remove.push_back(host); | 
| continue; | 
| } | 
| + // We push the profile per-host levels in through the HostZoomMap | 
| + // directly, which will update the zoom_level_prefs_store_ indirectly | 
| + // through the subsequent ZoomLevelChanged events. | 
| host_zoom_map->SetZoomLevelForHost(host, zoom_level); | 
| } | 
| - DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 
| - base::DictionaryValue* host_zoom_dictionary = update.Get(); | 
| - for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | 
| - it != keys_to_remove.end(); ++it) { | 
| - host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | 
| - } | 
| + // We're done migrating the profile per-host zoom level values, so we clear | 
| + // them all. | 
| + DictionaryPrefUpdate update(prefs_.get(), prefs::kProfilePerHostZoomLevels); | 
| + base::DictionaryValue* host_zoom_dictionary_update = update.Get(); | 
| + host_zoom_dictionary_update->Clear(); | 
| } | 
| - | 
| - zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | 
| - base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | 
| } | 
| base::FilePath ProfileImpl::last_selected_directory() { | 
| @@ -1012,6 +1041,10 @@ PrefService* ProfileImpl::GetPrefs() { | 
| return prefs_.get(); | 
| } | 
| +chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { | 
| + return zoom_level_prefs_store_.get(); | 
| +} | 
| + | 
| PrefService* ProfileImpl::GetOffTheRecordPrefs() { | 
| DCHECK(prefs_); | 
| if (!otr_prefs_) { | 
| @@ -1160,26 +1193,6 @@ history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 
| return top_sites_.get(); | 
| } | 
| -void ProfileImpl::OnDefaultZoomLevelChanged() { | 
| - HostZoomMap::GetDefaultForBrowserContext(this)->SetDefaultZoomLevel( | 
| - pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); | 
| -} | 
| - | 
| -void ProfileImpl::OnZoomLevelChanged( | 
| - const HostZoomMap::ZoomLevelChange& change) { | 
| - | 
| - if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | 
| - return; | 
| - HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 
| - double level = change.zoom_level; | 
| - DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 
| - base::DictionaryValue* host_zoom_dictionary = update.Get(); | 
| - if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) | 
| - host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | 
| - else | 
| - host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); | 
| -} | 
| - | 
| #if defined(ENABLE_SESSION_SERVICE) | 
| void ProfileImpl::StopCreateSessionServiceTimer() { | 
| create_session_service_timer_.Stop(); |