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

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

Issue 9617027: Chromoting: Implemented security attention sequence (SAS) emulation on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 9 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/plugin/host_script_object.cc ('k') | remoting/host/sas_injector.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 // This file implements a standalone host process for Me2Me, which is currently 5 // This file implements a standalone host process for Me2Me, which is currently
6 // used for the Linux-only Virtual Me2Me build. 6 // used for the Linux-only Virtual Me2Me build.
7 7
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/at_exit.h" 14 #include "base/at_exit.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/file_path.h" 18 #include "base/file_path.h"
19 #include "base/file_util.h" 19 #include "base/file_util.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/memory/scoped_ptr.h"
21 #include "base/message_loop.h" 22 #include "base/message_loop.h"
22 #include "base/path_service.h" 23 #include "base/path_service.h"
23 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #include "crypto/nss_util.h" 26 #include "crypto/nss_util.h"
26 #include "net/base/network_change_notifier.h" 27 #include "net/base/network_change_notifier.h"
27 #include "remoting/base/constants.h" 28 #include "remoting/base/constants.h"
28 #include "remoting/host/capturer.h" 29 #include "remoting/host/capturer.h"
29 #include "remoting/host/chromoting_host.h" 30 #include "remoting/host/chromoting_host.h"
30 #include "remoting/host/chromoting_host_context.h" 31 #include "remoting/host/chromoting_host_context.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 79
79 } // namespace 80 } // namespace
80 81
81 namespace remoting { 82 namespace remoting {
82 83
83 class HostProcess { 84 class HostProcess {
84 public: 85 public:
85 HostProcess() 86 HostProcess()
86 : message_loop_(MessageLoop::TYPE_UI), 87 : message_loop_(MessageLoop::TYPE_UI),
87 file_io_thread_("FileIO"), 88 file_io_thread_("FileIO"),
88 context_(message_loop_.message_loop_proxy()),
89 allow_nat_traversal_(true), 89 allow_nat_traversal_(true),
90 restarting_(false) { 90 restarting_(false) {
91 context_.Start();
92 file_io_thread_.StartWithOptions( 91 file_io_thread_.StartWithOptions(
93 base::Thread::Options(MessageLoop::TYPE_IO, 0)); 92 base::Thread::Options(MessageLoop::TYPE_IO, 0));
93
94 context_.reset(new ChromotingHostContext(
95 file_io_thread_.message_loop_proxy(),
96 message_loop_.message_loop_proxy()));
97 context_->Start();
94 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 98 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
95 } 99 }
96 100
97 void InitWithCommandLine(const CommandLine* cmd_line) { 101 void InitWithCommandLine(const CommandLine* cmd_line) {
98 FilePath default_config_dir = GetDefaultConfigDir(); 102 FilePath default_config_dir = GetDefaultConfigDir();
99 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { 103 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
100 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); 104 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
101 } else { 105 } else {
102 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); 106 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile);
103 } 107 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // chromiumsync because we do not have an HTTP stack with which we can 184 // chromiumsync because we do not have an HTTP stack with which we can
181 // easily request an OAuth2 access token even if we had a RefreshToken for 185 // easily request an OAuth2 access token even if we had a RefreshToken for
182 // the account. 186 // the account.
183 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; 187 xmpp_auth_service_ = kChromotingTokenDefaultServiceName;
184 } 188 }
185 189
186 return true; 190 return true;
187 } 191 }
188 192
189 void OnNatPolicyUpdate(bool nat_traversal_enabled) { 193 void OnNatPolicyUpdate(bool nat_traversal_enabled) {
190 if (!context_.network_message_loop()->BelongsToCurrentThread()) { 194 if (!context_->network_message_loop()->BelongsToCurrentThread()) {
191 context_.network_message_loop()->PostTask(FROM_HERE, base::Bind( 195 context_->network_message_loop()->PostTask(FROM_HERE, base::Bind(
192 &HostProcess::OnNatPolicyUpdate, base::Unretained(this), 196 &HostProcess::OnNatPolicyUpdate, base::Unretained(this),
193 nat_traversal_enabled)); 197 nat_traversal_enabled));
194 return; 198 return;
195 } 199 }
196 200
197 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled; 201 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled;
198 allow_nat_traversal_ = nat_traversal_enabled; 202 allow_nat_traversal_ = nat_traversal_enabled;
199 203
200 if (host_) { 204 if (host_) {
201 // Restart the host if the policy has changed while the host was 205 // Restart the host if the policy has changed while the host was
202 // online. 206 // online.
203 if (policy_changed) 207 if (policy_changed)
204 RestartHost(); 208 RestartHost();
205 } else { 209 } else {
206 // Just start the host otherwise. 210 // Just start the host otherwise.
207 StartHost(); 211 StartHost();
208 } 212 }
209 } 213 }
210 214
211 void StartHost() { 215 void StartHost() {
212 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); 216 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
213 DCHECK(!host_); 217 DCHECK(!host_);
214 218
215 if (!signal_strategy_.get()) { 219 if (!signal_strategy_.get()) {
216 signal_strategy_.reset( 220 signal_strategy_.reset(
217 new XmppSignalStrategy(context_.jingle_thread(), xmpp_login_, 221 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login_,
218 xmpp_auth_token_, xmpp_auth_service_)); 222 xmpp_auth_token_, xmpp_auth_service_));
219 signaling_connector_.reset( 223 signaling_connector_.reset(
220 new SignalingConnector(signal_strategy_.get())); 224 new SignalingConnector(signal_strategy_.get()));
221 } 225 }
222 226
223 if (!desktop_environment_.get()) 227 if (!desktop_environment_.get())
224 desktop_environment_.reset(DesktopEnvironment::Create(&context_)); 228 desktop_environment_ = DesktopEnvironment::Create(context_.get());
225 229
226 protocol::NetworkSettings network_settings(allow_nat_traversal_); 230 protocol::NetworkSettings network_settings(allow_nat_traversal_);
227 if (!allow_nat_traversal_) { 231 if (!allow_nat_traversal_) {
228 network_settings.min_port = kMinPortNumber; 232 network_settings.min_port = kMinPortNumber;
229 network_settings.max_port = kMaxPortNumber; 233 network_settings.max_port = kMaxPortNumber;
230 } 234 }
231 235
232 host_ = new ChromotingHost( 236 host_ = new ChromotingHost(
233 &context_, signal_strategy_.get(), desktop_environment_.get(), 237 context_.get(), signal_strategy_.get(), desktop_environment_.get(),
234 network_settings); 238 network_settings);
235 239
236 heartbeat_sender_.reset( 240 heartbeat_sender_.reset(
237 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); 241 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_));
238 242
239 log_to_server_.reset( 243 log_to_server_.reset(
240 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); 244 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get()));
241 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 245 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
242 246
243 host_->Start(); 247 host_->Start();
244 248
245 // Create authenticator factory. 249 // Create authenticator factory.
246 scoped_ptr<protocol::AuthenticatorFactory> factory( 250 scoped_ptr<protocol::AuthenticatorFactory> factory(
247 new protocol::Me2MeHostAuthenticatorFactory( 251 new protocol::Me2MeHostAuthenticatorFactory(
248 xmpp_login_, key_pair_.GenerateCertificate(), 252 xmpp_login_, key_pair_.GenerateCertificate(),
249 *key_pair_.private_key(), host_secret_hash_)); 253 *key_pair_.private_key(), host_secret_hash_));
250 host_->SetAuthenticatorFactory(factory.Pass()); 254 host_->SetAuthenticatorFactory(factory.Pass());
251 } 255 }
252 256
253 void RestartHost() { 257 void RestartHost() {
254 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); 258 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
255 259
256 if (restarting_) 260 if (restarting_)
257 return; 261 return;
258 262
259 restarting_ = true; 263 restarting_ = true;
260 host_->Shutdown(base::Bind( 264 host_->Shutdown(base::Bind(
261 &HostProcess::RestartOnHostShutdown, base::Unretained(this))); 265 &HostProcess::RestartOnHostShutdown, base::Unretained(this)));
262 } 266 }
263 267
264 void RestartOnHostShutdown() { 268 void RestartOnHostShutdown() {
265 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); 269 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
266 270
267 restarting_ = false; 271 restarting_ = false;
268 272
269 host_ = NULL; 273 host_ = NULL;
270 log_to_server_.reset(); 274 log_to_server_.reset();
271 host_event_logger_.reset(); 275 host_event_logger_.reset();
272 heartbeat_sender_.reset(); 276 heartbeat_sender_.reset();
273 277
274 StartHost(); 278 StartHost();
275 } 279 }
276 280
277 MessageLoop message_loop_; 281 MessageLoop message_loop_;
278 base::Thread file_io_thread_; 282 base::Thread file_io_thread_;
279 ChromotingHostContext context_; 283 scoped_ptr<ChromotingHostContext> context_;
280 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 284 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
281 285
282 FilePath auth_config_path_; 286 FilePath auth_config_path_;
283 FilePath host_config_path_; 287 FilePath host_config_path_;
284 288
285 std::string host_id_; 289 std::string host_id_;
286 HostKeyPair key_pair_; 290 HostKeyPair key_pair_;
287 protocol::SharedSecretHash host_secret_hash_; 291 protocol::SharedSecretHash host_secret_hash_;
288 std::string xmpp_login_; 292 std::string xmpp_login_;
289 std::string xmpp_auth_token_; 293 std::string xmpp_auth_token_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 int CALLBACK WinMain(HINSTANCE instance, 336 int CALLBACK WinMain(HINSTANCE instance,
333 HINSTANCE previous_instance, 337 HINSTANCE previous_instance,
334 LPSTR command_line, 338 LPSTR command_line,
335 int show_command) { 339 int show_command) {
336 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 340 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
337 // the command line from GetCommandLineW(), so we can safely pass NULL here. 341 // the command line from GetCommandLineW(), so we can safely pass NULL here.
338 return main(0, NULL); 342 return main(0, NULL);
339 } 343 }
340 344
341 #endif 345 #endif
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.cc ('k') | remoting/host/sas_injector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698