summaryrefslogtreecommitdiffstats
path: root/cloud_print
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-14 22:30:04 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-14 22:30:04 +0000
commit719ce089c9ac840947831c933881db4237d7a588 (patch)
treed510e941caf61ac7a1329e2f3e4001fa95836792 /cloud_print
parent9c88e5615608f133483adb6c5c1ba5e170290d6b (diff)
downloadchromium_src-719ce089c9ac840947831c933881db4237d7a588.zip
chromium_src-719ce089c9ac840947831c933881db4237d7a588.tar.gz
chromium_src-719ce089c9ac840947831c933881db4237d7a588.tar.bz2
Moved chrome detection to service process.
Renamed related code. BUG=148913 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/10910282 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156906 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print')
-rw-r--r--cloud_print/service/service_switches.cc2
-rw-r--r--cloud_print/service/service_switches.h5
-rw-r--r--cloud_print/service/win/cloud_print_service.cc77
3 files changed, 49 insertions, 35 deletions
diff --git a/cloud_print/service/service_switches.cc b/cloud_print/service/service_switches.cc
index 823f031..8896349 100644
--- a/cloud_print/service/service_switches.cc
+++ b/cloud_print/service/service_switches.cc
@@ -7,7 +7,7 @@
const char kChromeTypeSwitch[] = "type";
const char kConsoleSwitch[] = "console";
const char kInstallSwitch[] = "install";
-const char kPrintersSwitch[] = "printers";
+const char kRequirementsSwitch[] = "requirements";
const char kServiceSwitch[] = "service";
const char kStartSwitch[] = "start";
const char kStopSwitch[] = "stop";
diff --git a/cloud_print/service/service_switches.h b/cloud_print/service/service_switches.h
index dfd6a78..a6704f7 100644
--- a/cloud_print/service/service_switches.h
+++ b/cloud_print/service/service_switches.h
@@ -8,8 +8,9 @@
extern const char kChromeTypeSwitch[];
extern const char kConsoleSwitch[];
extern const char kInstallSwitch[];
-extern const char kPrintersSwitch[];
-extern const char kServiceSwitch[];extern const char kStartSwitch[];
+extern const char kRequirementsSwitch[];
+extern const char kServiceSwitch[];
+extern const char kStartSwitch[];
extern const char kStopSwitch[];
extern const char kUninstallSwitch[];
extern const char kUserDataDirSwitch[];
diff --git a/cloud_print/service/win/cloud_print_service.cc b/cloud_print/service/win/cloud_print_service.cc
index 02b2daf..3d1e7f0 100644
--- a/cloud_print/service/win/cloud_print_service.cc
+++ b/cloud_print/service/win/cloud_print_service.cc
@@ -29,7 +29,9 @@
namespace {
-const wchar_t kPrintersFileName[] = L"printers.txt";
+const char kChromeIsNotAvalible[] = "\nChrome is not available\n";
+const char kChromeIsAvalible[] = "\nChrome is available\n";
+const wchar_t kRequirementsFileName[] = L"cloud_print_service_requirements.txt";
const wchar_t kServiceStateFileName[] = L"Service State";
// The traits class for Windows Service.
@@ -169,7 +171,7 @@ class CloudPrintServiceModule
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CLOUDPRINTSERVICE,
"{8013FB7C-2E3E-4992-B8BD-05C0C4AB0627}")
- CloudPrintServiceModule() : detect_printers_(false) {
+ CloudPrintServiceModule() : check_requirements_(false) {
}
HRESULT InitializeSecurity() {
@@ -181,18 +183,12 @@ class CloudPrintServiceModule
HRESULT InstallService(const string16& user,
const string16& password,
const char* run_switch) {
- using namespace chrome_launcher_support;
-
// TODO(vitalybuka): consider "lite" version if we don't want unregister
// printers here.
HRESULT hr = UninstallService();
if (FAILED(hr))
return hr;
- if (GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION).empty()) {
- LOG(WARNING) << "Found no Chrome installed for all users.";
- }
-
hr = UpdateRegistryAppId(true);
if (FAILED(hr))
return hr;
@@ -262,8 +258,8 @@ class CloudPrintServiceModule
if (FAILED(hr))
return hr;
- if (detect_printers_) {
- hr = DetectPrinters();
+ if (check_requirements_) {
+ hr = CheckRequirements();
if (FAILED(hr))
return hr;
// Don't run message loop and stop service.
@@ -324,9 +320,9 @@ class CloudPrintServiceModule
return StartService();
if (command_line.HasSwitch(kServiceSwitch) ||
- command_line.HasSwitch(kPrintersSwitch)) {
+ command_line.HasSwitch(kRequirementsSwitch)) {
*is_service = true;
- detect_printers_ = command_line.HasSwitch(kPrintersSwitch);
+ check_requirements_ = command_line.HasSwitch(kRequirementsSwitch);
return S_OK;
}
@@ -350,30 +346,42 @@ class CloudPrintServiceModule
WideToASCII(*run_as_user), false));
*run_as_password = ASCIIToWide(GetOption("Password", "", true));
- FilePath printers_filename(user_data_dir_);
- printers_filename = printers_filename.Append(kPrintersFileName);
+ FilePath requirements_filename(user_data_dir_);
+ requirements_filename =
+ requirements_filename.Append(kRequirementsFileName);
- file_util::Delete(printers_filename, false);
+ file_util::Delete(requirements_filename, false);
+ if (file_util::PathExists(requirements_filename)) {
+ LOG(ERROR) << "Unable to delete " <<
+ requirements_filename.value() << ".";
+ continue;
+ }
if (FAILED(InstallService(run_as_user->c_str(),
run_as_password->c_str(),
- kPrintersSwitch))) {
+ kRequirementsSwitch))) {
continue;
}
- if (FAILED(StartService())) {
+ bool service_started = SUCCEEDED(StartService());
+ UninstallService();
+ if (!service_started) {
LOG(ERROR) << "Failed to start service as " << *run_as_user << ".";
continue;
}
- UninstallService();
- if (!file_util::PathExists(printers_filename)) {
- LOG(ERROR) << "Service can't create " << printers_filename.value();
+ std::string printers;
+ if (!file_util::PathExists(requirements_filename) ||
+ !file_util::ReadFileToString(requirements_filename, &printers)) {
+ LOG(ERROR) << "Service can't create " << requirements_filename.value();
continue;
}
- std::string printers;
- file_util::ReadFileToString(printers_filename, &printers);
- std::cout << "\nPrinters available for " << run_as_user << ":\n";
+ if (EndsWith(printers, kChromeIsNotAvalible, true)) {
+ LOG(ERROR) << kChromeIsNotAvalible << " for " << *run_as_user << ".";
+ continue;
+ }
+
+ std::cout << "\nService requirements check result: \n";
std::cout << printers << "\n";
- file_util::Delete(printers_filename, false);
+ file_util::Delete(requirements_filename, false);
if (AskUser("Do you want to use " + WideToASCII(*run_as_user) + "?"))
return;
@@ -483,19 +491,24 @@ class CloudPrintServiceModule
return S_OK;
}
- HRESULT DetectPrinters() {
- FilePath printers_filename(user_data_dir_);
- printers_filename = printers_filename.Append(kPrintersFileName);
- std::string printers;
+ HRESULT CheckRequirements() {
+ FilePath requirements_filename(user_data_dir_);
+ requirements_filename = requirements_filename.Append(kRequirementsFileName);
+ std::string output;
+ output.append("Printers available for " +
+ WideToASCII(GetCurrentUserName()) + ":\n");
scoped_refptr<printing::PrintBackend> backend(
printing::PrintBackend::CreateInstance(NULL));
printing::PrinterList printer_list;
backend->EnumeratePrinters(&printer_list);
for (size_t i = 0; i < printer_list.size(); ++i) {
- printers += printer_list[i].printer_name;
- printers += "\n";
+ output += " ";
+ output += printer_list[i].printer_name;
+ output += "\n";
}
- file_util::WriteFile(printers_filename, printers.c_str(), printers.size());
+ FilePath chrome = chrome_launcher_support::GetAnyChromePath();
+ output.append(chrome.empty() ? kChromeIsNotAvalible : kChromeIsAvalible);
+ file_util::WriteFile(requirements_filename, output.c_str(), output.size());
return S_OK;
}
@@ -513,7 +526,7 @@ class CloudPrintServiceModule
static BOOL WINAPI ConsoleCtrlHandler(DWORD type);
- bool detect_printers_;
+ bool check_requirements_;
FilePath user_data_dir_;
scoped_ptr<ChromeLauncher> chrome_;
};