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

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

Issue 2745006: Implement a chromoting client using X11 (Closed)
Patch Set: removed all.gyp 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
« no previous file with comments | « remoting/host/session_manager_unittest.cc ('k') | 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"
(...skipping 26 matching lines...) Expand all
37 // object. 37 // object.
38 main_loop_.Run(); 38 main_loop_.Run();
39 } 39 }
40 40
41 // This method is called when we need to the host process. 41 // This method is called when we need to the host process.
42 void SimpleHost::DestroySession() { 42 void SimpleHost::DestroySession() {
43 DCHECK_EQ(&main_loop_, MessageLoop::current()); 43 DCHECK_EQ(&main_loop_, MessageLoop::current());
44 44
45 // First we tell the session to pause and then we wait until all 45 // First we tell the session to pause and then we wait until all
46 // the tasks are done. 46 // the tasks are done.
47 session_->Pause(); 47 if (session_.get()) {
48 session_->Pause();
48 49
49 // TODO(hclam): Revise the order. 50 // TODO(hclam): Revise the order.
50 encode_thread_.Stop(); 51 DCHECK(encode_thread_.IsRunning());
51 capture_thread_.Stop(); 52 encode_thread_.Stop();
53
54 DCHECK(capture_thread_.IsRunning());
55 capture_thread_.Stop();
56 }
52 } 57 }
53 58
54 // This method talks to the cloud to register the host process. If 59 // This method talks to the cloud to register the host process. If
55 // successful we will start listening to network requests. 60 // successful we will start listening to network requests.
56 void SimpleHost::RegisterHost() { 61 void SimpleHost::RegisterHost() {
57 DCHECK_EQ(&main_loop_, MessageLoop::current()); 62 DCHECK_EQ(&main_loop_, MessageLoop::current());
58 DCHECK(!jingle_client_); 63 DCHECK(!jingle_client_);
59 64
60 // Connect to the talk network with a JingleClient. 65 // Connect to the talk network with a JingleClient.
61 jingle_client_ = new JingleClient(); 66 jingle_client_ = new JingleClient();
62 jingle_client_->Init(username_, password_, this); 67 jingle_client_->Init(username_, password_, this);
63 } 68 }
64 69
65 // This method is called if a client is connected to this object. 70 // This method is called if a client is connected to this object.
66 void SimpleHost::OnClientConnected(ClientConnection* client) { 71 void SimpleHost::OnClientConnected(ClientConnection* client) {
67 DCHECK_EQ(&main_loop_, MessageLoop::current()); 72 DCHECK_EQ(&main_loop_, MessageLoop::current());
68 73
69 // Create a new RecordSession if there was none. 74 // Create a new RecordSession if there was none.
70 if (!session_) { 75 if (!session_.get()) {
71 // The first we need to make sure capture and encode thread are 76 // The first we need to make sure capture and encode thread are
72 // running. 77 // running.
73 capture_thread_.Start(); 78 capture_thread_.Start();
74 encode_thread_.Start(); 79 encode_thread_.Start();
75 80
76 // Then we create a SessionManager passing the message loops that 81 // Then we create a SessionManager passing the message loops that
77 // it should run on. 82 // it should run on.
78 // Note that we pass the ownership of the capturer and encoder to 83 // Note that we pass the ownership of the capturer and encoder to
79 // the session manager. 84 // the session manager.
80 DCHECK(capturer_.get()); 85 DCHECK(capturer_.get());
(...skipping 11 matching lines...) Expand all
92 } else { 97 } else {
93 // If a session manager already exists we simply add the new client. 98 // If a session manager already exists we simply add the new client.
94 session_->AddClient(client); 99 session_->AddClient(client);
95 } 100 }
96 } 101 }
97 102
98 void SimpleHost::OnClientDisconnected(ClientConnection* client) { 103 void SimpleHost::OnClientDisconnected(ClientConnection* client) {
99 DCHECK_EQ(&main_loop_, MessageLoop::current()); 104 DCHECK_EQ(&main_loop_, MessageLoop::current());
100 105
101 // Remove the client from the session manager. 106 // Remove the client from the session manager.
102 DCHECK(session_); 107 if (session_.get())
103 session_->RemoveClient(client); 108 session_->RemoveClient(client);
104 109
105 // Also remove reference to ClientConnection from this object. 110 // Also remove reference to ClientConnection from this object.
106 client_ = NULL; 111 client_ = NULL;
107 112
108 // TODO(hclam): If the last client has disconnected we need destroy 113 // TODO(hclam): If the last client has disconnected we need destroy
109 // the session manager and shutdown the capture and encode threads. 114 // the session manager and shutdown the capture and encode threads.
110 // Right now we assume there's only one client. 115 // Right now we assume there's only one client.
111 DestroySession(); 116 DestroySession();
112 } 117 }
113 118
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 OnClientDisconnected(client_.get()); 153 OnClientDisconnected(client_.get());
149 } 154 }
150 155
151 //////////////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////////////
152 // JingleClient::Callback implementations 157 // JingleClient::Callback implementations
153 void SimpleHost::OnStateChange(JingleClient* jingle_client, 158 void SimpleHost::OnStateChange(JingleClient* jingle_client,
154 JingleClient::State state) { 159 JingleClient::State state) {
155 DCHECK_EQ(jingle_client_.get(), jingle_client); 160 DCHECK_EQ(jingle_client_.get(), jingle_client);
156 161
157 if (state == JingleClient::CONNECTED) { 162 if (state == JingleClient::CONNECTED) {
158 // TODO(hclam): Change to use LOG(INFO). 163 LOG(INFO) << "Host connected as "
159 // LOG(INFO) << "Host connected as " 164 << jingle_client->GetFullJid() << "." << std::endl;
160 // << jingle_client->GetFullJid() << "." << std::endl;
161 printf("Host connected as %s\n", jingle_client->GetFullJid().c_str());
162 165
163 // Start heartbeating after we connected 166 // Start heartbeating after we connected
164 heartbeat_sender_ = new HeartbeatSender(); 167 heartbeat_sender_ = new HeartbeatSender();
165 // TODO(sergeyu): where do we get host id? 168 // TODO(sergeyu): where do we get host id?
166 heartbeat_sender_->Start(jingle_client_.get(), "HostID"); 169 heartbeat_sender_->Start(jingle_client_.get(), "HostID");
167 } else if (state == JingleClient::CLOSED) { 170 } else if (state == JingleClient::CLOSED) {
168 LOG(INFO) << "Host disconnected from talk network." << std::endl; 171 LOG(INFO) << "Host disconnected from talk network." << std::endl;
172 heartbeat_sender_ = NULL;
169 173
170 heartbeat_sender_ = NULL; 174 // Quit the message loop if disconected.
175 main_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask());
171 } 176 }
172 } 177 }
173 178
174 bool SimpleHost::OnAcceptConnection( 179 bool SimpleHost::OnAcceptConnection(
175 JingleClient* jingle_client, const std::string& jid, 180 JingleClient* jingle_client, const std::string& jid,
176 JingleChannel::Callback** channel_callback) { 181 JingleChannel::Callback** channel_callback) {
177 DCHECK_EQ(jingle_client_.get(), jingle_client); 182 DCHECK_EQ(jingle_client_.get(), jingle_client);
178 183
184 // TODO(hclam): Allow multiple clients to connect to the host.
179 if (client_.get()) 185 if (client_.get())
180 return false; 186 return false;
181 187
182 LOG(INFO) << "Client connected: " << jid << std::endl; 188 LOG(INFO) << "Client connected: " << jid << std::endl;
183 189
184 // If we accept the connected then create a client object and set the 190 // If we accept the connected then create a client object and set the
185 // callback. 191 // callback.
186 client_ = new ClientConnection(&main_loop_, new ProtocolDecoder(), this); 192 client_ = new ClientConnection(&main_loop_, new ProtocolDecoder(), this);
187 *channel_callback = client_.get(); 193 *channel_callback = client_.get();
188 return true; 194 return true;
189 } 195 }
190 196
191 void SimpleHost::OnNewConnection(JingleClient* jingle_client, 197 void SimpleHost::OnNewConnection(JingleClient* jingle_client,
192 scoped_refptr<JingleChannel> channel) { 198 scoped_refptr<JingleChannel> channel) {
193 DCHECK_EQ(jingle_client_.get(), jingle_client); 199 DCHECK_EQ(jingle_client_.get(), jingle_client);
194 200
195 // Since the session manager has not started, it is still safe to access 201 // 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 202 // the client directly. Note that we give the ownership of the channel
197 // to the client. 203 // to the client.
198 client_->set_jingle_channel(channel); 204 client_->set_jingle_channel(channel);
199 } 205 }
200 206
201 } // namespace remoting 207 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/session_manager_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698