Commit 0ffeb598 authored by sanjeevr@chromium.org's avatar sanjeevr@chromium.org

Code to send diagnostic messages about cloud print proxy. Currently diagnostic...

Code to send diagnostic messages about cloud print proxy. Currently diagnostic messages are sent if the print system fails to initialize (this can happen on Windows if the XPS Framework is not installed on XP) as well when printer registration fails because we could not get the capabilities for the printer.

BUG=None
TEST=None

Review URL: http://codereview.chromium.org/6245005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72037 0039d316-1c4b-4281-b951-d872f2087c98
parent 9fc18674
...@@ -5364,6 +5364,12 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -5364,6 +5364,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_CLOUD_PRINT_SETUP_TEST_PAGE" desc="Label on button for printing a test page."> <message name="IDS_CLOUD_PRINT_SETUP_TEST_PAGE" desc="Label on button for printing a test page.">
Print a Test Page Print a Test Page
</message> </message>
<message name="IDS_CLOUD_PRINT_REGISTER_PRINTER_FAILED" desc="Status message to be sent to the server when we failed to retrieve information about a printer to register.">
An error occurred while retrieving printer capabilities for printer <ph name="PRINTER_NAME">$1<ex>HP Laserjet 7900</ex></ph>. This printer could not be registered with <ph name="CLOUD_PRINT_NAME">Google Cloud Print</ph>.
</message>
<message name="IDS_CLOUD_PRINT_XPS_UNAVAILABLE" desc="Status message to be sent to the Cloud Print server when the XPS framework is missing.">
The Microsoft XML Paper Specification Essentials Pack is not installed on the machine running the Google Cloud Print connector.
</message>
<!-- Print Preview --> <!-- Print Preview -->
<message name="IDS_PRINT_PREVIEW_TITLE" desc="Title for print preview page "> <message name="IDS_PRINT_PREVIEW_TITLE" desc="Title for print preview page ">
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/service/service_process_control.h" #include "chrome/browser/service/service_process_control.h"
#include "app/app_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/process_util.h" #include "base/process_util.h"
...@@ -215,6 +216,9 @@ void ServiceProcessControl::Launch(Task* success_task, Task* failure_task) { ...@@ -215,6 +216,9 @@ void ServiceProcessControl::Launch(Task* success_task, Task* failure_task) {
cmd_line->AppendSwitch(switches::kWaitForDebugger); cmd_line->AppendSwitch(switches::kWaitForDebugger);
} }
std::string locale = g_browser_process->GetApplicationLocale();
cmd_line->AppendSwitchASCII(switches::kLang, locale);
// And then start the process asynchronously. // And then start the process asynchronously.
launcher_ = new Launcher(this, cmd_line); launcher_ = new Launcher(this, cmd_line);
launcher_->Run( launcher_->Run(
......
...@@ -1081,6 +1081,7 @@ ...@@ -1081,6 +1081,7 @@
'type': '<(library)', 'type': '<(library)',
'msvs_guid': '2DA87614-55C5-4E56-A17E-0CD099786197', 'msvs_guid': '2DA87614-55C5-4E56-A17E-0CD099786197',
'dependencies': [ 'dependencies': [
'chrome_strings',
'common', 'common',
'common_net', 'common_net',
'../base/base.gyp:base', '../base/base.gyp:base',
......
include_rules = [ include_rules = [
"+grit", # For generated headers
# For Chromoting Host Process # For Chromoting Host Process
"+remoting/base", "+remoting/base",
"+remoting/host", "+remoting/host",
......
...@@ -14,6 +14,7 @@ const char kPrinterDefaultsValue[] = "defaults"; ...@@ -14,6 +14,7 @@ const char kPrinterDefaultsValue[] = "defaults";
const char kPrinterStatusValue[] = "status"; const char kPrinterStatusValue[] = "status";
const char kPrinterTagValue[] = "tag"; const char kPrinterTagValue[] = "tag";
const char kPrinterRemoveTagValue[] = "remove_tag"; const char kPrinterRemoveTagValue[] = "remove_tag";
const char kMessageTextValue[] = "message";
// Values in the respone JSON from the cloud print server // Values in the respone JSON from the cloud print server
const char kPrinterListValue[] = "printers"; const char kPrinterListValue[] = "printers";
...@@ -53,3 +54,7 @@ const char kJobFetchReasonNotified[] = "notified"; ...@@ -53,3 +54,7 @@ const char kJobFetchReasonNotified[] = "notified";
// Job fetch after a successful print to query for more jobs. // Job fetch after a successful print to query for more jobs.
const char kJobFetchReasonQueryMore[] = "querymore"; const char kJobFetchReasonQueryMore[] = "querymore";
// Short message ids for diagnostic messages sent to the server.
const char kPrintSystemFailedMessageId[] = "printsystemfail";
const char kGetPrinterCapsFailedMessageId[] = "getprncapsfail";
...@@ -17,6 +17,7 @@ extern const char kPrinterDefaultsValue[]; ...@@ -17,6 +17,7 @@ extern const char kPrinterDefaultsValue[];
extern const char kPrinterStatusValue[]; extern const char kPrinterStatusValue[];
extern const char kPrinterTagValue[]; extern const char kPrinterTagValue[];
extern const char kPrinterRemoveTagValue[]; extern const char kPrinterRemoveTagValue[];
extern const char kMessageTextValue[];
// Values in the respone JSON from the cloud print server // Values in the respone JSON from the cloud print server
extern const char kPrinterListValue[]; extern const char kPrinterListValue[];
extern const char kSuccessValue[]; extern const char kSuccessValue[];
...@@ -42,6 +43,8 @@ extern const char kJobFetchReasonStartup[]; ...@@ -42,6 +43,8 @@ extern const char kJobFetchReasonStartup[];
extern const char kJobFetchReasonPoll[]; extern const char kJobFetchReasonPoll[];
extern const char kJobFetchReasonNotified[]; extern const char kJobFetchReasonNotified[];
extern const char kJobFetchReasonQueryMore[]; extern const char kJobFetchReasonQueryMore[];
extern const char kPrintSystemFailedMessageId[];
extern const char kGetPrinterCapsFailedMessageId[];
// Max retry count for job data fetch requests. // Max retry count for job data fetch requests.
const int kJobDataMaxRetryCount = 5; const int kJobDataMaxRetryCount = 5;
......
...@@ -137,6 +137,16 @@ GURL CloudPrintHelpers::GetUrlForJobStatusUpdate( ...@@ -137,6 +137,16 @@ GURL CloudPrintHelpers::GetUrlForJobStatusUpdate(
return cloud_print_server_url.ReplaceComponents(replacements); return cloud_print_server_url.ReplaceComponents(replacements);
} }
GURL CloudPrintHelpers::GetUrlForUserMessage(const GURL& cloud_print_server_url,
const std::string& message_id) {
std::string path(AppendPathToUrl(cloud_print_server_url, "user/message"));
GURL::Replacements replacements;
replacements.SetPathStr(path);
std::string query = StringPrintf("code=%s", message_id.c_str());
replacements.SetQueryStr(query);
return cloud_print_server_url.ReplaceComponents(replacements);
}
bool CloudPrintHelpers::ParseResponseJSON( bool CloudPrintHelpers::ParseResponseJSON(
const std::string& response_data, bool* succeeded, const std::string& response_data, bool* succeeded,
DictionaryValue** response_dict) { DictionaryValue** response_dict) {
......
...@@ -35,6 +35,9 @@ class CloudPrintHelpers { ...@@ -35,6 +35,9 @@ class CloudPrintHelpers {
static GURL GetUrlForJobStatusUpdate( static GURL GetUrlForJobStatusUpdate(
const GURL& cloud_print_server_url, const std::string& job_id, const GURL& cloud_print_server_url, const std::string& job_id,
const cloud_print::PrintJobDetails& details); const cloud_print::PrintJobDetails& details);
static GURL GetUrlForUserMessage(const GURL& cloud_print_server_url,
const std::string& message_id);
// Parses the response data for any cloud print server request. The method // Parses the response data for any cloud print server request. The method
// returns false if there was an error in parsing the JSON. The succeeded // returns false if there was an error in parsing the JSON. The succeeded
// value returns the value of the "success" value in the response JSON. // value returns the value of the "success" value in the response JSON.
......
...@@ -73,6 +73,12 @@ void CheckURLs(const GURL& server_base_url) { ...@@ -73,6 +73,12 @@ void CheckURLs(const GURL& server_base_url) {
"code=2&message=Out%%20of%%20Paper&numpages=345&" "code=2&message=Out%%20of%%20Paper&numpages=345&"
"pagesprinted=47", expected_url_base.c_str()); "pagesprinted=47", expected_url_base.c_str());
EXPECT_EQ(expected_url, url.spec()); EXPECT_EQ(expected_url, url.spec());
url = CloudPrintHelpers::GetUrlForUserMessage(server_base_url,
"blahmessageid");
expected_url = StringPrintf("%suser/message?code=blahmessageid",
expected_url_base.c_str());
EXPECT_EQ(expected_url, url.spec());
} }
} // namespace } // namespace
......
...@@ -106,7 +106,7 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) { ...@@ -106,7 +106,7 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) {
cloud_print_email_, proxy_id); cloud_print_email_, proxy_id);
} }
if (client_) { if (client_) {
client_->OnCloudPrintProxyEnabled(); client_->OnCloudPrintProxyEnabled(true);
} }
} }
...@@ -115,7 +115,7 @@ void CloudPrintProxy::DisableForUser() { ...@@ -115,7 +115,7 @@ void CloudPrintProxy::DisableForUser() {
cloud_print_email_.clear(); cloud_print_email_.clear();
Shutdown(); Shutdown();
if (client_) { if (client_) {
client_->OnCloudPrintProxyDisabled(); client_->OnCloudPrintProxyDisabled(true);
} }
} }
...@@ -161,6 +161,15 @@ void CloudPrintProxy::OnAuthenticationFailed() { ...@@ -161,6 +161,15 @@ void CloudPrintProxy::OnAuthenticationFailed() {
FROM_HERE, NewRunnableFunction(&ShowTokenExpiredNotificationInBrowser)); FROM_HERE, NewRunnableFunction(&ShowTokenExpiredNotificationInBrowser));
} }
void CloudPrintProxy::OnPrintSystemUnavailable() {
// If the print system is unavailable, we want to shutdown the proxy and
// disable it non-persistently.
Shutdown();
if (client_) {
client_->OnCloudPrintProxyDisabled(false);
}
}
void CloudPrintProxy::Shutdown() { void CloudPrintProxy::Shutdown() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (backend_.get()) if (backend_.get())
......
...@@ -23,8 +23,8 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, ...@@ -23,8 +23,8 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
class Client { class Client {
public: public:
virtual ~Client() {} virtual ~Client() {}
virtual void OnCloudPrintProxyEnabled() {} virtual void OnCloudPrintProxyEnabled(bool persist_state) {}
virtual void OnCloudPrintProxyDisabled() {} virtual void OnCloudPrintProxyDisabled(bool persist_state) {}
}; };
CloudPrintProxy(); CloudPrintProxy();
virtual ~CloudPrintProxy(); virtual ~CloudPrintProxy();
...@@ -44,13 +44,14 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, ...@@ -44,13 +44,14 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
return cloud_print_email_; return cloud_print_email_;
} }
// Notification methods from the backend. Called on UI thread. // CloudPrintProxyFrontend implementation. Called on UI thread.
virtual void OnPrinterListAvailable( virtual void OnPrinterListAvailable(
const printing::PrinterList& printer_list); const printing::PrinterList& printer_list);
virtual void OnAuthenticated(const std::string& cloud_print_token, virtual void OnAuthenticated(const std::string& cloud_print_token,
const std::string& cloud_print_xmpp_token, const std::string& cloud_print_xmpp_token,
const std::string& email); const std::string& email);
virtual void OnAuthenticationFailed(); virtual void OnAuthenticationFailed();
virtual void OnPrintSystemUnavailable();
protected: protected:
void Shutdown(); void Shutdown();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include "app/l10n_util.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/md5.h" #include "base/md5.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "chrome/service/gaia/service_gaia_authenticator.h" #include "chrome/service/gaia/service_gaia_authenticator.h"
#include "chrome/service/service_process.h" #include "chrome/service/service_process.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "jingle/notifier/base/notifier_options.h" #include "jingle/notifier/base/notifier_options.h"
#include "jingle/notifier/listener/push_notifications_thread.h" #include "jingle/notifier/listener/push_notifications_thread.h"
#include "jingle/notifier/listener/talk_mediator_impl.h" #include "jingle/notifier/listener/talk_mediator_impl.h"
...@@ -106,6 +108,18 @@ class CloudPrintProxyBackend::Core ...@@ -106,6 +108,18 @@ class CloudPrintProxyBackend::Core
const GURL& url, const GURL& url,
DictionaryValue* json_data, DictionaryValue* json_data,
bool succeeded); bool succeeded);
CloudPrintURLFetcher::ResponseAction HandleRegisterFailedStatusResponse(
const URLFetcher* source,
const GURL& url,
DictionaryValue* json_data,
bool succeeded);
CloudPrintURLFetcher::ResponseAction HandlePrintSystemUnavailableResponse(
const URLFetcher* source,
const GURL& url,
DictionaryValue* json_data,
bool succeeded);
// End response handlers // End response handlers
// NotifyXXX is how the Core communicates with the frontend across // NotifyXXX is how the Core communicates with the frontend across
...@@ -117,6 +131,7 @@ class CloudPrintProxyBackend::Core ...@@ -117,6 +131,7 @@ class CloudPrintProxyBackend::Core
const std::string& cloud_print_xmpp_token, const std::string& cloud_print_xmpp_token,
const std::string& email); const std::string& email);
void NotifyAuthenticationFailed(); void NotifyAuthenticationFailed();
void NotifyPrintSystemUnavailable();
// Starts a new printer registration process. // Starts a new printer registration process.
void StartRegistration(); void StartRegistration();
...@@ -135,6 +150,9 @@ class CloudPrintProxyBackend::Core ...@@ -135,6 +150,9 @@ class CloudPrintProxyBackend::Core
// handler is responsible for checking for pending print jobs for this // handler is responsible for checking for pending print jobs for this
// printer and print them. // printer and print them.
void InitJobHandlerForPrinter(DictionaryValue* printer_data); void InitJobHandlerForPrinter(DictionaryValue* printer_data);
// Sends a diagnostic message to the cloud print server that the print
// system failed to initialize.
void ReportPrintSystemUnavailable(const std::string& failure_message);
// Callback method for GetPrinterCapsAndDefaults. // Callback method for GetPrinterCapsAndDefaults.
void OnReceivePrinterCaps( void OnReceivePrinterCaps(
...@@ -332,16 +350,18 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken( ...@@ -332,16 +350,18 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken(
return; // No print system available, fail initalization. return; // No print system available, fail initalization.
} }
print_system_->Init(); cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init();
// TODO(sanjeevr): Validate the tokens. // TODO(sanjeevr): Validate the tokens.
auth_token_ = cloud_print_token; auth_token_ = cloud_print_token;
if (result.succeeded()) {
const notifier::NotifierOptions kNotifierOptions; const notifier::NotifierOptions kNotifierOptions;
const bool kInvalidateXmppAuthToken = false; const bool kInvalidateXmppAuthToken = false;
const bool kAllowInsecureXmppConnection = false; const bool kAllowInsecureXmppConnection = false;
talk_mediator_.reset(new notifier::TalkMediatorImpl( talk_mediator_.reset(new notifier::TalkMediatorImpl(
new notifier::PushNotificationsThread(kNotifierOptions, new notifier::PushNotificationsThread(
kNotifierOptions,
kCloudPrintPushNotificationsSource), kCloudPrintPushNotificationsSource),
kInvalidateXmppAuthToken, kInvalidateXmppAuthToken,
kAllowInsecureXmppConnection)); kAllowInsecureXmppConnection));
...@@ -360,6 +380,10 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken( ...@@ -360,6 +380,10 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken(
proxy_id_ = proxy_id; proxy_id_ = proxy_id;
StartRegistration(); StartRegistration();
} else {
// We could not initialize the print system. We need to notify the server.
ReportPrintSystemUnavailable(result.message());
}
} }
void CloudPrintProxyBackend::Core::StartRegistration() { void CloudPrintProxyBackend::Core::StartRegistration() {
...@@ -454,6 +478,10 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( ...@@ -454,6 +478,10 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps(
const std::string& printer_name, const std::string& printer_name,
const printing::PrinterCapsAndDefaults& caps_and_defaults) { const printing::PrinterCapsAndDefaults& caps_and_defaults) {
DCHECK(next_upload_index_ < printer_list_.size()); DCHECK(next_upload_index_ < printer_list_.size());
std::string mime_boundary;
CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary);
std::string post_data;
GURL post_url;
if (succeeded) { if (succeeded) {
const printing::PrinterBasicInfo& info = const printing::PrinterBasicInfo& info =
printer_list_.at(next_upload_index_); printer_list_.at(next_upload_index_);
...@@ -461,9 +489,6 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( ...@@ -461,9 +489,6 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps(
last_uploaded_printer_name_ = info.printer_name; last_uploaded_printer_name_ = info.printer_name;
last_uploaded_printer_info_ = caps_and_defaults; last_uploaded_printer_info_ = caps_and_defaults;
std::string mime_boundary;
CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary);
std::string post_data;
CloudPrintHelpers::AddMultipartValueForUpload(kProxyIdValue, proxy_id_, CloudPrintHelpers::AddMultipartValueForUpload(kProxyIdValue, proxy_id_,
mime_boundary, mime_boundary,
std::string(), &post_data); std::string(), &post_data);
...@@ -497,26 +522,38 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( ...@@ -497,26 +522,38 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps(
kPrinterCapsHashValue, kPrinterCapsHashValue,
MD5String(last_uploaded_printer_info_.printer_capabilities), MD5String(last_uploaded_printer_info_.printer_capabilities),
mime_boundary, std::string(), &post_data); mime_boundary, std::string(), &post_data);
// Terminate the request body post_url = CloudPrintHelpers::GetUrlForPrinterRegistration(
post_data.append("--" + mime_boundary + "--\r\n");
std::string mime_type("multipart/form-data; boundary=");
mime_type += mime_boundary;
GURL register_url = CloudPrintHelpers::GetUrlForPrinterRegistration(
cloud_print_server_url_); cloud_print_server_url_);
next_response_handler_ = next_response_handler_ =
&CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse;
request_ = new CloudPrintURLFetcher;
request_->StartPostRequest(register_url, this, auth_token_,
kCloudPrintAPIMaxRetryCount, mime_type,
post_data);
} else { } else {
LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " <<
printer_name; printer_name;
next_upload_index_++; // This printer failed to register, notify the server of this failure.
MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, post_url = CloudPrintHelpers::GetUrlForUserMessage(
&CloudPrintProxyBackend::Core::RegisterNextPrinter)); cloud_print_server_url_,
kGetPrinterCapsFailedMessageId);
string16 printer_name_utf16 = UTF8ToUTF16(printer_name);
std::string status_message = l10n_util::GetStringFUTF8(
IDS_CLOUD_PRINT_REGISTER_PRINTER_FAILED,
printer_name_utf16);
CloudPrintHelpers::AddMultipartValueForUpload(kMessageTextValue,
status_message,
mime_boundary,
std::string(),
&post_data);
next_response_handler_ =
&CloudPrintProxyBackend::Core::HandleRegisterFailedStatusResponse;
} }
// Terminate the request body
post_data.append("--" + mime_boundary + "--\r\n");
std::string mime_type("multipart/form-data; boundary=");
mime_type += mime_boundary;
request_ = new CloudPrintURLFetcher;
request_->StartPostRequest(post_url, this, auth_token_,
kCloudPrintAPIMaxRetryCount, mime_type,
post_data);
} }
void CloudPrintProxyBackend::Core::HandlePrinterNotification( void CloudPrintProxyBackend::Core::HandlePrinterNotification(
...@@ -594,6 +631,11 @@ void CloudPrintProxyBackend::Core::NotifyAuthenticationFailed() { ...@@ -594,6 +631,11 @@ void CloudPrintProxyBackend::Core::NotifyAuthenticationFailed() {
backend_->frontend_->OnAuthenticationFailed(); backend_->frontend_->OnAuthenticationFailed();
} }
void CloudPrintProxyBackend::Core::NotifyPrintSystemUnavailable() {
DCHECK(MessageLoop::current() == backend_->frontend_loop_);
backend_->frontend_->OnPrintSystemUnavailable();
}
CloudPrintURLFetcher::ResponseAction CloudPrintURLFetcher::ResponseAction
CloudPrintProxyBackend::Core::HandlePrinterListResponse( CloudPrintProxyBackend::Core::HandlePrinterListResponse(
const URLFetcher* source, const URLFetcher* source,
...@@ -683,6 +725,32 @@ void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter( ...@@ -683,6 +725,32 @@ void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
} }
} }
void CloudPrintProxyBackend::Core::ReportPrintSystemUnavailable(
const std::string& failure_message) {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
std::string mime_boundary;
CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary);
GURL post_url = CloudPrintHelpers::GetUrlForUserMessage(
cloud_print_server_url_,
kPrintSystemFailedMessageId);
std::string post_data;
CloudPrintHelpers::AddMultipartValueForUpload(kMessageTextValue,
failure_message,
mime_boundary,
std::string(),
&post_data);
next_response_handler_ =
&CloudPrintProxyBackend::Core::HandlePrintSystemUnavailableResponse;
// Terminate the request body
post_data.append("--" + mime_boundary + "--\r\n");
std::string mime_type("multipart/form-data; boundary=");
mime_type += mime_boundary;
request_ = new CloudPrintURLFetcher;
request_->StartPostRequest(post_url, this, auth_token_,
kCloudPrintAPIMaxRetryCount, mime_type,
post_data);
}
CloudPrintURLFetcher::ResponseAction CloudPrintURLFetcher::ResponseAction
CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse(
const URLFetcher* source, const URLFetcher* source,
...@@ -709,6 +777,36 @@ CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( ...@@ -709,6 +777,36 @@ CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse(
return CloudPrintURLFetcher::STOP_PROCESSING; return CloudPrintURLFetcher::STOP_PROCESSING;
} }
CloudPrintURLFetcher::ResponseAction
CloudPrintProxyBackend::Core::HandleRegisterFailedStatusResponse(
const URLFetcher* source,
const GURL& url,
DictionaryValue* json_data,
bool succeeded) {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
next_upload_index_++;
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableMethod(this,
&CloudPrintProxyBackend::Core::RegisterNextPrinter));
return CloudPrintURLFetcher::STOP_PROCESSING;
}
CloudPrintURLFetcher::ResponseAction
CloudPrintProxyBackend::Core::HandlePrintSystemUnavailableResponse(
const URLFetcher* source,
const GURL& url,
DictionaryValue* json_data,
bool succeeded) {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
// Let the frontend know that we do not have a print system.
backend_->frontend_loop_->PostTask(
FROM_HERE,
NewRunnableMethod(this,
&Core::NotifyPrintSystemUnavailable));
return CloudPrintURLFetcher::STOP_PROCESSING;
}
bool CloudPrintProxyBackend::Core::RemovePrinterFromList( bool CloudPrintProxyBackend::Core::RemovePrinterFromList(
const std::string& printer_name) { const std::string& printer_name) {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
......
...@@ -34,6 +34,8 @@ class CloudPrintProxyFrontend { ...@@ -34,6 +34,8 @@ class CloudPrintProxyFrontend {
const std::string& email) = 0; const std::string& email) = 0;
// We have invalid/expired credentials. // We have invalid/expired credentials.
virtual void OnAuthenticationFailed() = 0; virtual void OnAuthenticationFailed() = 0;
// The print system could not be initialized.
virtual void OnPrintSystemUnavailable() = 0;
protected: protected:
// Don't delete through SyncFrontend interface. // Don't delete through SyncFrontend interface.
......
...@@ -131,6 +131,20 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { ...@@ -131,6 +131,20 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
JobSpooler::Delegate* delegate) = 0; JobSpooler::Delegate* delegate) = 0;
}; };
class PrintSystemResult {
public:
PrintSystemResult(bool succeeded, const std::string& message)
: succeeded_(succeeded), message_(message) { }
bool succeeded() const { return succeeded_; }
std::string message() const { return message_; }
private:
bool succeeded_;
std::string message_;
PrintSystemResult() { }
};
typedef Callback3< typedef Callback3<
bool, bool,
const std::string&, const std::string&,
...@@ -141,7 +155,7 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { ...@@ -141,7 +155,7 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
// Initialize print system. This need to be called before any other function // Initialize print system. This need to be called before any other function
// of PrintSystem. // of PrintSystem.
virtual void Init() = 0; virtual PrintSystemResult Init() = 0;
// Enumerates the list of installed local and network printers. // Enumerates the list of installed local and network printers.
virtual void EnumeratePrinters(printing::PrinterList* printer_list) = 0; virtual void EnumeratePrinters(printing::PrinterList* printer_list) = 0;
......
...@@ -72,7 +72,7 @@ class PrintSystemCUPS : public PrintSystem { ...@@ -72,7 +72,7 @@ class PrintSystemCUPS : public PrintSystem {
explicit PrintSystemCUPS(const DictionaryValue* print_system_settings); explicit PrintSystemCUPS(const DictionaryValue* print_system_settings);
// PrintSystem implementation. // PrintSystem implementation.
virtual void Init(); virtual PrintSystemResult Init();
virtual void EnumeratePrinters(printing::PrinterList* printer_list); virtual void EnumeratePrinters(printing::PrinterList* printer_list);
...@@ -405,9 +405,10 @@ void PrintSystemCUPS::AddPrintServer(const std::string& url) { ...@@ -405,9 +405,10 @@ void PrintSystemCUPS::AddPrintServer(const std::string& url) {
print_servers_.push_back(print_server); print_servers_.push_back(print_server);
} }
void PrintSystemCUPS::Init() { PrintSystem::PrintSystemResult PrintSystemCUPS::Init() {
UpdatePrinters(); UpdatePrinters();
initialized_ = true; initialized_ = true;
return PrintSystemResult(true, std::string());
} }
void PrintSystemCUPS::UpdatePrinters() { void PrintSystemCUPS::UpdatePrinters() {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <objidl.h> #include <objidl.h>
#include <winspool.h> #include <winspool.h>
#include "app/l10n_util.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/scoped_ptr.h" #include "base/scoped_ptr.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "chrome/service/service_process.h" #include "chrome/service/service_process.h"
#include "chrome/service/service_utility_process_host.h" #include "chrome/service/service_utility_process_host.h"
#include "gfx/rect.h" #include "gfx/rect.h"
#include "grit/generated_resources.h"
#include "printing/backend/print_backend.h" #include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h" #include "printing/backend/print_backend_consts.h"
#include "printing/backend/win_helper.h" #include "printing/backend/win_helper.h"
...@@ -246,7 +248,7 @@ class PrintSystemWin : public PrintSystem { ...@@ -246,7 +248,7 @@ class PrintSystemWin : public PrintSystem {
PrintSystemWin(); PrintSystemWin();
// PrintSystem implementation. // PrintSystem implementation.
virtual void Init(); virtual PrintSystemResult Init();
virtual void EnumeratePrinters(printing::PrinterList* printer_list); virtual void EnumeratePrinters(printing::PrinterList* printer_list);
...@@ -594,7 +596,13 @@ PrintSystemWin::PrintSystemWin() { ...@@ -594,7 +596,13 @@ PrintSystemWin::PrintSystemWin() {
print_backend_ = printing::PrintBackend::CreateInstance(NULL); print_backend_ = printing::PrintBackend::CreateInstance(NULL);
} }
void PrintSystemWin::Init() { PrintSystem::PrintSystemResult PrintSystemWin::Init() {
if (!printing::XPSModule::Init()) {
std::string message = l10n_util::GetStringUTF8(
IDS_CLOUD_PRINT_XPS_UNAVAILABLE);
return PrintSystemResult(false, message);
}
return PrintSystemResult(true, std::string());
} }
void PrintSystemWin::EnumeratePrinters(printing::PrinterList* printer_list) { void PrintSystemWin::EnumeratePrinters(printing::PrinterList* printer_list) {
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <algorithm> #include <algorithm>
#include "app/app_switches.h"
#include "app/resource_bundle.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/path_service.h" #include "base/path_service.h"
...@@ -36,6 +38,8 @@ namespace { ...@@ -36,6 +38,8 @@ namespace {
// a shutdown. // a shutdown.
const int64 kShutdownDelay = 60000; const int64 kShutdownDelay = 60000;
const char kDefaultServiceProcessLocale[] = "en-US";
class ServiceIOThread : public base::Thread { class ServiceIOThread : public base::Thread {
public: public:
explicit ServiceIOThread(const char* name); explicit ServiceIOThread(const char* name);
...@@ -97,6 +101,21 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop, ...@@ -97,6 +101,21 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop,
new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy())); new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy()));
service_prefs_->ReadPrefs(); service_prefs_->ReadPrefs();
// Check if a locale override has been specified on the command-line.
std::string locale = command_line.GetSwitchValueASCII(switches::kLang);
if (!locale.empty()) {
service_prefs_->SetString(prefs::kApplicationLocale, locale);
service_prefs_->WritePrefs();
} else {
// If no command-line value was specified, read the last used locale from
// the prefs.
service_prefs_->GetString(prefs::kApplicationLocale, &locale);
// If no locale was specified anywhere, use the default one.
if (locale.empty())
locale = kDefaultServiceProcessLocale;
}
ResourceBundle::InitSharedInstance(locale);
#if defined(ENABLE_REMOTING) #if defined(ENABLE_REMOTING)
// Initialize chromoting host manager. // Initialize chromoting host manager.
remoting_host_manager_ = new remoting::ChromotingHostManager(this); remoting_host_manager_ = new remoting::ChromotingHostManager(this);
...@@ -176,17 +195,21 @@ CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { ...@@ -176,17 +195,21 @@ CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() {
return cloud_print_proxy_.get(); return cloud_print_proxy_.get();
} }
void ServiceProcess::OnCloudPrintProxyEnabled() { void ServiceProcess::OnCloudPrintProxyEnabled(bool persist_state) {
if (persist_state) {
// Save the preference that we have enabled the cloud print proxy. // Save the preference that we have enabled the cloud print proxy.
service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true); service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true);
service_prefs_->WritePrefs(); service_prefs_->WritePrefs();
}
OnServiceEnabled(); OnServiceEnabled();
} }
void ServiceProcess::OnCloudPrintProxyDisabled() { void ServiceProcess::OnCloudPrintProxyDisabled(bool persist_state) {
if (persist_state) {
// Save the preference that we have disabled the cloud print proxy. // Save the preference that we have disabled the cloud print proxy.
service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false);
service_prefs_->WritePrefs(); service_prefs_->WritePrefs();
}
OnServiceDisabled(); OnServiceDisabled();
} }
......
...@@ -82,8 +82,8 @@ class ServiceProcess : public CloudPrintProxy::Client, ...@@ -82,8 +82,8 @@ class ServiceProcess : public CloudPrintProxy::Client,
CloudPrintProxy* GetCloudPrintProxy(); CloudPrintProxy* GetCloudPrintProxy();
// CloudPrintProxy::Client implementation. // CloudPrintProxy::Client implementation.
virtual void OnCloudPrintProxyEnabled(); virtual void OnCloudPrintProxyEnabled(bool persist_state);
virtual void OnCloudPrintProxyDisabled(); virtual void OnCloudPrintProxyDisabled(bool persist_state);
// ChromotingHostManager::Observer interface. // ChromotingHostManager::Observer interface.
virtual void OnRemotingHostEnabled(); virtual void OnRemotingHostEnabled();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment