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