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

Side by Side Diff: remoting/host/ipc_desktop_environment_factory.cc

Issue 11761019: Tiny little refactoring of DesktopEnvironment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/ipc_desktop_environment_factory.h ('k') | remoting/host/ipc_event_executor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "remoting/host/ipc_desktop_environment_factory.h" 5 #include "remoting/host/ipc_desktop_environment_factory.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ipc/ipc_channel_proxy.h" 9 #include "ipc/ipc_channel_proxy.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
11 #include "remoting/capturer/video_frame_capturer.h" 11 #include "remoting/capturer/video_frame_capturer.h"
12 #include "remoting/host/audio_capturer.h" 12 #include "remoting/host/audio_capturer.h"
13 #include "remoting/host/chromoting_host.h" 13 #include "remoting/host/chromoting_host.h"
14 #include "remoting/host/chromoting_host_context.h" 14 #include "remoting/host/chromoting_host_context.h"
15 #include "remoting/host/chromoting_messages.h" 15 #include "remoting/host/chromoting_messages.h"
16 #include "remoting/host/desktop_session_connector.h" 16 #include "remoting/host/desktop_session_connector.h"
17 #include "remoting/host/desktop_session_proxy.h" 17 #include "remoting/host/desktop_session_proxy.h"
18 #include "remoting/host/event_executor.h" 18 #include "remoting/host/event_executor.h"
19 #include "remoting/host/ipc_desktop_environment.h" 19 #include "remoting/host/ipc_desktop_environment.h"
20 20
21 namespace remoting { 21 namespace remoting {
22 22
23 IpcDesktopEnvironmentFactory::IpcDesktopEnvironmentFactory( 23 IpcDesktopEnvironmentFactory::IpcDesktopEnvironmentFactory(
24 IPC::ChannelProxy* daemon_channel, 24 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
25 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner, 25 IPC::ChannelProxy* daemon_channel)
26 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, 26 : DesktopEnvironmentFactory(caller_task_runner),
27 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
28 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
29 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner)
30 : DesktopEnvironmentFactory(input_task_runner, ui_task_runner),
31 daemon_channel_(daemon_channel), 27 daemon_channel_(daemon_channel),
32 audio_capture_task_runner_(audio_capture_task_runner), 28 connector_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
33 network_task_runner_(network_task_runner),
34 video_capture_task_runner_(video_capture_task_runner),
35 next_id_(0) { 29 next_id_(0) {
36 } 30 }
37 31
38 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() { 32 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() {
33 DCHECK(caller_task_runner()->BelongsToCurrentThread());
39 } 34 }
40 35
41 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create() { 36 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create(
42 DCHECK(network_task_runner_->BelongsToCurrentThread()); 37 const std::string& client_jid,
43 38 const base::Closure& disconnect_callback) {
44 scoped_refptr<DesktopSessionProxy> desktop_session_proxy( 39 DCHECK(caller_task_runner()->BelongsToCurrentThread());
45 new DesktopSessionProxy(audio_capture_task_runner_,
46 network_task_runner_,
47 video_capture_task_runner_));
48 40
49 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment( 41 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment(
50 input_task_runner_, network_task_runner_, ui_task_runner_, 42 caller_task_runner(), client_jid, disconnect_callback,
51 this, desktop_session_proxy)); 43 connector_factory_.GetWeakPtr()));
52 } 44 }
53 45
54 void IpcDesktopEnvironmentFactory::ConnectTerminal( 46 void IpcDesktopEnvironmentFactory::ConnectTerminal(
55 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) { 47 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) {
56 DCHECK(network_task_runner_->BelongsToCurrentThread()); 48 DCHECK(caller_task_runner()->BelongsToCurrentThread());
57 49
58 int id = next_id_++; 50 int id = next_id_++;
59 bool inserted = active_connections_.insert( 51 bool inserted = active_connections_.insert(
60 std::make_pair(id, desktop_session_proxy)).second; 52 std::make_pair(id, desktop_session_proxy)).second;
61 CHECK(inserted); 53 CHECK(inserted);
62 54
63 VLOG(1) << "Network: registered desktop environment " << id; 55 VLOG(1) << "Network: registered desktop environment " << id;
64 daemon_channel_->Send(new ChromotingNetworkHostMsg_ConnectTerminal(id)); 56 daemon_channel_->Send(new ChromotingNetworkHostMsg_ConnectTerminal(id));
65 } 57 }
66 58
67 void IpcDesktopEnvironmentFactory::DisconnectTerminal( 59 void IpcDesktopEnvironmentFactory::DisconnectTerminal(
68 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) { 60 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) {
69 DCHECK(network_task_runner_->BelongsToCurrentThread()); 61 DCHECK(caller_task_runner()->BelongsToCurrentThread());
70 62
71 ActiveConnectionsList::iterator i; 63 ActiveConnectionsList::iterator i;
72 for (i = active_connections_.begin(); i != active_connections_.end(); ++i) { 64 for (i = active_connections_.begin(); i != active_connections_.end(); ++i) {
73 if (i->second.get() == desktop_session_proxy.get()) 65 if (i->second.get() == desktop_session_proxy.get())
74 break; 66 break;
75 } 67 }
76 68
77 if (i != active_connections_.end()) { 69 if (i != active_connections_.end()) {
78 int id = i->first; 70 int id = i->first;
79 active_connections_.erase(i); 71 active_connections_.erase(i);
80 72
81 VLOG(1) << "Network: unregistered desktop environment " << id; 73 VLOG(1) << "Network: unregistered desktop environment " << id;
82 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id)); 74 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id));
83 } 75 }
84 } 76 }
85 77
86 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached( 78 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached(
87 int terminal_id, 79 int terminal_id,
88 IPC::PlatformFileForTransit desktop_process, 80 IPC::PlatformFileForTransit desktop_process,
89 IPC::PlatformFileForTransit desktop_pipe) { 81 IPC::PlatformFileForTransit desktop_pipe) {
90 if (!network_task_runner_->BelongsToCurrentThread()) { 82 if (!caller_task_runner()->BelongsToCurrentThread()) {
91 network_task_runner_->PostTask(FROM_HERE, base::Bind( 83 caller_task_runner()->PostTask(FROM_HERE, base::Bind(
92 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached, 84 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached,
93 base::Unretained(this), terminal_id, desktop_process, desktop_pipe)); 85 base::Unretained(this), terminal_id, desktop_process, desktop_pipe));
94 return; 86 return;
95 } 87 }
96 88
97 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); 89 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id);
98 if (i != active_connections_.end()) { 90 if (i != active_connections_.end()) {
99 i->second->DetachFromDesktop(); 91 i->second->DetachFromDesktop();
100 i->second->AttachToDesktop(desktop_process, desktop_pipe); 92 i->second->AttachToDesktop(desktop_process, desktop_pipe);
101 } else { 93 } else {
102 #if defined(OS_POSIX) 94 #if defined(OS_POSIX)
103 DCHECK(desktop_process.auto_close); 95 DCHECK(desktop_process.auto_close);
104 DCHECK(desktop_pipe.auto_close); 96 DCHECK(desktop_pipe.auto_close);
105 97
106 base::ClosePlatformFile(desktop_process.fd); 98 base::ClosePlatformFile(desktop_process.fd);
107 base::ClosePlatformFile(desktop_pipe.fd); 99 base::ClosePlatformFile(desktop_pipe.fd);
108 #elif defined(OS_WIN) 100 #elif defined(OS_WIN)
109 base::ClosePlatformFile(desktop_process); 101 base::ClosePlatformFile(desktop_process);
110 #endif // defined(OS_WIN) 102 #endif // defined(OS_WIN)
111 } 103 }
112 } 104 }
113 105
114 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { 106 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) {
115 if (!network_task_runner_->BelongsToCurrentThread()) { 107 if (!caller_task_runner()->BelongsToCurrentThread()) {
116 network_task_runner_->PostTask(FROM_HERE, base::Bind( 108 caller_task_runner()->PostTask(FROM_HERE, base::Bind(
117 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, 109 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected,
118 base::Unretained(this), terminal_id)); 110 base::Unretained(this), terminal_id));
119 return; 111 return;
120 } 112 }
121 113
122 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); 114 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id);
123 if (i != active_connections_.end()) { 115 if (i != active_connections_.end()) {
124 scoped_refptr<DesktopSessionProxy> desktop_session_proxy = i->second; 116 scoped_refptr<DesktopSessionProxy> desktop_session_proxy = i->second;
125 active_connections_.erase(i); 117 active_connections_.erase(i);
126 118
127 // Disconnect the client session. 119 // Disconnect the client session.
128 desktop_session_proxy->DisconnectSession(); 120 desktop_session_proxy->DisconnectSession();
129 } 121 }
130 } 122 }
131 123
132 } // namespace remoting 124 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/ipc_desktop_environment_factory.h ('k') | remoting/host/ipc_event_executor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698