summaryrefslogtreecommitdiffstats
path: root/chrome/browser/service
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/service')
-rw-r--r--chrome/browser/service/service_process_control.cc33
-rw-r--r--chrome/browser/service/service_process_control.h36
-rw-r--r--chrome/browser/service/service_process_control_browsertest.cc6
3 files changed, 46 insertions, 29 deletions
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc
index ccce948..2873ddc 100644
--- a/chrome/browser/service/service_process_control.cc
+++ b/chrome/browser/service/service_process_control.cc
@@ -96,8 +96,7 @@ class ServiceProcessControl::Launcher
// ServiceProcessControl implementation.
ServiceProcessControl::ServiceProcessControl(Profile* profile)
- : profile_(profile),
- message_handler_(NULL) {
+ : profile_(profile) {
}
ServiceProcessControl::~ServiceProcessControl() {
@@ -279,10 +278,11 @@ void ServiceProcessControl::Observe(NotificationType type,
}
void ServiceProcessControl::OnGoodDay() {
- if (!message_handler_)
- return;
-
- message_handler_->OnGoodDay();
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ for (std::set<MessageHandler*>::iterator it = message_handlers_.begin();
+ it != message_handlers_.end(); ++it) {
+ (*it)->OnGoodDay();
+ }
}
void ServiceProcessControl::OnCloudPrintProxyIsEnabled(bool enabled,
@@ -297,9 +297,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);
}
}
@@ -335,11 +335,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..78c3141 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,20 @@ 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|..
@@ -103,29 +109,30 @@ class ServiceProcessControl : public IPC::Channel::Sender,
// 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 +168,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..519c005 100644
--- a/chrome/browser/service/service_process_control_browsertest.cc
+++ b/chrome/browser/service/service_process_control_browsertest.cc
@@ -72,7 +72,7 @@ class ServiceProcessControlBrowserTest
service_pid,
base::kProcessAccessWaitForTermination,
&service_process_handle_));
- process()->SetMessageHandler(this);
+ process()->AddMessageHandler(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.
@@ -90,6 +90,10 @@ class ServiceProcessControlBrowserTest
MessageLoop::current()->Quit();
}
+ virtual void OnRemotingHostInfo(
+ const remoting::ChromotingHostInfo& host_info) {
+ }
+
ServiceProcessControl* process() { return process_; }
private: