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