Chromium Code Reviews| 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 "services/preferences/tracked/registry_hash_store_contents_win.h" | 5 #include "services/preferences/tracked/registry_hash_store_contents_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/files/scoped_temp_dir.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 12 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | |
| 15 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 15 #include "base/values.h" |
| 18 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
| 19 #include "services/preferences/public/cpp/tracked/tracked_preference_histogram_n ames.h" | 17 #include "services/preferences/public/cpp/tracked/tracked_preference_histogram_n ames.h" |
| 20 | 18 |
| 21 using base::win::RegistryValueIterator; | 19 using base::win::RegistryValueIterator; |
| 22 | 20 |
| 23 namespace { | 21 namespace { |
| 24 | 22 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 const std::string& split_key_name) { | 59 const std::string& split_key_name) { |
| 62 base::win::RegKey key; | 60 base::win::RegKey key; |
| 63 if (key.Open(HKEY_CURRENT_USER, | 61 if (key.Open(HKEY_CURRENT_USER, |
| 64 GetSplitPrefKeyName(reg_key_name, split_key_name).c_str(), | 62 GetSplitPrefKeyName(reg_key_name, split_key_name).c_str(), |
| 65 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | 63 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
| 66 return key.DeleteKey(L"") == ERROR_SUCCESS; | 64 return key.DeleteKey(L"") == ERROR_SUCCESS; |
| 67 } | 65 } |
| 68 return false; | 66 return false; |
| 69 } | 67 } |
| 70 | 68 |
| 69 // Deletes |reg_key_name| if it exists. | |
| 70 void DeleteRegistryKey(const base::string16& reg_key_name) { | |
| 71 base::win::RegKey key; | |
| 72 if (key.Open(HKEY_CURRENT_USER, reg_key_name.c_str(), | |
| 73 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
| 74 LONG result = key.DeleteKey(L""); | |
| 75 DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result; | |
| 76 } | |
| 77 } | |
| 78 | |
| 71 } // namespace | 79 } // namespace |
| 72 | 80 |
| 73 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( | 81 void TempScopedDirRegistryCleaner::SetRegistryPath( |
| 74 const base::string16& registry_path, | 82 const base::string16& registry_path) { |
| 75 const base::string16& store_key) | 83 DCHECK(registry_path_ == L"" || registry_path_ == registry_path); |
| 76 : preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key), | 84 registry_path_ = registry_path; |
|
gab
2017/06/12 15:52:16
if (resitry_path_.empty())
registry_path_ = regi
proberge
2017/06/12 18:46:02
Done.
| |
| 77 reset_on_delete_(base::StartsWith(store_key, | |
| 78 base::ScopedTempDir::GetTempDirPrefix(), | |
| 79 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 80 } | 85 } |
| 81 | 86 |
| 82 RegistryHashStoreContentsWin::~RegistryHashStoreContentsWin() { | 87 TempScopedDirRegistryCleaner::~TempScopedDirRegistryCleaner() { |
| 83 if (reset_on_delete_) | 88 DCHECK(registry_path_ != L""); |
|
gab
2017/06/12 15:52:16
DCHECK(!registry_path_.empty());
proberge
2017/06/12 18:46:02
Done.
| |
| 84 Reset(); | 89 DeleteRegistryKey(registry_path_); |
| 85 } | 90 } |
| 86 | 91 |
| 87 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( | 92 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( |
| 93 const base::string16& registry_path, | |
| 94 const base::string16& store_key, | |
| 95 scoped_refptr<TempScopedDirCleaner> temp_dir_cleaner) | |
| 96 : preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key), | |
| 97 temp_dir_cleaner_(temp_dir_cleaner) { | |
|
gab
2017/06/12 15:52:16
std::move
proberge
2017/06/12 18:46:02
Done.
| |
| 98 if (temp_dir_cleaner_) | |
| 99 static_cast<TempScopedDirRegistryCleaner*>(temp_dir_cleaner_.get()) | |
| 100 ->SetRegistryPath(preference_key_name_); | |
| 101 } | |
| 102 | |
| 103 RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( | |
| 88 const RegistryHashStoreContentsWin& other) = default; | 104 const RegistryHashStoreContentsWin& other) = default; |
| 89 | 105 |
| 90 bool RegistryHashStoreContentsWin::IsCopyable() const { | 106 bool RegistryHashStoreContentsWin::IsCopyable() const { |
| 91 return true; | 107 return true; |
| 92 } | 108 } |
| 93 | 109 |
| 94 std::unique_ptr<HashStoreContents> RegistryHashStoreContentsWin::MakeCopy() | 110 std::unique_ptr<HashStoreContents> RegistryHashStoreContentsWin::MakeCopy() |
| 95 const { | 111 const { |
| 96 return base::WrapUnique(new RegistryHashStoreContentsWin(*this)); | 112 return base::WrapUnique(new RegistryHashStoreContentsWin(*this)); |
| 97 } | 113 } |
| 98 | 114 |
| 99 base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const { | 115 base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const { |
| 100 return user_prefs::tracked::kTrackedPrefRegistryValidationSuffix; | 116 return user_prefs::tracked::kTrackedPrefRegistryValidationSuffix; |
| 101 } | 117 } |
| 102 | 118 |
| 103 void RegistryHashStoreContentsWin::Reset() { | 119 void RegistryHashStoreContentsWin::Reset() { |
| 104 base::win::RegKey key; | 120 DeleteRegistryKey(preference_key_name_); |
| 105 if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(), | |
| 106 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
| 107 LONG result = key.DeleteKey(L""); | |
| 108 DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result; | |
| 109 } | |
| 110 } | 121 } |
| 111 | 122 |
| 112 bool RegistryHashStoreContentsWin::GetMac(const std::string& path, | 123 bool RegistryHashStoreContentsWin::GetMac(const std::string& path, |
| 113 std::string* out_value) { | 124 std::string* out_value) { |
| 114 base::win::RegKey key; | 125 base::win::RegKey key; |
| 115 if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(), | 126 if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(), |
| 116 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | 127 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
| 117 return ReadMacFromRegistry(key, path, out_value); | 128 return ReadMacFromRegistry(key, path, out_value); |
| 118 } | 129 } |
| 119 | 130 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 std::string RegistryHashStoreContentsWin::GetSuperMac() const { | 195 std::string RegistryHashStoreContentsWin::GetSuperMac() const { |
| 185 NOTREACHED() | 196 NOTREACHED() |
| 186 << "RegistryHashStoreContents does not support the GetSuperMac operation"; | 197 << "RegistryHashStoreContents does not support the GetSuperMac operation"; |
| 187 return NULL; | 198 return NULL; |
| 188 } | 199 } |
| 189 | 200 |
| 190 void RegistryHashStoreContentsWin::SetSuperMac(const std::string& super_mac) { | 201 void RegistryHashStoreContentsWin::SetSuperMac(const std::string& super_mac) { |
| 191 NOTREACHED() | 202 NOTREACHED() |
| 192 << "RegistryHashStoreContents does not support the SetSuperMac operation"; | 203 << "RegistryHashStoreContents does not support the SetSuperMac operation"; |
| 193 } | 204 } |
| OLD | NEW |