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

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

Issue 2790002: Set up the message loop of the mac host to be UI based so that it can pick up... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 6 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 | « no previous file | no next file » | 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/simple_host.h" 5 #include "remoting/host/simple_host.h"
6 6
7 #include "base/stl_util-inl.h" 7 #include "base/stl_util-inl.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "remoting/base/protocol_decoder.h" 9 #include "remoting/base/protocol_decoder.h"
10 #include "remoting/host/session_manager.h" 10 #include "remoting/host/session_manager.h"
11 #include "remoting/jingle_glue/jingle_channel.h" 11 #include "remoting/jingle_glue/jingle_channel.h"
12 12
13 namespace remoting { 13 namespace remoting {
14 14
15 #if defined (OS_MACOSX)
16 // The Mac depends on system callbacks to tell it what rectangles need to
17 // be updated, so we need to use the system message loop.
18 const MessageLoop::Type kSimpleHostMessageLoopType = MessageLoop::TYPE_UI;
19 #else
20 const MessageLoop::Type kSimpleHostMessageLoopType = MessageLoop::TYPE_DEFAULT;
21 #endif // defined (OS_MACOSX)
22
15 SimpleHost::SimpleHost(const std::string& username, 23 SimpleHost::SimpleHost(const std::string& username,
16 const std::string& password, 24 const std::string& password,
17 Capturer* capturer, 25 Capturer* capturer,
18 Encoder* encoder, 26 Encoder* encoder,
19 EventExecutor* executor) 27 EventExecutor* executor)
20 : capture_thread_("CaptureThread"), 28 : main_loop_(kSimpleHostMessageLoopType),
29 capture_thread_("CaptureThread"),
21 encode_thread_("EncodeThread"), 30 encode_thread_("EncodeThread"),
22 username_(username), 31 username_(username),
23 password_(password), 32 password_(password),
24 capturer_(capturer), 33 capturer_(capturer),
25 encoder_(encoder), 34 encoder_(encoder),
26 executor_(executor) { 35 executor_(executor) {
27 } 36 }
28 37
29 void SimpleHost::Run() { 38 void SimpleHost::Run() {
30 DCHECK_EQ(&main_loop_, MessageLoop::current()); 39 DCHECK_EQ(&main_loop_, MessageLoop::current());
31 40
32 // Submit a task to perform host registration. We'll also start 41 // Submit a task to perform host registration. We'll also start
33 // listening to connection if registration is done. 42 // listening to connection if registration is done.
34 RegisterHost(); 43 RegisterHost();
35 44
36 // Run the main message loop. This is the main loop of this host 45 // Run the main message loop. This is the main loop of this host
37 // object. 46 // object.
38 main_loop_.Run(); 47 main_loop_.Run();
39 } 48 }
40 49
41 // This method is called when we need to the host process. 50 // This method is called when we need to destroy the host process.
42 void SimpleHost::DestroySession() { 51 void SimpleHost::DestroySession() {
43 DCHECK_EQ(&main_loop_, MessageLoop::current()); 52 DCHECK_EQ(&main_loop_, MessageLoop::current());
44 53
45 // First we tell the session to pause and then we wait until all 54 // First we tell the session to pause and then we wait until all
46 // the tasks are done. 55 // the tasks are done.
47 session_->Pause(); 56 session_->Pause();
48 57
49 // TODO(hclam): Revise the order. 58 // TODO(hclam): Revise the order.
50 encode_thread_.Stop(); 59 encode_thread_.Stop();
51 capture_thread_.Stop(); 60 capture_thread_.Stop();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void SimpleHost::OnClientDisconnected(ClientConnection* client) { 107 void SimpleHost::OnClientDisconnected(ClientConnection* client) {
99 DCHECK_EQ(&main_loop_, MessageLoop::current()); 108 DCHECK_EQ(&main_loop_, MessageLoop::current());
100 109
101 // Remove the client from the session manager. 110 // Remove the client from the session manager.
102 DCHECK(session_); 111 DCHECK(session_);
103 session_->RemoveClient(client); 112 session_->RemoveClient(client);
104 113
105 // Also remove reference to ClientConnection from this object. 114 // Also remove reference to ClientConnection from this object.
106 client_ = NULL; 115 client_ = NULL;
107 116
108 // TODO(hclam): If the last client has disconnected we need destroy 117 // TODO(hclam): If the last client has disconnected we need to destroy
109 // the session manager and shutdown the capture and encode threads. 118 // the session manager and shutdown the capture and encode threads.
110 // Right now we assume there's only one client. 119 // Right now we assume that there's only one client.
111 DestroySession(); 120 DestroySession();
112 } 121 }
113 122
114 //////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////
115 // ClientConnection::EventHandler implementations 124 // ClientConnection::EventHandler implementations
116 void SimpleHost::HandleMessages(ClientConnection* client, 125 void SimpleHost::HandleMessages(ClientConnection* client,
117 ClientMessageList* messages) { 126 ClientMessageList* messages) {
118 DCHECK_EQ(&main_loop_, MessageLoop::current()); 127 DCHECK_EQ(&main_loop_, MessageLoop::current());
119 128
120 // Delegate the messages to EventExecutor and delete the unhandled 129 // Delegate the messages to EventExecutor and delete the unhandled
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 scoped_refptr<JingleChannel> channel) { 201 scoped_refptr<JingleChannel> channel) {
193 DCHECK_EQ(jingle_client_.get(), jingle_client); 202 DCHECK_EQ(jingle_client_.get(), jingle_client);
194 203
195 // Since the session manager has not started, it is still safe to access 204 // Since the session manager has not started, it is still safe to access
196 // the client directly. Note that we give the ownership of the channel 205 // the client directly. Note that we give the ownership of the channel
197 // to the client. 206 // to the client.
198 client_->set_jingle_channel(channel); 207 client_->set_jingle_channel(channel);
199 } 208 }
200 209
201 } // namespace remoting 210 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698