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