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

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

Issue 2384063008: Enables delegating signal strategy for It2Me Host. (Closed)
Patch Set: Created 4 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 <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
17 #include "components/policy/policy_constants.h" 17 #include "components/policy/policy_constants.h"
18 #include "net/socket/client_socket_factory.h"
19 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
20 #include "remoting/base/auto_thread.h" 19 #include "remoting/base/auto_thread.h"
21 #include "remoting/base/chromium_url_request.h" 20 #include "remoting/base/chromium_url_request.h"
22 #include "remoting/base/logging.h" 21 #include "remoting/base/logging.h"
23 #include "remoting/base/rsa_key_pair.h" 22 #include "remoting/base/rsa_key_pair.h"
24 #include "remoting/host/chromoting_host.h" 23 #include "remoting/host/chromoting_host.h"
25 #include "remoting/host/chromoting_host_context.h" 24 #include "remoting/host/chromoting_host_context.h"
26 #include "remoting/host/host_event_logger.h" 25 #include "remoting/host/host_event_logger.h"
27 #include "remoting/host/host_secret.h" 26 #include "remoting/host/host_secret.h"
28 #include "remoting/host/host_status_logger.h" 27 #include "remoting/host/host_status_logger.h"
(...skipping 25 matching lines...) Expand all
54 typedef ValidatingAuthenticator::Result ValidationResult; 53 typedef ValidatingAuthenticator::Result ValidationResult;
55 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; 54 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback;
56 55
57 } // namespace 56 } // namespace
58 57
59 It2MeHost::It2MeHost( 58 It2MeHost::It2MeHost(
60 std::unique_ptr<ChromotingHostContext> host_context, 59 std::unique_ptr<ChromotingHostContext> host_context,
61 std::unique_ptr<PolicyWatcher> policy_watcher, 60 std::unique_ptr<PolicyWatcher> policy_watcher,
62 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog, 61 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog,
63 base::WeakPtr<It2MeHost::Observer> observer, 62 base::WeakPtr<It2MeHost::Observer> observer,
64 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 63 std::unique_ptr<SignalStrategy> signal_strategy,
64 const std::string& username,
65 const std::string& directory_bot_jid) 65 const std::string& directory_bot_jid)
66 : host_context_(std::move(host_context)), 66 : host_context_(std::move(host_context)),
67 observer_(observer), 67 observer_(observer),
68 xmpp_server_config_(xmpp_server_config), 68 signal_strategy_(std::move(signal_strategy)),
69 username_(username),
69 directory_bot_jid_(directory_bot_jid), 70 directory_bot_jid_(directory_bot_jid),
70 policy_watcher_(std::move(policy_watcher)), 71 policy_watcher_(std::move(policy_watcher)),
71 confirmation_dialog_(std::move(confirmation_dialog)) { 72 confirmation_dialog_(std::move(confirmation_dialog)) {
72 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); 73 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread());
73 } 74 }
74 75
75 It2MeHost::~It2MeHost() { 76 It2MeHost::~It2MeHost() {
76 // Check that resources that need to be torn down on the UI thread are gone. 77 // Check that resources that need to be torn down on the UI thread are gone.
77 DCHECK(!desktop_environment_factory_.get()); 78 DCHECK(!desktop_environment_factory_.get());
78 DCHECK(!policy_watcher_.get()); 79 DCHECK(!policy_watcher_.get());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void It2MeHost::FinishConnect() { 167 void It2MeHost::FinishConnect() {
167 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 168 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
168 169
169 if (state_ != kStarting) { 170 if (state_ != kStarting) {
170 // Host has been stopped while we were fetching policy. 171 // Host has been stopped while we were fetching policy.
171 return; 172 return;
172 } 173 }
173 174
174 // Check the host domain policy. 175 // Check the host domain policy.
175 if (!required_host_domain_.empty() && 176 if (!required_host_domain_.empty() &&
176 !base::EndsWith(xmpp_server_config_.username, 177 !base::EndsWith(username_,
177 std::string("@") + required_host_domain_, 178 std::string("@") + required_host_domain_,
178 base::CompareCase::INSENSITIVE_ASCII)) { 179 base::CompareCase::INSENSITIVE_ASCII)) {
179 SetState(kInvalidDomainError, ""); 180 SetState(kInvalidDomainError, "");
180 return; 181 return;
181 } 182 }
182 183
183 // Generate a key pair for the Host to use. 184 // Generate a key pair for the Host to use.
184 // TODO(wez): Move this to the worker thread. 185 // TODO(wez): Move this to the worker thread.
185 host_key_pair_ = RsaKeyPair::Generate(); 186 host_key_pair_ = RsaKeyPair::Generate();
186 187
187 // Create XMPP connection.
188 std::unique_ptr<SignalStrategy> signal_strategy(new XmppSignalStrategy(
189 net::ClientSocketFactory::GetDefaultFactory(),
190 host_context_->url_request_context_getter(), xmpp_server_config_));
191
192 // Request registration of the host for support. 188 // Request registration of the host for support.
193 std::unique_ptr<RegisterSupportHostRequest> register_request( 189 std::unique_ptr<RegisterSupportHostRequest> register_request(
194 new RegisterSupportHostRequest( 190 new RegisterSupportHostRequest(
195 signal_strategy.get(), host_key_pair_, directory_bot_jid_, 191 signal_strategy_.get(), host_key_pair_, directory_bot_jid_,
196 base::Bind(&It2MeHost::OnReceivedSupportID, base::Unretained(this)))); 192 base::Bind(&It2MeHost::OnReceivedSupportID, base::Unretained(this))));
197 193
198 // Beyond this point nothing can fail, so save the config and request. 194 // Beyond this point nothing can fail, so save the config and request.
199 signal_strategy_ = std::move(signal_strategy);
200 register_request_ = std::move(register_request); 195 register_request_ = std::move(register_request);
201 196
202 // If NAT traversal is off then limit port range to allow firewall pin-holing. 197 // If NAT traversal is off then limit port range to allow firewall pin-holing.
203 HOST_LOG << "NAT state: " << nat_traversal_enabled_; 198 HOST_LOG << "NAT state: " << nat_traversal_enabled_;
204 protocol::NetworkSettings network_settings( 199 protocol::NetworkSettings network_settings(
205 nat_traversal_enabled_ ? 200 nat_traversal_enabled_ ?
206 protocol::NetworkSettings::NAT_TRAVERSAL_FULL : 201 protocol::NetworkSettings::NAT_TRAVERSAL_FULL :
207 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED); 202 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED);
208 if (!nat_traversal_enabled_) { 203 if (!nat_traversal_enabled_) {
209 network_settings.port_range.min_port = 204 network_settings.port_range.min_port =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 host_status_logger_.reset( 237 host_status_logger_.reset(
243 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::IT2ME, 238 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::IT2ME,
244 signal_strategy_.get(), directory_bot_jid_)); 239 signal_strategy_.get(), directory_bot_jid_));
245 240
246 // Create event logger. 241 // Create event logger.
247 host_event_logger_ = 242 host_event_logger_ =
248 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); 243 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName);
249 244
250 // Connect signaling and start the host. 245 // Connect signaling and start the host.
251 signal_strategy_->Connect(); 246 signal_strategy_->Connect();
252 host_->Start(xmpp_server_config_.username); 247 host_->Start(username_);
253 248
254 SetState(kRequestedAccessCode, ""); 249 SetState(kRequestedAccessCode, "");
255 return; 250 return;
256 } 251 }
257 252
258 void It2MeHost::OnAccessDenied(const std::string& jid) { 253 void It2MeHost::OnAccessDenied(const std::string& jid) {
259 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 254 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
260 255
261 ++failed_login_attempts_; 256 ++failed_login_attempts_;
262 if (failed_login_attempts_ == kMaxLoginAttempts) { 257 if (failed_login_attempts_ == kMaxLoginAttempts) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 531 }
537 532
538 It2MeHostFactory::It2MeHostFactory() {} 533 It2MeHostFactory::It2MeHostFactory() {}
539 534
540 It2MeHostFactory::~It2MeHostFactory() {} 535 It2MeHostFactory::~It2MeHostFactory() {}
541 536
542 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( 537 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost(
543 std::unique_ptr<ChromotingHostContext> context, 538 std::unique_ptr<ChromotingHostContext> context,
544 policy::PolicyService* policy_service, 539 policy::PolicyService* policy_service,
545 base::WeakPtr<It2MeHost::Observer> observer, 540 base::WeakPtr<It2MeHost::Observer> observer,
546 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 541 std::unique_ptr<SignalStrategy> signal_strategy,
542 const std::string& username,
547 const std::string& directory_bot_jid) { 543 const std::string& directory_bot_jid) {
548 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); 544 DCHECK(context->ui_task_runner()->BelongsToCurrentThread());
549 545
550 std::unique_ptr<PolicyWatcher> policy_watcher = 546 std::unique_ptr<PolicyWatcher> policy_watcher =
551 PolicyWatcher::Create(policy_service, context->file_task_runner()); 547 PolicyWatcher::Create(policy_service, context->file_task_runner());
552 return new It2MeHost(std::move(context), std::move(policy_watcher), 548 return new It2MeHost(std::move(context), std::move(policy_watcher),
553 It2MeConfirmationDialog::Create(), observer, 549 It2MeConfirmationDialog::Create(), observer,
554 xmpp_server_config, directory_bot_jid); 550 std::move(signal_strategy), username, directory_bot_jid);
555 } 551 }
556 552
557 } // namespace remoting 553 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698