diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 23:19:33 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 23:19:33 +0000 |
commit | 0ffeb598304f119e2d3df70d47a592d2dbc722da (patch) | |
tree | 8d1519e141a036af64cb4c943b1132060503a24f /chrome/service | |
parent | 9fc18674a68e4b4c366ffb81fb4c84b6c6bed9d2 (diff) | |
download | chromium_src-0ffeb598304f119e2d3df70d47a592d2dbc722da.zip chromium_src-0ffeb598304f119e2d3df70d47a592d2dbc722da.tar.gz chromium_src-0ffeb598304f119e2d3df70d47a592d2dbc722da.tar.bz2 |
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
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/DEPS | 1 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_consts.cc | 5 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_consts.h | 3 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers.cc | 10 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers.h | 3 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.cc | 13 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.h | 7 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy_backend.cc | 174 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy_backend.h | 2 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system.h | 16 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_cups.cc | 5 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 12 | ||||
-rw-r--r-- | chrome/service/service_process.cc | 39 | ||||
-rw-r--r-- | chrome/service/service_process.h | 4 |
15 files changed, 242 insertions, 58 deletions
diff --git a/chrome/service/DEPS b/chrome/service/DEPS index 6563aaa..14500cf 100644 --- a/chrome/service/DEPS +++ b/chrome/service/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+grit", # For generated headers # For Chromoting Host Process "+remoting/base", "+remoting/host", diff --git a/chrome/service/cloud_print/cloud_print_consts.cc b/chrome/service/cloud_print/cloud_print_consts.cc index ece7e33..1654844 100644 --- a/chrome/service/cloud_print/cloud_print_consts.cc +++ b/chrome/service/cloud_print/cloud_print_consts.cc @@ -14,6 +14,7 @@ const char kPrinterDefaultsValue[] = "defaults"; const char kPrinterStatusValue[] = "status"; const char kPrinterTagValue[] = "tag"; const char kPrinterRemoveTagValue[] = "remove_tag"; +const char kMessageTextValue[] = "message"; // Values in the respone JSON from the cloud print server const char kPrinterListValue[] = "printers"; @@ -53,3 +54,7 @@ const char kJobFetchReasonNotified[] = "notified"; // Job fetch after a successful print to query for more jobs. const char kJobFetchReasonQueryMore[] = "querymore"; +// Short message ids for diagnostic messages sent to the server. +const char kPrintSystemFailedMessageId[] = "printsystemfail"; +const char kGetPrinterCapsFailedMessageId[] = "getprncapsfail"; + diff --git a/chrome/service/cloud_print/cloud_print_consts.h b/chrome/service/cloud_print/cloud_print_consts.h index a0bdc48..409eb72 100644 --- a/chrome/service/cloud_print/cloud_print_consts.h +++ b/chrome/service/cloud_print/cloud_print_consts.h @@ -17,6 +17,7 @@ extern const char kPrinterDefaultsValue[]; extern const char kPrinterStatusValue[]; extern const char kPrinterTagValue[]; extern const char kPrinterRemoveTagValue[]; +extern const char kMessageTextValue[]; // Values in the respone JSON from the cloud print server extern const char kPrinterListValue[]; extern const char kSuccessValue[]; @@ -42,6 +43,8 @@ extern const char kJobFetchReasonStartup[]; extern const char kJobFetchReasonPoll[]; extern const char kJobFetchReasonNotified[]; extern const char kJobFetchReasonQueryMore[]; +extern const char kPrintSystemFailedMessageId[]; +extern const char kGetPrinterCapsFailedMessageId[]; // Max retry count for job data fetch requests. const int kJobDataMaxRetryCount = 5; diff --git a/chrome/service/cloud_print/cloud_print_helpers.cc b/chrome/service/cloud_print/cloud_print_helpers.cc index ada2f6c..1c7220d 100644 --- a/chrome/service/cloud_print/cloud_print_helpers.cc +++ b/chrome/service/cloud_print/cloud_print_helpers.cc @@ -137,6 +137,16 @@ GURL CloudPrintHelpers::GetUrlForJobStatusUpdate( 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( const std::string& response_data, bool* succeeded, DictionaryValue** response_dict) { diff --git a/chrome/service/cloud_print/cloud_print_helpers.h b/chrome/service/cloud_print/cloud_print_helpers.h index afc98c2..7ee1ded 100644 --- a/chrome/service/cloud_print/cloud_print_helpers.h +++ b/chrome/service/cloud_print/cloud_print_helpers.h @@ -35,6 +35,9 @@ class CloudPrintHelpers { static GURL GetUrlForJobStatusUpdate( const GURL& cloud_print_server_url, const std::string& job_id, 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 // 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. diff --git a/chrome/service/cloud_print/cloud_print_helpers_unittest.cc b/chrome/service/cloud_print/cloud_print_helpers_unittest.cc index 7c55026..c60a0c3 100644 --- a/chrome/service/cloud_print/cloud_print_helpers_unittest.cc +++ b/chrome/service/cloud_print/cloud_print_helpers_unittest.cc @@ -73,6 +73,12 @@ void CheckURLs(const GURL& server_base_url) { "code=2&message=Out%%20of%%20Paper&numpages=345&" "pagesprinted=47", expected_url_base.c_str()); 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 diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc index 9bb789d..8f925a1 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.cc +++ b/chrome/service/cloud_print/cloud_print_proxy.cc @@ -106,7 +106,7 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) { cloud_print_email_, proxy_id); } if (client_) { - client_->OnCloudPrintProxyEnabled(); + client_->OnCloudPrintProxyEnabled(true); } } @@ -115,7 +115,7 @@ void CloudPrintProxy::DisableForUser() { cloud_print_email_.clear(); Shutdown(); if (client_) { - client_->OnCloudPrintProxyDisabled(); + client_->OnCloudPrintProxyDisabled(true); } } @@ -161,6 +161,15 @@ void CloudPrintProxy::OnAuthenticationFailed() { 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() { DCHECK(CalledOnValidThread()); if (backend_.get()) diff --git a/chrome/service/cloud_print/cloud_print_proxy.h b/chrome/service/cloud_print/cloud_print_proxy.h index d30957e..dff7e76 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.h +++ b/chrome/service/cloud_print/cloud_print_proxy.h @@ -23,8 +23,8 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, class Client { public: virtual ~Client() {} - virtual void OnCloudPrintProxyEnabled() {} - virtual void OnCloudPrintProxyDisabled() {} + virtual void OnCloudPrintProxyEnabled(bool persist_state) {} + virtual void OnCloudPrintProxyDisabled(bool persist_state) {} }; CloudPrintProxy(); virtual ~CloudPrintProxy(); @@ -44,13 +44,14 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, return cloud_print_email_; } - // Notification methods from the backend. Called on UI thread. + // CloudPrintProxyFrontend implementation. Called on UI thread. virtual void OnPrinterListAvailable( const printing::PrinterList& printer_list); virtual void OnAuthenticated(const std::string& cloud_print_token, const std::string& cloud_print_xmpp_token, const std::string& email); virtual void OnAuthenticationFailed(); + virtual void OnPrintSystemUnavailable(); protected: void Shutdown(); diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc index 816a183..021aaf8 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc @@ -7,6 +7,7 @@ #include <map> #include <vector> +#include "app/l10n_util.h" #include "base/file_util.h" #include "base/md5.h" #include "base/rand_util.h" @@ -22,6 +23,7 @@ #include "chrome/service/gaia/service_gaia_authenticator.h" #include "chrome/service/service_process.h" #include "googleurl/src/gurl.h" +#include "grit/generated_resources.h" #include "jingle/notifier/base/notifier_options.h" #include "jingle/notifier/listener/push_notifications_thread.h" #include "jingle/notifier/listener/talk_mediator_impl.h" @@ -106,6 +108,18 @@ class CloudPrintProxyBackend::Core const GURL& url, DictionaryValue* json_data, 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 // NotifyXXX is how the Core communicates with the frontend across @@ -117,6 +131,7 @@ class CloudPrintProxyBackend::Core const std::string& cloud_print_xmpp_token, const std::string& email); void NotifyAuthenticationFailed(); + void NotifyPrintSystemUnavailable(); // Starts a new printer registration process. void StartRegistration(); @@ -135,6 +150,9 @@ class CloudPrintProxyBackend::Core // handler is responsible for checking for pending print jobs for this // printer and print them. 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. void OnReceivePrinterCaps( @@ -332,34 +350,40 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken( return; // No print system available, fail initalization. } - print_system_->Init(); + cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init(); // TODO(sanjeevr): Validate the tokens. auth_token_ = cloud_print_token; - const notifier::NotifierOptions kNotifierOptions; - const bool kInvalidateXmppAuthToken = false; - const bool kAllowInsecureXmppConnection = false; - talk_mediator_.reset(new notifier::TalkMediatorImpl( - new notifier::PushNotificationsThread(kNotifierOptions, - kCloudPrintPushNotificationsSource), - kInvalidateXmppAuthToken, - kAllowInsecureXmppConnection)); - push_notifications_channel_ = kCloudPrintPushNotificationsSource; - push_notifications_channel_.append("/proxy/"); - push_notifications_channel_.append(proxy_id); - talk_mediator_->AddSubscribedServiceUrl(push_notifications_channel_); - talk_mediator_->SetDelegate(this); - talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, - kSyncGaiaServiceId); - talk_mediator_->Login(); + if (result.succeeded()) { + const notifier::NotifierOptions kNotifierOptions; + const bool kInvalidateXmppAuthToken = false; + const bool kAllowInsecureXmppConnection = false; + talk_mediator_.reset(new notifier::TalkMediatorImpl( + new notifier::PushNotificationsThread( + kNotifierOptions, + kCloudPrintPushNotificationsSource), + kInvalidateXmppAuthToken, + kAllowInsecureXmppConnection)); + push_notifications_channel_ = kCloudPrintPushNotificationsSource; + push_notifications_channel_.append("/proxy/"); + push_notifications_channel_.append(proxy_id); + talk_mediator_->AddSubscribedServiceUrl(push_notifications_channel_); + talk_mediator_->SetDelegate(this); + talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, + kSyncGaiaServiceId); + talk_mediator_->Login(); + + print_server_watcher_ = print_system_->CreatePrintServerWatcher(); + print_server_watcher_->StartWatching(this); + + proxy_id_ = proxy_id; - print_server_watcher_ = print_system_->CreatePrintServerWatcher(); - print_server_watcher_->StartWatching(this); - - 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() { @@ -454,6 +478,10 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( const std::string& printer_name, const printing::PrinterCapsAndDefaults& caps_and_defaults) { DCHECK(next_upload_index_ < printer_list_.size()); + std::string mime_boundary; + CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); + std::string post_data; + GURL post_url; if (succeeded) { const printing::PrinterBasicInfo& info = printer_list_.at(next_upload_index_); @@ -461,9 +489,6 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( last_uploaded_printer_name_ = info.printer_name; last_uploaded_printer_info_ = caps_and_defaults; - std::string mime_boundary; - CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); - std::string post_data; CloudPrintHelpers::AddMultipartValueForUpload(kProxyIdValue, proxy_id_, mime_boundary, std::string(), &post_data); @@ -497,26 +522,38 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( kPrinterCapsHashValue, MD5String(last_uploaded_printer_info_.printer_capabilities), mime_boundary, std::string(), &post_data); - // Terminate the request body - post_data.append("--" + mime_boundary + "--\r\n"); - std::string mime_type("multipart/form-data; boundary="); - mime_type += mime_boundary; - GURL register_url = CloudPrintHelpers::GetUrlForPrinterRegistration( + post_url = CloudPrintHelpers::GetUrlForPrinterRegistration( cloud_print_server_url_); next_response_handler_ = &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; - request_ = new CloudPrintURLFetcher; - request_->StartPostRequest(register_url, this, auth_token_, - kCloudPrintAPIMaxRetryCount, mime_type, - post_data); } else { LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << printer_name; - next_upload_index_++; - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, - &CloudPrintProxyBackend::Core::RegisterNextPrinter)); + // This printer failed to register, notify the server of this failure. + post_url = CloudPrintHelpers::GetUrlForUserMessage( + 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( @@ -594,6 +631,11 @@ void CloudPrintProxyBackend::Core::NotifyAuthenticationFailed() { backend_->frontend_->OnAuthenticationFailed(); } +void CloudPrintProxyBackend::Core::NotifyPrintSystemUnavailable() { + DCHECK(MessageLoop::current() == backend_->frontend_loop_); + backend_->frontend_->OnPrintSystemUnavailable(); +} + CloudPrintURLFetcher::ResponseAction CloudPrintProxyBackend::Core::HandlePrinterListResponse( const URLFetcher* source, @@ -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 CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( const URLFetcher* source, @@ -709,6 +777,36 @@ CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( 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( const std::string& printer_name) { DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.h b/chrome/service/cloud_print/cloud_print_proxy_backend.h index 4ef417c..2a6b3df 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.h +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.h @@ -34,6 +34,8 @@ class CloudPrintProxyFrontend { const std::string& email) = 0; // We have invalid/expired credentials. virtual void OnAuthenticationFailed() = 0; + // The print system could not be initialized. + virtual void OnPrintSystemUnavailable() = 0; protected: // Don't delete through SyncFrontend interface. diff --git a/chrome/service/cloud_print/print_system.h b/chrome/service/cloud_print/print_system.h index 517a665..32fa8f8 100644 --- a/chrome/service/cloud_print/print_system.h +++ b/chrome/service/cloud_print/print_system.h @@ -131,6 +131,20 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { 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< bool, const std::string&, @@ -141,7 +155,7 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { // Initialize print system. This need to be called before any other function // of PrintSystem. - virtual void Init() = 0; + virtual PrintSystemResult Init() = 0; // Enumerates the list of installed local and network printers. virtual void EnumeratePrinters(printing::PrinterList* printer_list) = 0; diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index 1a8e7d7..a92af54 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -72,7 +72,7 @@ class PrintSystemCUPS : public PrintSystem { explicit PrintSystemCUPS(const DictionaryValue* print_system_settings); // PrintSystem implementation. - virtual void Init(); + virtual PrintSystemResult Init(); virtual void EnumeratePrinters(printing::PrinterList* printer_list); @@ -405,9 +405,10 @@ void PrintSystemCUPS::AddPrintServer(const std::string& url) { print_servers_.push_back(print_server); } -void PrintSystemCUPS::Init() { +PrintSystem::PrintSystemResult PrintSystemCUPS::Init() { UpdatePrinters(); initialized_ = true; + return PrintSystemResult(true, std::string()); } void PrintSystemCUPS::UpdatePrinters() { diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index 88c38d9..a6427cd 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -7,6 +7,7 @@ #include <objidl.h> #include <winspool.h> +#include "app/l10n_util.h" #include "base/file_path.h" #include "base/scoped_ptr.h" #include "base/utf_string_conversions.h" @@ -18,6 +19,7 @@ #include "chrome/service/service_process.h" #include "chrome/service/service_utility_process_host.h" #include "gfx/rect.h" +#include "grit/generated_resources.h" #include "printing/backend/print_backend.h" #include "printing/backend/print_backend_consts.h" #include "printing/backend/win_helper.h" @@ -246,7 +248,7 @@ class PrintSystemWin : public PrintSystem { PrintSystemWin(); // PrintSystem implementation. - virtual void Init(); + virtual PrintSystemResult Init(); virtual void EnumeratePrinters(printing::PrinterList* printer_list); @@ -594,7 +596,13 @@ PrintSystemWin::PrintSystemWin() { 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) { diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index c2f43f2..b141b01 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -6,6 +6,8 @@ #include <algorithm> +#include "app/app_switches.h" +#include "app/resource_bundle.h" #include "base/basictypes.h" #include "base/command_line.h" #include "base/path_service.h" @@ -36,6 +38,8 @@ namespace { // a shutdown. const int64 kShutdownDelay = 60000; +const char kDefaultServiceProcessLocale[] = "en-US"; + class ServiceIOThread : public base::Thread { public: explicit ServiceIOThread(const char* name); @@ -97,6 +101,21 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop, new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy())); 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) // Initialize chromoting host manager. remoting_host_manager_ = new remoting::ChromotingHostManager(this); @@ -176,17 +195,21 @@ CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { return cloud_print_proxy_.get(); } -void ServiceProcess::OnCloudPrintProxyEnabled() { - // Save the preference that we have enabled the cloud print proxy. - service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true); - service_prefs_->WritePrefs(); +void ServiceProcess::OnCloudPrintProxyEnabled(bool persist_state) { + if (persist_state) { + // Save the preference that we have enabled the cloud print proxy. + service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true); + service_prefs_->WritePrefs(); + } OnServiceEnabled(); } -void ServiceProcess::OnCloudPrintProxyDisabled() { - // Save the preference that we have disabled the cloud print proxy. - service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); - service_prefs_->WritePrefs(); +void ServiceProcess::OnCloudPrintProxyDisabled(bool persist_state) { + if (persist_state) { + // Save the preference that we have disabled the cloud print proxy. + service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); + service_prefs_->WritePrefs(); + } OnServiceDisabled(); } diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h index ee1727f..f293143 100644 --- a/chrome/service/service_process.h +++ b/chrome/service/service_process.h @@ -82,8 +82,8 @@ class ServiceProcess : public CloudPrintProxy::Client, CloudPrintProxy* GetCloudPrintProxy(); // CloudPrintProxy::Client implementation. - virtual void OnCloudPrintProxyEnabled(); - virtual void OnCloudPrintProxyDisabled(); + virtual void OnCloudPrintProxyEnabled(bool persist_state); + virtual void OnCloudPrintProxyDisabled(bool persist_state); // ChromotingHostManager::Observer interface. virtual void OnRemotingHostEnabled(); |