Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ | 5 #ifndef CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ |
| 6 #define CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ | 6 #define CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/process.h" | 14 #include "base/process.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "chrome/common/notification_observer.h" | 17 #include "chrome/common/notification_observer.h" |
| 18 #include "chrome/common/notification_registrar.h" | 18 #include "chrome/common/notification_registrar.h" |
| 19 #include "ipc/ipc_sync_channel.h" | 19 #include "ipc/ipc_sync_channel.h" |
| 20 | 20 |
| 21 class Profile; | 21 class Profile; |
| 22 | 22 |
| 23 namespace remoting { | |
| 24 class ChromotingHostInfo; | |
| 25 } // namespace remoting | |
| 26 | |
| 23 // A ServiceProcessControl works as a portal between the service process and | 27 // A ServiceProcessControl works as a portal between the service process and |
| 24 // the browser process. | 28 // the browser process. |
| 25 // | 29 // |
| 26 // It is used to start and terminate the service process. It is also used | 30 // It is used to start and terminate the service process. It is also used |
| 27 // to send and receive IPC messages from the service process. | 31 // to send and receive IPC messages from the service process. |
| 28 // | 32 // |
| 29 // THREADING | 33 // THREADING |
| 30 // | 34 // |
| 31 // This class is accessed on the UI thread through some UI actions. It then | 35 // This class is accessed on the UI thread through some UI actions. It then |
| 32 // talks to the IPC channel on the IO thread. | 36 // talks to the IPC channel on the IO thread. |
| 33 class ServiceProcessControl : public IPC::Channel::Sender, | 37 class ServiceProcessControl : public IPC::Channel::Sender, |
| 34 public IPC::Channel::Listener, | 38 public IPC::Channel::Listener, |
| 35 public NotificationObserver { | 39 public NotificationObserver { |
| 36 public: | 40 public: |
| 37 typedef IDMap<ServiceProcessControl>::iterator iterator; | 41 typedef IDMap<ServiceProcessControl>::iterator iterator; |
| 38 typedef std::queue<IPC::Message> MessageQueue; | 42 typedef std::queue<IPC::Message> MessageQueue; |
| 43 typedef Callback1<const remoting::ChromotingHostInfo&>::Type | |
| 44 GetChromotingHostStatusCallback; | |
| 39 | 45 |
| 40 // An interface for handling messages received from the service process. | 46 // An interface for handling messages received from the service process. |
| 41 class MessageHandler { | 47 class MessageHandler { |
| 42 public: | 48 public: |
| 43 virtual ~MessageHandler() {} | 49 virtual ~MessageHandler() {} |
| 44 // This is a test signal sent from the service process. This can be used | 50 // This is a test signal sent from the service process. This can be used |
| 45 // the healthiness of the service. | 51 // the healthiness of the service. |
| 46 virtual void OnGoodDay() = 0; | 52 virtual void OnGoodDay() = 0; |
| 47 }; | 53 }; |
| 48 | 54 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 79 virtual bool Send(IPC::Message* message); | 85 virtual bool Send(IPC::Message* message); |
| 80 | 86 |
| 81 // NotificationObserver implementation. | 87 // NotificationObserver implementation. |
| 82 virtual void Observe(NotificationType type, | 88 virtual void Observe(NotificationType type, |
| 83 const NotificationSource& source, | 89 const NotificationSource& source, |
| 84 const NotificationDetails& details); | 90 const NotificationDetails& details); |
| 85 | 91 |
| 86 // Message handlers | 92 // Message handlers |
| 87 void OnGoodDay(); | 93 void OnGoodDay(); |
| 88 void OnCloudPrintProxyIsEnabled(bool enabled, std::string email); | 94 void OnCloudPrintProxyIsEnabled(bool enabled, std::string email); |
| 95 void OnChromotingHostInfo(remoting::ChromotingHostInfo host_info); | |
| 89 | 96 |
| 90 // Send a hello message to the service process for testing purpose. | 97 // Send a hello message to the service process for testing purpose. |
| 91 // Return true if the message was sent. | 98 // Return true if the message was sent. |
| 92 bool SendHello(); | 99 bool SendHello(); |
| 93 | 100 |
| 94 // Send a shutdown message to the service process. IPC channel will be | 101 // Send a shutdown message to the service process. IPC channel will be |
| 95 // destroyed after calling this method. | 102 // destroyed after calling this method. |
| 96 // Return true if the message was sent. | 103 // Return true if the message was sent. |
| 97 bool Shutdown(); | 104 bool Shutdown(); |
| 98 | 105 |
| 99 // Send a message to enable the remoting service in the service process. | |
| 100 // Return true if the message was sent. | |
| 101 bool EnableRemotingWithTokens(const std::string& user, | |
| 102 const std::string& remoting_token, | |
| 103 const std::string& talk_token); | |
| 104 | |
| 105 // Send a message to the service process to request a response | 106 // Send a message to the service process to request a response |
| 106 // containing the enablement status of the cloud print proxy and the | 107 // containing the enablement status of the cloud print proxy and the |
| 107 // registered email address. The callback gets the information when | 108 // registered email address. The callback gets the information when |
| 108 // received. | 109 // received. |
| 109 bool GetCloudPrintProxyStatus( | 110 bool GetCloudPrintProxyStatus( |
| 110 Callback2<bool, std::string>::Type* cloud_print_status_callback); | 111 Callback2<bool, std::string>::Type* cloud_print_status_callback); |
| 111 | 112 |
| 113 // Send a message to enable the remoting service in the service process. | |
| 114 // Return true if the message was sent. | |
| 115 bool SetChromotingHostCredentials(const std::string& user, | |
| 116 const std::string& auth_token); | |
| 117 | |
| 118 bool EnableChromotingHost(); | |
|
Alpha Left Google
2010/12/16 21:32:44
This should have a callback to get the results of
Sergey Ulanov
2010/12/17 00:05:43
per our discussion, I will add other messages to m
| |
| 119 bool DisableChromotingHost(); | |
| 120 | |
| 121 bool GetChromotingHostStatus( | |
| 122 GetChromotingHostStatusCallback* status_callback); | |
| 123 | |
| 112 // Set the message handler for receiving messages from the service process. | 124 // Set the message handler for receiving messages from the service process. |
| 113 // TODO(hclam): Allow more than 1 handler. | 125 // TODO(hclam): Allow more than 1 handler. |
| 114 void SetMessageHandler(MessageHandler* message_handler) { | 126 void SetMessageHandler(MessageHandler* message_handler) { |
| 115 message_handler_ = message_handler; | 127 message_handler_ = message_handler; |
| 116 } | 128 } |
| 117 | 129 |
| 118 private: | 130 private: |
| 119 class Launcher; | 131 class Launcher; |
| 120 typedef std::vector<Task*> TaskList; | 132 typedef std::vector<Task*> TaskList; |
| 121 | 133 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 142 // if there was a failure in connecting. | 154 // if there was a failure in connecting. |
| 143 TaskList connect_done_tasks_; | 155 TaskList connect_done_tasks_; |
| 144 // Callbacks that get invoked ONLY when the channel is successfully connected. | 156 // Callbacks that get invoked ONLY when the channel is successfully connected. |
| 145 TaskList connect_success_tasks_; | 157 TaskList connect_success_tasks_; |
| 146 // Callbacks that get invoked ONLY when there was a connection failure. | 158 // Callbacks that get invoked ONLY when there was a connection failure. |
| 147 TaskList connect_failure_tasks_; | 159 TaskList connect_failure_tasks_; |
| 148 | 160 |
| 149 // Callback that gets invoked when a status message is received from | 161 // Callback that gets invoked when a status message is received from |
| 150 // the cloud print proxy. | 162 // the cloud print proxy. |
| 151 scoped_ptr<Callback2<bool, std::string>::Type> cloud_print_status_callback_; | 163 scoped_ptr<Callback2<bool, std::string>::Type> cloud_print_status_callback_; |
| 164 scoped_ptr<GetChromotingHostStatusCallback> chromoting_host_status_callback_; | |
| 152 | 165 |
| 153 // Handler for messages from service process. | 166 // Handler for messages from service process. |
| 154 MessageHandler* message_handler_; | 167 MessageHandler* message_handler_; |
| 155 | 168 |
| 156 NotificationRegistrar registrar_; | 169 NotificationRegistrar registrar_; |
| 157 }; | 170 }; |
| 158 | 171 |
| 159 #endif // CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ | 172 #endif // CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ |
| OLD | NEW |