Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: components/user_prefs/tracked/registry_hash_store_contents_win.cc

Issue 2204943002: Integrate registry_hash_store_contents with the rest of tracked prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and added important_file_writer CL as dependent patchset Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" 16 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h"
17 17
18 using base::win::RegistryValueIterator; 18 using base::win::RegistryValueIterator;
19 19
20 namespace { 20 namespace {
21 21
22 constexpr size_t kMacSize = 32; 22 constexpr size_t kMacSize = 64;
23 23
24 base::string16 GetSplitPrefKeyName(const base::string16& reg_key_name, 24 base::string16 GetSplitPrefKeyName(const base::string16& reg_key_name,
25 const std::string& split_key_name) { 25 const std::string& split_key_name) {
26 return reg_key_name + L"\\" + base::UTF8ToUTF16(split_key_name); 26 return reg_key_name + L"\\" + base::UTF8ToUTF16(split_key_name);
27 } 27 }
28 28
29 bool ReadMacFromRegistry(const base::win::RegKey& key, 29 bool ReadMacFromRegistry(const base::win::RegKey& key,
30 const std::string& value_name, 30 const std::string& value_name,
31 std::string* out_mac) { 31 std::string* out_mac) {
32 base::string16 string_value; 32 base::string16 string_value;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return false; 65 return false;
66 } 66 }
67 67
68 } // namespace 68 } // namespace
69 69
70 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( 70 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin(
71 const base::string16& registry_path, 71 const base::string16& registry_path,
72 const base::string16& store_key) 72 const base::string16& store_key)
73 : preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key) {} 73 : preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key) {}
74 74
75 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin(
76 const base::string16& preference_key_name)
77 : preference_key_name_(preference_key_name) {}
78
79 bool RegistryHashStoreContentsWin::IsCopyable() const {
80 return true;
81 }
82
83 std::unique_ptr<HashStoreContents> RegistryHashStoreContentsWin::MakeCopy()
84 const {
85 return std::unique_ptr<HashStoreContents>(
86 new RegistryHashStoreContentsWin(preference_key_name_));
gab 2016/09/16 19:47:33 return base::MakeUnique<RegistryHashStoreContentsW
proberge 2016/09/20 21:35:45 Done, but getting compiler errors on this line rel
gab 2016/09/21 17:55:30 Ah indeed because MakeUnique needs access to the c
proberge 2016/09/21 21:09:24 Done.
87 }
88
75 base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const { 89 base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const {
76 return user_prefs::tracked::kTrackedPrefRegistryValidationSuffix; 90 return user_prefs::tracked::kTrackedPrefRegistryValidationSuffix;
77 } 91 }
78 92
79 void RegistryHashStoreContentsWin::Reset() { 93 void RegistryHashStoreContentsWin::Reset() {
80 base::win::RegKey key; 94 base::win::RegKey key;
81 if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(), 95 if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(),
82 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { 96 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
83 LONG result = key.DeleteKey(L""); 97 LONG result = key.DeleteKey(L"");
84 DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result; 98 DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 148
135 if (key.Create(HKEY_CURRENT_USER, 149 if (key.Create(HKEY_CURRENT_USER,
136 GetSplitPrefKeyName(preference_key_name_, path).c_str(), 150 GetSplitPrefKeyName(preference_key_name_, path).c_str(),
137 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { 151 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
138 key.WriteValue(base::UTF8ToUTF16(split_path).c_str(), 152 key.WriteValue(base::UTF8ToUTF16(split_path).c_str(),
139 base::UTF8ToUTF16(value).c_str()); 153 base::UTF8ToUTF16(value).c_str());
140 } 154 }
141 } 155 }
142 156
143 bool RegistryHashStoreContentsWin::RemoveEntry(const std::string& path) { 157 bool RegistryHashStoreContentsWin::RemoveEntry(const std::string& path) {
144 // ClearSplitMac is first to avoid short-circuit issues.
145 return ClearAtomicMac(preference_key_name_, path) || 158 return ClearAtomicMac(preference_key_name_, path) ||
146 ClearSplitMac(preference_key_name_, path); 159 ClearSplitMac(preference_key_name_, path);
147 } 160 }
148 161
149 void RegistryHashStoreContentsWin::ImportEntry(const std::string& path, 162 void RegistryHashStoreContentsWin::ImportEntry(const std::string& path,
150 const base::Value* in_value) { 163 const base::Value* in_value) {
151 NOTREACHED() 164 NOTREACHED()
152 << "RegistryHashStore does not support the ImportEntry operation"; 165 << "RegistryHashStoreContents does not support the ImportEntry operation";
153 } 166 }
154 167
155 const base::DictionaryValue* RegistryHashStoreContentsWin::GetContents() const { 168 const base::DictionaryValue* RegistryHashStoreContentsWin::GetContents() const {
156 NOTREACHED() 169 NOTREACHED()
157 << "RegistryHashStore does not support the GetContents operation"; 170 << "RegistryHashStoreContents does not support the GetContents operation";
158 return NULL; 171 return NULL;
159 } 172 }
160 173
161 std::string RegistryHashStoreContentsWin::GetSuperMac() const { 174 std::string RegistryHashStoreContentsWin::GetSuperMac() const {
162 NOTREACHED() 175 NOTREACHED()
163 << "RegistryHashStore does not support the GetSuperMac operation"; 176 << "RegistryHashStoreContents does not support the GetSuperMac operation";
164 return NULL; 177 return NULL;
165 } 178 }
166 179
167 void RegistryHashStoreContentsWin::SetSuperMac(const std::string& super_mac) { 180 void RegistryHashStoreContentsWin::SetSuperMac(const std::string& super_mac) {
168 NOTREACHED() 181 NOTREACHED()
169 << "RegistryHashStore does not support the SetSuperMac operation"; 182 << "RegistryHashStoreContents does not support the SetSuperMac operation";
170 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698