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

Side by Side Diff: rlz/win/lib/registry_util.cc

Issue 768973003: Cleanup: Get rid of base::ASCIIToWide(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build Created 6 years 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 | « rlz/win/lib/registry_util.h ('k') | rlz/win/lib/rlz_value_store_registry.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // A helper library to keep track of a user's key by SID. 5 // A helper library to keep track of a user's key by SID.
6 // Used by RLZ libary. Also to be used by SearchWithGoogle library. 6 // Used by RLZ libary. Also to be used by SearchWithGoogle library.
7 7
8 #include "rlz/win/lib/registry_util.h" 8 #include "rlz/win/lib/registry_util.h"
9 9
10 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/win/registry.h" 12 #include "base/win/registry.h"
13 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
14 #include "rlz/lib/assert.h" 14 #include "rlz/lib/assert.h"
15 #include "rlz/win/lib/process_info.h" 15 #include "rlz/win/lib/process_info.h"
16 16
17 namespace rlz_lib { 17 namespace rlz_lib {
18 18
19 bool RegKeyReadValue(base::win::RegKey& key, const wchar_t* name, 19 bool RegKeyReadValue(const base::win::RegKey& key, const wchar_t* name,
20 char* value, size_t* value_size) { 20 char* value, size_t* value_size) {
21 value[0] = 0; 21 value[0] = 0;
22 22
23 std::wstring value_string; 23 std::wstring value_string;
24 if (key.ReadValue(name, &value_string) != ERROR_SUCCESS) { 24 if (key.ReadValue(name, &value_string) != ERROR_SUCCESS) {
25 return false; 25 return false;
26 } 26 }
27 27
28 if (value_string.length() > *value_size) { 28 if (value_string.length() > *value_size) {
29 *value_size = value_string.length(); 29 *value_size = value_string.length();
30 return false; 30 return false;
31 } 31 }
32 32
33 // Note that RLZ string are always ASCII by design. 33 // Note that RLZ string are always ASCII by design.
34 strncpy(value, base::WideToUTF8(value_string).c_str(), *value_size); 34 strncpy(value, base::WideToUTF8(value_string).c_str(), *value_size);
35 value[*value_size - 1] = 0; 35 value[*value_size - 1] = 0;
36 return true; 36 return true;
37 } 37 }
38 38
39 bool RegKeyWriteValue(base::win::RegKey& key, const wchar_t* name, 39 bool RegKeyWriteValue(base::win::RegKey* key, const wchar_t* name,
40 const char* value) { 40 const char* value) {
41 std::wstring value_string(base::ASCIIToWide(value)); 41 base::string16 value_string(base::ASCIIToUTF16(value));
42 return key.WriteValue(name, value_string.c_str()) == ERROR_SUCCESS; 42 return key->WriteValue(name, value_string.c_str()) == ERROR_SUCCESS;
43 } 43 }
44 44
45 bool HasUserKeyAccess(bool write_access) { 45 bool HasUserKeyAccess(bool write_access) {
46 // The caller is trying to access HKEY_CURRENT_USER. Test to see if we can 46 // The caller is trying to access HKEY_CURRENT_USER. Test to see if we can
47 // read from there. Don't try HKEY_CURRENT_USER because this will cause 47 // read from there. Don't try HKEY_CURRENT_USER because this will cause
48 // problems in the unit tests: if we open HKEY_CURRENT_USER directly here, 48 // problems in the unit tests: if we open HKEY_CURRENT_USER directly here,
49 // the overriding done for unit tests will no longer work. So we try subkey 49 // the overriding done for unit tests will no longer work. So we try subkey
50 // "Software" which is known to always exist. 50 // "Software" which is known to always exist.
51 base::win::RegKey key; 51 base::win::RegKey key;
52 if (key.Open(HKEY_CURRENT_USER, L"Software", KEY_READ) != ERROR_SUCCESS) 52 if (key.Open(HKEY_CURRENT_USER, L"Software", KEY_READ) != ERROR_SUCCESS)
(...skipping 15 matching lines...) Expand all
68 } 68 }
69 if (level <= base::LOW_INTEGRITY) { 69 if (level <= base::LOW_INTEGRITY) {
70 ASSERT_STRING("UserKey::HasAccess: Cannot write from Low Integrity."); 70 ASSERT_STRING("UserKey::HasAccess: Cannot write from Low Integrity.");
71 return false; 71 return false;
72 } 72 }
73 } 73 }
74 return true; 74 return true;
75 } 75 }
76 76
77 } // namespace rlz_lib 77 } // namespace rlz_lib
OLDNEW
« no previous file with comments | « rlz/win/lib/registry_util.h ('k') | rlz/win/lib/rlz_value_store_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698