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

Side by Side Diff: chrome/common/importer/importer_test_registry_overrider_win.cc

Issue 1880143002: Convert chrome/common to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « chrome/common/extensions/value_counter_unittest.cc ('k') | chrome/common/logging_chrome.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/common/importer/importer_test_registry_overrider_win.h" 5 #include "chrome/common/importer/importer_test_registry_overrider_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <memory>
9 #include <string> 10 #include <string>
10 11
11 #include "base/environment.h" 12 #include "base/environment.h"
12 #include "base/guid.h" 13 #include "base/guid.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/win/registry.h" 15 #include "base/win/registry.h"
16 16
17 namespace { 17 namespace {
18 18
19 // The key to which a random subkey will be appended. This key itself will never 19 // The key to which a random subkey will be appended. This key itself will never
20 // be deleted. 20 // be deleted.
21 const wchar_t kTestHKCUOverrideKeyPrefix[] = L"SOFTWARE\\Chromium Unit Tests\\"; 21 const wchar_t kTestHKCUOverrideKeyPrefix[] = L"SOFTWARE\\Chromium Unit Tests\\";
22 const char kTestHKCUOverrideEnvironmentVariable[] = 22 const char kTestHKCUOverrideEnvironmentVariable[] =
23 "IE_IMPORTER_TEST_OVERRIDE_HKCU"; 23 "IE_IMPORTER_TEST_OVERRIDE_HKCU";
24 24
25 // Reads the environment variable set by a previous call to 25 // Reads the environment variable set by a previous call to
26 // SetTestRegistryOverride() into |key| if it exists and |key| is not NULL. 26 // SetTestRegistryOverride() into |key| if it exists and |key| is not NULL.
27 // Returns true if the variable was successfully read. 27 // Returns true if the variable was successfully read.
28 bool GetTestKeyFromEnvironment(base::string16* key) { 28 bool GetTestKeyFromEnvironment(base::string16* key) {
29 scoped_ptr<base::Environment> env(base::Environment::Create()); 29 std::unique_ptr<base::Environment> env(base::Environment::Create());
30 std::string value; 30 std::string value;
31 bool result = env->GetVar(kTestHKCUOverrideEnvironmentVariable, &value); 31 bool result = env->GetVar(kTestHKCUOverrideEnvironmentVariable, &value);
32 if (result) 32 if (result)
33 *key = base::UTF8ToUTF16(value); 33 *key = base::UTF8ToUTF16(value);
34 return result; 34 return result;
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
40 // ImporterTestRegistryOverrider, public: 40 // ImporterTestRegistryOverrider, public:
41 41
42 ImporterTestRegistryOverrider::ImporterTestRegistryOverrider() 42 ImporterTestRegistryOverrider::ImporterTestRegistryOverrider()
43 : temporary_key_(kTestHKCUOverrideKeyPrefix + 43 : temporary_key_(kTestHKCUOverrideKeyPrefix +
44 base::UTF8ToUTF16(base::GenerateGUID())) { 44 base::UTF8ToUTF16(base::GenerateGUID())) {
45 DCHECK(!GetTestKeyFromEnvironment(NULL)); 45 DCHECK(!GetTestKeyFromEnvironment(NULL));
46 46
47 scoped_ptr<base::Environment> env(base::Environment::Create()); 47 std::unique_ptr<base::Environment> env(base::Environment::Create());
48 bool success = env->SetVar(kTestHKCUOverrideEnvironmentVariable, 48 bool success = env->SetVar(kTestHKCUOverrideEnvironmentVariable,
49 base::UTF16ToUTF8(temporary_key_)); 49 base::UTF16ToUTF8(temporary_key_));
50 DCHECK(success); 50 DCHECK(success);
51 } 51 }
52 52
53 ImporterTestRegistryOverrider::~ImporterTestRegistryOverrider() { 53 ImporterTestRegistryOverrider::~ImporterTestRegistryOverrider() {
54 base::win::RegKey reg_key(HKEY_CURRENT_USER, temporary_key_.c_str(), 54 base::win::RegKey reg_key(HKEY_CURRENT_USER, temporary_key_.c_str(),
55 KEY_ALL_ACCESS); 55 KEY_ALL_ACCESS);
56 DCHECK(reg_key.Valid()); 56 DCHECK(reg_key.Valid());
57 reg_key.DeleteKey(L""); 57 reg_key.DeleteKey(L"");
58 58
59 scoped_ptr<base::Environment> env(base::Environment::Create()); 59 std::unique_ptr<base::Environment> env(base::Environment::Create());
60 bool success = env->UnSetVar(kTestHKCUOverrideEnvironmentVariable); 60 bool success = env->UnSetVar(kTestHKCUOverrideEnvironmentVariable);
61 DCHECK(success); 61 DCHECK(success);
62 } 62 }
63 63
64 // static 64 // static
65 base::string16 ImporterTestRegistryOverrider::GetTestRegistryOverride() { 65 base::string16 ImporterTestRegistryOverrider::GetTestRegistryOverride() {
66 base::string16 key; 66 base::string16 key;
67 if (!GetTestKeyFromEnvironment(&key)) 67 if (!GetTestKeyFromEnvironment(&key))
68 return base::string16(); 68 return base::string16();
69 return key; 69 return key;
70 } 70 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/value_counter_unittest.cc ('k') | chrome/common/logging_chrome.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698