| Index: chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc
|
| diff --git a/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc b/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc
|
| index 65576ae8c34a1564339f73fcabfc979a81b829a7..6246ef7359acfd73ea845e1891356920a71d7259 100644
|
| --- a/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc
|
| +++ b/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc
|
| @@ -7,48 +7,29 @@
|
| #include <stddef.h>
|
|
|
| #include "base/bind.h"
|
| -#include "base/strings/string_number_conversions.h"
|
| +#include "base/metrics/histogram_macros.h"
|
| #include "base/values.h"
|
| +#include "chrome/browser/ui/zoom/chrome_zoom_prefs_helper.h"
|
| #include "chrome/common/chrome_constants.h"
|
| #include "chrome/common/pref_names.h"
|
| -#include "components/prefs/json_pref_store.h"
|
| -#include "components/prefs/pref_filter.h"
|
| -#include "components/prefs/pref_registry_simple.h"
|
| -#include "components/prefs/pref_service_factory.h"
|
| #include "components/prefs/scoped_user_pref_update.h"
|
| #include "components/zoom/zoom_event_manager.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/host_zoom_map.h"
|
| #include "content/public/common/page_zoom.h"
|
|
|
| -namespace {
|
| -
|
| -std::string GetHash(const base::FilePath& relative_path) {
|
| - size_t int_key = BASE_HASH_NAMESPACE::hash<base::FilePath>()(relative_path);
|
| - return base::SizeTToString(int_key);
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| ChromeZoomLevelPrefs::ChromeZoomLevelPrefs(
|
| PrefService* pref_service,
|
| const base::FilePath& profile_path,
|
| const base::FilePath& partition_path,
|
| base::WeakPtr<zoom::ZoomEventManager> zoom_event_manager)
|
| - : pref_service_(pref_service),
|
| + : partitioned_prefs_(pref_service, profile_path, partition_path),
|
| zoom_event_manager_(zoom_event_manager),
|
| host_zoom_map_(nullptr) {
|
| - DCHECK(pref_service_);
|
| -
|
| - DCHECK(!partition_path.empty());
|
| - DCHECK((partition_path == profile_path) ||
|
| - profile_path.IsParent(partition_path));
|
| - // Create a partition_key string with no '.'s in it. For the default
|
| - // StoragePartition, this string will always be "0".
|
| - base::FilePath partition_relative_path;
|
| - profile_path.AppendRelativePath(partition_path, &partition_relative_path);
|
| - partition_key_ = GetHash(partition_relative_path);
|
| -
|
| + // If this is the default partition, emit the zoom scope setting.
|
| + if (profile_path == partition_path)
|
| + UMA_HISTOGRAM_BOOLEAN("Settings.ZoomScopeIsPerOrigin",
|
| + GetZoomScopeIsPerOriginPref());
|
| }
|
|
|
| ChromeZoomLevelPrefs::~ChromeZoomLevelPrefs() {
|
| @@ -56,15 +37,14 @@ ChromeZoomLevelPrefs::~ChromeZoomLevelPrefs() {
|
|
|
| std::string ChromeZoomLevelPrefs::GetHashForTesting(
|
| const base::FilePath& relative_path) {
|
| - return GetHash(relative_path);
|
| + return ChromeZoomPrefsHelper::GetHashForTesting(relative_path);
|
| }
|
|
|
| void ChromeZoomLevelPrefs::SetDefaultZoomLevelPref(double level) {
|
| if (content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel()))
|
| return;
|
|
|
| - DictionaryPrefUpdate update(pref_service_, prefs::kPartitionDefaultZoomLevel);
|
| - update->SetDouble(partition_key_, level);
|
| + partitioned_prefs_.SetDouble(prefs::kPartitionDefaultZoomLevel, level);
|
| // For unregistered paths, OnDefaultZoomLevelChanged won't be called, so
|
| // set this manually.
|
| host_zoom_map_->SetDefaultZoomLevel(level);
|
| @@ -76,11 +56,10 @@ void ChromeZoomLevelPrefs::SetDefaultZoomLevelPref(double level) {
|
| double ChromeZoomLevelPrefs::GetDefaultZoomLevelPref() const {
|
| double default_zoom_level = 0.0;
|
|
|
| - const base::DictionaryValue* default_zoom_level_dictionary =
|
| - pref_service_->GetDictionary(prefs::kPartitionDefaultZoomLevel);
|
| // If no default has been previously set, the default returned is the
|
| // value used to initialize default_zoom_level in this function.
|
| - default_zoom_level_dictionary->GetDouble(partition_key_, &default_zoom_level);
|
| + partitioned_prefs_.GetDouble(prefs::kPartitionDefaultZoomLevel,
|
| + &default_zoom_level);
|
| return default_zoom_level;
|
| }
|
|
|
| @@ -90,6 +69,31 @@ ChromeZoomLevelPrefs::RegisterDefaultZoomLevelCallback(
|
| return default_zoom_changed_callbacks_.Add(callback);
|
| }
|
|
|
| +void ChromeZoomLevelPrefs::SetZoomScopeIsPerOriginPref(bool is_per_origin) {
|
| + if (is_per_origin == GetZoomScopeIsPerOriginPref())
|
| + return;
|
| +
|
| + partitioned_prefs_.SetBoolean(prefs::kPartitionZoomScopeIsPerOrigin,
|
| + is_per_origin);
|
| + default_scope_changed_callbacks_.Notify();
|
| +}
|
| +
|
| +bool ChromeZoomLevelPrefs::GetZoomScopeIsPerOriginPref() const {
|
| + bool is_per_origin = kZoomScopeSettingDefault;
|
| +
|
| + // If no value has been previously set, |is_per_origin| will be untouched
|
| + // from the default value we've set above.
|
| + partitioned_prefs_.GetBoolean(prefs::kPartitionZoomScopeIsPerOrigin,
|
| + &is_per_origin);
|
| + return is_per_origin;
|
| +}
|
| +
|
| +std::unique_ptr<ChromeZoomLevelPrefs::DefaultZoomScopeSubscription>
|
| +ChromeZoomLevelPrefs::RegisterDefaultZoomScopeCallback(
|
| + const base::Closure& callback) {
|
| + return default_scope_changed_callbacks_.Add(callback);
|
| +}
|
| +
|
| void ChromeZoomLevelPrefs::OnZoomLevelChanged(
|
| const content::HostZoomMap::ZoomLevelChange& change) {
|
| // If there's a manager to aggregate ZoomLevelChanged events, pass this event
|
| @@ -101,20 +105,14 @@ void ChromeZoomLevelPrefs::OnZoomLevelChanged(
|
| if (change.mode != content::HostZoomMap::ZOOM_CHANGED_FOR_HOST)
|
| return;
|
| double level = change.zoom_level;
|
| - DictionaryPrefUpdate update(pref_service_,
|
| - prefs::kPartitionPerHostZoomLevels);
|
| - base::DictionaryValue* host_zoom_dictionaries = update.Get();
|
| - DCHECK(host_zoom_dictionaries);
|
| + std::unique_ptr<DictionaryPrefUpdate> update(
|
| + partitioned_prefs_.GetUpdate(prefs::kPartitionPerHostZoomLevels));
|
|
|
| bool modification_is_removal =
|
| content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel());
|
|
|
| - base::DictionaryValue* host_zoom_dictionary = nullptr;
|
| - if (!host_zoom_dictionaries->GetDictionary(partition_key_,
|
| - &host_zoom_dictionary)) {
|
| - host_zoom_dictionary = new base::DictionaryValue();
|
| - host_zoom_dictionaries->Set(partition_key_, host_zoom_dictionary);
|
| - }
|
| + base::DictionaryValue* host_zoom_dictionary(
|
| + partitioned_prefs_.GetMutableDictionary(update.get()));
|
|
|
| if (modification_is_removal)
|
| host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, nullptr);
|
| @@ -166,12 +164,10 @@ void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels(
|
| // Sanitize prefs to remove entries that match the default zoom level and/or
|
| // have an empty host.
|
| {
|
| - DictionaryPrefUpdate update(pref_service_,
|
| - prefs::kPartitionPerHostZoomLevels);
|
| - base::DictionaryValue* host_zoom_dictionaries = update.Get();
|
| - base::DictionaryValue* host_zoom_dictionary = nullptr;
|
| - host_zoom_dictionaries->GetDictionary(partition_key_,
|
| - &host_zoom_dictionary);
|
| + std::unique_ptr<DictionaryPrefUpdate> update(
|
| + partitioned_prefs_.GetUpdate(prefs::kPartitionPerHostZoomLevels));
|
| + base::DictionaryValue* host_zoom_dictionary(
|
| + partitioned_prefs_.GetMutableDictionary(update.get()));
|
| for (const std::string& s : keys_to_remove)
|
| host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr);
|
| }
|
| @@ -189,11 +185,9 @@ void ChromeZoomLevelPrefs::InitHostZoomMap(
|
|
|
| // Initialize the HostZoomMap with per-host zoom levels from the persisted
|
| // zoom-level preference values.
|
| - const base::DictionaryValue* host_zoom_dictionaries =
|
| - pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels);
|
| const base::DictionaryValue* host_zoom_dictionary = nullptr;
|
| - if (host_zoom_dictionaries->GetDictionary(partition_key_,
|
| - &host_zoom_dictionary)) {
|
| + if (partitioned_prefs_.GetDictionary(prefs::kPartitionPerHostZoomLevels,
|
| + &host_zoom_dictionary)) {
|
| // Since we're calling this before setting up zoom_subscription_ below we
|
| // don't need to worry that host_zoom_dictionary is indirectly affected
|
| // by calls to HostZoomMap::SetZoomLevelForHost().
|
|
|