diff options
author | Kristian Monsen <kristianm@google.com> | 2011-05-24 16:24:13 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-05-25 14:13:32 +0100 |
commit | 3f50c38dc070f4bb515c1b64450dae14f316474e (patch) | |
tree | 29f309f9534e05c47244eedb438fc612578d133b /chrome/browser/service | |
parent | e23bef148f7be2bdf9c3cb2cd3aa5ceebf1190fb (diff) | |
download | external_chromium-3f50c38dc070f4bb515c1b64450dae14f316474e.zip external_chromium-3f50c38dc070f4bb515c1b64450dae14f316474e.tar.gz external_chromium-3f50c38dc070f4bb515c1b64450dae14f316474e.tar.bz2 |
Merge Chromium at r10.0.634.0: Initial merge by git.
Change-Id: Iac2af492818d119bcc2562eb5fdabf5ab0b6df9c
Diffstat (limited to 'chrome/browser/service')
-rw-r--r-- | chrome/browser/service/service_process_control.cc | 42 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.h | 43 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control_browsertest.cc | 27 |
3 files changed, 51 insertions, 61 deletions
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc index 27e3a2d..0ca4729 100644 --- a/chrome/browser/service/service_process_control.cc +++ b/chrome/browser/service/service_process_control.cc @@ -8,8 +8,8 @@ #include "base/file_path.h" #include "base/process_util.h" #include "base/stl_util-inl.h" -#include "base/thread.h" -#include "base/thread_restrictions.h" +#include "base/threading/thread.h" +#include "base/threading/thread_restrictions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/io_thread.h" @@ -96,8 +96,7 @@ class ServiceProcessControl::Launcher // ServiceProcessControl implementation. ServiceProcessControl::ServiceProcessControl(Profile* profile) - : profile_(profile), - message_handler_(NULL) { + : profile_(profile) { } ServiceProcessControl::~ServiceProcessControl() { @@ -239,9 +238,8 @@ void ServiceProcessControl::OnProcessLaunched() { } bool ServiceProcessControl::OnMessageReceived(const IPC::Message& message) { - bool handled = true;; + bool handled = true; IPC_BEGIN_MESSAGE_MAP(ServiceProcessControl, message) - IPC_MESSAGE_HANDLER(ServiceHostMsg_GoodDay, OnGoodDay) IPC_MESSAGE_HANDLER(ServiceHostMsg_CloudPrintProxy_IsEnabled, OnCloudPrintProxyIsEnabled) IPC_MESSAGE_HANDLER(ServiceHostMsg_RemotingHost_HostInfo, @@ -278,13 +276,6 @@ void ServiceProcessControl::Observe(NotificationType type, } } -void ServiceProcessControl::OnGoodDay() { - if (!message_handler_) - return; - - message_handler_->OnGoodDay(); -} - void ServiceProcessControl::OnCloudPrintProxyIsEnabled(bool enabled, std::string email) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -297,9 +288,9 @@ void ServiceProcessControl::OnCloudPrintProxyIsEnabled(bool enabled, void ServiceProcessControl::OnRemotingHostInfo( remoting::ChromotingHostInfo host_info) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (remoting_host_status_callback_ != NULL) { - remoting_host_status_callback_->Run(host_info); - remoting_host_status_callback_.reset(); + for (std::set<MessageHandler*>::iterator it = message_handlers_.begin(); + it != message_handlers_.end(); ++it) { + (*it)->OnRemotingHostInfo(host_info); } } @@ -310,10 +301,6 @@ bool ServiceProcessControl::GetCloudPrintProxyStatus( return Send(new ServiceMsg_IsCloudPrintProxyEnabled); } -bool ServiceProcessControl::SendHello() { - return Send(new ServiceMsg_Hello()); -} - bool ServiceProcessControl::Shutdown() { bool ret = Send(new ServiceMsg_Shutdown()); channel_.reset(); @@ -335,11 +322,18 @@ bool ServiceProcessControl::DisableRemotingHost() { return Send(new ServiceMsg_DisableRemotingHost()); } -bool ServiceProcessControl::GetRemotingHostStatus( - GetRemotingHostStatusCallback* status_callback) { - DCHECK(status_callback); - remoting_host_status_callback_.reset(status_callback); +bool ServiceProcessControl::RequestRemotingHostStatus() { return Send(new ServiceMsg_GetRemotingHostInfo); } +void ServiceProcessControl::AddMessageHandler( + MessageHandler* message_handler) { + message_handlers_.insert(message_handler); +} + +void ServiceProcessControl::RemoveMessageHandler( + MessageHandler* message_handler) { + message_handlers_.erase(message_handler); +} + DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControl); diff --git a/chrome/browser/service/service_process_control.h b/chrome/browser/service/service_process_control.h index 9162736..c2f18ba 100644 --- a/chrome/browser/service/service_process_control.h +++ b/chrome/browser/service/service_process_control.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ #include <queue> +#include <set> #include <string> #include <vector> @@ -41,15 +42,16 @@ class ServiceProcessControl : public IPC::Channel::Sender, typedef IDMap<ServiceProcessControl>::iterator iterator; typedef std::queue<IPC::Message> MessageQueue; typedef Callback1<const remoting::ChromotingHostInfo&>::Type - GetRemotingHostStatusCallback; + RemotingHostStatusHandler; // An interface for handling messages received from the service process. class MessageHandler { public: virtual ~MessageHandler() {} - // This is a test signal sent from the service process. This can be used - // the healthiness of the service. - virtual void OnGoodDay() = 0; + + // Called when we receive reply to remoting host status request. + virtual void OnRemotingHostInfo( + const remoting::ChromotingHostInfo& host_info) = 0; }; // Construct a ServiceProcessControl with |profile|.. @@ -90,42 +92,38 @@ class ServiceProcessControl : public IPC::Channel::Sender, const NotificationDetails& details); // Message handlers - void OnGoodDay(); void OnCloudPrintProxyIsEnabled(bool enabled, std::string email); void OnRemotingHostInfo(remoting::ChromotingHostInfo host_info); - // Send a hello message to the service process for testing purpose. - // Return true if the message was sent. - bool SendHello(); - // 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 a message to the service process to request a response - // containing the enablement status of the cloud print proxy and the - // registered email address. The callback gets the information when - // received. + // 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 a message to enable the remoting service in the service process. // Return true if the message was sent. bool SetRemotingHostCredentials(const std::string& user, - const std::string& auth_token); + const std::string& auth_token); bool EnableRemotingHost(); bool DisableRemotingHost(); - bool GetRemotingHostStatus( - GetRemotingHostStatusCallback* status_callback); + // Send request for current status of the remoting service. + bool RequestRemotingHostStatus(); + + // Add a message handler for receiving messages from the service + // process. + void AddMessageHandler(MessageHandler* message_handler); - // Set the message handler for receiving messages from the service process. - // TODO(hclam): Allow more than 1 handler. - void SetMessageHandler(MessageHandler* message_handler) { - message_handler_ = message_handler; - } + // Remove a message handler from the list of message handlers. Must + // not be called from a message handler (i.e. while a message is + // being processed). + void RemoveMessageHandler(MessageHandler* message_handler); private: class Launcher; @@ -161,10 +159,9 @@ 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<GetRemotingHostStatusCallback> remoting_host_status_callback_; // Handler for messages from service process. - MessageHandler* message_handler_; + std::set<MessageHandler*> message_handlers_; NotificationRegistrar registrar_; }; diff --git a/chrome/browser/service/service_process_control_browsertest.cc b/chrome/browser/service/service_process_control_browsertest.cc index 8cf596c..9087b8d 100644 --- a/chrome/browser/service/service_process_control_browsertest.cc +++ b/chrome/browser/service/service_process_control_browsertest.cc @@ -13,8 +13,7 @@ #include "chrome/test/ui_test_utils.h" class ServiceProcessControlBrowserTest - : public InProcessBrowserTest, - public ServiceProcessControl::MessageHandler { + : public InProcessBrowserTest { public: ServiceProcessControlBrowserTest() : service_process_handle_(base::kNullProcessHandle) { @@ -46,12 +45,18 @@ class ServiceProcessControlBrowserTest ui_test_utils::RunMessageLoop(); } - void SayHelloAndWait() { - // Send a hello message to the service process and wait for a reply. - process()->SendHello(); + // Send a remoting host status request and wait reply from the service. + void SendRequestAndWait() { + process()->GetCloudPrintProxyStatus(NewCallback( + this, &ServiceProcessControlBrowserTest::CloudPrintStatusCallback)); ui_test_utils::RunMessageLoop(); } + void CloudPrintStatusCallback( + bool enabled, std::string email) { + MessageLoop::current()->Quit(); + } + void Disconnect() { // This will delete all instances of ServiceProcessControl and close the IPC // connections. @@ -72,7 +77,6 @@ class ServiceProcessControlBrowserTest service_pid, base::kProcessAccessWaitForTermination, &service_process_handle_)); - process()->SetMessageHandler(this); // Quit the current message. Post a QuitTask instead of just calling Quit() // because this can get invoked in the context of a Launch() call and we // may not be in Run() yet. @@ -85,11 +89,6 @@ class ServiceProcessControlBrowserTest MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } - // ServiceProcessControl::MessageHandler implementations. - virtual void OnGoodDay() { - MessageLoop::current()->Quit(); - } - ServiceProcessControl* process() { return process_; } private: @@ -105,7 +104,7 @@ IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchAndIPC) { // Make sure we are connected to the service process. EXPECT_TRUE(process()->is_connected()); - SayHelloAndWait(); + SendRequestAndWait(); // And then shutdown the service process. EXPECT_TRUE(process()->Shutdown()); @@ -119,12 +118,12 @@ IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchTwice) { // Make sure we are connected to the service process. EXPECT_TRUE(process()->is_connected()); - SayHelloAndWait(); + SendRequestAndWait(); // Launch the service process again. LaunchServiceProcessControl(); EXPECT_TRUE(process()->is_connected()); - SayHelloAndWait(); + SendRequestAndWait(); // And then shutdown the service process. EXPECT_TRUE(process()->Shutdown()); |