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

Side by Side Diff: cloud_print/common/win/cloud_print_utils.cc

Issue 107383002: Use base namespace for string16 in components and cloud_print. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « cloud_print/common/win/cloud_print_utils.h ('k') | cloud_print/common/win/install_utils.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cloud_print/common/win/cloud_print_utils.h" 5 #include "cloud_print/common/win/cloud_print_utils.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 10
11 namespace cloud_print { 11 namespace cloud_print {
12 12
13 namespace { 13 namespace {
14 14
15 // Google Update related constants. 15 // Google Update related constants.
16 const wchar_t kClientStateKey[] = L"SOFTWARE\\Google\\Update\\ClientState\\"; 16 const wchar_t kClientStateKey[] = L"SOFTWARE\\Google\\Update\\ClientState\\";
17 const wchar_t* kUsageKey = L"dr"; 17 const wchar_t* kUsageKey = L"dr";
18 18
19 } // namespace 19 } // namespace
20 20
21 HRESULT GetLastHResult() { 21 HRESULT GetLastHResult() {
22 DWORD error_code = GetLastError(); 22 DWORD error_code = GetLastError();
23 return error_code ? HRESULT_FROM_WIN32(error_code) : E_FAIL; 23 return error_code ? HRESULT_FROM_WIN32(error_code) : E_FAIL;
24 } 24 }
25 25
26 string16 LoadLocalString(DWORD id) { 26 base::string16 LoadLocalString(DWORD id) {
27 static wchar_t dummy = L'\0'; 27 static wchar_t dummy = L'\0';
28 HMODULE module = NULL; 28 HMODULE module = NULL;
29 ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | 29 ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
30 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, &dummy, &module); 30 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, &dummy, &module);
31 LPCWSTR buffer = NULL; 31 LPCWSTR buffer = NULL;
32 // If the last parameter is 0, LoadString assume that 3rd parameter type is 32 // If the last parameter is 0, LoadString assume that 3rd parameter type is
33 // LPCWSTR* and assign pointer to read-only memory with resource. 33 // LPCWSTR* and assign pointer to read-only memory with resource.
34 int count = ::LoadString(module, id, reinterpret_cast<LPWSTR>(&buffer), 0); 34 int count = ::LoadString(module, id, reinterpret_cast<LPWSTR>(&buffer), 0);
35 if (!buffer) 35 if (!buffer)
36 return string16(); 36 return base::string16();
37 return string16(buffer, buffer + count); 37 return base::string16(buffer, buffer + count);
38 } 38 }
39 39
40 string16 GetErrorMessage(HRESULT hr) { 40 base::string16 GetErrorMessage(HRESULT hr) {
41 LPWSTR buffer = NULL; 41 LPWSTR buffer = NULL;
42 ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | 42 ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
43 FORMAT_MESSAGE_ALLOCATE_BUFFER, 43 FORMAT_MESSAGE_ALLOCATE_BUFFER,
44 0, hr, 0, reinterpret_cast<LPWSTR>(&buffer), 0, NULL); 44 0, hr, 0, reinterpret_cast<LPWSTR>(&buffer), 0, NULL);
45 string16 result(buffer); 45 base::string16 result(buffer);
46 ::LocalFree(buffer); 46 ::LocalFree(buffer);
47 return result; 47 return result;
48 } 48 }
49 49
50 void SetGoogleUpdateUsage(const string16& product_id) { 50 void SetGoogleUpdateUsage(const base::string16& product_id) {
51 // Set appropriate key to 1 to let Omaha record usage. 51 // Set appropriate key to 1 to let Omaha record usage.
52 base::win::RegKey key; 52 base::win::RegKey key;
53 if (key.Create(HKEY_CURRENT_USER, 53 if (key.Create(HKEY_CURRENT_USER,
54 (kClientStateKey + product_id).c_str(), 54 (kClientStateKey + product_id).c_str(),
55 KEY_SET_VALUE) != ERROR_SUCCESS || 55 KEY_SET_VALUE) != ERROR_SUCCESS ||
56 key.WriteValue(kUsageKey, L"1") != ERROR_SUCCESS) { 56 key.WriteValue(kUsageKey, L"1") != ERROR_SUCCESS) {
57 LOG(ERROR) << "Unable to set usage key"; 57 LOG(ERROR) << "Unable to set usage key";
58 } 58 }
59 } 59 }
60 60
61 } // namespace cloud_print 61 } // namespace cloud_print
OLDNEW
« no previous file with comments | « cloud_print/common/win/cloud_print_utils.h ('k') | cloud_print/common/win/install_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698