Chromium Code Reviews| Index: services/preferences/tracked/registry_hash_store_contents_win.cc |
| diff --git a/services/preferences/tracked/registry_hash_store_contents_win.cc b/services/preferences/tracked/registry_hash_store_contents_win.cc |
| index 76ee57f3cd1caa8aef225a751e17b6578fac7985..cb92ae77eddff665700549ea746c4efaeca80dff 100644 |
| --- a/services/preferences/tracked/registry_hash_store_contents_win.cc |
| +++ b/services/preferences/tracked/registry_hash_store_contents_win.cc |
| @@ -6,12 +6,10 @@ |
| #include <windows.h> |
| -#include "base/files/scoped_temp_dir.h" |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/numerics/safe_conversions.h" |
| #include "base/strings/string_split.h" |
| -#include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| @@ -68,20 +66,38 @@ bool ClearSplitMac(const base::string16& reg_key_name, |
| return false; |
| } |
| +// Deletes |reg_key_name| if it exists. |
| +void DeleteRegistryKey(const base::string16& reg_key_name) { |
| + base::win::RegKey key; |
| + if (key.Open(HKEY_CURRENT_USER, reg_key_name.c_str(), |
| + KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
| + LONG result = key.DeleteKey(L""); |
| + DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result; |
| + } |
| +} |
| + |
| } // namespace |
| +void TempScopedDirRegistryCleaner::SetRegistryPath( |
| + const base::string16& registry_path) { |
| + DCHECK(registry_path_ == L"" || registry_path_ == registry_path); |
| + 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.
|
| +} |
| + |
| +TempScopedDirRegistryCleaner::~TempScopedDirRegistryCleaner() { |
| + DCHECK(registry_path_ != L""); |
|
gab
2017/06/12 15:52:16
DCHECK(!registry_path_.empty());
proberge
2017/06/12 18:46:02
Done.
|
| + DeleteRegistryKey(registry_path_); |
| +} |
| + |
| RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( |
| const base::string16& registry_path, |
| - const base::string16& store_key) |
| + const base::string16& store_key, |
| + scoped_refptr<TempScopedDirCleaner> temp_dir_cleaner) |
| : preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key), |
| - reset_on_delete_(base::StartsWith(store_key, |
| - base::ScopedTempDir::GetTempDirPrefix(), |
| - base::CompareCase::INSENSITIVE_ASCII)) { |
| -} |
| - |
| -RegistryHashStoreContentsWin::~RegistryHashStoreContentsWin() { |
| - if (reset_on_delete_) |
| - Reset(); |
| + temp_dir_cleaner_(temp_dir_cleaner) { |
|
gab
2017/06/12 15:52:16
std::move
proberge
2017/06/12 18:46:02
Done.
|
| + if (temp_dir_cleaner_) |
| + static_cast<TempScopedDirRegistryCleaner*>(temp_dir_cleaner_.get()) |
| + ->SetRegistryPath(preference_key_name_); |
| } |
| RegistryHashStoreContentsWin::RegistryHashStoreContentsWin( |
| @@ -101,12 +117,7 @@ base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const { |
| } |
| void RegistryHashStoreContentsWin::Reset() { |
| - base::win::RegKey key; |
| - if (key.Open(HKEY_CURRENT_USER, preference_key_name_.c_str(), |
| - KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
| - LONG result = key.DeleteKey(L""); |
| - DCHECK(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND) << result; |
| - } |
| + DeleteRegistryKey(preference_key_name_); |
| } |
| bool RegistryHashStoreContentsWin::GetMac(const std::string& path, |