summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 18:11:50 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 18:11:50 +0000
commit1495a4025955def63a9559f11fc61428e8fb8f33 (patch)
treecace72102e4014664ecfa85220217dd1df18e8cf
parent3337ac067ed505d6fa74d92635163eabdbbd6d7a (diff)
downloadchromium_src-1495a4025955def63a9559f11fc61428e8fb8f33.zip
chromium_src-1495a4025955def63a9559f11fc61428e8fb8f33.tar.gz
chromium_src-1495a4025955def63a9559f11fc61428e8fb8f33.tar.bz2
Added Chrome profile option in registry.
Added check of both HKCU and HKLM values. Chrome location detection switched to launcher_support. BUG=none TEST=unittest Review URL: https://chromiumcodereview.appspot.com/10687007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144492 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--cloud_print/virtual_driver/virtual_driver_switches.cc4
-rw-r--r--cloud_print/virtual_driver/virtual_driver_switches.h5
-rw-r--r--cloud_print/virtual_driver/win/install/setup.cc2
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor.cc82
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor.h10
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor_dll.cc3
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor_unittest.cc57
-rw-r--r--cloud_print/virtual_driver/win/virtual_driver.gypi1
8 files changed, 104 insertions, 60 deletions
diff --git a/cloud_print/virtual_driver/virtual_driver_switches.cc b/cloud_print/virtual_driver/virtual_driver_switches.cc
index e8bd347..ed73e5e 100644
--- a/cloud_print/virtual_driver/virtual_driver_switches.cc
+++ b/cloud_print/virtual_driver/virtual_driver_switches.cc
@@ -1,10 +1,12 @@
-// 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.
#include "cloud_print/virtual_driver/virtual_driver_switches.h"
namespace switches {
+// Same value as as Chrome.
+const char kCloudPrintUserDataDir[] = "user-data-dir";
const char kCloudPrintDeleteFile[] = "cloud-print-delete-file";
const char kCloudPrintFile[] = "cloud-print-file";
const char kCloudPrintJobTitle[] = "cloud-print-job-title";
diff --git a/cloud_print/virtual_driver/virtual_driver_switches.h b/cloud_print/virtual_driver/virtual_driver_switches.h
index 54db54c..6515dd8 100644
--- a/cloud_print/virtual_driver/virtual_driver_switches.h
+++ b/cloud_print/virtual_driver/virtual_driver_switches.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.
@@ -12,6 +12,9 @@ namespace switches {
// TODO(abodenha@chromium.org) Reunify them in some sensible manner.
// Bug: www.crbug.com/88991
+// Location of Chrome user profile. Optional.
+extern const char kCloudPrintUserDataDir[];
+
// Used with kCloudPrintFile. Tells Chrome to delete the file when
// finished displaying the print dialog.
extern const char kCloudPrintDeleteFile[];
diff --git a/cloud_print/virtual_driver/win/install/setup.cc b/cloud_print/virtual_driver/win/install/setup.cc
index f4e81007..d0efc35 100644
--- a/cloud_print/virtual_driver/win/install/setup.cc
+++ b/cloud_print/virtual_driver/win/install/setup.cc
@@ -48,7 +48,7 @@ void SetOmahaKeys() {
}
// Get the version from the resource file.
- std::wstring version_string;
+ string16 version_string;
scoped_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfoForCurrentModule());
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 dc46b95d..ba6b959 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
@@ -23,6 +23,7 @@
#include "base/win/registry.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
+#include "chrome/installer/launcher_support/chrome_launcher_support.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"
@@ -37,7 +38,7 @@ 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";
+const wchar_t kCloudPrintRegKey[] = L"Software\\Google\\CloudPrint";
const wchar_t kXpsMimeType[] = L"application/vnd.ms-xpsdocument";
@@ -178,12 +179,20 @@ bool LaunchPrintDialog(const string16& xps_path,
}
base::win::ScopedHandle primary_token_scoped(token);
- FilePath chrome_path;
- if (!GetChromeExePath(&chrome_path)) {
+ FilePath chrome_path = GetChromeExePath();
+ if (chrome_path.empty()) {
LOG(ERROR) << "Unable to get chrome exe path.";
return false;
}
+
CommandLine command_line(chrome_path);
+
+ FilePath chrome_profile = GetChromeProfilePath();
+ if (!chrome_profile.empty()) {
+ command_line.AppendSwitchPath(switches::kCloudPrintUserDataDir,
+ chrome_profile);
+ }
+
command_line.AppendSwitchPath(switches::kCloudPrintFile,
FilePath(xps_path));
command_line.AppendSwitchNative(switches::kCloudPrintFileType,
@@ -251,38 +260,35 @@ bool ValidateCurrentUser() {
}
} // namespace
-bool GetChromeExePath(FilePath* chrome_path) {
- base::win::RegKey app_path_key(HKEY_CURRENT_USER,
- kChromePathRegKey,
- KEY_READ);
- DCHECK(chrome_path != NULL);
- std::wstring reg_data;
- if (SUCCEEDED(app_path_key.ReadValue(kChromePathRegValue,
- &reg_data))) {
- if (!reg_data.empty() && file_util::PathExists(FilePath(reg_data))) {
- *chrome_path = FilePath(reg_data);
- return true;
- }
+FilePath ReadPathFromRegistry(HKEY root, const wchar_t* path_name) {
+ base::win::RegKey gcp_key(HKEY_CURRENT_USER, kCloudPrintRegKey, KEY_READ);
+ string16 data;
+ if (SUCCEEDED(gcp_key.ReadValue(path_name, &data)) &&
+ file_util::PathExists(FilePath(data))) {
+ return FilePath(data);
}
- // First check %localappdata%\google\chrome\application\chrome.exe
- FilePath path;
- PathService::Get(base::DIR_LOCAL_APP_DATA, &path);
- path = path.Append(kChromeExePath);
- if (file_util::PathExists(path)) {
- *chrome_path = FilePath(path.value());
- return true;
- }
-
- // Chrome doesn't appear to be installed per user.
- // Now check %programfiles(x86)%\google\chrome\application
- PathService::Get(base::DIR_PROGRAM_FILESX86, &path);
- path = path.Append(kChromeExePath);
- if (file_util::PathExists(path)) {
- *chrome_path = FilePath(path.value());
- return true;
- }
- LOG(WARNING) << kChromeExePath << " not found.";
- return false;
+ return FilePath();
+}
+
+FilePath ReadPathFromAnyRegistry(const wchar_t* path_name) {
+ FilePath result = ReadPathFromRegistry(HKEY_CURRENT_USER, path_name);
+ if (!result.empty())
+ return result;
+ return ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path_name);
+}
+
+FilePath GetChromeExePath() {
+ FilePath path = ReadPathFromAnyRegistry(kChromeExePathRegValue);
+ if (!path.empty())
+ return path;
+ return chrome_launcher_support::GetAnyChromePath();
+}
+
+FilePath GetChromeProfilePath() {
+ FilePath path = ReadPathFromAnyRegistry(kChromeProfilePathRegValue);
+ if (!path.empty() && file_util::DirectoryExists(path))
+ return path;
+ return FilePath();
}
BOOL WINAPI Monitor2EnumPorts(HANDLE,
@@ -605,10 +611,10 @@ MONITOR2* WINAPI InitializePrintMonitor2(MONITORINIT*,
}
if (handle != NULL) {
*handle = (HANDLE)monitor_data;
- #ifndef UNIT_TEST
- // Unit tests set up their own AtExitManager
- monitor_data->at_exit_manager = new base::AtExitManager();
- #endif
+ if (!cloud_print::kIsUnittest) {
+ // Unit tests set up their own AtExitManager
+ monitor_data->at_exit_manager = new base::AtExitManager();
+ }
} else {
SetLastError(ERROR_INVALID_PARAMETER);
return NULL;
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 e9e83f0..05df124 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.h
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.h
@@ -14,8 +14,11 @@
namespace cloud_print {
-// Fills chrome_path with the path to be used for launching Chrome.
-bool GetChromeExePath(FilePath* chrome_path);
+// Returns path to be used for launching Chrome.
+FilePath GetChromeExePath();
+
+// Returns path to user profile to be used for launching Chrome.
+FilePath GetChromeProfilePath();
// Implementations for the function pointers in the MONITOR2 structure
// returned by InitializePrintMonitor2. The prototypes and behaviors
@@ -79,7 +82,8 @@ BOOL WINAPI MonitorUiConfigureOrDeletePortUI(const wchar_t*,
const wchar_t* port_name);
extern const wchar_t kChromeExePath[];
-extern const wchar_t kChromePathRegValue[];
+extern const wchar_t kChromeExePathRegValue[];
+extern const wchar_t kChromeProfilePathRegValue[];
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
index 39fc604..c6acfda 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor_dll.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor_dll.cc
@@ -31,7 +31,8 @@
namespace cloud_print {
const wchar_t kChromeExePath[] = L"google\\chrome\\application\\chrome.exe";
-const wchar_t kChromePathRegValue[] = L"PathToChromeExe";
+const wchar_t kChromeExePathRegValue[] = L"PathToChromeExe";
+const wchar_t kChromeProfilePathRegValue[] = L"PathToChromeProfile";
const bool kIsUnittest = false;
namespace {
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 5148276..15bac4b 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
@@ -15,7 +15,8 @@
namespace cloud_print {
const wchar_t kChromeExePath[] = L"google\\chrome\\application\\chrometest.exe";
-const wchar_t kChromePathRegValue[] =L"PathToChromeTestExe";
+const wchar_t kChromeExePathRegValue[] = L"PathToChromeTestExe";
+const wchar_t kChromeProfilePathRegValue[] = L"PathToChromeTestProfile";
const bool kIsUnittest = true;
namespace {
@@ -23,7 +24,7 @@ namespace {
const wchar_t kAlternateChromeExePath[] =
L"google\\chrome\\application\\chrometestalternate.exe";
-const wchar_t kChromePathRegKey[] = L"Software\\Google\\CloudPrint";
+const wchar_t kCloudPrintRegKey[] = L"Software\\Google\\CloudPrint";
} // namespace
@@ -35,22 +36,29 @@ class PortMonitorTest : public testing::Test {
virtual void SetUpChromeExeRegistry() {
// Create a temporary chrome.exe location value.
base::win::RegKey key(HKEY_CURRENT_USER,
- cloud_print::kChromePathRegKey,
+ cloud_print::kCloudPrintRegKey,
KEY_ALL_ACCESS);
FilePath path;
PathService::Get(base::DIR_LOCAL_APP_DATA, &path);
path = path.Append(kAlternateChromeExePath);
ASSERT_EQ(ERROR_SUCCESS,
- key.WriteValue(cloud_print::kChromePathRegValue,
+ key.WriteValue(cloud_print::kChromeExePathRegValue,
path.value().c_str()));
+ FilePath temp;
+ PathService::Get(base::DIR_TEMP, &temp);
+ // Write any dir here.
+ ASSERT_EQ(ERROR_SUCCESS,
+ key.WriteValue(cloud_print::kChromeProfilePathRegValue,
+ temp.value().c_str()));
}
// Deletes the registry entry created in SetUpChromeExeRegistry
virtual void DeleteChromeExeRegistry() {
base::win::RegKey key(HKEY_CURRENT_USER,
- cloud_print::kChromePathRegKey,
+ cloud_print::kCloudPrintRegKey,
KEY_ALL_ACCESS);
- key.DeleteValue(cloud_print::kChromePathRegValue);
+ key.DeleteValue(cloud_print::kChromeExePathRegValue);
+ key.DeleteValue(cloud_print::kChromeProfilePathRegValue);
}
virtual void CreateTempChromeExeFiles() {
@@ -72,24 +80,43 @@ class PortMonitorTest : public testing::Test {
ASSERT_TRUE(file_util::Delete(alternate_path, true));
}
+ protected:
+ virtual void SetUp() {
+ SetUpChromeExeRegistry();
+ }
+
+ virtual void TearDown() {
+ DeleteChromeExeRegistry();
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(PortMonitorTest);
};
TEST_F(PortMonitorTest, GetChromeExePathTest) {
- FilePath chrome_path;
- SetUpChromeExeRegistry();
CreateTempChromeExeFiles();
- EXPECT_TRUE(cloud_print::GetChromeExePath(&chrome_path));
+ FilePath chrome_path = cloud_print::GetChromeExePath();
+ EXPECT_FALSE(chrome_path.empty());
EXPECT_TRUE(
chrome_path.value().rfind(kAlternateChromeExePath) != std::string::npos);
+ EXPECT_TRUE(file_util::PathExists(chrome_path));
+ DeleteChromeExeRegistry();
+ chrome_path = cloud_print::GetChromeExePath();
+ // No Chrome or regular chrome path.
+ EXPECT_TRUE(chrome_path.empty() ||
+ chrome_path.value().rfind(kChromeExePath) == std::string::npos);
+}
+
+TEST_F(PortMonitorTest, GetChromeProfilePathTest) {
+ FilePath data_path = cloud_print::GetChromeProfilePath();
+ EXPECT_FALSE(data_path.empty());
+ FilePath temp;
+ PathService::Get(base::DIR_TEMP, &temp);
+ EXPECT_EQ(data_path, temp);
+ EXPECT_TRUE(file_util::DirectoryExists(data_path));
DeleteChromeExeRegistry();
- chrome_path.clear();
- EXPECT_TRUE(cloud_print::GetChromeExePath(&chrome_path));
- EXPECT_TRUE(chrome_path.value().rfind(kChromeExePath) != std::string::npos);
- EXPECT_TRUE(file_util::PathExists(FilePath(chrome_path)));
- DeleteTempChromeExeFiles();
- EXPECT_FALSE(cloud_print::GetChromeExePath(&chrome_path));
+ data_path = cloud_print::GetChromeProfilePath();
+ EXPECT_TRUE(data_path.empty());
}
TEST_F(PortMonitorTest, EnumPortsTest) {
diff --git a/cloud_print/virtual_driver/win/virtual_driver.gypi b/cloud_print/virtual_driver/win/virtual_driver.gypi
index 1c57af9..96d8445 100644
--- a/cloud_print/virtual_driver/win/virtual_driver.gypi
+++ b/cloud_print/virtual_driver/win/virtual_driver.gypi
@@ -35,6 +35,7 @@
'port_monitor/port_monitor.h',
],
'dependencies': [
+ '<(DEPTH)/chrome/chrome.gyp:launcher_support<(virtual_driver_suffix)',
'virtual_driver_lib<(virtual_driver_suffix)',
],
},