OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "base/test/test_reg_util_win.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace registry_util { |
| 10 |
| 11 const wchar_t ScopedRegistryKeyOverride::kTempTestKeyPath[] = |
| 12 L"Software\\Chromium\\TempTestKeys"; |
| 13 |
| 14 ScopedRegistryKeyOverride::ScopedRegistryKeyOverride( |
| 15 HKEY override, |
| 16 const std::wstring& temp_name) |
| 17 : override_(override), |
| 18 temp_name_(temp_name) { |
| 19 DCHECK(temp_name_.length() > 0); |
| 20 std::wstring key_path(kTempTestKeyPath); |
| 21 key_path += L"\\" + temp_name_; |
| 22 EXPECT_EQ(ERROR_SUCCESS, |
| 23 temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS)); |
| 24 EXPECT_EQ(ERROR_SUCCESS, |
| 25 ::RegOverridePredefKey(override_, temp_key_.Handle())); |
| 26 } |
| 27 |
| 28 ScopedRegistryKeyOverride::~ScopedRegistryKeyOverride() { |
| 29 ::RegOverridePredefKey(override_, NULL); |
| 30 // The temp key will be deleted via a call to DeleteAllTempKeys(). |
| 31 } |
| 32 |
| 33 // static |
| 34 void ScopedRegistryKeyOverride::DeleteAllTempKeys() { |
| 35 base::win::RegKey key; |
| 36 if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS) == ERROR_SUCCESS) { |
| 37 key.DeleteKey(kTempTestKeyPath); |
| 38 } |
| 39 } |
| 40 |
| 41 ScopedRegistryTempPathCleanup::ScopedRegistryTempPathCleanup() { |
| 42 ScopedRegistryKeyOverride::DeleteAllTempKeys(); |
| 43 } |
| 44 |
| 45 ScopedRegistryTempPathCleanup::~ScopedRegistryTempPathCleanup() { |
| 46 ScopedRegistryKeyOverride::DeleteAllTempKeys(); |
| 47 } |
| 48 |
| 49 } // namespace registry_util |
OLD | NEW |