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