From f2f16fd6f3ad05106f9a76d1c828657febc122c2 Mon Sep 17 00:00:00 2001
From: "vitalybuka@chromium.org"
 <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Tue, 5 Mar 2013 07:38:04 +0000
Subject: Error message about missing XPS driver.

BUG=179290
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/12389088

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186126 0039d316-1c4b-4281-b951-d872f2087c98
---
 cloud_print/virtual_driver/win/install/setup.cc    | 37 ++++++++++++++++++----
 .../win/install/virtual_driver_setup_resources.grd |  4 +++
 .../win/port_monitor/port_monitor.cc               |  8 ++---
 .../virtual_driver/win/virtual_driver_consts.cc    | 10 ++++--
 .../virtual_driver/win/virtual_driver_consts.h     |  6 ++--
 5 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/cloud_print/virtual_driver/win/install/setup.cc b/cloud_print/virtual_driver/win/install/setup.cc
index cd2d222..22ea834 100644
--- a/cloud_print/virtual_driver/win/install/setup.cc
+++ b/cloud_print/virtual_driver/win/install/setup.cc
@@ -30,8 +30,6 @@
 
 namespace {
 
-const wchar_t kVersionKey[] = L"pv";
-const wchar_t kNameKey[] = L"name";
 const wchar_t kNameValue[] = L"GCP Virtual Driver";
 const wchar_t kUninstallRegistry[] =
     L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
@@ -62,9 +60,17 @@ const char kRegisterSwitch[] = "register";
 const char kUninstallSwitch[] = "uninstall";
 const char kUnregisterSwitch[] = "unregister";
 
+// Google update related constants.
+const wchar_t kVersionKey[] = L"pv";
+const wchar_t kNameKey[] = L"name";
+const DWORD kInstallerResultFailedCustomError = 1;
+const wchar_t kRegValueLastInstallerResult[] = L"LastInstallerResult";
+const wchar_t kRegValueLastInstallerResultUIString[] =
+    L"LastInstallerResultUIString";
+
 void SetGoogleUpdateKeys() {
   base::win::RegKey key;
-  if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation,
+  if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientsKey,
                  KEY_SET_VALUE) != ERROR_SUCCESS) {
     LOG(ERROR) << "Unable to open key";
   }
@@ -90,9 +96,24 @@ void SetGoogleUpdateKeys() {
   }
 }
 
