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

Side by Side Diff: remoting/host/it2me/it2me_host.cc

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ChromotingHostContext cleanup Created 6 years, 2 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/it2me/it2me_host.h" 5 #include "remoting/host/it2me/it2me_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
11 #include "net/socket/client_socket_factory.h" 10 #include "net/socket/client_socket_factory.h"
12 #include "remoting/base/auto_thread.h" 11 #include "remoting/base/auto_thread.h"
13 #include "remoting/base/logging.h" 12 #include "remoting/base/logging.h"
14 #include "remoting/base/rsa_key_pair.h" 13 #include "remoting/base/rsa_key_pair.h"
15 #include "remoting/host/chromoting_host.h" 14 #include "remoting/host/chromoting_host.h"
16 #include "remoting/host/chromoting_host_context.h" 15 #include "remoting/host/chromoting_host_context.h"
17 #include "remoting/host/host_event_logger.h" 16 #include "remoting/host/host_event_logger.h"
18 #include "remoting/host/host_secret.h" 17 #include "remoting/host/host_secret.h"
19 #include "remoting/host/host_status_logger.h" 18 #include "remoting/host/host_status_logger.h"
20 #include "remoting/host/it2me_desktop_environment.h" 19 #include "remoting/host/it2me_desktop_environment.h"
21 #include "remoting/host/policy_hack/policy_watcher.h" 20 #include "remoting/host/policy_hack/policy_watcher.h"
22 #include "remoting/host/register_support_host_request.h" 21 #include "remoting/host/register_support_host_request.h"
23 #include "remoting/host/session_manager_factory.h" 22 #include "remoting/host/session_manager_factory.h"
24 #include "remoting/protocol/it2me_host_authenticator_factory.h" 23 #include "remoting/protocol/it2me_host_authenticator_factory.h"
25 #include "remoting/protocol/network_settings.h" 24 #include "remoting/protocol/network_settings.h"
26 #include "remoting/signaling/server_log_entry.h" 25 #include "remoting/signaling/server_log_entry.h"
27 26
28 namespace remoting { 27 namespace remoting {
29 28
30 namespace { 29 namespace {
31 30
32 // This is used for tagging system event logs. 31 // This is used for tagging system event logs.
33 const char kApplicationName[] = "chromoting"; 32 const char kApplicationName[] = "chromoting";
34 const int kMaxLoginAttempts = 5; 33 const int kMaxLoginAttempts = 5;
35 34
36 } // namespace 35 } // namespace
37 36
38 It2MeHost::It2MeHost( 37 It2MeHost::It2MeHost(
39 ChromotingHostContext* host_context, 38 scoped_ptr<ChromotingHostContext> host_context,
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 39 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher,
41 base::WeakPtr<It2MeHost::Observer> observer, 40 base::WeakPtr<It2MeHost::Observer> observer,
42 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 41 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
43 const std::string& directory_bot_jid) 42 const std::string& directory_bot_jid)
44 : host_context_(host_context), 43 : host_context_(host_context.Pass()),
45 task_runner_(task_runner), 44 task_runner_(host_context_->ui_task_runner()),
46 observer_(observer), 45 observer_(observer),
47 xmpp_server_config_(xmpp_server_config), 46 xmpp_server_config_(xmpp_server_config),
48 directory_bot_jid_(directory_bot_jid), 47 directory_bot_jid_(directory_bot_jid),
49 state_(kDisconnected), 48 state_(kDisconnected),
50 failed_login_attempts_(0), 49 failed_login_attempts_(0),
50 policy_watcher_(policy_watcher.Pass()),
51 nat_traversal_enabled_(false), 51 nat_traversal_enabled_(false),
52 policy_received_(false) { 52 policy_received_(false) {
53 DCHECK(task_runner_->BelongsToCurrentThread()); 53 DCHECK(task_runner_->BelongsToCurrentThread());
54 } 54 }
55 55
56 void It2MeHost::Connect() { 56 void It2MeHost::Connect() {
57 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { 57 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) {
58 DCHECK(task_runner_->BelongsToCurrentThread()); 58 DCHECK(task_runner_->BelongsToCurrentThread());
59 host_context_->ui_task_runner()->PostTask( 59 host_context_->ui_task_runner()->PostTask(
60 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); 60 FROM_HERE, base::Bind(&It2MeHost::Connect, this));
61 return; 61 return;
62 } 62 }
63 63
64 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( 64 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory(
65 host_context_->network_task_runner(), 65 host_context_->network_task_runner(),
66 host_context_->input_task_runner(), 66 host_context_->input_task_runner(),
67 host_context_->ui_task_runner())); 67 host_context_->ui_task_runner()));
68 68
69 // Start monitoring configured policies. 69 // Start monitoring configured policies.
70 policy_watcher_.reset( 70 policy_watcher_->StartWatching(base::Bind(&It2MeHost::OnPolicyUpdate, this));
71 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner()));
72 policy_watcher_->StartWatching(
73 base::Bind(&It2MeHost::OnPolicyUpdate, this));
74 71
75 // Switch to the network thread to start the actual connection. 72 // Switch to the network thread to start the actual connection.
76 host_context_->network_task_runner()->PostTask( 73 host_context_->network_task_runner()->PostTask(
77 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); 74 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this));
78 } 75 }
79 76
80 void It2MeHost::Disconnect() { 77 void It2MeHost::Disconnect() {
81 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 78 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
82 DCHECK(task_runner_->BelongsToCurrentThread()); 79 DCHECK(task_runner_->BelongsToCurrentThread());
83 host_context_->network_task_runner()->PostTask( 80 host_context_->network_task_runner()->PostTask(
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 247 }
251 248
252 void It2MeHost::ShutdownOnUiThread() { 249 void It2MeHost::ShutdownOnUiThread() {
253 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); 250 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread());
254 251
255 // Destroy the DesktopEnvironmentFactory, to free thread references. 252 // Destroy the DesktopEnvironmentFactory, to free thread references.
256 desktop_environment_factory_.reset(); 253 desktop_environment_factory_.reset();
257 254
258 // Stop listening for policy updates. 255 // Stop listening for policy updates.
259 if (policy_watcher_.get()) { 256 if (policy_watcher_.get()) {
260 base::WaitableEvent policy_watcher_stopped_(true, false); 257 policy_watcher_->StopWatching(
261 policy_watcher_->StopWatching(&policy_watcher_stopped_); 258 base::Bind(&It2MeHost::OnPolicyWatcherShutdown, this));
262 policy_watcher_stopped_.Wait(); 259 return;
263 policy_watcher_.reset();
264 } 260 }
265 } 261 }
266 262
263 void It2MeHost::OnPolicyWatcherShutdown() {
264 policy_watcher_.reset();
265 }
266
267 void It2MeHost::OnAccessDenied(const std::string& jid) { 267 void It2MeHost::OnAccessDenied(const std::string& jid) {
268 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 268 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
269 269
270 ++failed_login_attempts_; 270 ++failed_login_attempts_;
271 if (failed_login_attempts_ == kMaxLoginAttempts) { 271 if (failed_login_attempts_ == kMaxLoginAttempts) {
272 Disconnect(); 272 Disconnect();
273 } 273 }
274 } 274 }
275 275
276 void It2MeHost::OnClientAuthenticated(const std::string& jid) { 276 void It2MeHost::OnClientAuthenticated(const std::string& jid) {
(...skipping 27 matching lines...) Expand all
304 SetState(kConnected); 304 SetState(kConnected);
305 } 305 }
306 306
307 void It2MeHost::OnClientDisconnected(const std::string& jid) { 307 void It2MeHost::OnClientDisconnected(const std::string& jid) {
308 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 308 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
309 309
310 Disconnect(); 310 Disconnect();
311 } 311 }
312 312
313 void It2MeHost::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { 313 void It2MeHost::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) {
314 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 314 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
Wez 2014/10/24 00:28:48 Previous code assumed/required that this be called
kelvinp 2014/10/24 21:39:42 Because on ChromeOS, the policy_watcher runs in th
Wez 2014/10/24 23:29:26 Right, and on other platforms it runs on some othe
kelvinp 2014/10/29 01:22:51 The policy watcher supports being called from any
315 host_context_->network_task_runner()->PostTask(
316 FROM_HERE,
317 base::Bind(&It2MeHost::OnPolicyUpdate, this, base::Passed(&policies)));
318 return;
319 }
315 320
316 bool nat_policy; 321 bool nat_policy;
317 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, 322 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName,
318 &nat_policy)) { 323 &nat_policy)) {
319 UpdateNatPolicy(nat_policy); 324 UpdateNatPolicy(nat_policy);
320 } 325 }
321 std::string host_domain; 326 std::string host_domain;
322 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, 327 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName,
323 &host_domain)) { 328 &host_domain)) {
324 UpdateHostDomainPolicy(host_domain); 329 UpdateHostDomainPolicy(host_domain);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 host_->SetAuthenticatorFactory(factory.Pass()); 457 host_->SetAuthenticatorFactory(factory.Pass());
453 458
454 // Pass the Access Code to the script object before changing state. 459 // Pass the Access Code to the script object before changing state.
455 task_runner_->PostTask( 460 task_runner_->PostTask(
456 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, 461 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode,
457 observer_, access_code, lifetime)); 462 observer_, access_code, lifetime));
458 463
459 SetState(kReceivedAccessCode); 464 SetState(kReceivedAccessCode);
460 } 465 }
461 466
462 It2MeHostFactory::It2MeHostFactory() {} 467 It2MeHostFactory::It2MeHostFactory(policy::PolicyService* policy_service)
468 : policy_service_(policy_service) {
469 }
463 470
464 It2MeHostFactory::~It2MeHostFactory() {} 471 It2MeHostFactory::~It2MeHostFactory() {}
465 472
466 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( 473 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost(
467 ChromotingHostContext* context, 474 scoped_ptr<ChromotingHostContext> context,
468 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
469 base::WeakPtr<It2MeHost::Observer> observer, 475 base::WeakPtr<It2MeHost::Observer> observer,
470 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 476 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
471 const std::string& directory_bot_jid) { 477 const std::string& directory_bot_jid) {
472 return new It2MeHost( 478 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher =
473 context, task_runner, observer, xmpp_server_config, directory_bot_jid); 479 policy_hack::PolicyWatcher::Create(policy_service_,
480 context->network_task_runner());
481 return new It2MeHost(context.Pass(), policy_watcher.Pass(), observer,
482 xmpp_server_config, directory_bot_jid);
474 } 483 }
475 484
476 } // namespace remoting 485 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698