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

Side by Side Diff: chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc

Issue 393133002: Migrate HostZoomMap to live in StoragePartition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments; patch for landing. Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/zoom/chrome_zoom_level_prefs.h" 5 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/prefs/json_pref_store.h" 10 #include "base/prefs/json_pref_store.h"
(...skipping 16 matching lines...) Expand all
27 size_t int_key = 27 size_t int_key =
28 BASE_HASH_NAMESPACE::hash<base::FilePath>()(relative_path); 28 BASE_HASH_NAMESPACE::hash<base::FilePath>()(relative_path);
29 return base::SizeTToString(int_key); 29 return base::SizeTToString(int_key);
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 namespace chrome { 34 namespace chrome {
35 35
36 ChromeZoomLevelPrefs::ChromeZoomLevelPrefs(PrefService* pref_service, 36 ChromeZoomLevelPrefs::ChromeZoomLevelPrefs(PrefService* pref_service,
37 const base::FilePath& profile_path) 37 const base::FilePath& profile_path,
38 const base::FilePath& partition_path)
38 : pref_service_(pref_service), 39 : pref_service_(pref_service),
39 profile_path_(profile_path),
40 host_zoom_map_(nullptr) { 40 host_zoom_map_(nullptr) {
41 DCHECK(pref_service_); 41 DCHECK(pref_service_);
42
43 DCHECK(!partition_path.empty());
44 DCHECK((partition_path == profile_path) ||
45 profile_path.IsParent(partition_path));
46 // Create a partition_key string with no '.'s in it. For the default
47 // StoragePartition, this string will always be "0".
48 base::FilePath partition_relative_path;
49 profile_path.AppendRelativePath(partition_path, &partition_relative_path);
50 partition_key_ = GetHash(partition_relative_path);
51
42 } 52 }
43 53
44 ChromeZoomLevelPrefs::~ChromeZoomLevelPrefs() { 54 ChromeZoomLevelPrefs::~ChromeZoomLevelPrefs() {
45 } 55 }
46 56
47 void ChromeZoomLevelPrefs::InitPrefsAndCopyToHostZoomMap(
48 const base::FilePath& partition_path,
49 content::HostZoomMap* host_zoom_map) {
50 DCHECK(!partition_path.empty());
51 DCHECK((partition_path == profile_path_) ||
52 profile_path_.IsParent(partition_path));
53 // This init function must be called only once.
54 DCHECK(!host_zoom_map_);
55 DCHECK(host_zoom_map);
56 host_zoom_map_ = host_zoom_map;
57
58 // Create a partition_key string with no '.'s in it. For the default
59 // StoragePartition, this string will always be "0".
60 base::FilePath partition_relative_path;
61 profile_path_.AppendRelativePath(partition_path, &partition_relative_path);
62 partition_key_ = GetHash(partition_relative_path);
63
64 // Initialize the default zoom level.
65 host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref());
66
67 // Initialize the HostZoomMap with per-host zoom levels from the persisted
68 // zoom-level preference values.
69 const base::DictionaryValue* host_zoom_dictionaries =
70 pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels);
71 const base::DictionaryValue* host_zoom_dictionary = nullptr;
72 if (host_zoom_dictionaries->GetDictionary(partition_key_,
73 &host_zoom_dictionary)) {
74 // Since we're calling this before setting up zoom_subscription_ below we
75 // don't need to worry that host_zoom_dictionary is indirectly affected
76 // by calls to HostZoomMap::SetZoomLevelForHost().
77 ExtractPerHostZoomLevels(host_zoom_dictionary,
78 true /* sanitize_partition_host_zoom_levels */);
79 }
80 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind(
81 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this)));
82 }
83
84 std::string ChromeZoomLevelPrefs::GetHashForTesting( 57 std::string ChromeZoomLevelPrefs::GetHashForTesting(
85 const base::FilePath& relative_path) { 58 const base::FilePath& relative_path) {
86 return GetHash(relative_path); 59 return GetHash(relative_path);
87 } 60 }
88 61
89 void ChromeZoomLevelPrefs::SetDefaultZoomLevelPref(double level) { 62 void ChromeZoomLevelPrefs::SetDefaultZoomLevelPref(double level) {
90 if (content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel())) 63 if (content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel()))
91 return; 64 return;
92 65
93 DictionaryPrefUpdate update(pref_service_, prefs::kPartitionDefaultZoomLevel); 66 DictionaryPrefUpdate update(pref_service_, prefs::kPartitionDefaultZoomLevel);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 prefs::kPartitionPerHostZoomLevels); 162 prefs::kPartitionPerHostZoomLevels);
190 base::DictionaryValue* host_zoom_dictionaries = update.Get(); 163 base::DictionaryValue* host_zoom_dictionaries = update.Get();
191 base::DictionaryValue* host_zoom_dictionary = nullptr; 164 base::DictionaryValue* host_zoom_dictionary = nullptr;
192 host_zoom_dictionaries->GetDictionary(partition_key_, 165 host_zoom_dictionaries->GetDictionary(partition_key_,
193 &host_zoom_dictionary); 166 &host_zoom_dictionary);
194 for (const std::string& s : keys_to_remove) 167 for (const std::string& s : keys_to_remove)
195 host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr); 168 host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr);
196 } 169 }
197 } 170 }
198 171
172 void ChromeZoomLevelPrefs::InitHostZoomMap(
173 content::HostZoomMap* host_zoom_map) {
174 // This init function must be called only once.
175 DCHECK(!host_zoom_map_);
176 DCHECK(host_zoom_map);
177 host_zoom_map_ = host_zoom_map;
178
179 // Initialize the default zoom level.
180 host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref());
181
182 // Initialize the HostZoomMap with per-host zoom levels from the persisted
183 // zoom-level preference values.
184 const base::DictionaryValue* host_zoom_dictionaries =
185 pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels);
186 const base::DictionaryValue* host_zoom_dictionary = nullptr;
187 if (host_zoom_dictionaries->GetDictionary(partition_key_,
188 &host_zoom_dictionary)) {
189 // Since we're calling this before setting up zoom_subscription_ below we
190 // don't need to worry that host_zoom_dictionary is indirectly affected
191 // by calls to HostZoomMap::SetZoomLevelForHost().
192 ExtractPerHostZoomLevels(host_zoom_dictionary,
193 true /* sanitize_partition_host_zoom_levels */);
194 }
195 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind(
196 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this)));
197 }
198
199 } // namespace chrome 199 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/zoom/chrome_zoom_level_prefs.h ('k') | chrome/browser/ui/zoom/zoom_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698