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();
......
...@@ -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) {
// Save the preference that we have enabled the cloud print proxy. if (persist_state) {
service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true); // Save the preference that we have enabled the cloud print proxy.
service_prefs_->WritePrefs(); service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true);
service_prefs_->WritePrefs();
}
OnServiceEnabled(); OnServiceEnabled();
} }
void ServiceProcess::OnCloudPrintProxyDisabled() { void ServiceProcess::OnCloudPrintProxyDisabled(bool persist_state) {
// Save the preference that we have disabled the cloud print proxy. if (persist_state) {
service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); // Save the preference that we have disabled the cloud print proxy.
service_prefs_->WritePrefs(); service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false);
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