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

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

Issue 2310303002: Moving It2Me confirmation prompt into the Validation callback flow (Closed)
Patch Set: Fixing a DCHECK issue. Created 4 years, 3 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>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 host_context_->video_capture_task_runner(), 92 host_context_->video_capture_task_runner(),
93 host_context_->input_task_runner(), host_context_->ui_task_runner())); 93 host_context_->input_task_runner(), host_context_->ui_task_runner()));
94 94
95 // Start monitoring configured policies. 95 // Start monitoring configured policies.
96 policy_watcher_->StartWatching( 96 policy_watcher_->StartWatching(
97 base::Bind(&It2MeHost::OnPolicyUpdate, this), 97 base::Bind(&It2MeHost::OnPolicyUpdate, this),
98 base::Bind(&It2MeHost::OnPolicyError, this)); 98 base::Bind(&It2MeHost::OnPolicyError, this));
99 99
100 // Switch to the network thread to start the actual connection. 100 // Switch to the network thread to start the actual connection.
101 host_context_->network_task_runner()->PostTask( 101 host_context_->network_task_runner()->PostTask(
102 FROM_HERE, base::Bind(&It2MeHost::ShowConfirmationPrompt, this)); 102 FROM_HERE, base::Bind(&It2MeHost::SetState, this, kStarting, ""));
Sergey Ulanov 2016/09/09 18:50:40 Call SetState() in ReadPolicyAndConnect()?
joedow 2016/09/10 02:50:36 Done.
103
104 host_context_->network_task_runner()->PostTask(
105 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this));
103 } 106 }
104 107
105 void It2MeHost::Disconnect() { 108 void It2MeHost::Disconnect() {
106 DCHECK(task_runner_->BelongsToCurrentThread()); 109 DCHECK(task_runner_->BelongsToCurrentThread());
107 host_context_->network_task_runner()->PostTask( 110 host_context_->network_task_runner()->PostTask(
108 FROM_HERE, base::Bind(&It2MeHost::DisconnectOnNetworkThread, this)); 111 FROM_HERE, base::Bind(&It2MeHost::DisconnectOnNetworkThread, this));
109 } 112 }
110 113
111 void It2MeHost::DisconnectOnNetworkThread() { 114 void It2MeHost::DisconnectOnNetworkThread() {
112 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 115 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
(...skipping 30 matching lines...) Expand all
143 DCHECK(task_runner_->BelongsToCurrentThread()); 146 DCHECK(task_runner_->BelongsToCurrentThread());
144 host_context_->network_task_runner()->PostTask( 147 host_context_->network_task_runner()->PostTask(
145 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this)); 148 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this));
146 return; 149 return;
147 } 150 }
148 151
149 if (policy_received_) 152 if (policy_received_)
150 UpdateNatPolicy(nat_traversal_enabled_); 153 UpdateNatPolicy(nat_traversal_enabled_);
151 } 154 }
152 155
153 void It2MeHost::ShowConfirmationPrompt() {
154 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
155
156 SetState(kStarting, "");
157
158 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog =
159 confirmation_dialog_factory_->Create();
160
161 // TODO(dcaiafa): Remove after dialog implementations for all platforms exist.
162 if (!confirmation_dialog) {
163 ReadPolicyAndConnect();
164 return;
165 }
166
167 confirmation_dialog_proxy_.reset(
168 new It2MeConfirmationDialogProxy(host_context_->ui_task_runner(),
169 std::move(confirmation_dialog)));
170
171 confirmation_dialog_proxy_->Show(
172 base::Bind(&It2MeHost::OnConfirmationResult, base::Unretained(this)));
173 }
174
175 void It2MeHost::OnConfirmationResult(It2MeConfirmationDialog::Result result) {
176 switch (result) {
177 case It2MeConfirmationDialog::Result::OK:
178 ReadPolicyAndConnect();
179 break;
180
181 case It2MeConfirmationDialog::Result::CANCEL:
182 DisconnectOnNetworkThread();
183 break;
184
185 default:
186 NOTREACHED();
187 return;
188 }
189 }
190
191 void It2MeHost::ReadPolicyAndConnect() { 156 void It2MeHost::ReadPolicyAndConnect() {
192 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 157 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
193 DCHECK_EQ(kStarting, state_); 158 DCHECK_EQ(kStarting, state_);
194 159
195 // Only proceed to FinishConnect() if at least one policy update has been 160 // Only proceed to FinishConnect() if at least one policy update has been
196 // received. 161 // received. Otherwise, create the policy watcher and thunk the connect.
197 if (policy_received_) { 162 if (policy_received_) {
198 FinishConnect(); 163 FinishConnect();
199 } else { 164 } else {
200 // Otherwise, create the policy watcher, and thunk the connect. 165 pending_connect_ = base::Bind(&It2MeHost::FinishConnect, this);
201 pending_connect_ =
202 base::Bind(&It2MeHost::FinishConnect, this);
203 } 166 }
204 } 167 }
205 168
206 void It2MeHost::FinishConnect() { 169 void It2MeHost::FinishConnect() {
207 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 170 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
208 171
209 if (state_ != kStarting) { 172 if (state_ != kStarting) {
210 // Host has been stopped while we were fetching policy. 173 // Host has been stopped while we were fetching policy.
211 return; 174 return;
212 } 175 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 267 }
305 } 268 }
306 269
307 void It2MeHost::OnClientConnected(const std::string& jid) { 270 void It2MeHost::OnClientConnected(const std::string& jid) {
308 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 271 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
309 272
310 // ChromotingHost doesn't allow multiple concurrent connection and the 273 // ChromotingHost doesn't allow multiple concurrent connection and the
311 // host is destroyed in OnClientDisconnected() after the first connection. 274 // host is destroyed in OnClientDisconnected() after the first connection.
312 CHECK_NE(state_, kConnected); 275 CHECK_NE(state_, kConnected);
313 276
314 std::string client_username = jid; 277 std::string client_username;
315 size_t pos = client_username.find('/'); 278 if (!SplitJidResource(jid, &client_username, /*resource=*/nullptr)) {
316 if (pos != std::string::npos) 279 LOG(WARNING) << "Incorrectly formatted JID received: " << jid;
317 client_username.replace(pos, std::string::npos, ""); 280 client_username = jid;
281 }
318 282
319 HOST_LOG << "Client " << client_username << " connected."; 283 HOST_LOG << "Client " << client_username << " connected.";
320 284
321 // Pass the client user name to the script object before changing state. 285 // Pass the client user name to the script object before changing state.
322 task_runner_->PostTask( 286 task_runner_->PostTask(
323 FROM_HERE, base::Bind(&It2MeHost::Observer::OnClientAuthenticated, 287 FROM_HERE, base::Bind(&It2MeHost::Observer::OnClientAuthenticated,
324 observer_, client_username)); 288 observer_, client_username));
325 289
326 SetState(kConnected, ""); 290 SetState(kConnected, "");
327 } 291 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 task_runner_->PostTask( 479 task_runner_->PostTask(
516 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, 480 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode,
517 observer_, access_code, lifetime)); 481 observer_, access_code, lifetime));
518 482
519 SetState(kReceivedAccessCode, ""); 483 SetState(kReceivedAccessCode, "");
520 } 484 }
521 485
522 void It2MeHost::ValidateConnectionDetails( 486 void It2MeHost::ValidateConnectionDetails(
523 const std::string& remote_jid, 487 const std::string& remote_jid,
524 const protocol::ValidatingAuthenticator::ResultCallback& result_callback) { 488 const protocol::ValidatingAuthenticator::ResultCallback& result_callback) {
489 // First ensure the JID we received is valid.
490 std::string client_username;
491 if (!SplitJidResource(remote_jid, &client_username, /*resource=*/nullptr)) {
492 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid
493 << ": Invalid JID.";
494 result_callback.Run(
495 protocol::ValidatingAuthenticator::Result::ERROR_INVALID_ACCOUNT);
496 return;
497 }
498
525 // Check the client domain policy. 499 // Check the client domain policy.
526 if (!required_client_domain_.empty()) { 500 if (!required_client_domain_.empty()) {
527 std::string client_username;
528 if (!SplitJidResource(remote_jid, &client_username, /*resource=*/nullptr)) {
529 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid
530 << ": Invalid JID.";
531 result_callback.Run(ValidationResult::ERROR_INVALID_ACCOUNT);
532 return;
533 }
534 if (!base::EndsWith(client_username, 501 if (!base::EndsWith(client_username,
535 std::string("@") + required_client_domain_, 502 std::string("@") + required_client_domain_,
536 base::CompareCase::INSENSITIVE_ASCII)) { 503 base::CompareCase::INSENSITIVE_ASCII)) {
537 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid 504 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid
538 << ": Domain mismatch."; 505 << ": Domain mismatch.";
539 result_callback.Run(ValidationResult::ERROR_INVALID_ACCOUNT); 506 result_callback.Run(ValidationResult::ERROR_INVALID_ACCOUNT);
540 return; 507 return;
541 } 508 }
542 } 509 }
543 510
544 result_callback.Run(ValidationResult::SUCCESS); 511 // Show a confirmation dialog to the user to allow them to confirm/reject it.
512 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog =
513 confirmation_dialog_factory_->Create();
514
515 if (!confirmation_dialog) {
Sergey Ulanov 2016/09/09 18:46:57 Add a comment that this is only temporary until we
joedow 2016/09/10 02:50:36 Done.
516 result_callback.Run(ValidationResult::SUCCESS);
517 return;
518 }
519
520 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy(
521 host_context_->ui_task_runner(), std::move(confirmation_dialog)));
522
523 confirmation_dialog_proxy_->Show(
524 client_username, base::Bind(&It2MeHost::OnConfirmationResult,
525 base::Unretained(this), result_callback));
526 }
527
528 void It2MeHost::OnConfirmationResult(
529 const protocol::ValidatingAuthenticator::ResultCallback& result_callback,
530 It2MeConfirmationDialog::Result result) {
531 switch (result) {
532 case It2MeConfirmationDialog::Result::OK:
533 result_callback.Run(ValidationResult::SUCCESS);
534 break;
535
536 case It2MeConfirmationDialog::Result::CANCEL:
537 result_callback.Run(ValidationResult::ERROR_REJECTED_BY_USER);
538 break;
539 }
545 } 540 }
546 541
547 It2MeHostFactory::It2MeHostFactory() {} 542 It2MeHostFactory::It2MeHostFactory() {}
548 543
549 It2MeHostFactory::~It2MeHostFactory() {} 544 It2MeHostFactory::~It2MeHostFactory() {}
550 545
551 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( 546 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost(
552 std::unique_ptr<ChromotingHostContext> context, 547 std::unique_ptr<ChromotingHostContext> context,
553 policy::PolicyService* policy_service, 548 policy::PolicyService* policy_service,
554 base::WeakPtr<It2MeHost::Observer> observer, 549 base::WeakPtr<It2MeHost::Observer> observer,
555 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 550 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
556 const std::string& directory_bot_jid) { 551 const std::string& directory_bot_jid) {
557 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); 552 DCHECK(context->ui_task_runner()->BelongsToCurrentThread());
558 553
559 std::unique_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory( 554 std::unique_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory(
560 new It2MeConfirmationDialogFactory()); 555 new It2MeConfirmationDialogFactory());
561 std::unique_ptr<PolicyWatcher> policy_watcher = 556 std::unique_ptr<PolicyWatcher> policy_watcher =
562 PolicyWatcher::Create(policy_service, context->file_task_runner()); 557 PolicyWatcher::Create(policy_service, context->file_task_runner());
563 return new It2MeHost(std::move(context), std::move(policy_watcher), 558 return new It2MeHost(std::move(context), std::move(policy_watcher),
564 std::move(confirmation_dialog_factory), observer, 559 std::move(confirmation_dialog_factory), observer,
565 xmpp_server_config, directory_bot_jid); 560 xmpp_server_config, directory_bot_jid);
566 } 561 }
567 562
568 } // namespace remoting 563 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698