diff options
-rw-r--r-- | chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc | 17 | ||||
-rw-r--r-- | chrome/browser/printing/cloud_print/cloud_print_proxy_service.h | 10 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.cc | 24 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.h | 19 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control_browsertest.cc | 8 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/common/cloud_print/cloud_print_proxy_info.cc | 14 | ||||
-rw-r--r-- | chrome/common/cloud_print/cloud_print_proxy_info.h | 24 | ||||
-rw-r--r-- | chrome/common/service_messages.h | 26 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.cc | 15 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.h | 9 | ||||
-rw-r--r-- | chrome/service/service_ipc_server.cc | 21 | ||||
-rw-r--r-- | chrome/service/service_ipc_server.h | 4 |
13 files changed, 124 insertions, 69 deletions
diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc index 0190ae2..88b8953 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc @@ -18,6 +18,7 @@ #include "chrome/browser/service/service_process_control.h" #include "chrome/browser/service/service_process_control_manager.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/common/cloud_print/cloud_print_proxy_info.h" #include "chrome/common/pref_names.h" #include "chrome/common/service_messages.h" #include "content/browser/browser_thread.h" @@ -146,10 +147,10 @@ void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { ServiceProcessControl* process_control = ServiceProcessControlManager::GetInstance()->GetProcessControl(profile_); DCHECK(process_control->is_connected()); - Callback2<bool, std::string>::Type* callback = - NewCallback(this, &CloudPrintProxyService::StatusCallback); - // GetCloudPrintProxyStatus takes ownership of callback. - process_control->GetCloudPrintProxyStatus(callback); + ServiceProcessControl::CloudPrintProxyInfoHandler* callback = + NewCallback(this, &CloudPrintProxyService::ProxyInfoCallback); + // GetCloudPrintProxyInfo takes ownership of callback. + process_control->GetCloudPrintProxyInfo(callback); } void CloudPrintProxyService::EnableCloudPrintProxy(const std::string& lsid, @@ -171,9 +172,11 @@ void CloudPrintProxyService::DisableCloudPrintProxy() { profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); } -void CloudPrintProxyService::StatusCallback(bool enabled, std::string email) { - profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, - enabled ? email : std::string()); +void CloudPrintProxyService::ProxyInfoCallback( + const cloud_print::CloudPrintProxyInfo& proxy_info) { + profile_->GetPrefs()->SetString( + prefs::kCloudPrintEmail, + proxy_info.enabled ? proxy_info.email : std::string()); } bool CloudPrintProxyService::InvokeServiceTask(Task* task) { diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h index fc2d94c..f6b01a0 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h @@ -15,6 +15,10 @@ class Profile; +namespace cloud_print { +struct CloudPrintProxyInfo; +} // namespace cloud_print + // Layer between the browser user interface and the cloud print proxy code // running in the service process. class CloudPrintProxyService @@ -55,8 +59,10 @@ class CloudPrintProxyService void EnableCloudPrintProxy(const std::string& lsid, const std::string& email); void DisableCloudPrintProxy(); - // Callback that gets the cloud print proxy status. - void StatusCallback(bool enabled, std::string email); + // Callback that gets the cloud print proxy info. + void ProxyInfoCallback( + const cloud_print::CloudPrintProxyInfo& proxy_info); + // Invoke a task that gets run after the service process successfully // launches. The task typically involves sending an IPC to the service // process. diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc index 0d71241..5c07223 100644 --- a/chrome/browser/service/service_process_control.cc +++ b/chrome/browser/service/service_process_control.cc @@ -185,8 +185,8 @@ void ServiceProcessControl::OnProcessLaunched() { bool ServiceProcessControl::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(ServiceProcessControl, message) - IPC_MESSAGE_HANDLER(ServiceHostMsg_CloudPrintProxy_IsEnabled, - OnCloudPrintProxyIsEnabled) + IPC_MESSAGE_HANDLER(ServiceHostMsg_CloudPrintProxy_Info, + OnCloudPrintProxyInfo) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -230,20 +230,20 @@ void ServiceProcessControl::Observe(NotificationType type, } } -void ServiceProcessControl::OnCloudPrintProxyIsEnabled(bool enabled, - std::string email) { +void ServiceProcessControl::OnCloudPrintProxyInfo( + const cloud_print::CloudPrintProxyInfo& proxy_info) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (cloud_print_status_callback_ != NULL) { - cloud_print_status_callback_->Run(enabled, email); - cloud_print_status_callback_.reset(); + if (cloud_print_info_callback_ != NULL) { + cloud_print_info_callback_->Run(proxy_info); + cloud_print_info_callback_.reset(); } } -bool ServiceProcessControl::GetCloudPrintProxyStatus( - Callback2<bool, std::string>::Type* cloud_print_status_callback) { - DCHECK(cloud_print_status_callback); - cloud_print_status_callback_.reset(cloud_print_status_callback); - return Send(new ServiceMsg_IsCloudPrintProxyEnabled); +bool ServiceProcessControl::GetCloudPrintProxyInfo( + CloudPrintProxyInfoHandler* cloud_print_info_callback) { + DCHECK(cloud_print_info_callback); + cloud_print_info_callback_.reset(cloud_print_info_callback); + return Send(new ServiceMsg_GetCloudPrintProxyInfo()); } bool ServiceProcessControl::Shutdown() { diff --git a/chrome/browser/service/service_process_control.h b/chrome/browser/service/service_process_control.h index 7a9456b..10e9aa0 100644 --- a/chrome/browser/service/service_process_control.h +++ b/chrome/browser/service/service_process_control.h @@ -23,6 +23,10 @@ class Profile; class CommandLine; +namespace cloud_print { +struct CloudPrintProxyInfo; +} // namespace cloud_print + // A ServiceProcessControl works as a portal between the service process and // the browser process. // @@ -39,6 +43,8 @@ class ServiceProcessControl : public IPC::Channel::Sender, public: typedef IDMap<ServiceProcessControl>::iterator iterator; typedef std::queue<IPC::Message> MessageQueue; + typedef Callback1<const cloud_print::CloudPrintProxyInfo&>::Type + CloudPrintProxyInfoHandler; // Construct a ServiceProcessControl with |profile|.. explicit ServiceProcessControl(Profile* profile); @@ -78,17 +84,18 @@ class ServiceProcessControl : public IPC::Channel::Sender, const NotificationDetails& details); // Message handlers - void OnCloudPrintProxyIsEnabled(bool enabled, std::string email); + void OnCloudPrintProxyInfo( + const cloud_print::CloudPrintProxyInfo& proxy_info); // Send a shutdown message to the service process. IPC channel will be // destroyed after calling this method. // Return true if the message was sent. bool Shutdown(); - // Send request for cloud print proxy status and the registered - // email address. The callback gets the information when received. - bool GetCloudPrintProxyStatus( - Callback2<bool, std::string>::Type* cloud_print_status_callback); + // Send request for cloud print proxy info (enabled state, email, proxy id). + // The callback gets the information when received. + bool GetCloudPrintProxyInfo( + CloudPrintProxyInfoHandler* cloud_print_status_callback); private: // This class is responsible for launching the service process on the @@ -152,7 +159,7 @@ class ServiceProcessControl : public IPC::Channel::Sender, // Callback that gets invoked when a status message is received from // the cloud print proxy. - scoped_ptr<Callback2<bool, std::string>::Type> cloud_print_status_callback_; + scoped_ptr<CloudPrintProxyInfoHandler> cloud_print_info_callback_; NotificationRegistrar registrar_; }; diff --git a/chrome/browser/service/service_process_control_browsertest.cc b/chrome/browser/service/service_process_control_browsertest.cc index b7b0c58..b75ec4a 100644 --- a/chrome/browser/service/service_process_control_browsertest.cc +++ b/chrome/browser/service/service_process_control_browsertest.cc @@ -54,13 +54,13 @@ class ServiceProcessControlBrowserTest // Send a Cloud Print status request and wait for a reply from the service. void SendRequestAndWait() { - process()->GetCloudPrintProxyStatus(NewCallback( - this, &ServiceProcessControlBrowserTest::CloudPrintStatusCallback)); + process()->GetCloudPrintProxyInfo(NewCallback( + this, &ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); ui_test_utils::RunMessageLoop(); } - void CloudPrintStatusCallback( - bool enabled, std::string email) { + void CloudPrintInfoCallback( + const cloud_print::CloudPrintProxyInfo& proxy_info) { MessageLoop::current()->Quit(); } diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 9c10b32..e01028c 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -144,6 +144,8 @@ 'common/chrome_content_client.h', 'common/chrome_content_plugin_client.cc', 'common/chrome_content_plugin_client.h', + 'common/cloud_print/cloud_print_proxy_info.cc', + 'common/cloud_print/cloud_print_proxy_info.h', 'common/common_glue.cc', 'common/common_message_generator.cc', 'common/common_message_generator.h', diff --git a/chrome/common/cloud_print/cloud_print_proxy_info.cc b/chrome/common/cloud_print/cloud_print_proxy_info.cc new file mode 100644 index 0000000..6e38663 --- /dev/null +++ b/chrome/common/cloud_print/cloud_print_proxy_info.cc @@ -0,0 +1,14 @@ +// Copyright (c) 2011 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 "chrome/common/cloud_print/cloud_print_proxy_info.h" + +namespace cloud_print { + +CloudPrintProxyInfo::CloudPrintProxyInfo() : enabled(false) { +} + +CloudPrintProxyInfo::~CloudPrintProxyInfo() {} + +} // namespace cloud_print diff --git a/chrome/common/cloud_print/cloud_print_proxy_info.h b/chrome/common/cloud_print/cloud_print_proxy_info.h new file mode 100644 index 0000000..2b97378 --- /dev/null +++ b/chrome/common/cloud_print/cloud_print_proxy_info.h @@ -0,0 +1,24 @@ +// Copyright (c) 2011 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. + +#ifndef CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_PROXY_INFO_H_ +#define CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_PROXY_INFO_H_ + +#include <string> + +namespace cloud_print { + +// This struct is used for ServiceHostMsg_CloudPrint_Info IPC message. +struct CloudPrintProxyInfo { + CloudPrintProxyInfo(); + ~CloudPrintProxyInfo(); + + bool enabled; + std::string email; + std::string proxy_id; +}; + +} // namespace cloud_print + +#endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_PROXY_INFO_H_ diff --git a/chrome/common/service_messages.h b/chrome/common/service_messages.h index faf5b1a..c46c4af 100644 --- a/chrome/common/service_messages.h +++ b/chrome/common/service_messages.h @@ -5,11 +5,18 @@ // Multiply-included message file, no traditional include guard. #include <string> +#include "chrome/common/cloud_print/cloud_print_proxy_info.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #define IPC_MESSAGE_START ServiceMsgStart +IPC_STRUCT_TRAITS_BEGIN(cloud_print::CloudPrintProxyInfo) + IPC_STRUCT_TRAITS_MEMBER(enabled) + IPC_STRUCT_TRAITS_MEMBER(email) + IPC_STRUCT_TRAITS_MEMBER(proxy_id) +IPC_STRUCT_TRAITS_END() + //----------------------------------------------------------------------------- // Service process messages: // These are messages from the browser to the service process. @@ -17,17 +24,13 @@ // of the account to be used. IPC_MESSAGE_CONTROL1(ServiceMsg_EnableCloudPrintProxy, std::string /* lsid */) -// Tell the service process to enable the cloud proxy passing in specific -// tokens to be used. -IPC_MESSAGE_CONTROL2(ServiceMsg_EnableCloudPrintProxyWithTokens, - std::string, /* token for cloudprint service */ - std::string /* token for Google Talk service */) + // Tell the service process to disable the cloud proxy. IPC_MESSAGE_CONTROL0(ServiceMsg_DisableCloudPrintProxy) -// Requests a message back on whether the cloud print proxy is -// enabled. -IPC_MESSAGE_CONTROL0(ServiceMsg_IsCloudPrintProxyEnabled) +// Requests a message back on the current status of the cloud print proxy +// (whether it is enabled, the email address and the proxy id). +IPC_MESSAGE_CONTROL0(ServiceMsg_GetCloudPrintProxyInfo) // Tell the service process to shutdown. IPC_MESSAGE_CONTROL0(ServiceMsg_Shutdown) @@ -41,7 +44,6 @@ IPC_MESSAGE_CONTROL0(ServiceMsg_UpdateAvailable) // Sent when the cloud print proxy has an authentication error. IPC_MESSAGE_CONTROL0(ServiceHostMsg_CloudPrintProxy_AuthError) -// Sent as a response to a request for enablement status. -IPC_MESSAGE_CONTROL2(ServiceHostMsg_CloudPrintProxy_IsEnabled, - bool, /* Is the proxy enabled? */ - std::string /* Email address of account */) +// Sent as a response to a request for cloud print proxy info +IPC_MESSAGE_CONTROL1(ServiceHostMsg_CloudPrintProxy_Info, + cloud_print::CloudPrintProxyInfo /* proxy info */) diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc index 8a99596..39ffffc 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.cc +++ b/chrome/service/cloud_print/cloud_print_proxy.cc @@ -9,6 +9,7 @@ #include "base/process_util.h" #include "base/values.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/cloud_print/cloud_print_proxy_info.h" #include "chrome/common/net/gaia/gaia_oauth_client.h" #include "chrome/common/pref_names.h" #include "chrome/service/cloud_print/cloud_print_consts.h" @@ -150,11 +151,14 @@ void CloudPrintProxy::DisableForUser() { } } -bool CloudPrintProxy::IsEnabled(std::string* email) const { - if (enabled_ && email) { - *email = user_email(); - } - return enabled_; +void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { + info->enabled = enabled_; + info->email.clear(); + info->proxy_id.clear(); + if (enabled_) + info->email = user_email(); + if (service_prefs_) + service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id); } // Notification methods from the backend. Called on UI thread. @@ -217,3 +221,4 @@ void CloudPrintProxy::Shutdown() { backend_->Shutdown(); backend_.reset(); } + diff --git a/chrome/service/cloud_print/cloud_print_proxy.h b/chrome/service/cloud_print/cloud_print_proxy.h index 2ff6dfb..8510a5b 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.h +++ b/chrome/service/cloud_print/cloud_print_proxy.h @@ -15,6 +15,10 @@ class ServiceProcessPrefs; +namespace cloud_print { +struct CloudPrintProxyInfo; +} // namespace cloud_print + // CloudPrintProxy is the layer between the service process UI thread // and the cloud print proxy backend. class CloudPrintProxy : public CloudPrintProxyFrontend, @@ -36,9 +40,8 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, // Enables/disables cloud printing for the user void EnableForUser(const std::string& lsid); void DisableForUser(); - // Returns the enabled stata of the proxy. If enabled, the email address used - // for authentication is also returned in the optional |email| argument. - bool IsEnabled(std::string* email) const; + // Returns the proxy info. + void GetProxyInfo(cloud_print::CloudPrintProxyInfo* info); const std::string& user_email() const { return user_email_; diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc index 493831e..6f08401 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -101,12 +101,10 @@ bool ServiceIPCServer::OnMessageReceived(const IPC::Message& msg) { IPC_BEGIN_MESSAGE_MAP(ServiceIPCServer, msg) IPC_MESSAGE_HANDLER(ServiceMsg_EnableCloudPrintProxy, OnEnableCloudPrintProxy) - IPC_MESSAGE_HANDLER(ServiceMsg_EnableCloudPrintProxyWithTokens, - OnEnableCloudPrintProxyWithTokens) IPC_MESSAGE_HANDLER(ServiceMsg_DisableCloudPrintProxy, OnDisableCloudPrintProxy) - IPC_MESSAGE_HANDLER(ServiceMsg_IsCloudPrintProxyEnabled, - OnIsCloudPrintProxyEnabled) + IPC_MESSAGE_HANDLER(ServiceMsg_GetCloudPrintProxyInfo, + OnGetCloudPrintProxyInfo) IPC_MESSAGE_HANDLER(ServiceMsg_Shutdown, OnShutdown); IPC_MESSAGE_HANDLER(ServiceMsg_UpdateAvailable, OnUpdateAvailable); IPC_MESSAGE_UNHANDLED(handled = false) @@ -118,17 +116,10 @@ void ServiceIPCServer::OnEnableCloudPrintProxy(const std::string& lsid) { g_service_process->GetCloudPrintProxy()->EnableForUser(lsid); } -void ServiceIPCServer::OnEnableCloudPrintProxyWithTokens( - const std::string& cloud_print_token, const std::string& talk_token) { - // TODO(sanjeevr): Implement this. - NOTIMPLEMENTED(); -} - -void ServiceIPCServer::OnIsCloudPrintProxyEnabled() { - std::string email; - bool is_enabled = g_service_process->GetCloudPrintProxy()->IsEnabled(&email); - channel_->Send(new ServiceHostMsg_CloudPrintProxy_IsEnabled(is_enabled, - email)); +void ServiceIPCServer::OnGetCloudPrintProxyInfo() { + cloud_print::CloudPrintProxyInfo info; + g_service_process->GetCloudPrintProxy()->GetProxyInfo(&info); + channel_->Send(new ServiceHostMsg_CloudPrintProxy_Info(info)); } void ServiceIPCServer::OnDisableCloudPrintProxy() { diff --git a/chrome/service/service_ipc_server.h b/chrome/service/service_ipc_server.h index 01f6f89..71c2a59 100644 --- a/chrome/service/service_ipc_server.h +++ b/chrome/service/service_ipc_server.h @@ -42,9 +42,7 @@ class ServiceIPCServer : public IPC::Channel::Listener, // IPC message handlers. void OnEnableCloudPrintProxy(const std::string& lsid); - void OnEnableCloudPrintProxyWithTokens(const std::string& cloud_print_token, - const std::string& talk_token); - void OnIsCloudPrintProxyEnabled(); + void OnGetCloudPrintProxyInfo(); void OnDisableCloudPrintProxy(); void OnShutdown(); |