Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Unified Diff: remoting/host/remoting_me2me_host.cc

Issue 11028128: [Chromoting] Request the daemon to open a terminal once a connection has been accepted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/remoting_me2me_host.cc
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index 55bf29856120c4a8fcb3b2f7978fe87a9a45cd59..57bcab6c6f4ef213973a8e8c10d277f167d44a4e 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -5,8 +5,10 @@
// This file implements a standalone host process for Me2Me.
#include <string>
+#include <utility>
#include "base/at_exit.h"
+#include "base/atomic_sequence_num.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
@@ -39,6 +41,7 @@
#include "remoting/host/config_file_watcher.h"
#include "remoting/host/curtain_mode.h"
#include "remoting/host/curtaining_host_observer.h"
+#include "remoting/host/daemon_sender.h"
#include "remoting/host/desktop_environment_factory.h"
#include "remoting/host/desktop_resizer.h"
#include "remoting/host/dns_blackhole_checker.h"
@@ -48,6 +51,7 @@
#include "remoting/host/host_event_logger.h"
#include "remoting/host/host_exit_codes.h"
#include "remoting/host/host_user_interface.h"
+#include "remoting/host/ipc_desktop_environment_factory.h"
#include "remoting/host/json_host_config.h"
#include "remoting/host/log_to_server.h"
#include "remoting/host/network_settings.h"
@@ -112,9 +116,12 @@ void QuitMessageLoop(MessageLoop* message_loop) {
namespace remoting {
class HostProcess
- : public HeartbeatSender::Listener,
- public IPC::Listener,
- public ConfigFileWatcher::Delegate {
+ : public ConfigFileWatcher::Delegate,
+#if defined(REMOTING_MULTI_PROCESS)
+ public DaemonSender,
+#endif // defined(REMOTING_MULTI_PROCESS)
+ public HeartbeatSender::Listener,
+ public IPC::Listener {
public:
explicit HostProcess(scoped_ptr<ChromotingHostContext> context)
: context_(context.Pass()),
@@ -122,7 +129,12 @@ class HostProcess
allow_nat_traversal_(true),
restarting_(false),
shutting_down_(false),
-#if defined(OS_WIN)
+#if defined(OS_WIN) && defined(REMOTING_MULTI_PROCESS)
+ desktop_environment_factory_(new IpcDesktopEnvironmentFactory(
+ context_->input_task_runner(),
+ context_->ui_task_runner(),
+ ALLOW_THIS_IN_INITIALIZER_LIST(this))),
+#elif defined(OS_WIN) && !defined(REMOTING_MULTI_PROCESS)
desktop_environment_factory_(new SessionDesktopEnvironmentFactory(
context_->input_task_runner(), context_->ui_task_runner())),
#else // !defined(OS_WIN)
@@ -281,6 +293,8 @@ class HostProcess
IPC_BEGIN_MESSAGE_MAP(HostProcess, message)
IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration,
OnConfigUpdated)
+ IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_TerminalClosed,
+ OnTerminalClosed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -307,6 +321,16 @@ class HostProcess
int get_exit_code() const { return exit_code_; }
+#if defined(REMOTING_MULTI_PROCESS)
+ // DaemonSender implementation
+ virtual void CloseTerminal(DesktopEnvironment* desktop_environment) OVERRIDE;
+ virtual void OpenTerminal(DesktopEnvironment* desktop_environment) OVERRIDE;
+
+ // Maps |termonal_id| to the correspondinf desktop environment instance and
Wez 2012/10/13 00:47:15 typo: |terminal_id|
Wez 2012/10/13 00:47:15 typo: corresponding
Wez 2012/10/13 00:47:15 nit: desktop environment -> DesktopEnvironment
Wez 2012/10/13 00:47:15 nit: Reword "Closes any client connection that is
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
+ // closes the corresponding connection if needed.
+ void OnTerminalClosed(int terminal_id);
+#endif // defined(REMOTING_MULTI_PROCESS)
+
private:
void ShutdownHostProcess() {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
@@ -692,8 +716,74 @@ class HostProcess
scoped_refptr<ChromotingHost> host_;
int exit_code_;
+
+#if defined(REMOTING_MULTI_PROCESS)
+ // A list of desktop environment instances known to the daemon process.
+ std::map<int, DesktopEnvironment*> registered_terminals_;
Wez 2012/10/13 00:47:15 nit: registered -> active
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
+
+ // This gives us more than 67 years of unique IDs assuming a new ID is
+ // allocated every second.
+ static base::StaticAtomicSequenceNumber terminal_id_;
Wez 2012/10/13 00:47:15 Do we need StatucAtomicSequenceNumber; we're not r
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
+#endif // defined(REMOTING_MULTI_PROCESS)
+
};
+#if defined(REMOTING_MULTI_PROCESS)
Wez 2012/10/13 00:47:15 I really think we need to move the multi-process s
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
+
+base::StaticAtomicSequenceNumber HostProcess::terminal_id_;
+
+void HostProcess::CloseTerminal(DesktopEnvironment* desktop_environment) {
+ DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
+
+ std::map<int, DesktopEnvironment*>::iterator i;
+ for (i = registered_terminals_.begin(); i != registered_terminals_.end();
+ ++i) {
+ if (i->second == desktop_environment)
+ break;
+ }
+
+ if (i != registered_terminals_.end()) {
+ int terminal_id = i->first;
+ registered_terminals_.erase(i);
+
+ VLOG(1) << "Network: unregistered desktop environment " << terminal_id;
+ daemon_channel_->Send(
+ new ChromotingNetworkHostMsg_CloseTerminal(terminal_id));
+ }
+}
+
+void HostProcess::OpenTerminal(DesktopEnvironment* desktop_environment) {
Wez 2012/10/13 00:47:15 OpenTerminal -> CreateTerminal / AttachTerminal
alexeypa (please no reviews) 2012/10/16 19:32:25 Done.
+ DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
+
+ int terminal_id = terminal_id_.GetNext();
+ bool inserted = registered_terminals_.insert(
+ std::make_pair(terminal_id, desktop_environment)).second;
+ CHECK(inserted);
+
+ VLOG(1) << "Network: registered desktop environment " << terminal_id;
+ daemon_channel_->Send(new ChromotingNetworkHostMsg_OpenTerminal(terminal_id));
+}
+
+void HostProcess::OnTerminalClosed(int terminal_id) {
+ if (!context_->network_task_runner()->BelongsToCurrentThread()) {
+ context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
+ &HostProcess::OnTerminalClosed, base::Unretained(this), terminal_id));
+ return;
+ }
+
+ std::map<int, DesktopEnvironment*>::iterator i =
+ registered_terminals_.find(terminal_id);
+ if (i != registered_terminals_.end()) {
+ DesktopEnvironment* desktop_environment = i->second;
+ registered_terminals_.erase(i);
Wez 2012/10/13 00:47:15 Why not let the client disconnection trigger Close
alexeypa (please no reviews) 2012/10/16 19:32:25 This gives one less message sent over IPC and make
+
+ // Disconnect the client for given desktop environment.
+ host_->DisconnectClient(desktop_environment);
+ }
+}
+
+#endif // defined(REMOTING_MULTI_PROCESS)
+
} // namespace remoting
int main(int argc, char** argv) {

Powered by Google App Engine
This is Rietveld 408576698