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

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service.cc

Issue 2475073003: Refactor ArcSupportHost and ArcAuthService part 1. (Closed)
Patch Set: 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/chromeos/arc/arc_auth_service.h" 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/shelf/shelf_delegate.h" 9 #include "ash/common/shelf/shelf_delegate.h"
10 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h" 16 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h"
17 #include "chrome/browser/chromeos/arc/arc_auth_context.h" 17 #include "chrome/browser/chromeos/arc/arc_auth_context.h"
18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" 18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h"
19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
20 #include "chrome/browser/chromeos/arc/arc_support_host.h" 20 #include "chrome/browser/chromeos/arc/arc_support_host.h"
21 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler.h"
21 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" 22 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h"
22 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" 23 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
23 #include "chrome/browser/chromeos/profiles/profile_helper.h" 24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
24 #include "chrome/browser/extensions/extension_util.h" 25 #include "chrome/browser/extensions/extension_util.h"
25 #include "chrome/browser/policy/profile_policy_connector.h" 26 #include "chrome/browser/policy/profile_policy_connector.h"
26 #include "chrome/browser/policy/profile_policy_connector_factory.h" 27 #include "chrome/browser/policy/profile_policy_connector_factory.h"
27 #include "chrome/browser/prefs/pref_service_syncable_util.h" 28 #include "chrome/browser/prefs/pref_service_syncable_util.h"
28 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" 30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h"
30 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 31 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
31 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 32 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
33 #include "chrome/browser/ui/browser_commands.h"
32 #include "chrome/browser/ui/extensions/app_launch_params.h" 34 #include "chrome/browser/ui/extensions/app_launch_params.h"
33 #include "chrome/browser/ui/extensions/application_launch.h" 35 #include "chrome/browser/ui/extensions/application_launch.h"
34 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
35 #include "chrome/grit/generated_resources.h" 37 #include "chrome/grit/generated_resources.h"
36 #include "chromeos/chromeos_switches.h" 38 #include "chromeos/chromeos_switches.h"
37 #include "chromeos/cryptohome/cryptohome_parameters.h" 39 #include "chromeos/cryptohome/cryptohome_parameters.h"
38 #include "chromeos/dbus/dbus_thread_manager.h" 40 #include "chromeos/dbus/dbus_thread_manager.h"
39 #include "chromeos/dbus/session_manager_client.h" 41 #include "chromeos/dbus/session_manager_client.h"
40 #include "components/arc/arc_bridge_service.h" 42 #include "components/arc/arc_bridge_service.h"
41 #include "components/pref_registry/pref_registry_syncable.h" 43 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 error_message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR; 404 error_message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR;
403 break; 405 break;
404 default: 406 default:
405 error_message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR; 407 error_message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR;
406 break; 408 break;
407 } 409 }
408 410
409 if (result == ProvisioningResult::ARC_STOPPED) { 411 if (result == ProvisioningResult::ARC_STOPPED) {
410 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) 412 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn))
411 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 413 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
412 ShutdownBridgeAndShowUI(UIPage::ERROR, 414 ShutdownBridgeAndShowUI(ArcSupportHost::UIPage::ERROR,
413 l10n_util::GetStringUTF16(error_message_id)); 415 l10n_util::GetStringUTF16(error_message_id));
414 return; 416 return;
415 } 417 }
416 418
417 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 419 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
418 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 420 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
419 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 421 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
420 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is 422 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is
421 // fully setup, but Chrome does not. 423 // fully setup, but Chrome does not.
422 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || 424 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT ||
423 // Just to be safe, remove data if we don't know the cause. 425 // Just to be safe, remove data if we don't know the cause.
424 result == ProvisioningResult::UNKNOWN_ERROR) { 426 result == ProvisioningResult::UNKNOWN_ERROR) {
425 RemoveArcData(); 427 RemoveArcData();
426 } 428 }
427 429
428 // We'll delay shutting down the bridge in this case to allow people to send 430 // We'll delay shutting down the bridge in this case to allow people to send
429 // feedback. 431 // feedback.
430 ShowUI(UIPage::ERROR_WITH_FEEDBACK, 432 ShowUI(ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK,
431 l10n_util::GetStringUTF16(error_message_id)); 433 l10n_util::GetStringUTF16(error_message_id));
432 } 434 }
433 435
434 void ArcAuthService::GetIsAccountManaged( 436 void ArcAuthService::GetIsAccountManaged(
435 const GetIsAccountManagedCallback& callback) { 437 const GetIsAccountManagedCallback& callback) {
436 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 438 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
437 439
438 callback.Run(policy_util::IsAccountManaged(profile_)); 440 callback.Run(policy_util::IsAccountManaged(profile_));
439 } 441 }
440 442
(...skipping 26 matching lines...) Expand all
467 VLOG(2) << "Enterprise users are not supported in ARC."; 469 VLOG(2) << "Enterprise users are not supported in ARC.";
468 return; 470 return;
469 } 471 }
470 472
471 profile_ = profile; 473 profile_ = profile;
472 // Create the support host at initialization. Note that, practically, 474 // Create the support host at initialization. Note that, practically,
473 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). 475 // ARC support Chrome app is rarely used (only opt-in and re-auth flow).
474 // So, it may be better to initialize it lazily. 476 // So, it may be better to initialize it lazily.
475 // TODO(hidehiko): Revisit to think about lazy initialization. 477 // TODO(hidehiko): Revisit to think about lazy initialization.
476 support_host_.reset(new ArcSupportHost()); 478 support_host_.reset(new ArcSupportHost());
479 support_host_->set_observer(this);
480 preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>(
481 this, profile_->GetPrefs());
482 // This automatically updates all preferences.
483 preference_handler_->Start();
484
477 SetState(State::STOPPED); 485 SetState(State::STOPPED);
478 486
479 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( 487 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver(
480 prefs::kArcEnabled, this); 488 prefs::kArcEnabled, this);
481 489
482 context_.reset(new ArcAuthContext(this, profile_)); 490 context_.reset(new ArcAuthContext(this, profile_));
483 491
484 // In case UI is disabled we assume that ARC is opted-in. 492 // In case UI is disabled we assume that ARC is opted-in.
485 if (IsOptInVerificationDisabled()) { 493 if (IsOptInVerificationDisabled()) {
486 auth_code_.clear(); 494 auth_code_.clear();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 PrefServiceSyncableFromProfile(profile_); 538 PrefServiceSyncableFromProfile(profile_);
531 pref_service_syncable->RemoveObserver(this); 539 pref_service_syncable->RemoveObserver(this);
532 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); 540 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this);
533 } 541 }
534 pref_change_registrar_.RemoveAll(); 542 pref_change_registrar_.RemoveAll();
535 context_.reset(); 543 context_.reset();
536 profile_ = nullptr; 544 profile_ = nullptr;
537 SetState(State::NOT_INITIALIZED); 545 SetState(State::NOT_INITIALIZED);
538 } 546 }
539 547
540 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { 548 void ArcAuthService::ShowUI(ArcSupportHost::UIPage page,
549 const base::string16& status) {
541 if (g_disable_ui_for_testing || IsOptInVerificationDisabled()) 550 if (g_disable_ui_for_testing || IsOptInVerificationDisabled())
542 return; 551 return;
543 552
544 SetUIPage(page, status); 553 SetUIPage(page, status);
545 const extensions::AppWindowRegistry* const app_window_registry = 554 const extensions::AppWindowRegistry* const app_window_registry =
546 extensions::AppWindowRegistry::Get(profile_); 555 extensions::AppWindowRegistry::Get(profile_);
547 DCHECK(app_window_registry); 556 DCHECK(app_window_registry);
548 if (app_window_registry->GetCurrentAppWindowForApp( 557 if (app_window_registry->GetCurrentAppWindowForApp(
549 ArcSupportHost::kHostAppId)) { 558 ArcSupportHost::kHostAppId)) {
550 return; 559 return;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 SetState(State::STOPPED); 670 SetState(State::STOPPED);
662 for (auto& observer : observer_list_) 671 for (auto& observer : observer_list_)
663 observer.OnShutdownBridge(); 672 observer.OnShutdownBridge();
664 } 673 }
665 674
666 void ArcAuthService::ShutdownBridgeAndCloseUI() { 675 void ArcAuthService::ShutdownBridgeAndCloseUI() {
667 ShutdownBridge(); 676 ShutdownBridge();
668 CloseUI(); 677 CloseUI();
669 } 678 }
670 679
671 void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page, 680 void ArcAuthService::ShutdownBridgeAndShowUI(ArcSupportHost::UIPage page,
672 const base::string16& status) { 681 const base::string16& status) {
673 ShutdownBridge(); 682 ShutdownBridge();
674 ShowUI(page, status); 683 ShowUI(page, status);
675 } 684 }
676 685
677 void ArcAuthService::AddObserver(Observer* observer) { 686 void ArcAuthService::AddObserver(Observer* observer) {
678 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 687 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
679 observer_list_.AddObserver(observer); 688 observer_list_.AddObserver(observer);
680 } 689 }
681 690
682 void ArcAuthService::RemoveObserver(Observer* observer) { 691 void ArcAuthService::RemoveObserver(Observer* observer) {
683 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 692 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
684 observer_list_.RemoveObserver(observer); 693 observer_list_.RemoveObserver(observer);
685 } 694 }
686 695
687 void ArcAuthService::CloseUI() { 696 void ArcAuthService::CloseUI() {
688 ui_page_ = UIPage::NO_PAGE; 697 ui_page_ = ArcSupportHost::UIPage::NO_PAGE;
689 ui_page_status_.clear(); 698 ui_page_status_.clear();
690 if (support_host_) 699 if (support_host_)
691 support_host_->Close(); 700 support_host_->Close();
692 if (!g_disable_ui_for_testing) 701 if (!g_disable_ui_for_testing)
693 ArcAuthNotification::Hide(); 702 ArcAuthNotification::Hide();
694 } 703 }
695 704
696 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { 705 void ArcAuthService::SetUIPage(ArcSupportHost::UIPage page,
706 const base::string16& status) {
697 ui_page_ = page; 707 ui_page_ = page;
698 ui_page_status_ = status; 708 ui_page_status_ = status;
699 if (support_host_) 709 if (support_host_)
700 support_host_->ShowPage(ui_page_, ui_page_status_); 710 support_host_->ShowPage(ui_page_, ui_page_status_);
701 } 711 }
702 712
703 // This is the special method to support enterprise mojo API. 713 // This is the special method to support enterprise mojo API.
704 // TODO(hidehiko): Remove this. 714 // TODO(hidehiko): Remove this.
705 void ArcAuthService::StopAndEnableArc() { 715 void ArcAuthService::StopAndEnableArc() {
706 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 716 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 28 matching lines...) Expand all
735 } 745 }
736 746
737 if (state_ != State::FETCHING_CODE) { 747 if (state_ != State::FETCHING_CODE) {
738 ShutdownBridgeAndCloseUI(); 748 ShutdownBridgeAndCloseUI();
739 return; 749 return;
740 } 750 }
741 751
742 sign_in_time_ = base::Time::Now(); 752 sign_in_time_ = base::Time::Now();
743 VLOG(1) << "Starting ARC for first sign in."; 753 VLOG(1) << "Starting ARC for first sign in.";
744 754
745 SetUIPage(UIPage::START_PROGRESS, base::string16()); 755 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16());
746 ShutdownBridge(); 756 ShutdownBridge();
747 auth_code_ = auth_code; 757 auth_code_ = auth_code;
748 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, 758 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout,
749 base::Bind(&ArcAuthService::OnArcSignInTimeout, 759 base::Bind(&ArcAuthService::OnArcSignInTimeout,
750 weak_ptr_factory_.GetWeakPtr())); 760 weak_ptr_factory_.GetWeakPtr()));
751 StartArc(); 761 StartArc();
752 } 762 }
753 763
754 void ArcAuthService::OnArcSignInTimeout() { 764 void ArcAuthService::OnArcSignInTimeout() {
755 LOG(ERROR) << "Timed out waiting for first sign in."; 765 LOG(ERROR) << "Timed out waiting for first sign in.";
756 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); 766 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT);
757 } 767 }
758 768
759 void ArcAuthService::StartLso() { 769 void ArcAuthService::StartLso() {
760 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 770 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
761 771
762 // Update UMA only if error (with or without feedback) is currently shown. 772 // Update UMA only if error (with or without feedback) is currently shown.
763 if (ui_page_ == UIPage::ERROR) { 773 if (ui_page_ == ArcSupportHost::UIPage::ERROR) {
764 UpdateOptInActionUMA(OptInActionType::RETRY); 774 UpdateOptInActionUMA(OptInActionType::RETRY);
765 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) { 775 } else if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) {
766 UpdateOptInActionUMA(OptInActionType::RETRY); 776 UpdateOptInActionUMA(OptInActionType::RETRY);
767 ShutdownBridge(); 777 ShutdownBridge();
768 } 778 }
769 779
770 // TODO(khmel): Use PrepareContextForAuthCodeRequest for this case. 780 // TODO(khmel): Use PrepareContextForAuthCodeRequest for this case.
771 initial_opt_in_ = false; 781 initial_opt_in_ = false;
772 StartUI(); 782 StartUI();
773 } 783 }
774 784
775 void ArcAuthService::CancelAuthCode() { 785 void ArcAuthService::CancelAuthCode() {
776 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 786 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
777 787
778 if (state_ == State::NOT_INITIALIZED) { 788 if (state_ == State::NOT_INITIALIZED) {
779 NOTREACHED(); 789 NOTREACHED();
780 return; 790 return;
781 } 791 }
782 792
783 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means 793 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means
784 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not 794 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not
785 // be started). If Arc is booting normally dont't stop it on progress close. 795 // be started). If Arc is booting normally dont't stop it on progress close.
786 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR && 796 if (state_ != State::FETCHING_CODE &&
787 ui_page_ != UIPage::ERROR_WITH_FEEDBACK) { 797 ui_page_ != ArcSupportHost::UIPage::ERROR &&
798 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK)
Luis Héctor Chávez 2016/11/04 17:55:15 nit: un-elide braces (multi-line conditions cannot
hidehiko 2016/11/04 22:19:50 Done.
788 return; 799 return;
789 }
790 800
791 // Update UMA with user cancel only if error is not currently shown. 801 // Update UMA with user cancel only if error is not currently shown.
792 if (ui_page_ != UIPage::ERROR && ui_page_ == UIPage::ERROR_WITH_FEEDBACK && 802 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) {
Luis Héctor Chávez 2016/11/04 17:55:15 nit: elide braces
hidehiko 2016/11/04 22:19:50 Done.
793 ui_page_ != UIPage::NO_PAGE) {
794 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 803 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
795 } 804 }
796 805
797 StopArc(); 806 StopArc();
798 807
799 if (IsArcManaged()) 808 if (IsArcManaged())
800 return; 809 return;
801 810
802 DisableArc(); 811 DisableArc();
803 } 812 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 DCHECK(profile_); 844 DCHECK(profile_);
836 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 845 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
837 } 846 }
838 847
839 void ArcAuthService::StartUI() { 848 void ArcAuthService::StartUI() {
840 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 849 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
841 850
842 if (!arc_bridge_service()->stopped()) { 851 if (!arc_bridge_service()->stopped()) {
843 // If the user attempts to re-enable ARC while the bridge is still running 852 // If the user attempts to re-enable ARC while the bridge is still running
844 // the user should not be able to continue until the bridge has stopped. 853 // the user should not be able to continue until the bridge has stopped.
845 ShowUI(UIPage::ERROR, l10n_util::GetStringUTF16( 854 ShowUI(
846 IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); 855 ArcSupportHost::UIPage::ERROR,
856 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR));
847 return; 857 return;
848 } 858 }
849 859
850 SetState(State::FETCHING_CODE); 860 SetState(State::FETCHING_CODE);
851 861
852 if (initial_opt_in_) { 862 if (initial_opt_in_) {
853 initial_opt_in_ = false; 863 initial_opt_in_ = false;
854 ShowUI(UIPage::TERMS, base::string16()); 864 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16());
855 } else { 865 } else {
856 context_->PrepareContext(); 866 context_->PrepareContext();
857 } 867 }
858 } 868 }
859 869
860 void ArcAuthService::OnPrepareContextFailed() { 870 void ArcAuthService::OnPrepareContextFailed() {
861 DCHECK_EQ(state_, State::FETCHING_CODE); 871 DCHECK_EQ(state_, State::FETCHING_CODE);
862 872
863 ShutdownBridgeAndShowUI( 873 ShutdownBridgeAndShowUI(
864 UIPage::ERROR, 874 ArcSupportHost::UIPage::ERROR,
865 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 875 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
866 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 876 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
867 } 877 }
868 878
869 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { 879 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) {
870 SetAuthCodeAndStartArc(auth_code); 880 SetAuthCodeAndStartArc(auth_code);
871 } 881 }
872 882
873 void ArcAuthService::OnAuthCodeFailed() { 883 void ArcAuthService::OnAuthCodeFailed() {
874 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 884 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
875 DCHECK_EQ(state_, State::FETCHING_CODE); 885 DCHECK_EQ(state_, State::FETCHING_CODE);
876 ShutdownBridgeAndShowUI( 886 ShutdownBridgeAndShowUI(
877 UIPage::ERROR, 887 ArcSupportHost::UIPage::ERROR,
878 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 888 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
879 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 889 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
880 } 890 }
881 891
882 void ArcAuthService::OnAndroidManagementChecked( 892 void ArcAuthService::OnAndroidManagementChecked(
883 policy::AndroidManagementClient::Result result) { 893 policy::AndroidManagementClient::Result result) {
884 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 894 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
885 switch (result) { 895 switch (result) {
886 case policy::AndroidManagementClient::Result::UNMANAGED: 896 case policy::AndroidManagementClient::Result::UNMANAGED:
887 OnAndroidManagementPassed(); 897 OnAndroidManagementPassed();
888 break; 898 break;
889 case policy::AndroidManagementClient::Result::MANAGED: 899 case policy::AndroidManagementClient::Result::MANAGED:
890 ShutdownBridgeAndShowUI( 900 ShutdownBridgeAndShowUI(
891 UIPage::ERROR, 901 ArcSupportHost::UIPage::ERROR,
892 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); 902 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
893 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); 903 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
894 break; 904 break;
895 case policy::AndroidManagementClient::Result::ERROR: 905 case policy::AndroidManagementClient::Result::ERROR:
896 ShutdownBridgeAndShowUI( 906 ShutdownBridgeAndShowUI(
897 UIPage::ERROR, 907 ArcSupportHost::UIPage::ERROR,
898 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 908 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
899 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 909 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
900 break; 910 break;
901 } 911 }
902 } 912 }
903 913
904 void ArcAuthService::OnBackgroundAndroidManagementChecked( 914 void ArcAuthService::OnBackgroundAndroidManagementChecked(
905 policy::AndroidManagementClient::Result result) { 915 policy::AndroidManagementClient::Result result) {
906 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 916 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
907 switch (result) { 917 switch (result) {
(...skipping 18 matching lines...) Expand all
926 std::string auth_endpoint; 936 std::string auth_endpoint;
927 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { 937 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
928 auth_endpoint = command_line->GetSwitchValueASCII( 938 auth_endpoint = command_line->GetSwitchValueASCII(
929 chromeos::switches::kArcUseAuthEndpoint); 939 chromeos::switches::kArcUseAuthEndpoint);
930 } 940 }
931 941
932 if (!auth_endpoint.empty()) { 942 if (!auth_endpoint.empty()) {
933 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( 943 auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
934 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); 944 this, context_->GetURLRequestContext(), profile_, auth_endpoint));
935 } else { 945 } else {
936 ShowUI(UIPage::LSO_PROGRESS, base::string16()); 946 ShowUI(ArcSupportHost::UIPage::LSO_PROGRESS, base::string16());
937 } 947 }
938 } 948 }
939 949
940 void ArcAuthService::OnAndroidManagementPassed() { 950 void ArcAuthService::OnAndroidManagementPassed() {
941 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 951 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
942 952
943 if (state_ == State::ACTIVE) { 953 if (state_ == State::ACTIVE) {
944 if (IsAuthCodeRequest()) 954 if (IsAuthCodeRequest())
945 FetchAuthCode(); 955 FetchAuthCode();
946 return; 956 return;
947 } 957 }
948 958
949 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || 959 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) ||
950 IsOptInVerificationDisabled()) { 960 IsOptInVerificationDisabled()) {
951 StartArc(); 961 StartArc();
952 } else { 962 } else {
953 FetchAuthCode(); 963 FetchAuthCode();
954 } 964 }
955 } 965 }
956 966
967 void ArcAuthService::OnWindowClosed() {
968 CancelAuthCode();
969 }
970
971 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled,
972 bool is_backup_and_restore_enabled,
973 bool is_location_service_enabled) {
974 preference_handler_->EnableMetrics(is_metrics_enabled);
975 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled);
976 preference_handler_->EnableLocationService(is_location_service_enabled);
977 StartLso();
978 }
979
980 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) {
981 SetAuthCodeAndStartArc(auth_code);
982 }
983
984 void ArcAuthService::OnSendFeedbackClicked() {
985 chrome::OpenFeedbackDialog(nullptr);
986 }
987
988 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) {
989 if (support_host_)
Luis Héctor Chávez 2016/11/04 17:55:15 nit: if (!support_host_) return;
hidehiko 2016/11/04 22:19:50 Done.
990 support_host_->SetMetricsPreferenceCheckbox(enabled, managed);
991 }
992
993 void ArcAuthService::OnBackupAndRestoreModeChanged(bool enabled, bool managed) {
994 if (support_host_)
995 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed);
996 }
997
998 void ArcAuthService::OnLocationServicesModeChanged(bool enabled, bool managed) {
999 if (support_host_)
1000 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed);
1001 }
1002
957 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { 1003 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
958 switch (state) { 1004 switch (state) {
959 case ArcAuthService::State::NOT_INITIALIZED: 1005 case ArcAuthService::State::NOT_INITIALIZED:
960 return os << "NOT_INITIALIZED"; 1006 return os << "NOT_INITIALIZED";
961 case ArcAuthService::State::STOPPED: 1007 case ArcAuthService::State::STOPPED:
962 return os << "STOPPED"; 1008 return os << "STOPPED";
963 case ArcAuthService::State::FETCHING_CODE: 1009 case ArcAuthService::State::FETCHING_CODE:
964 return os << "FETCHING_CODE"; 1010 return os << "FETCHING_CODE";
965 case ArcAuthService::State::ACTIVE: 1011 case ArcAuthService::State::ACTIVE:
966 return os << "ACTIVE"; 1012 return os << "ACTIVE";
967 default: 1013 default:
968 NOTREACHED(); 1014 NOTREACHED();
969 return os; 1015 return os;
970 } 1016 }
971 } 1017 }
972 1018
973 } // namespace arc 1019 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698