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 <memory> | |
10 | |
11 #include "base/bind.h" | 9 #include "base/bind.h" |
12 #include "base/memory/ptr_util.h" | |
13 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
14 #include "base/values.h" | 11 #include "base/values.h" |
15 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
17 #include "components/prefs/json_pref_store.h" | 14 #include "components/prefs/json_pref_store.h" |
18 #include "components/prefs/pref_filter.h" | 15 #include "components/prefs/pref_filter.h" |
19 #include "components/prefs/pref_registry_simple.h" | 16 #include "components/prefs/pref_registry_simple.h" |
20 #include "components/prefs/pref_service_factory.h" | 17 #include "components/prefs/pref_service_factory.h" |
21 #include "components/prefs/scoped_user_pref_update.h" | 18 #include "components/prefs/scoped_user_pref_update.h" |
22 #include "components/zoom/zoom_event_manager.h" | 19 #include "components/zoom/zoom_event_manager.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 return; | 102 return; |
106 double level = change.zoom_level; | 103 double level = change.zoom_level; |
107 DictionaryPrefUpdate update(pref_service_, | 104 DictionaryPrefUpdate update(pref_service_, |
108 prefs::kPartitionPerHostZoomLevels); | 105 prefs::kPartitionPerHostZoomLevels); |
109 base::DictionaryValue* host_zoom_dictionaries = update.Get(); | 106 base::DictionaryValue* host_zoom_dictionaries = update.Get(); |
110 DCHECK(host_zoom_dictionaries); | 107 DCHECK(host_zoom_dictionaries); |
111 | 108 |
112 bool modification_is_removal = | 109 bool modification_is_removal = |
113 content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel()); | 110 content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel()); |
114 | 111 |
115 base::DictionaryValue* host_zoom_dictionary_weak = nullptr; | 112 base::DictionaryValue* host_zoom_dictionary = nullptr; |
116 if (!host_zoom_dictionaries->GetDictionary(partition_key_, | 113 if (!host_zoom_dictionaries->GetDictionary(partition_key_, |
117 &host_zoom_dictionary_weak)) { | 114 &host_zoom_dictionary)) { |
118 auto host_zoom_dictionary = base::MakeUnique<base::DictionaryValue>(); | 115 host_zoom_dictionary = new base::DictionaryValue(); |
119 host_zoom_dictionary_weak = host_zoom_dictionary.get(); | 116 host_zoom_dictionaries->Set(partition_key_, host_zoom_dictionary); |
120 host_zoom_dictionaries->Set(partition_key_, | |
121 std::move(host_zoom_dictionary)); | |
122 } | 117 } |
123 | 118 |
124 if (modification_is_removal) { | 119 if (modification_is_removal) |
125 host_zoom_dictionary_weak->RemoveWithoutPathExpansion(change.host, nullptr); | 120 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, nullptr); |
126 } else { | 121 else |
127 host_zoom_dictionary_weak->SetDoubleWithoutPathExpansion(change.host, | 122 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); |
128 level); | |
129 } | |
130 } | 123 } |
131 | 124 |
132 // TODO(wjmaclean): Remove the dictionary_path once the migration code is | 125 // TODO(wjmaclean): Remove the dictionary_path once the migration code is |
133 // removed. crbug.com/420643 | 126 // removed. crbug.com/420643 |
134 void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels( | 127 void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels( |
135 const base::DictionaryValue* host_zoom_dictionary, | 128 const base::DictionaryValue* host_zoom_dictionary, |
136 bool sanitize_partition_host_zoom_levels) { | 129 bool sanitize_partition_host_zoom_levels) { |
137 std::vector<std::string> keys_to_remove; | 130 std::vector<std::string> keys_to_remove; |
138 std::unique_ptr<base::DictionaryValue> host_zoom_dictionary_copy = | 131 std::unique_ptr<base::DictionaryValue> host_zoom_dictionary_copy = |
139 host_zoom_dictionary->DeepCopyWithoutEmptyChildren(); | 132 host_zoom_dictionary->DeepCopyWithoutEmptyChildren(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 &host_zoom_dictionary)) { | 196 &host_zoom_dictionary)) { |
204 // 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 |
205 // 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 |
206 // by calls to HostZoomMap::SetZoomLevelForHost(). | 199 // by calls to HostZoomMap::SetZoomLevelForHost(). |
207 ExtractPerHostZoomLevels(host_zoom_dictionary, | 200 ExtractPerHostZoomLevels(host_zoom_dictionary, |
208 true /* sanitize_partition_host_zoom_levels */); | 201 true /* sanitize_partition_host_zoom_levels */); |
209 } | 202 } |
210 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( | 203 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( |
211 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); | 204 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); |
212 } | 205 } |
OLD | NEW |