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

Unified Diff: chrome/browser/ui/zoom/chrome_zoom_prefs_helper.cc

Issue 2630583002: Add setting to isolate zoom changes by default. (Closed)
Patch Set: ... and tell closure_compiler. Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/zoom/chrome_zoom_prefs_helper.cc
diff --git a/chrome/browser/ui/zoom/chrome_zoom_prefs_helper.cc b/chrome/browser/ui/zoom/chrome_zoom_prefs_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4676b0d1b29c519738c084563f92c926f9ba2fe0
--- /dev/null
+++ b/chrome/browser/ui/zoom/chrome_zoom_prefs_helper.cc
@@ -0,0 +1,90 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/zoom/chrome_zoom_prefs_helper.h"
+
+#include "base/files/file_path.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/values.h"
+#include "components/prefs/pref_service.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
+
+ChromeZoomPrefsHelper::ChromeZoomPrefsHelper(
+ PrefService* pref_service,
+ const base::FilePath& profile_path,
+ const base::FilePath& partition_path)
+ : pref_service_(pref_service) {
+ 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);
+}
+
+std::string ChromeZoomPrefsHelper::GetHashForTesting(
+ const base::FilePath& relative_path) {
+ return GetHash(relative_path);
+}
+
+bool ChromeZoomPrefsHelper::GetBoolean(const char* pref_name,
+ bool* value) const {
+ return pref_service_->GetDictionary(pref_name)->GetBoolean(partition_key_,
+ value);
+}
+
+void ChromeZoomPrefsHelper::SetBoolean(const char* pref_name, bool value) {
+ DictionaryPrefUpdate update(pref_service_, pref_name);
+ update->SetBoolean(partition_key_, value);
+}
+
+bool ChromeZoomPrefsHelper::GetDouble(const char* pref_name,
+ double* value) const {
+ return pref_service_->GetDictionary(pref_name)->GetDouble(partition_key_,
+ value);
+}
+
+void ChromeZoomPrefsHelper::SetDouble(const char* pref_name, double value) {
+ DictionaryPrefUpdate update(pref_service_, pref_name);
+ update->SetDouble(partition_key_, value);
+}
+
+bool ChromeZoomPrefsHelper::GetDictionary(
+ const char* pref_name,
+ const base::DictionaryValue** value) const {
+ return pref_service_->GetDictionary(pref_name)->GetDictionary(partition_key_,
+ value);
+}
+
+std::unique_ptr<DictionaryPrefUpdate> ChromeZoomPrefsHelper::GetUpdate(
+ const char* pref_name) {
+ return base::MakeUnique<DictionaryPrefUpdate>(pref_service_, pref_name);
+}
+
+base::DictionaryValue* ChromeZoomPrefsHelper::GetMutableDictionary(
+ DictionaryPrefUpdate* update) const {
+ base::DictionaryValue* dictionaries = update->Get();
+ DCHECK(dictionaries);
+
+ base::DictionaryValue* dictionary = nullptr;
+ if (!dictionaries->GetDictionary(partition_key_, &dictionary)) {
+ dictionary = new base::DictionaryValue();
+ dictionaries->Set(partition_key_, base::WrapUnique(dictionary));
+ }
+
+ return dictionary;
+}
« no previous file with comments | « chrome/browser/ui/zoom/chrome_zoom_prefs_helper.h ('k') | chrome/browser/ui/zoom/zoom_controller_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698