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

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

Issue 2452223002: It2Me Host changes to better support Confirmation Dialog (Closed)
Patch Set: Reordering enum Created 4 years, 1 month 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/it2me/it2me_host.h ('k') | remoting/host/it2me/it2me_host_unittest.cc » ('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 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 NOTIMPLEMENTED(); 338 NOTIMPLEMENTED();
339 } 339 }
340 340
341 void It2MeHost::UpdateNatPolicy(bool nat_traversal_enabled) { 341 void It2MeHost::UpdateNatPolicy(bool nat_traversal_enabled) {
342 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 342 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
343 343
344 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled; 344 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled;
345 345
346 // When transitioning from enabled to disabled, force disconnect any 346 // When transitioning from enabled to disabled, force disconnect any
347 // existing session. 347 // existing session.
348 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsConnected()) { 348 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsRunning()) {
349 DisconnectOnNetworkThread(); 349 DisconnectOnNetworkThread();
350 } 350 }
351 351
352 nat_traversal_enabled_ = nat_traversal_enabled; 352 nat_traversal_enabled_ = nat_traversal_enabled;
353 353
354 // Notify the web-app of the policy setting. 354 // Notify the web-app of the policy setting.
355 host_context_->ui_task_runner()->PostTask( 355 host_context_->ui_task_runner()->PostTask(
356 FROM_HERE, base::Bind(&It2MeHost::Observer::OnNatPolicyChanged, observer_, 356 FROM_HERE, base::Bind(&It2MeHost::Observer::OnNatPolicyChanged, observer_,
357 nat_traversal_enabled_)); 357 nat_traversal_enabled_));
358 } 358 }
359 359
360 void It2MeHost::UpdateHostDomainPolicy(const std::string& host_domain) { 360 void It2MeHost::UpdateHostDomainPolicy(const std::string& host_domain) {
361 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 361 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
362 362
363 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain; 363 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain;
364 364
365 // When setting a host domain policy, force disconnect any existing session. 365 // When setting a host domain policy, force disconnect any existing session.
366 if (!host_domain.empty() && IsConnected()) { 366 if (!host_domain.empty() && IsRunning()) {
367 DisconnectOnNetworkThread(); 367 DisconnectOnNetworkThread();
368 } 368 }
369 369
370 required_host_domain_ = host_domain; 370 required_host_domain_ = host_domain;
371 } 371 }
372 372
373 void It2MeHost::UpdateClientDomainPolicy(const std::string& client_domain) { 373 void It2MeHost::UpdateClientDomainPolicy(const std::string& client_domain) {
374 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 374 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
375 375
376 VLOG(2) << "UpdateClientDomainPolicy: " << client_domain; 376 VLOG(2) << "UpdateClientDomainPolicy: " << client_domain;
377 377
378 // When setting a client domain policy, disconnect any existing session. 378 // When setting a client domain policy, disconnect any existing session.
379 if (!client_domain.empty() && IsConnected()) { 379 if (!client_domain.empty() && IsRunning()) {
380 DisconnectOnNetworkThread(); 380 DisconnectOnNetworkThread();
381 } 381 }
382 382
383 required_client_domain_ = client_domain; 383 required_client_domain_ = client_domain;
384 } 384 }
385 385
386 void It2MeHost::SetState(It2MeHostState state, 386 void It2MeHost::SetState(It2MeHostState state,
387 const std::string& error_message) { 387 const std::string& error_message) {
388 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 388 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
389 389
390 switch (state_) { 390 switch (state_) {
391 case kDisconnected: 391 case kDisconnected:
392 DCHECK(state == kStarting || 392 DCHECK(state == kStarting ||
393 state == kError) << state; 393 state == kError) << state;
394 break; 394 break;
395 case kStarting: 395 case kStarting:
396 DCHECK(state == kRequestedAccessCode || 396 DCHECK(state == kRequestedAccessCode ||
397 state == kDisconnected || 397 state == kDisconnected ||
398 state == kError || 398 state == kError ||
399 state == kInvalidDomainError) << state; 399 state == kInvalidDomainError) << state;
400 break; 400 break;
401 case kRequestedAccessCode: 401 case kRequestedAccessCode:
402 DCHECK(state == kReceivedAccessCode || 402 DCHECK(state == kReceivedAccessCode ||
403 state == kDisconnected || 403 state == kDisconnected ||
404 state == kError) << state; 404 state == kError) << state;
405 break; 405 break;
406 case kReceivedAccessCode: 406 case kReceivedAccessCode:
407 DCHECK(state == kConnecting ||
408 state == kDisconnected ||
409 state == kError) << state;
410 break;
411 case kConnecting:
407 DCHECK(state == kConnected || 412 DCHECK(state == kConnected ||
408 state == kDisconnected || 413 state == kDisconnected ||
409 state == kError) << state; 414 state == kError) << state;
410 break; 415 break;
411 case kConnected: 416 case kConnected:
412 DCHECK(state == kDisconnected || 417 DCHECK(state == kDisconnected ||
413 state == kError) << state; 418 state == kError) << state;
414 break; 419 break;
415 case kError: 420 case kError:
416 DCHECK(state == kDisconnected) << state; 421 DCHECK(state == kDisconnected) << state;
417 break; 422 break;
418 case kInvalidDomainError: 423 case kInvalidDomainError:
419 DCHECK(state == kDisconnected) << state; 424 DCHECK(state == kDisconnected) << state;
420 break; 425 break;
421 }; 426 };
422 427
423 state_ = state; 428 state_ = state;
424 429
425 // Post a state-change notification to the web-app. 430 // Post a state-change notification to the web-app.
426 host_context_->ui_task_runner()->PostTask( 431 host_context_->ui_task_runner()->PostTask(
427 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStateChanged, observer_, 432 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStateChanged, observer_,
428 state, error_message)); 433 state, error_message));
429 } 434 }
430 435
431 bool It2MeHost::IsConnected() const { 436 bool It2MeHost::IsRunning() const {
432 return state_ == kRequestedAccessCode || state_ == kReceivedAccessCode || 437 return state_ == kRequestedAccessCode || state_ == kReceivedAccessCode ||
433 state_ == kConnected; 438 state_ == kConnected || state_ == kConnecting;
434 } 439 }
435 440
436 void It2MeHost::OnReceivedSupportID( 441 void It2MeHost::OnReceivedSupportID(
437 const std::string& support_id, 442 const std::string& support_id,
438 const base::TimeDelta& lifetime, 443 const base::TimeDelta& lifetime,
439 const std::string& error_message) { 444 const std::string& error_message) {
440 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 445 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
441 446
442 if (!error_message.empty()) { 447 if (!error_message.empty()) {
443 SetState(kError, error_message); 448 SetState(kError, error_message);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 std::string("@") + required_client_domain_, 509 std::string("@") + required_client_domain_,
505 base::CompareCase::INSENSITIVE_ASCII)) { 510 base::CompareCase::INSENSITIVE_ASCII)) {
506 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid 511 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid
507 << ": Domain mismatch."; 512 << ": Domain mismatch.";
508 result_callback.Run(ValidationResult::ERROR_INVALID_ACCOUNT); 513 result_callback.Run(ValidationResult::ERROR_INVALID_ACCOUNT);
509 DisconnectOnNetworkThread(); 514 DisconnectOnNetworkThread();
510 return; 515 return;
511 } 516 }
512 } 517 }
513 518
519 HOST_LOG << "Client " << client_username << " connecting.";
520 SetState(kConnecting, std::string());
521
514 // Show a confirmation dialog to the user to allow them to confirm/reject it. 522 // Show a confirmation dialog to the user to allow them to confirm/reject it.
515 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy( 523 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy(
516 host_context_->ui_task_runner(), std::move(confirmation_dialog_))); 524 host_context_->ui_task_runner(), std::move(confirmation_dialog_)));
517 525
518 confirmation_dialog_proxy_->Show( 526 confirmation_dialog_proxy_->Show(
519 client_username, base::Bind(&It2MeHost::OnConfirmationResult, 527 client_username, base::Bind(&It2MeHost::OnConfirmationResult,
520 base::Unretained(this), result_callback)); 528 base::Unretained(this), result_callback));
521 } 529 }
522 530
523 void It2MeHost::OnConfirmationResult( 531 void It2MeHost::OnConfirmationResult(
(...skipping 27 matching lines...) Expand all
551 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); 559 DCHECK(context->ui_task_runner()->BelongsToCurrentThread());
552 560
553 std::unique_ptr<PolicyWatcher> policy_watcher = 561 std::unique_ptr<PolicyWatcher> policy_watcher =
554 PolicyWatcher::Create(policy_service, context->file_task_runner()); 562 PolicyWatcher::Create(policy_service, context->file_task_runner());
555 return new It2MeHost(std::move(context), std::move(policy_watcher), 563 return new It2MeHost(std::move(context), std::move(policy_watcher),
556 It2MeConfirmationDialog::Create(), observer, 564 It2MeConfirmationDialog::Create(), observer,
557 std::move(signal_strategy), username, directory_bot_jid); 565 std::move(signal_strategy), username, directory_bot_jid);
558 } 566 }
559 567
560 } // namespace remoting 568 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_host.h ('k') | remoting/host/it2me/it2me_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698