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

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

Issue 665283002: Fix crash in ChromeZoomLevelPrefs::ExtractPerHostZoomLevels(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wjmResetZoomLevel
Patch Set: Convert parameter to bool. Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/zoom/chrome_zoom_level_prefs.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // Initialize the HostZoomMap with per-host zoom levels from the persisted 71 // Initialize the HostZoomMap with per-host zoom levels from the persisted
72 // zoom-level preference values. 72 // zoom-level preference values.
73 const base::DictionaryValue* host_zoom_dictionaries = 73 const base::DictionaryValue* host_zoom_dictionaries =
74 pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels); 74 pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels);
75 const base::DictionaryValue* host_zoom_dictionary = nullptr; 75 const base::DictionaryValue* host_zoom_dictionary = nullptr;
76 if (host_zoom_dictionaries->GetDictionary(partition_key_, 76 if (host_zoom_dictionaries->GetDictionary(partition_key_,
77 &host_zoom_dictionary)) { 77 &host_zoom_dictionary)) {
78 // Since we're calling this before setting up zoom_subscription_ below we 78 // Since we're calling this before setting up zoom_subscription_ below we
79 // don't need to worry that host_zoom_dictionary is indirectly affected 79 // don't need to worry that host_zoom_dictionary is indirectly affected
80 // by calls to HostZoomMap::SetZoomLevelForHost(). 80 // by calls to HostZoomMap::SetZoomLevelForHost().
81 ExtractPerHostZoomLevels(host_zoom_dictionary); 81 ExtractPerHostZoomLevels(host_zoom_dictionary,
82 true /* sanitize_partition_host_zoom_levels */);
82 } 83 }
83 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( 84 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind(
84 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); 85 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this)));
85 } 86 }
86 87
87 std::string ChromeZoomLevelPrefs::GetHashForTesting( 88 std::string ChromeZoomLevelPrefs::GetHashForTesting(
88 const base::FilePath& relative_path) { 89 const base::FilePath& relative_path) {
89 return GetHash(relative_path); 90 return GetHash(relative_path);
90 } 91 }
91 92
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 host_zoom_dictionary = new base::DictionaryValue(); 138 host_zoom_dictionary = new base::DictionaryValue();
138 host_zoom_dictionaries->Set(partition_key_, host_zoom_dictionary); 139 host_zoom_dictionaries->Set(partition_key_, host_zoom_dictionary);
139 } 140 }
140 141
141 if (modification_is_removal) 142 if (modification_is_removal)
142 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, nullptr); 143 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, nullptr);
143 else 144 else
144 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); 145 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level);
145 } 146 }
146 147
148 // TODO(wjmaclean): Remove the dictionary_path once the migration code is
149 // removed. crbug.com/420643
147 void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels( 150 void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels(
148 const base::DictionaryValue* host_zoom_dictionary) { 151 const base::DictionaryValue* host_zoom_dictionary,
152 bool sanitize_partition_host_zoom_levels) {
149 std::vector<std::string> keys_to_remove; 153 std::vector<std::string> keys_to_remove;
150 scoped_ptr<base::DictionaryValue> host_zoom_dictionary_copy( 154 scoped_ptr<base::DictionaryValue> host_zoom_dictionary_copy(
151 host_zoom_dictionary->DeepCopyWithoutEmptyChildren()); 155 host_zoom_dictionary->DeepCopyWithoutEmptyChildren());
152 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary_copy); 156 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary_copy);
153 !i.IsAtEnd(); 157 !i.IsAtEnd();
154 i.Advance()) { 158 i.Advance()) {
155 const std::string& host(i.key()); 159 const std::string& host(i.key());
156 double zoom_level = 0; 160 double zoom_level = 0;
157 161
158 bool has_valid_zoom_level = i.value().GetAsDouble(&zoom_level); 162 bool has_valid_zoom_level = i.value().GetAsDouble(&zoom_level);
159 163
160 // Filter out A) the empty host, B) zoom levels equal to the default; and 164 // Filter out A) the empty host, B) zoom levels equal to the default; and
161 // remember them, so that we can later erase them from Prefs. 165 // remember them, so that we can later erase them from Prefs.
162 // Values of type A and B could have been stored due to crbug.com/364399. 166 // Values of type A and B could have been stored due to crbug.com/364399.
163 // Values of type B could further have been stored before the default zoom 167 // Values of type B could further have been stored before the default zoom
164 // level was set to its current value. In either case, SetZoomLevelForHost 168 // level was set to its current value. In either case, SetZoomLevelForHost
165 // will ignore type B values, thus, to have consistency with HostZoomMap's 169 // will ignore type B values, thus, to have consistency with HostZoomMap's
166 // internal state, these values must also be removed from Prefs. 170 // internal state, these values must also be removed from Prefs.
167 if (host.empty() || !has_valid_zoom_level || 171 if (host.empty() || !has_valid_zoom_level ||
168 content::ZoomValuesEqual(zoom_level, 172 content::ZoomValuesEqual(zoom_level,
169 host_zoom_map_->GetDefaultZoomLevel())) { 173 host_zoom_map_->GetDefaultZoomLevel())) {
170 keys_to_remove.push_back(host); 174 keys_to_remove.push_back(host);
171 continue; 175 continue;
172 } 176 }
173 177
174 host_zoom_map_->SetZoomLevelForHost(host, zoom_level); 178 host_zoom_map_->SetZoomLevelForHost(host, zoom_level);
175 } 179 }
176 180
181 // We don't bother sanitizing non-partition dictionaries as they will be
182 // discarded in the migration process. Note: since the structure of partition
183 // per-host zoom level dictionaries is different from the legacy profile
184 // per-host zoom level dictionaries, the following code will fail if run
185 // on the legacy dictionaries.
186 if (!sanitize_partition_host_zoom_levels)
187 return;
188
177 // Sanitize prefs to remove entries that match the default zoom level and/or 189 // Sanitize prefs to remove entries that match the default zoom level and/or
178 // have an empty host. 190 // have an empty host.
179 { 191 {
180 DictionaryPrefUpdate update(pref_service_, 192 DictionaryPrefUpdate update(pref_service_,
181 prefs::kPartitionPerHostZoomLevels); 193 prefs::kPartitionPerHostZoomLevels);
182 base::DictionaryValue* host_zoom_dictionaries = update.Get(); 194 base::DictionaryValue* host_zoom_dictionaries = update.Get();
183 base::DictionaryValue* host_zoom_dictionary = nullptr; 195 base::DictionaryValue* host_zoom_dictionary = nullptr;
184 host_zoom_dictionaries->GetDictionary(partition_key_, 196 host_zoom_dictionaries->GetDictionary(partition_key_,
185 &host_zoom_dictionary); 197 &host_zoom_dictionary);
186 for (const std::string& s : keys_to_remove) 198 for (const std::string& s : keys_to_remove)
187 host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr); 199 host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr);
188 } 200 }
189 } 201 }
190 202
191 } // namespace chrome 203 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/zoom/chrome_zoom_level_prefs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698