OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 double default_zoom_level = 0.0; | 77 double default_zoom_level = 0.0; |
78 | 78 |
79 const base::DictionaryValue* default_zoom_level_dictionary = | 79 const base::DictionaryValue* default_zoom_level_dictionary = |
80 pref_service_->GetDictionary(prefs::kPartitionDefaultZoomLevel); | 80 pref_service_->GetDictionary(prefs::kPartitionDefaultZoomLevel); |
81 // If no default has been previously set, the default returned is the | 81 // If no default has been previously set, the default returned is the |
82 // value used to initialize default_zoom_level in this function. | 82 // value used to initialize default_zoom_level in this function. |
83 default_zoom_level_dictionary->GetDouble(partition_key_, &default_zoom_level); | 83 default_zoom_level_dictionary->GetDouble(partition_key_, &default_zoom_level); |
84 return default_zoom_level; | 84 return default_zoom_level; |
85 } | 85 } |
86 | 86 |
87 scoped_ptr<ChromeZoomLevelPrefs::DefaultZoomLevelSubscription> | 87 std::unique_ptr<ChromeZoomLevelPrefs::DefaultZoomLevelSubscription> |
88 ChromeZoomLevelPrefs::RegisterDefaultZoomLevelCallback( | 88 ChromeZoomLevelPrefs::RegisterDefaultZoomLevelCallback( |
89 const base::Closure& callback) { | 89 const base::Closure& callback) { |
90 return default_zoom_changed_callbacks_.Add(callback); | 90 return default_zoom_changed_callbacks_.Add(callback); |
91 } | 91 } |
92 | 92 |
93 void ChromeZoomLevelPrefs::OnZoomLevelChanged( | 93 void ChromeZoomLevelPrefs::OnZoomLevelChanged( |
94 const content::HostZoomMap::ZoomLevelChange& change) { | 94 const content::HostZoomMap::ZoomLevelChange& change) { |
95 // If there's a manager to aggregate ZoomLevelChanged events, pass this event | 95 // If there's a manager to aggregate ZoomLevelChanged events, pass this event |
96 // along. Since we already hold a subscription to our associated HostZoomMap, | 96 // along. Since we already hold a subscription to our associated HostZoomMap, |
97 // we don't need to create a separate subscription for this. | 97 // we don't need to create a separate subscription for this. |
(...skipping 23 matching lines...) Expand all Loading... |
121 else | 121 else |
122 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); | 122 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); |
123 } | 123 } |
124 | 124 |
125 // TODO(wjmaclean): Remove the dictionary_path once the migration code is | 125 // TODO(wjmaclean): Remove the dictionary_path once the migration code is |
126 // removed. crbug.com/420643 | 126 // removed. crbug.com/420643 |
127 void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels( | 127 void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels( |
128 const base::DictionaryValue* host_zoom_dictionary, | 128 const base::DictionaryValue* host_zoom_dictionary, |
129 bool sanitize_partition_host_zoom_levels) { | 129 bool sanitize_partition_host_zoom_levels) { |
130 std::vector<std::string> keys_to_remove; | 130 std::vector<std::string> keys_to_remove; |
131 scoped_ptr<base::DictionaryValue> host_zoom_dictionary_copy = | 131 std::unique_ptr<base::DictionaryValue> host_zoom_dictionary_copy = |
132 host_zoom_dictionary->DeepCopyWithoutEmptyChildren(); | 132 host_zoom_dictionary->DeepCopyWithoutEmptyChildren(); |
133 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary_copy); | 133 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary_copy); |
134 !i.IsAtEnd(); | 134 !i.IsAtEnd(); |
135 i.Advance()) { | 135 i.Advance()) { |
136 const std::string& host(i.key()); | 136 const std::string& host(i.key()); |
137 double zoom_level = 0; | 137 double zoom_level = 0; |
138 | 138 |
139 bool has_valid_zoom_level = i.value().GetAsDouble(&zoom_level); | 139 bool has_valid_zoom_level = i.value().GetAsDouble(&zoom_level); |
140 | 140 |
141 // Filter out A) the empty host, B) zoom levels equal to the default; and | 141 // Filter out A) the empty host, B) zoom levels equal to the default; and |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 &host_zoom_dictionary)) { | 196 &host_zoom_dictionary)) { |
197 // Since we're calling this before setting up zoom_subscription_ below we | 197 // Since we're calling this before setting up zoom_subscription_ below we |
198 // don't need to worry that host_zoom_dictionary is indirectly affected | 198 // don't need to worry that host_zoom_dictionary is indirectly affected |
199 // by calls to HostZoomMap::SetZoomLevelForHost(). | 199 // by calls to HostZoomMap::SetZoomLevelForHost(). |
200 ExtractPerHostZoomLevels(host_zoom_dictionary, | 200 ExtractPerHostZoomLevels(host_zoom_dictionary, |
201 true /* sanitize_partition_host_zoom_levels */); | 201 true /* sanitize_partition_host_zoom_levels */); |
202 } | 202 } |
203 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( | 203 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( |
204 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); | 204 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); |
205 } | 205 } |
OLD | NEW |