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

Unified Diff: cloud_print/common/win/cloud_print_utils.cc

Issue 2541123003: Resurrect the cloud printer driver. (Closed)
Patch Set: Remove cross-compiling option for the portmon dll. Created 4 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cloud_print/common/win/cloud_print_utils.cc
diff --git a/cloud_print/common/win/cloud_print_utils.cc b/cloud_print/common/win/cloud_print_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5a8574c1a9e563358312256648c288e0e1421c97
--- /dev/null
+++ b/cloud_print/common/win/cloud_print_utils.cc
@@ -0,0 +1,61 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cloud_print/common/win/cloud_print_utils.h"
+
+#include <windows.h>
+
+#include "base/win/registry.h"
+
+namespace cloud_print {
+
+namespace {
+
+// Google Update related constants.
+const wchar_t kClientStateKey[] = L"SOFTWARE\\Google\\Update\\ClientState\\";
+const wchar_t* kUsageKey = L"dr";
+
+} // namespace
+
+HRESULT GetLastHResult() {
+ DWORD error_code = GetLastError();
+ return error_code ? HRESULT_FROM_WIN32(error_code) : E_FAIL;
+}
+
+base::string16 LoadLocalString(DWORD id) {
+ static wchar_t dummy = L'\0';
+ HMODULE module = NULL;
+ ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
+ GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ &dummy, &module);
+ LPCWSTR buffer = NULL;
+ // If the last parameter is 0, LoadString assume that 3rd parameter type is
+ // LPCWSTR* and assign pointer to read-only memory with resource.
+ int count = ::LoadString(module, id, reinterpret_cast<LPWSTR>(&buffer), 0);
+ if (!buffer)
+ return base::string16();
+ return base::string16(buffer, buffer + count);
+}
+
+base::string16 GetErrorMessage(HRESULT hr) {
+ LPWSTR buffer = NULL;
+ ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ 0, hr, 0, reinterpret_cast<LPWSTR>(&buffer), 0, NULL);
+ base::string16 result(buffer);
+ ::LocalFree(buffer);
+ return result;
+}
+
+void SetGoogleUpdateUsage(const base::string16& product_id) {
+ // Set appropriate key to 1 to let Omaha record usage.
+ base::win::RegKey key;
+ if (key.Create(HKEY_CURRENT_USER, (kClientStateKey + product_id).c_str(),
+ KEY_SET_VALUE) != ERROR_SUCCESS ||
+ key.WriteValue(kUsageKey, L"1") != ERROR_SUCCESS) {
+ LOG(ERROR) << "Unable to set usage key";
+ }
+}
+
+} // namespace cloud_print
« 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