summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 02:42:07 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 02:42:07 +0000
commite1a31ac75aa84f07134de78fc0cec6a49added50 (patch)
treee3a3289a65448e8b90244f299340b5b7721d019f
parent2e2392b161702bd41f3a0058afd3786a912dfd3b (diff)
downloadchromium_src-e1a31ac75aa84f07134de78fc0cec6a49added50.zip
chromium_src-e1a31ac75aa84f07134de78fc0cec6a49added50.tar.gz
chromium_src-e1a31ac75aa84f07134de78fc0cec6a49added50.tar.bz2
Single binary for unittests.
Root solution for src/cloud_print. Build cloud_print_unittests on bots. Added virtual_driver_lib with shared files. Moved service_state out of win dir as platform independent. BUG=131058 TEST=unittests Review URL: https://chromiumcodereview.appspot.com/10505010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140703 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/all.gyp13
-rw-r--r--cloud_print/cloud_print.gyp48
-rw-r--r--cloud_print/service/DEPS (renamed from cloud_print/service/win/DEPS)0
-rw-r--r--cloud_print/service/service.gyp (renamed from cloud_print/service/win/service.gyp)35
-rw-r--r--cloud_print/service/service_state.cc (renamed from cloud_print/service/win/service_state.cc)2
-rw-r--r--cloud_print/service/service_state.h (renamed from cloud_print/service/win/service_state.h)0
-rw-r--r--cloud_print/service/service_state_unittest.cc (renamed from cloud_print/service/win/service_state_unittest.cc)2
-rw-r--r--cloud_print/service/service_switches.cc (renamed from cloud_print/service/win/service_switches.cc)2
-rw-r--r--cloud_print/service/service_switches.h (renamed from cloud_print/service/win/service_switches.h)0
-rw-r--r--cloud_print/service/win/chrome_launcher.cc2
-rw-r--r--cloud_print/service/win/cloud_print_service.cc4
-rw-r--r--cloud_print/virtual_driver/virtual_driver.gyp15
-rw-r--r--cloud_print/virtual_driver/win/install/virtual_driver_install.gyp9
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor.cc73
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor.h4
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor_dll.cc103
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor_unittest.cc11
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp66
-rw-r--r--cloud_print/virtual_driver/win/virtual_driver.gyp18
-rw-r--r--cloud_print/virtual_driver/win/virtual_driver.gypi53
-rw-r--r--cloud_print/virtual_driver/win/virtual_driver64.gyp26
21 files changed, 294 insertions, 192 deletions
diff --git a/build/all.gyp b/build/all.gyp
index 0f8ef6a..7198959 100644
--- a/build/all.gyp
+++ b/build/all.gyp
@@ -107,8 +107,7 @@
'dependencies': [
'../breakpad/breakpad.gyp:*',
'../chrome_frame/chrome_frame.gyp:*',
- '../cloud_print/service/win/service.gyp:*',
- '../cloud_print/virtual_driver/virtual_driver.gyp:*',
+ '../cloud_print/cloud_print.gyp:*',
'../courgette/courgette.gyp:*',
'../rlz/rlz.gyp:*',
'../sandbox/sandbox.gyp:*',
@@ -179,6 +178,7 @@
'../chrome/chrome.gyp:safe_browsing_tests',
'../chrome/chrome.gyp:sync_integration_tests',
'../chrome/chrome.gyp:unit_tests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../content/content.gyp:content_browsertests',
'../content/content.gyp:content_unittests',
'../crypto/crypto.gyp:crypto_unittests',
@@ -308,6 +308,7 @@
'../chrome/chrome.gyp:safe_browsing_tests',
'../chrome/chrome.gyp:sync_integration_tests',
'../chrome/chrome.gyp:unit_tests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../content/content.gyp:content_browsertests',
'../content/content.gyp:content_unittests',
'../ui/ui.gyp:gfx_unittests',
@@ -335,6 +336,7 @@
'../chrome/chrome.gyp:safe_browsing_tests',
'../chrome/chrome.gyp:sync_integration_tests',
'../chrome/chrome.gyp:unit_tests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../content/content.gyp:content_browsertests',
'../content/content.gyp:content_unittests',
'../ui/ui.gyp:gfx_unittests',
@@ -356,6 +358,7 @@
'type': 'none',
'dependencies': [
'../base/base.gyp:base_unittests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../crypto/crypto.gyp:crypto_unittests',
'temp_gyp/googleurl.gyp:googleurl_unittests',
'../net/net.gyp:net_unittests',
@@ -373,6 +376,7 @@
'type': 'none',
'dependencies': [
'../base/base.gyp:base_unittests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../crypto/crypto.gyp:crypto_unittests',
'../ipc/ipc.gyp:ipc_tests',
'../media/media.gyp:media_unittests',
@@ -410,6 +414,7 @@
'../chrome/chrome.gyp:safe_browsing_tests',
'../chrome/chrome.gyp:sync_integration_tests',
'../chrome/chrome.gyp:unit_tests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../content/content.gyp:content_browsertests',
'../content/content.gyp:content_unittests',
# mini_installer_tests depends on mini_installer. This should be
@@ -455,6 +460,7 @@
'type': 'none',
'dependencies': [
'../base/base.gyp:base_unittests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../content/content.gyp:content_unittests',
'../crypto/crypto.gyp:crypto_unittests',
'../ipc/ipc.gyp:ipc_tests',
@@ -475,6 +481,7 @@
'dependencies': [
'../base/base.gyp:base_unittests',
'../chrome/chrome.gyp:unit_tests',
+ '../cloud_print/cloud_print.gyp:cloud_print_unittests',
'../content/content.gyp:content_unittests',
'../crypto/crypto.gyp:crypto_unittests',
'../ipc/ipc.gyp:ipc_tests',
@@ -519,7 +526,7 @@
'../chrome_frame/chrome_frame.gyp:npchrome_frame',
'../courgette/courgette.gyp:courgette',
'../courgette/courgette.gyp:courgette64',
- '../cloud_print/virtual_driver/virtual_driver.gyp:virtual_driver',
+ '../cloud_print/cloud_print.gyp:cloud_print',
'../remoting/remoting.gyp:remoting_webapp',
'../third_party/adobe/flash/flash_player.gyp:flash_player',
],
diff --git a/cloud_print/cloud_print.gyp b/cloud_print/cloud_print.gyp
new file mode 100644
index 0000000..bb15405
--- /dev/null
+++ b/cloud_print/cloud_print.gyp
@@ -0,0 +1,48 @@
+# Copyright (c) 2012 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.
+{
+ 'targets': [
+ {
+ 'target_name': 'cloud_print',
+ 'type': 'none',
+ 'dependencies': [
+ 'service/service.gyp:*',
+ ],
+ 'conditions': [
+ ['OS=="win"', {
+ 'dependencies': [
+ 'virtual_driver/win/install/virtual_driver_install.gyp:*',
+ 'virtual_driver/win/virtual_driver.gyp:*',
+ 'virtual_driver/win/virtual_driver64.gyp:*',
+ ],
+ }],
+ ],
+ },
+ {
+ 'target_name': 'cloud_print_unittests',
+ 'type': 'executable',
+ 'sources': [
+ 'service/service_state_unittest.cc',
+ ],
+ 'dependencies': [
+ '<(DEPTH)/base/base.gyp:base',
+ '<(DEPTH)/base/base.gyp:run_all_unittests',
+ '<(DEPTH)/base/base.gyp:test_support_base',
+ '<(DEPTH)/testing/gmock.gyp:gmock',
+ '<(DEPTH)/testing/gtest.gyp:gtest',
+ 'service/service.gyp:cloud_print_service_lib',
+ ],
+ 'conditions': [
+ ['OS=="win"', {
+ 'sources': [
+ 'virtual_driver/win/port_monitor/port_monitor_unittest.cc',
+ ],
+ 'dependencies': [
+ 'virtual_driver/win/virtual_driver.gyp:gcp_portmon_lib',
+ ],
+ }],
+ ],
+ },
+ ],
+}
diff --git a/cloud_print/service/win/DEPS b/cloud_print/service/DEPS
index 8fa9d48..8fa9d48 100644
--- a/cloud_print/service/win/DEPS
+++ b/cloud_print/service/DEPS
diff --git a/cloud_print/service/win/service.gyp b/cloud_print/service/service.gyp
index b365e83..096e0d8 100644
--- a/cloud_print/service/win/service.gyp
+++ b/cloud_print/service/service.gyp
@@ -7,7 +7,7 @@
'chromium_code': 1,
},
'include_dirs': [
- '../../..',
+ '<(DEPTH)',
],
},
'targets': [
@@ -15,27 +15,27 @@
'target_name': 'cloud_print_service_lib',
'type': 'static_library',
'dependencies': [
- '../../../base/base.gyp:base',
- '../../../build/temp_gyp/googleurl.gyp:googleurl',
- '../../../net/net.gyp:net',
+ '<(DEPTH)/base/base.gyp:base',
+ '<(DEPTH)/build/temp_gyp/googleurl.gyp:googleurl',
+ '<(DEPTH)/net/net.gyp:net',
],
'sources': [
- 'chrome_launcher.cc',
- 'chrome_launcher.h',
'service_state.cc',
'service_state.h',
'service_switches.cc',
'service_switches.h',
+ 'win/chrome_launcher.cc',
+ 'win/chrome_launcher.h',
]
},
{
'target_name': 'cloud_print_service',
'type': 'executable',
'sources': [
- 'cloud_print_service.cc',
- 'cloud_print_service.h',
- 'cloud_print_service.rc',
- 'resource.h',
+ 'win/cloud_print_service.cc',
+ 'win/cloud_print_service.h',
+ 'win/cloud_print_service.rc',
+ 'win/resource.h',
],
'dependencies': [
'cloud_print_service_lib',
@@ -47,20 +47,5 @@
},
},
},
- {
- 'target_name': 'cloud_print_service_unittests',
- 'type': 'executable',
- 'sources': [
- 'service_state_unittest.cc',
- ],
- 'dependencies': [
- '../../../base/base.gyp:run_all_unittests',
- '../../../base/base.gyp:base',
- '../../../base/base.gyp:test_support_base',
- '../../../testing/gmock.gyp:gmock',
- '../../../testing/gtest.gyp:gtest',
- 'cloud_print_service_lib',
- ],
- },
],
}
diff --git a/cloud_print/service/win/service_state.cc b/cloud_print/service/service_state.cc
index 8641000..545210d 100644
--- a/cloud_print/service/win/service_state.cc
+++ b/cloud_print/service/service_state.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cloud_print/service/win/service_state.h"
+#include "cloud_print/service/service_state.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
diff --git a/cloud_print/service/win/service_state.h b/cloud_print/service/service_state.h
index ef037bb..ef037bb 100644
--- a/cloud_print/service/win/service_state.h
+++ b/cloud_print/service/service_state.h
diff --git a/cloud_print/service/win/service_state_unittest.cc b/cloud_print/service/service_state_unittest.cc
index 00c651e..4e5d2d0 100644
--- a/cloud_print/service/win/service_state_unittest.cc
+++ b/cloud_print/service/service_state_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cloud_print/service/win/service_state.h"
+#include "cloud_print/service/service_state.h"
#include "base/string_util.h"
#include "testing/gmock/include/gmock/gmock.h"
diff --git a/cloud_print/service/win/service_switches.cc b/cloud_print/service/service_switches.cc
index 296eae0..a03c89c 100644
--- a/cloud_print/service/win/service_switches.cc
+++ b/cloud_print/service/service_switches.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cloud_print/service/win/service_switches.h"
+#include "cloud_print/service/service_switches.h"
const char kChromeTypeSwitch[] = "type";
const char kConsoleSwitch[] = "console";
diff --git a/cloud_print/service/win/service_switches.h b/cloud_print/service/service_switches.h
index 17af981..17af981 100644
--- a/cloud_print/service/win/service_switches.h
+++ b/cloud_print/service/service_switches.h
diff --git a/cloud_print/service/win/chrome_launcher.cc b/cloud_print/service/win/chrome_launcher.cc
index 8b984f0..5921fd0 100644
--- a/cloud_print/service/win/chrome_launcher.cc
+++ b/cloud_print/service/win/chrome_launcher.cc
@@ -12,7 +12,7 @@
#include "base/win/registry.h"
#include "base/win/scoped_handle.h"
#include "base/win/scoped_process_information.h"
-#include "cloud_print/service/win/service_switches.h"
+#include "cloud_print/service/service_switches.h"
namespace {
diff --git a/cloud_print/service/win/cloud_print_service.cc b/cloud_print/service/win/cloud_print_service.cc
index c0948c4..f87c2888 100644
--- a/cloud_print/service/win/cloud_print_service.cc
+++ b/cloud_print/service/win/cloud_print_service.cc
@@ -15,10 +15,10 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/win/scoped_handle.h"
+#include "cloud_print/service/service_state.h"
+#include "cloud_print/service/service_switches.h"
#include "cloud_print/service/win/chrome_launcher.h"
#include "cloud_print/service/win/resource.h"
-#include "cloud_print/service/win/service_state.h"
-#include "cloud_print/service/win/service_switches.h"
namespace {
diff --git a/cloud_print/virtual_driver/virtual_driver.gyp b/cloud_print/virtual_driver/virtual_driver.gyp
deleted file mode 100644
index 8368ffb..0000000
--- a/cloud_print/virtual_driver/virtual_driver.gyp
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright (c) 2011 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.
-{
- 'targets': [
- {
- 'target_name': 'virtual_driver',
- 'type': 'none',
- 'dependencies': [
- 'win/install/virtual_driver_install.gyp:*',
- 'win/port_monitor/virtual_driver_port_monitor.gyp:*',
- ],
- },
- ],
-}
diff --git a/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp b/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp
index 5318f99..deb36e7 100644
--- a/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp
+++ b/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp
@@ -8,7 +8,7 @@
'chromium_code': 1,
},
'include_dirs': [
- '../../../..',
+ '<(DEPTH)',
],
},
'targets' : [
@@ -16,15 +16,12 @@
'target_name': 'virtual_driver_setup',
'type': 'executable',
'dependencies': [
- '../../../../base/base.gyp:base',
+ '../virtual_driver.gyp:virtual_driver_lib',
+ '<(DEPTH)/base/base.gyp:base',
'virtual_driver_setup_resources',
],
'sources': [
'setup.cc',
- '../virtual_driver_consts.h',
- '../virtual_driver_consts.cc',
- '../virtual_driver_helpers.h',
- '../virtual_driver_helpers.cc',
'../virtual_driver_common_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/virtual_driver_setup_resources/virtual_driver_setup_resources_ar.rc',
'<(SHARED_INTERMEDIATE_DIR)/virtual_driver_setup_resources/virtual_driver_setup_resources_bg.rc',
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 335b6a8..dc46b95d 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
@@ -30,17 +30,15 @@
namespace cloud_print {
-#ifndef UNIT_TEST
-const wchar_t kChromeExePath[] = L"google\\chrome\\application\\chrome.exe";
-const wchar_t kChromePathRegValue[] = L"PathToChromeExe";
-#endif
+namespace {
+
const wchar_t kIePath[] = L"Internet Explorer\\iexplore.exe";
+
const char kChromeInstallUrl[] =
"http://google.com/cloudprint/learn/chrome.html";
const wchar_t kChromePathRegKey[] = L"Software\\Google\\CloudPrint";
-namespace {
const wchar_t kXpsMimeType[] = L"application/vnd.ms-xpsdocument";
const size_t kMaxCommandLineLen = 0x7FFF;
@@ -91,36 +89,6 @@ MONITOR2 g_monitor_2 = {
Monitor2Shutdown
};
-// Returns true if Xps support is installed.
-bool XpsIsInstalled() {
- FilePath xps_path;
- if (!SUCCEEDED(GetPrinterDriverDir(&xps_path))) {
- return false;
- }
- xps_path = xps_path.Append(L"mxdwdrv.dll");
- if (!file_util::PathExists(xps_path)) {
- return false;
- }
- return true;
-}
-
-// Returns true if registration/unregistration can be attempted.
-bool CanRegister() {
- if (!XpsIsInstalled()) {
- return false;
- }
- if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
- base::IntegrityLevel level = base::INTEGRITY_UNKNOWN;
- if (!GetProcessIntegrityLevel(base::GetCurrentProcessHandle(), &level)) {
- return false;
- }
- if (level != base::HIGH_INTEGRITY) {
- return false;
- }
- }
- return true;
-}
-
// Frees any objects referenced by port_data and sets pointers to NULL.
void CleanupPortData(PortData* port_data) {
delete port_data->file_path;
@@ -234,8 +202,8 @@ bool LaunchPrintDialog(const string16& xps_path,
// rather than the generic chrome download page. See
// http://code.google.com/p/chromium/issues/detail?id=112019
void LaunchChromeDownloadPage() {
-// Probably best to NOT launch IE from a unit test.
-#ifndef UNIT_TEST
+ if (kIsUnittest)
+ return;
HANDLE token = NULL;
if (!GetUserToken(&token)) {
LOG(ERROR) << "Unable to get user token.";
@@ -252,7 +220,6 @@ void LaunchChromeDownloadPage() {
base::LaunchOptions options;
options.as_user = token_scoped;
base::LaunchProcess(command_line, options, NULL);
-#endif
}
// Returns false if the print job is being run in a context
@@ -653,33 +620,3 @@ MONITORUI* WINAPI InitializePrintMonitorUI(void) {
return &cloud_print::g_monitor_ui;
}
-HRESULT WINAPI DllRegisterServer(void) {
- base::AtExitManager at_exit_manager;
- if (!cloud_print::CanRegister()) {
- return E_ACCESSDENIED;
- }
- MONITOR_INFO_2 monitor_info = {0};
- // YUCK!!! I can either copy the constant, const_cast, or define my own
- // MONITOR_INFO_2 that will take const strings.
- FilePath dll_path(cloud_print::GetPortMonitorDllName());
- monitor_info.pDLLName = const_cast<LPWSTR>(dll_path.value().c_str());
- monitor_info.pName = const_cast<LPWSTR>(dll_path.value().c_str());
- if (AddMonitor(NULL, 2, reinterpret_cast<BYTE*>(&monitor_info))) {
- return S_OK;
- }
- return cloud_print::GetLastHResult();
-}
-
-HRESULT WINAPI DllUnregisterServer(void) {
- base::AtExitManager at_exit_manager;
- if (!cloud_print::CanRegister()) {
- return E_ACCESSDENIED;
- }
- FilePath dll_path(cloud_print::GetPortMonitorDllName());
- if (DeleteMonitor(NULL,
- NULL,
- const_cast<LPWSTR>(dll_path.value().c_str()))) {
- return S_OK;
- }
- return cloud_print::GetLastHResult();
-}
diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor.h b/cloud_print/virtual_driver/win/port_monitor/port_monitor.h
index 5b3c1b9..e9e83f0 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.h
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -79,8 +79,8 @@ BOOL WINAPI MonitorUiConfigureOrDeletePortUI(const wchar_t*,
const wchar_t* port_name);
extern const wchar_t kChromeExePath[];
-extern const wchar_t kChromePathRegKey[];
extern const wchar_t kChromePathRegValue[];
+extern const bool kIsUnittest;
} // namespace cloud_print
diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor_dll.cc b/cloud_print/virtual_driver/win/port_monitor/port_monitor_dll.cc
new file mode 100644
index 0000000..39fc604
--- /dev/null
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor_dll.cc
@@ -0,0 +1,103 @@
+// Copyright (c) 2012 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/virtual_driver/win/port_monitor/port_monitor.h"
+
+#include <lmcons.h>
+#include <shellapi.h>
+#include <shlobj.h>
+#include <strsafe.h>
+#include <userenv.h>
+#include <windows.h>
+#include <winspool.h>
+
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/process.h"
+#include "base/process_util.h"
+#include "base/string16.h"
+#include "base/win/registry.h"
+#include "base/win/scoped_handle.h"
+#include "base/win/windows_version.h"
+#include "cloud_print/virtual_driver/virtual_driver_switches.h"
+#include "cloud_print/virtual_driver/win/port_monitor/spooler_win.h"
+#include "cloud_print/virtual_driver/win/virtual_driver_consts.h"
+#include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
+
+namespace cloud_print {
+
+const wchar_t kChromeExePath[] = L"google\\chrome\\application\\chrome.exe";
+const wchar_t kChromePathRegValue[] = L"PathToChromeExe";
+const bool kIsUnittest = false;
+
+namespace {
+
+// Returns true if Xps support is installed.
+bool XpsIsInstalled() {
+ FilePath xps_path;
+ if (!SUCCEEDED(GetPrinterDriverDir(&xps_path))) {
+ return false;
+ }
+ xps_path = xps_path.Append(L"mxdwdrv.dll");
+ if (!file_util::PathExists(xps_path)) {
+ return false;
+ }
+ return true;
+}
+
+// Returns true if registration/unregistration can be attempted.
+bool CanRegister() {
+ if (!XpsIsInstalled()) {
+ return false;
+ }
+ if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
+ base::IntegrityLevel level = base::INTEGRITY_UNKNOWN;
+ if (!GetProcessIntegrityLevel(base::GetCurrentProcessHandle(), &level)) {
+ return false;
+ }
+ if (level != base::HIGH_INTEGRITY) {
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace
+
+
+} // namespace cloud_print
+
+HRESULT WINAPI DllRegisterServer(void) {
+ base::AtExitManager at_exit_manager;
+ if (!cloud_print::CanRegister()) {
+ return E_ACCESSDENIED;
+ }
+ MONITOR_INFO_2 monitor_info = {0};
+ // YUCK!!! I can either copy the constant, const_cast, or define my own
+ // MONITOR_INFO_2 that will take const strings.
+ FilePath dll_path(cloud_print::GetPortMonitorDllName());
+ monitor_info.pDLLName = const_cast<LPWSTR>(dll_path.value().c_str());
+ monitor_info.pName = const_cast<LPWSTR>(dll_path.value().c_str());
+ if (AddMonitor(NULL, 2, reinterpret_cast<BYTE*>(&monitor_info))) {
+ return S_OK;
+ }
+ return cloud_print::GetLastHResult();
+}
+
+HRESULT WINAPI DllUnregisterServer(void) {
+ base::AtExitManager at_exit_manager;
+ if (!cloud_print::CanRegister()) {
+ return E_ACCESSDENIED;
+ }
+ FilePath dll_path(cloud_print::GetPortMonitorDllName());
+ if (DeleteMonitor(NULL,
+ NULL,
+ const_cast<LPWSTR>(dll_path.value().c_str()))) {
+ return S_OK;
+ }
+ return cloud_print::GetLastHResult();
+}
diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor_unittest.cc b/cloud_print/virtual_driver/win/port_monitor/port_monitor_unittest.cc
index 93de765..5148276 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor_unittest.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor_unittest.cc
@@ -13,10 +13,19 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace cloud_print {
+
const wchar_t kChromeExePath[] = L"google\\chrome\\application\\chrometest.exe";
+const wchar_t kChromePathRegValue[] =L"PathToChromeTestExe";
+const bool kIsUnittest = true;
+
+namespace {
+
const wchar_t kAlternateChromeExePath[] =
L"google\\chrome\\application\\chrometestalternate.exe";
-const wchar_t kChromePathRegValue[] =L"PathToChromeTestExe";
+
+const wchar_t kChromePathRegKey[] = L"Software\\Google\\CloudPrint";
+
+} // namespace
class PortMonitorTest : public testing::Test {
public:
diff --git a/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp b/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp
deleted file mode 100644
index 630b5e4..0000000
--- a/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright (c) 2012 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.
-
-{
- 'target_defaults': {
- 'variables': {
- 'chromium_code': 1,
- },
- 'include_dirs': [
- '../..',
- ],
- 'libraries': [
- 'userenv.lib',
- ],
- 'sources': [
- '../../virtual_driver_switches.cc',
- '../../virtual_driver_switches.h',
- '../virtual_driver_consts.cc',
- '../virtual_driver_consts.h',
- '../virtual_driver_helpers.cc',
- '../virtual_driver_helpers.h',
- '../virtual_driver_common_resources.rc',
- 'port_monitor.cc',
- 'port_monitor.h',
- 'port_monitor.def',
- ],
- },
- 'targets' : [
- {
- 'target_name': 'gcp_portmon',
- 'type': 'loadable_module',
- 'dependencies': [
- '../../../../base/base.gyp:base',
- ],
- },
- {
- 'target_name': 'gcp_portmon64',
- 'type': 'loadable_module',
- 'defines': [
- '<@(nacl_win64_defines)',
- ],
- 'dependencies': [
- '../../../../base/base.gyp:base_nacl_win64',
- ],
- 'configurations': {
- 'Common_Base': {
- 'msvs_target_platform': 'x64',
- },
- },
- },
- {
- 'target_name': 'virtual_driver_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../../../base/base.gyp:base',
- '../../../../base/base.gyp:run_all_unittests',
- '../../../../testing/gmock.gyp:gmock',
- '../../../../testing/gtest.gyp:gtest',
- ],
- 'sources': [
- 'port_monitor_unittest.cc',
- ],
- },
- ],
-}
diff --git a/cloud_print/virtual_driver/win/virtual_driver.gyp b/cloud_print/virtual_driver/win/virtual_driver.gyp
new file mode 100644
index 0000000..d1bc0da0
--- /dev/null
+++ b/cloud_print/virtual_driver/win/virtual_driver.gyp
@@ -0,0 +1,18 @@
+# Copyright (c) 2012 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.
+
+{
+ 'variables': {
+ 'virtual_driver_suffix': '',
+ },
+ 'target_defaults': {
+ 'dependencies': [
+ '<(DEPTH)/base/base.gyp:base',
+ ],
+
+ },
+ 'includes': [
+ 'virtual_driver.gypi',
+ ],
+}
diff --git a/cloud_print/virtual_driver/win/virtual_driver.gypi b/cloud_print/virtual_driver/win/virtual_driver.gypi
new file mode 100644
index 0000000..2367dbd
--- /dev/null
+++ b/cloud_print/virtual_driver/win/virtual_driver.gypi
@@ -0,0 +1,53 @@
+# Copyright (c) 2012 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.
+
+{
+ 'variables': {
+ 'chromium_code': 1,
+ },
+ 'target_defaults': {
+ 'include_dirs': [
+ '<(DEPTH)',
+ ],
+ 'libraries': [
+ 'userenv.lib',
+ ],
+ },
+ 'targets' : [
+ {
+ 'target_name': 'virtual_driver_lib<(virtual_driver_suffix)',
+ 'type': 'static_library',
+ 'sources': [
+ '../virtual_driver_switches.cc',
+ '../virtual_driver_switches.h',
+ 'virtual_driver_consts.cc',
+ 'virtual_driver_consts.h',
+ 'virtual_driver_helpers.cc',
+ 'virtual_driver_helpers.h',
+ ],
+ },
+ {
+ 'target_name': 'gcp_portmon_lib<(virtual_driver_suffix)',
+ 'type': 'static_library',
+ 'sources': [
+ 'port_monitor/port_monitor.cc',
+ 'port_monitor/port_monitor.h',
+ ],
+ 'dependencies': [
+ 'virtual_driver_lib<(virtual_driver_suffix)',
+ ],
+ },
+ {
+ 'target_name': 'gcp_portmon<(virtual_driver_suffix)',
+ 'type': 'loadable_module',
+ 'sources': [
+ 'port_monitor/port_monitor_dll.cc',
+ 'virtual_driver_common_resources.rc',
+ ],
+ 'dependencies': [
+ 'gcp_portmon_lib<(virtual_driver_suffix)',
+ ],
+ },
+ ],
+}
diff --git a/cloud_print/virtual_driver/win/virtual_driver64.gyp b/cloud_print/virtual_driver/win/virtual_driver64.gyp
new file mode 100644
index 0000000..885fb7c
--- /dev/null
+++ b/cloud_print/virtual_driver/win/virtual_driver64.gyp
@@ -0,0 +1,26 @@
+# Copyright (c) 2012 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.
+
+{
+ 'variables': {
+ 'virtual_driver_suffix': '64',
+ },
+ 'target_defaults': {
+ 'defines': [
+ '<@(nacl_win64_defines)',
+ ],
+ 'dependencies': [
+ '<(DEPTH)/base/base.gyp:base_nacl_win64',
+ ],
+ 'configurations': {
+ 'Common_Base': {
+ 'msvs_target_platform': 'x64',
+ },
+ },
+ },
+ 'includes': [
+ 'virtual_driver.gypi',
+ ],
+}
+