+void SetGoogleUpdateError(const string16& message) {
+  base::win::RegKey key;
+  if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientStateKey,
+                 KEY_SET_VALUE) != ERROR_SUCCESS) {
+    LOG(ERROR) << "Unable to open key";
+  }
+
+  if (key.WriteValue(kRegValueLastInstallerResult,
+                     kInstallerResultFailedCustomError) != ERROR_SUCCESS ||
+      key.WriteValue(kRegValueLastInstallerResultUIString,
+                     message.c_str()) != ERROR_SUCCESS) {
+      LOG(ERROR) << "Unable to set registry keys";
+  }
+}
+
 void DeleteGoogleUpdateKeys() {
   base::win::RegKey key;
-  if (key.Open(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation,
+  if (key.Open(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientsKey,
                DELETE) != ERROR_SUCCESS) {
     LOG(ERROR) << "Unable to open key to delete";
     return;
@@ -251,8 +272,7 @@ UINT CALLBACK CabinetCallback(PVOID data,
 }
 
 void ReadyPpdDependencies(const base::FilePath& destination) {
-  base::win::Version version = base::win::GetVersion();
-  if (version >= base::win::VERSION_VISTA) {
+  if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
     // GetCorePrinterDrivers and GetPrinterDriverPackagePath only exist on
     // Vista and later. Winspool.drv must be delayloaded so these calls don't
     // create problems on XP.
@@ -301,6 +321,11 @@ HRESULT InstallPpd(const base::FilePath& install_path) {
   base::FilePath ui_path = temp_path.path().Append(kUiDriverName);
   base::FilePath ui_help_path = temp_path.path().Append(kHelpName);
 
+  if (!file_util::PathExists(xps_path)) {
+    SetGoogleUpdateError(cloud_print::LoadLocalString(IDS_ERROR_NO_XPS));
+    return HRESULT_FROM_WIN32(ERROR_BAD_DRIVER);
+  }
+
   DRIVER_INFO_6 driver_info = {0};
   // Set up supported print system version.  Must be 3.
   driver_info.cVersion = 3;
diff --git a/cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd b/cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd
index 81450c4..4d731ca 100644
--- a/cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd
+++ b/cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd
@@ -128,6 +128,10 @@ file.
                meaning="Driver Name" desc="The user visible name of the printer we create and its associated driver.">
         Google Cloud Printer
       </message>
+      <message name="IDS_ERROR_NO_XPS"
+               meaning="Error message" desc="XPS driver is not installed.">
+        &lt;a=&quot;http://www.microsoft.com/download/details.aspx?id=11816&quot;&gt;XPS driver&lt;/a&gt; is not installed.
+      </message>
     </messages>
   </release>
 </grit>
diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
index 2157d19..7e2ffe9 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
@@ -409,11 +409,9 @@ BOOL WINAPI Monitor2StartDocPort(HANDLE port_handle,
   const wchar_t* kUsageKey = L"dr";
   // Set appropriate key to 1 to let Omaha record usage.
   base::win::RegKey key;
-  if (key.Create(HKEY_CURRENT_USER, kKeyLocation,
-                 KEY_SET_VALUE) != ERROR_SUCCESS) {
-    LOG(ERROR) << "Unable to open key to log usage";
-  }
-  if (key.WriteValue(kUsageKey, L"1") != ERROR_SUCCESS) {
+  if (key.Create(HKEY_CURRENT_USER, kGoogleUpdateClientStateKey,
+                 KEY_SET_VALUE) != ERROR_SUCCESS ||
+      key.WriteValue(kUsageKey, L"1") != ERROR_SUCCESS) {
     LOG(ERROR) << "Unable to set usage key";
   }
   if (port_handle == NULL) {
diff --git a/cloud_print/virtual_driver/win/virtual_driver_consts.cc b/cloud_print/virtual_driver/win/virtual_driver_consts.cc
index 7d13eeb..8898043 100644
--- a/cloud_print/virtual_driver/win/virtual_driver_consts.cc
+++ b/cloud_print/virtual_driver/win/virtual_driver_consts.cc
@@ -7,9 +7,13 @@
 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
 
 namespace cloud_print {
+
 const wchar_t kPortName[] = L"GCP:";
 const size_t kPortNameSize = sizeof(kPortName);
-const wchar_t kKeyLocation[] =
-  L"SOFTWARE\\Google\\Update\\Clients\\{9B13FA92-1F73-4761-AB78-2C6ADAC3660D}";
-}
+const wchar_t kGoogleUpdateClientsKey[] = L"SOFTWARE\\Google\\Update\\"
+    L"Clients\\{9B13FA92-1F73-4761-AB78-2C6ADAC3660D}";
+const wchar_t kGoogleUpdateClientStateKey[] = L"SOFTWARE\\Google\\Update\\"
+    L"ClientState\\{9B13FA92-1F73-4761-AB78-2C6ADAC3660D}";
+
+}  // namespace cloud_print
 
diff --git a/cloud_print/virtual_driver/win/virtual_driver_consts.h b/cloud_print/virtual_driver/win/virtual_driver_consts.h
index 26cf8b8..9d4b893 100644
--- a/cloud_print/virtual_driver/win/virtual_driver_consts.h
+++ b/cloud_print/virtual_driver/win/virtual_driver_consts.h
@@ -6,11 +6,13 @@
 #define CLOUD_PRINT_VIRTUAL_DRIVER_WIN_VIRTUAL_DRIVER_CONSTS_H_
 
 namespace cloud_print {
+
 extern const wchar_t kPortName[];
 extern const size_t kPortNameSize;
-extern const wchar_t kKeyLocation[];
-}  // namespace cloud_print
+extern const wchar_t kGoogleUpdateClientsKey[];
+extern const wchar_t kGoogleUpdateClientStateKey[];
 
+}  // namespace cloud_print
 
 #endif  // CLOUD_PRINT_VIRTUAL_DRIVER_WIN_VIRTUAL_DRIVER_CONSTS_H_
 
-- 
cgit v1.1