OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "components/user_prefs/tracked/registry_hash_store_contents_win.h" | 5 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | |
11 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
12 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 14 #include "base/values.h" |
16 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
17 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" | 16 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" |
18 | 17 |
19 using base::win::RegistryValueIterator; | 18 using base::win::RegistryValueIterator; |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 constexpr size_t kMacSize = 64; | 22 constexpr size_t kMacSize = 32; |
24 | 23 |
25 base::string16 GetSplitPrefKeyName(const base::string16& reg_key_name, | 24 base::string16 GetSplitPrefKeyName(const base::string16& reg_key_name, |
26 const std::string& split_key_name) { | 25 const std::string& split_key_name) { |
27 return reg_key_name + L"\\" + base::UTF8ToUTF16(split_key_name); | 26 return reg_key_name + L"\\" + base::UTF8ToUTF16(split_key_name); |
28 } | 27 } |
29 | 28 |
30 bool ReadMacFromRegistry(const base::win::RegKey& key, | 29 bool ReadMacFromRegistry(const base::win::RegKey& key, |
31 const std::string& value_name, | 30 const std::string& value_name, |
32 std::string* out_mac) { | 31 std::string* out_mac) { |
33 base::string16 string_value; | 32 base::string16 string_value; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return false; | 65 return false; |
67 } | 66 } |
68 | 67 |
69 } // namespace | 68 } // namespace |
70 | 69 |
71 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( | 70 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( |
72 const base::string16& registry_path, | 71 const base::string16& registry_path, |
73 const base::string16& store_key) | 72 const base::string16& store_key) |
74 : preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key) {} | 73 : preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key) {} |
75 | 74 |
76 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( | |
77 const RegistryHashStoreContentsWin& other) = default; | |
78 | |
79 bool RegistryHashStoreContentsWin::IsCopyable() const { | |
80 return true; | |
81 } | |
82 | |
83 std::unique_ptr<HashStoreContents> RegistryHashStoreContentsWin::MakeCopy() | |
84 const { | |
85 return base::WrapUnique(new RegistryHashStoreContentsWin(*this)); | |
86 } | |
87 | |
88 base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const { | 75 base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const { |
89 return user_prefs::tracked::kTrackedPrefRegistryValidationSuffix; | 76 return user_prefs::tracked::kTrackedPrefRegistryValidationSuffix; |
90 } | 77 } |
91 | 78 |
92 void RegistryHashStoreContentsWin::Reset() { | 79 void RegistryHashStoreContentsWin::Reset() { |
93 base::win::RegKey key; | 80 base::win::RegKey key; |
94 if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(), | 81 if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(), |
95 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | 82 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
96 LONG result = key.DeleteKey(L""); | 83 LONG result = key.DeleteKey(L""); |
97 DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result; | 84 DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 134 |
148 if (key.Create(HKEY_CURRENT_USER, | 135 if (key.Create(HKEY_CURRENT_USER, |
149 GetSplitPrefKeyName(preference_key_name_, path).c_str(), | 136 GetSplitPrefKeyName(preference_key_name_, path).c_str(), |
150 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | 137 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
151 key.WriteValue(base::UTF8ToUTF16(split_path).c_str(), | 138 key.WriteValue(base::UTF8ToUTF16(split_path).c_str(), |
152 base::UTF8ToUTF16(value).c_str()); | 139 base::UTF8ToUTF16(value).c_str()); |
153 } | 140 } |
154 } | 141 } |
155 | 142 |
156 bool RegistryHashStoreContentsWin::RemoveEntry(const std::string& path) { | 143 bool RegistryHashStoreContentsWin::RemoveEntry(const std::string& path) { |
| 144 // ClearSplitMac is first to avoid short-circuit issues. |
157 return ClearAtomicMac(preference_key_name_, path) || | 145 return ClearAtomicMac(preference_key_name_, path) || |
158 ClearSplitMac(preference_key_name_, path); | 146 ClearSplitMac(preference_key_name_, path); |
159 } | 147 } |
160 | 148 |
161 void RegistryHashStoreContentsWin::ImportEntry(const std::string& path, | 149 void RegistryHashStoreContentsWin::ImportEntry(const std::string& path, |
162 const base::Value* in_value) { | 150 const base::Value* in_value) { |
163 NOTREACHED() | 151 NOTREACHED() |
164 << "RegistryHashStoreContents does not support the ImportEntry operation"; | 152 << "RegistryHashStore does not support the ImportEntry operation"; |
165 } | 153 } |
166 | 154 |
167 const base::DictionaryValue* RegistryHashStoreContentsWin::GetContents() const { | 155 const base::DictionaryValue* RegistryHashStoreContentsWin::GetContents() const { |
168 NOTREACHED() | 156 NOTREACHED() |
169 << "RegistryHashStoreContents does not support the GetContents operation"; | 157 << "RegistryHashStore does not support the GetContents operation"; |
170 return NULL; | 158 return NULL; |
171 } | 159 } |
172 | 160 |
173 std::string RegistryHashStoreContentsWin::GetSuperMac() const { | 161 std::string RegistryHashStoreContentsWin::GetSuperMac() const { |
174 NOTREACHED() | 162 NOTREACHED() |
175 << "RegistryHashStoreContents does not support the GetSuperMac operation"; | 163 << "RegistryHashStore does not support the GetSuperMac operation"; |
176 return NULL; | 164 return NULL; |
177 } | 165 } |
178 | 166 |
179 void RegistryHashStoreContentsWin::SetSuperMac(const std::string& super_mac) { | 167 void RegistryHashStoreContentsWin::SetSuperMac(const std::string& super_mac) { |
180 NOTREACHED() | 168 NOTREACHED() |
181 << "RegistryHashStoreContents does not support the SetSuperMac operation"; | 169 << "RegistryHashStore does not support the SetSuperMac operation"; |
182 } | 170 } |
OLD | NEW |