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 <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 Loading... |
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( | 57 void ChromeZoomLevelPrefs::InitHostZoomMap( |
48 const base::FilePath& partition_path, | |
49 content::HostZoomMap* host_zoom_map) { | 58 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. | 59 // This init function must be called only once. |
54 DCHECK(!host_zoom_map_); | 60 DCHECK(!host_zoom_map_); |
55 DCHECK(host_zoom_map); | 61 DCHECK(host_zoom_map); |
56 host_zoom_map_ = host_zoom_map; | 62 host_zoom_map_ = host_zoom_map; |
57 | 63 |
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. | 64 // Initialize the default zoom level. |
65 host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref()); | 65 host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref()); |
66 | 66 |
67 // Initialize the HostZoomMap with per-host zoom levels from the persisted | 67 // Initialize the HostZoomMap with per-host zoom levels from the persisted |
68 // zoom-level preference values. | 68 // zoom-level preference values. |
69 const base::DictionaryValue* host_zoom_dictionaries = | 69 const base::DictionaryValue* host_zoom_dictionaries = |
70 pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels); | 70 pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels); |
71 const base::DictionaryValue* host_zoom_dictionary = nullptr; | 71 const base::DictionaryValue* host_zoom_dictionary = nullptr; |
72 if (host_zoom_dictionaries->GetDictionary(partition_key_, | 72 if (host_zoom_dictionaries->GetDictionary(partition_key_, |
73 &host_zoom_dictionary)) { | 73 &host_zoom_dictionary)) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 base::DictionaryValue* host_zoom_dictionaries = update.Get(); | 190 base::DictionaryValue* host_zoom_dictionaries = update.Get(); |
191 base::DictionaryValue* host_zoom_dictionary = nullptr; | 191 base::DictionaryValue* host_zoom_dictionary = nullptr; |
192 host_zoom_dictionaries->GetDictionary(partition_key_, | 192 host_zoom_dictionaries->GetDictionary(partition_key_, |
193 &host_zoom_dictionary); | 193 &host_zoom_dictionary); |
194 for (const std::string& s : keys_to_remove) | 194 for (const std::string& s : keys_to_remove) |
195 host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr); | 195 host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr); |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 } // namespace chrome | 199 } // namespace chrome |
OLD | NEW |