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

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

Issue 6266023: Revert "Fix crashes in ChromotingHost" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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/chromoting_host.h ('k') | remoting/host/chromoting_host_unittest.cc » ('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) 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 #include "remoting/host/chromoting_host.h" 5 #include "remoting/host/chromoting_host.h"
6 6
7 #include "base/stl_util-inl.h" 7 #include "base/stl_util-inl.h"
8 #include "base/task.h" 8 #include "base/task.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "remoting/base/constants.h" 10 #include "remoting/base/constants.h"
11 #include "remoting/base/encoder.h" 11 #include "remoting/base/encoder.h"
12 #include "remoting/base/encoder_row_based.h" 12 #include "remoting/base/encoder_row_based.h"
13 #include "remoting/base/encoder_vp8.h" 13 #include "remoting/base/encoder_vp8.h"
14 #include "remoting/host/capturer.h" 14 #include "remoting/host/capturer.h"
15 #include "remoting/host/chromoting_host_context.h" 15 #include "remoting/host/chromoting_host_context.h"
16 #include "remoting/host/event_executor.h" 16 #include "remoting/host/event_executor.h"
17 #include "remoting/host/host_config.h" 17 #include "remoting/host/host_config.h"
18 #include "remoting/host/host_stub_fake.h" 18 #include "remoting/host/host_stub_fake.h"
19 #include "remoting/host/screen_recorder.h" 19 #include "remoting/host/screen_recorder.h"
20 #include "remoting/protocol/connection_to_client.h" 20 #include "remoting/protocol/connection_to_client.h"
21 #include "remoting/protocol/host_stub.h" 21 #include "remoting/protocol/host_stub.h"
22 #include "remoting/protocol/input_stub.h" 22 #include "remoting/protocol/input_stub.h"
23 #include "remoting/protocol/jingle_session_manager.h" 23 #include "remoting/protocol/jingle_session_manager.h"
24 #include "remoting/protocol/session_config.h" 24 #include "remoting/protocol/session_config.h"
25 25
26 using remoting::protocol::ConnectionToClient; 26 using remoting::protocol::ConnectionToClient;
27 using remoting::protocol::InputStub;
28 27
29 namespace remoting { 28 namespace remoting {
30 29
31 // static 30 // static
32 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, 31 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
33 MutableHostConfig* config) { 32 MutableHostConfig* config) {
34 Capturer* capturer = Capturer::Create(context->main_message_loop()); 33 return Create(context, config,
35 InputStub* input_stub = CreateEventExecutor(context->main_message_loop(), 34 Capturer::Create(context->main_message_loop()));
36 capturer);
37 return Create(context, config, capturer, input_stub);
38 } 35 }
39 36
40 // static 37 // static
41 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, 38 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
42 MutableHostConfig* config, 39 MutableHostConfig* config,
43 Capturer* capturer, 40 Capturer* capturer) {
44 InputStub* input_stub) { 41 return new ChromotingHost(context, config, capturer);
45 return new ChromotingHost(context, config, capturer, input_stub);
46 } 42 }
47 43
48 ChromotingHost::ChromotingHost(ChromotingHostContext* context, 44 ChromotingHost::ChromotingHost(ChromotingHostContext* context,
49 MutableHostConfig* config, 45 MutableHostConfig* config, Capturer* capturer)
50 Capturer* capturer,
51 InputStub* input_stub)
52 : context_(context), 46 : context_(context),
53 config_(config), 47 config_(config),
54 capturer_(capturer), 48 capturer_(capturer),
55 input_stub_(input_stub), 49 input_stub_(CreateEventExecutor(
50 context->main_message_loop(), capturer)),
56 host_stub_(new HostStubFake()), 51 host_stub_(new HostStubFake()),
57 state_(kInitial), 52 state_(kInitial),
58 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()) { 53 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()) {
59 } 54 }
60 55
61 56
62 ChromotingHost::~ChromotingHost() { 57 ChromotingHost::~ChromotingHost() {
63 } 58 }
64 59
65 void ChromotingHost::Start(Task* shutdown_task) { 60 void ChromotingHost::Start(Task* shutdown_task) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // No-op if this object is not started yet. 114 // No-op if this object is not started yet.
120 { 115 {
121 base::AutoLock auto_lock(lock_); 116 base::AutoLock auto_lock(lock_);
122 if (state_ != kStarted) { 117 if (state_ != kStarted) {
123 state_ = kStopped; 118 state_ = kStopped;
124 return; 119 return;
125 } 120 }
126 state_ = kStopped; 121 state_ = kStopped;
127 } 122 }
128 123
124 // Tell the session to stop and then disconnect all clients.
125 if (recorder_.get()) {
126 recorder_->Stop(NULL);
127 recorder_->RemoveAllConnections();
128 }
129
129 // Disconnect the client. 130 // Disconnect the client.
130 if (connection_) { 131 if (connection_) {
131 connection_->Disconnect(); 132 connection_->Disconnect();
132 } 133 }
133 134
134 // Stop the heartbeat sender. 135 // Stop the heartbeat sender.
135 if (heartbeat_sender_) { 136 if (heartbeat_sender_) {
136 heartbeat_sender_->Stop(); 137 heartbeat_sender_->Stop();
137 } 138 }
138 139
139 // Stop chromotocol session manager. 140 // Stop chromotocol session manager.
140 if (session_manager_) { 141 if (session_manager_) {
141 session_manager_->Close( 142 session_manager_->Close(
142 NewRunnableMethod(this, &ChromotingHost::OnServerClosed)); 143 NewRunnableMethod(this, &ChromotingHost::OnServerClosed));
143 } 144 }
144 145
145 // Disconnect from the talk network. 146 // Disconnect from the talk network.
146 if (jingle_client_) { 147 if (jingle_client_) {
147 jingle_client_->Close(); 148 jingle_client_->Close();
148 } 149 }
149 150
150 // Tell the recorder to stop and then disconnect all clients. 151 // Lastly call the shutdown task.
151 if (recorder_.get()) { 152 if (shutdown_task_.get()) {
152 recorder_->RemoveAllConnections();
153 recorder_->Stop(shutdown_task_.release());
154 } else {
155 shutdown_task_->Run(); 153 shutdown_task_->Run();
156 shutdown_task_.reset();
157 } 154 }
158 } 155 }
159 156
160 // This method is called when a client connects. 157 // This method is called when a client connects.
161 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) { 158 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) {
162 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); 159 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
163 160
164 // Create a new RecordSession if there was none. 161 // Create a new RecordSession if there was none.
165 if (!recorder_.get()) { 162 if (!recorder_.get()) {
166 // Then we create a ScreenRecorder passing the message loops that 163 // Then we create a ScreenRecorder passing the message loops that
167 // it should run on. 164 // it should run on.
168 DCHECK(capturer_.get()); 165 DCHECK(capturer_.get());
169 166
170 Encoder* encoder = CreateEncoder(connection->session()->config()); 167 Encoder* encoder = CreateEncoder(connection->session()->config());
171 168
172 recorder_ = new ScreenRecorder(context_->main_message_loop(), 169 recorder_ = new ScreenRecorder(context_->main_message_loop(),
173 context_->encode_message_loop(), 170 context_->encode_message_loop(),
174 context_->network_message_loop(), 171 context_->network_message_loop(),
175 capturer_.get(), 172 capturer_.release(),
176 encoder); 173 encoder);
177 } 174 }
178 175
179 // Immediately add the connection and start the session. 176 // Immediately add the connection and start the session.
180 recorder_->AddConnection(connection); 177 recorder_->AddConnection(connection);
181 recorder_->Start(); 178 recorder_->Start();
182 VLOG(1) << "Session manager started"; 179 VLOG(1) << "Session manager started";
183 } 180 }
184 181
185 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { 182 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) {
186 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); 183 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
187 184
188 // Remove the connection from the session manager and stop the session. 185 // Remove the connection from the session manager and stop the session.
189 // TODO(hclam): Stop only if the last connection disconnected. 186 // TODO(hclam): Stop only if the last connection disconnected.
190 if (recorder_.get()) { 187 if (recorder_.get()) {
191 recorder_->RemoveConnection(connection); 188 recorder_->RemoveConnection(connection);
192 recorder_->Stop(NULL); 189 recorder_->Stop(NULL);
193 recorder_ = NULL;
194 } 190 }
195 191
196 // Close the connection to connection just to be safe. 192 // Close the connection to connection just to be safe.
197 connection->Disconnect(); 193 connection->Disconnect();
198 194
199 // Also remove reference to ConnectionToClient from this object. 195 // Also remove reference to ConnectionToClient from this object.
200 connection_ = NULL; 196 connection_ = NULL;
201 } 197 }
202 198
203 //////////////////////////////////////////////////////////////////////////// 199 ////////////////////////////////////////////////////////////////////////////
204 // protocol::ConnectionToClient::EventHandler implementations 200 // protocol::ConnectionToClient::EventHandler implementations
205 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { 201 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) {
206 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); 202 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
207 203
208 // Completes the connection to the client. 204 // Completes the connection to the client.
209 VLOG(1) << "Connection to client established."; 205 VLOG(1) << "Connection to client established.";
210 context_->main_message_loop()->PostTask( 206 context_->main_message_loop()->PostTask(
211 FROM_HERE, 207 FROM_HERE,
212 NewRunnableMethod(this, &ChromotingHost::OnClientConnected, 208 NewRunnableMethod(this, &ChromotingHost::OnClientConnected,
213 make_scoped_refptr(connection))); 209 connection_));
214 } 210 }
215 211
216 void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) { 212 void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) {
217 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); 213 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
218 214
219 VLOG(1) << "Connection to client closed."; 215 VLOG(1) << "Connection to client closed.";
220 context_->main_message_loop()->PostTask( 216 context_->main_message_loop()->PostTask(
221 FROM_HERE, 217 FROM_HERE,
222 NewRunnableMethod(this, &ChromotingHost::OnClientDisconnected, 218 NewRunnableMethod(this, &ChromotingHost::OnClientDisconnected,
223 make_scoped_refptr(connection))); 219 connection_));
224 } 220 }
225 221
226 void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) { 222 void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) {
227 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); 223 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
228 224
229 LOG(ERROR) << "Connection failed unexpectedly."; 225 LOG(ERROR) << "Connection failed unexpectedly.";
230 context_->main_message_loop()->PostTask( 226 context_->main_message_loop()->PostTask(
231 FROM_HERE, 227 FROM_HERE,
232 NewRunnableMethod(this, &ChromotingHost::OnClientDisconnected, 228 NewRunnableMethod(this, &ChromotingHost::OnClientDisconnected,
233 make_scoped_refptr(connection))); 229 connection_));
234 } 230 }
235 231
236 //////////////////////////////////////////////////////////////////////////// 232 ////////////////////////////////////////////////////////////////////////////
237 // JingleClient::Callback implementations 233 // JingleClient::Callback implementations
238 void ChromotingHost::OnStateChange(JingleClient* jingle_client, 234 void ChromotingHost::OnStateChange(JingleClient* jingle_client,
239 JingleClient::State state) { 235 JingleClient::State state) {
240 if (state == JingleClient::CONNECTED) { 236 if (state == JingleClient::CONNECTED) {
241 DCHECK_EQ(jingle_client_.get(), jingle_client); 237 DCHECK_EQ(jingle_client_.get(), jingle_client);
242 VLOG(1) << "Host connected as " << jingle_client->GetFullJid(); 238 VLOG(1) << "Host connected as " << jingle_client->GetFullJid();
243 239
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 292 }
297 293
298 session->set_config(config); 294 session->set_config(config);
299 session->set_receiver_token( 295 session->set_receiver_token(
300 GenerateHostAuthToken(session->initiator_token())); 296 GenerateHostAuthToken(session->initiator_token()));
301 297
302 *response = protocol::SessionManager::ACCEPT; 298 *response = protocol::SessionManager::ACCEPT;
303 299
304 VLOG(1) << "Client connected: " << session->jid(); 300 VLOG(1) << "Client connected: " << session->jid();
305 301
306 // If we accept the connected then create a connection object. 302 // If we accept the connected then create a client object and set the
303 // callback.
307 connection_ = new ConnectionToClient(context_->network_message_loop(), 304 connection_ = new ConnectionToClient(context_->network_message_loop(),
308 this, host_stub_.get(), 305 this, host_stub_.get(),
309 input_stub_.get()); 306 input_stub_.get());
310 connection_->Init(session); 307 connection_->Init(session);
311 } 308 }
312 309
313 void ChromotingHost::set_protocol_config( 310 void ChromotingHost::set_protocol_config(
314 protocol::CandidateSessionConfig* config) { 311 protocol::CandidateSessionConfig* config) {
315 DCHECK(config_.get()); 312 DCHECK(config_.get());
316 DCHECK_EQ(state_, kInitial); 313 DCHECK_EQ(state_, kInitial);
(...skipping 23 matching lines...) Expand all
340 return NULL; 337 return NULL;
341 } 338 }
342 339
343 std::string ChromotingHost::GenerateHostAuthToken( 340 std::string ChromotingHost::GenerateHostAuthToken(
344 const std::string& encoded_client_token) { 341 const std::string& encoded_client_token) {
345 // TODO(ajwong): Return the signature of this instead. 342 // TODO(ajwong): Return the signature of this instead.
346 return encoded_client_token; 343 return encoded_client_token;
347 } 344 }
348 345
349 } // namespace remoting 346 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.h ('k') | remoting/host/chromoting_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698