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

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

Issue 2475073003: Refactor ArcSupportHost and ArcAuthService part 1. (Closed)
Patch Set: rebase 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_optin_uma.h" 18 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
19 #include "chrome/browser/chromeos/arc/arc_support_host.h" 19 #include "chrome/browser/chromeos/arc/arc_support_host.h"
20 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler.h"
20 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" 21 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h"
21 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" 22 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" 23 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/extensions/extension_util.h" 24 #include "chrome/browser/extensions/extension_util.h"
24 #include "chrome/browser/policy/profile_policy_connector.h" 25 #include "chrome/browser/policy/profile_policy_connector.h"
25 #include "chrome/browser/policy/profile_policy_connector_factory.h" 26 #include "chrome/browser/policy/profile_policy_connector_factory.h"
26 #include "chrome/browser/prefs/pref_service_syncable_util.h" 27 #include "chrome/browser/prefs/pref_service_syncable_util.h"
27 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" 29 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h"
29 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 30 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
30 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 31 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
32 #include "chrome/browser/ui/browser_commands.h"
31 #include "chrome/browser/ui/extensions/app_launch_params.h" 33 #include "chrome/browser/ui/extensions/app_launch_params.h"
32 #include "chrome/browser/ui/extensions/application_launch.h" 34 #include "chrome/browser/ui/extensions/application_launch.h"
33 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
34 #include "chrome/grit/generated_resources.h" 36 #include "chrome/grit/generated_resources.h"
35 #include "chromeos/chromeos_switches.h" 37 #include "chromeos/chromeos_switches.h"
36 #include "chromeos/cryptohome/cryptohome_parameters.h" 38 #include "chromeos/cryptohome/cryptohome_parameters.h"
37 #include "chromeos/dbus/dbus_thread_manager.h" 39 #include "chromeos/dbus/dbus_thread_manager.h"
38 #include "chromeos/dbus/session_manager_client.h" 40 #include "chromeos/dbus/session_manager_client.h"
39 #include "components/arc/arc_bridge_service.h" 41 #include "components/arc/arc_bridge_service.h"
40 #include "components/pref_registry/pref_registry_syncable.h" 42 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 error_message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR; 477 error_message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR;
476 break; 478 break;
477 default: 479 default:
478 error_message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR; 480 error_message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR;
479 break; 481 break;
480 } 482 }
481 483
482 if (result == ProvisioningResult::ARC_STOPPED) { 484 if (result == ProvisioningResult::ARC_STOPPED) {
483 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) 485 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn))
484 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 486 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
485 ShutdownBridgeAndShowUI(UIPage::ERROR, 487 ShutdownBridgeAndShowUI(ArcSupportHost::UIPage::ERROR,
486 l10n_util::GetStringUTF16(error_message_id)); 488 l10n_util::GetStringUTF16(error_message_id));
487 return; 489 return;
488 } 490 }
489 491
490 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 492 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
491 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 493 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
492 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 494 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
493 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is 495 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is
494 // fully setup, but Chrome does not. 496 // fully setup, but Chrome does not.
495 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || 497 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT ||
496 // Just to be safe, remove data if we don't know the cause. 498 // Just to be safe, remove data if we don't know the cause.
497 result == ProvisioningResult::UNKNOWN_ERROR) { 499 result == ProvisioningResult::UNKNOWN_ERROR) {
498 RemoveArcData(); 500 RemoveArcData();
499 } 501 }
500 502
501 // We'll delay shutting down the bridge in this case to allow people to send 503 // We'll delay shutting down the bridge in this case to allow people to send
502 // feedback. 504 // feedback.
503 ShowUI(UIPage::ERROR_WITH_FEEDBACK, 505 ShowUI(ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK,
504 l10n_util::GetStringUTF16(error_message_id)); 506 l10n_util::GetStringUTF16(error_message_id));
505 } 507 }
506 508
507 void ArcAuthService::GetIsAccountManagedDeprecated( 509 void ArcAuthService::GetIsAccountManagedDeprecated(
508 const GetIsAccountManagedDeprecatedCallback& callback) { 510 const GetIsAccountManagedDeprecatedCallback& callback) {
509 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 511 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
510 512
511 callback.Run(policy_util::IsAccountManaged(profile_)); 513 callback.Run(policy_util::IsAccountManaged(profile_));
512 } 514 }
513 515
(...skipping 21 matching lines...) Expand all
535 VLOG(2) << "Enterprise users are not supported in ARC."; 537 VLOG(2) << "Enterprise users are not supported in ARC.";
536 return; 538 return;
537 } 539 }
538 540
539 profile_ = profile; 541 profile_ = profile;
540 // Create the support host at initialization. Note that, practically, 542 // Create the support host at initialization. Note that, practically,
541 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). 543 // ARC support Chrome app is rarely used (only opt-in and re-auth flow).
542 // So, it may be better to initialize it lazily. 544 // So, it may be better to initialize it lazily.
543 // TODO(hidehiko): Revisit to think about lazy initialization. 545 // TODO(hidehiko): Revisit to think about lazy initialization.
544 support_host_.reset(new ArcSupportHost()); 546 support_host_.reset(new ArcSupportHost());
547 support_host_->AddObserver(this);
548 if (!g_disable_ui_for_testing && !IsOptInVerificationDisabled()) {
549 preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>(
550 this, profile_->GetPrefs());
551 // This automatically updates all preferences.
552 preference_handler_->Start();
553 }
554
545 SetState(State::STOPPED); 555 SetState(State::STOPPED);
546 556
547 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( 557 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver(
548 prefs::kArcEnabled, this); 558 prefs::kArcEnabled, this);
549 559
550 context_.reset(new ArcAuthContext(this, profile_)); 560 context_.reset(new ArcAuthContext(this, profile_));
551 561
552 // In case UI is disabled we assume that ARC is opted-in. 562 // In case UI is disabled we assume that ARC is opted-in.
553 if (IsOptInVerificationDisabled()) { 563 if (IsOptInVerificationDisabled()) {
554 auth_code_.clear(); 564 auth_code_.clear();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 PrefServiceSyncableFromProfile(profile_); 602 PrefServiceSyncableFromProfile(profile_);
593 pref_service_syncable->RemoveObserver(this); 603 pref_service_syncable->RemoveObserver(this);
594 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); 604 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this);
595 } 605 }
596 pref_change_registrar_.RemoveAll(); 606 pref_change_registrar_.RemoveAll();
597 context_.reset(); 607 context_.reset();
598 profile_ = nullptr; 608 profile_ = nullptr;
599 SetState(State::NOT_INITIALIZED); 609 SetState(State::NOT_INITIALIZED);
600 } 610 }
601 611
602 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { 612 void ArcAuthService::ShowUI(ArcSupportHost::UIPage page,
613 const base::string16& status) {
603 if (g_disable_ui_for_testing || IsOptInVerificationDisabled()) 614 if (g_disable_ui_for_testing || IsOptInVerificationDisabled())
604 return; 615 return;
605 616
606 SetUIPage(page, status); 617 SetUIPage(page, status);
607 const extensions::AppWindowRegistry* const app_window_registry = 618 const extensions::AppWindowRegistry* const app_window_registry =
608 extensions::AppWindowRegistry::Get(profile_); 619 extensions::AppWindowRegistry::Get(profile_);
609 DCHECK(app_window_registry); 620 DCHECK(app_window_registry);
610 if (app_window_registry->GetCurrentAppWindowForApp( 621 if (app_window_registry->GetCurrentAppWindowForApp(
611 ArcSupportHost::kHostAppId)) { 622 ArcSupportHost::kHostAppId)) {
612 return; 623 return;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 SetState(State::STOPPED); 735 SetState(State::STOPPED);
725 for (auto& observer : observer_list_) 736 for (auto& observer : observer_list_)
726 observer.OnShutdownBridge(); 737 observer.OnShutdownBridge();
727 } 738 }
728 739
729 void ArcAuthService::ShutdownBridgeAndCloseUI() { 740 void ArcAuthService::ShutdownBridgeAndCloseUI() {
730 ShutdownBridge(); 741 ShutdownBridge();
731 CloseUI(); 742 CloseUI();
732 } 743 }
733 744
734 void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page, 745 void ArcAuthService::ShutdownBridgeAndShowUI(ArcSupportHost::UIPage page,
735 const base::string16& status) { 746 const base::string16& status) {
736 ShutdownBridge(); 747 ShutdownBridge();
737 ShowUI(page, status); 748 ShowUI(page, status);
738 } 749 }
739 750
740 void ArcAuthService::AddObserver(Observer* observer) { 751 void ArcAuthService::AddObserver(Observer* observer) {
741 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 752 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
742 observer_list_.AddObserver(observer); 753 observer_list_.AddObserver(observer);
743 } 754 }
744 755
745 void ArcAuthService::RemoveObserver(Observer* observer) { 756 void ArcAuthService::RemoveObserver(Observer* observer) {
746 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 757 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
747 observer_list_.RemoveObserver(observer); 758 observer_list_.RemoveObserver(observer);
748 } 759 }
749 760
750 void ArcAuthService::CloseUI() { 761 void ArcAuthService::CloseUI() {
751 ui_page_ = UIPage::NO_PAGE; 762 ui_page_ = ArcSupportHost::UIPage::NO_PAGE;
752 ui_page_status_.clear(); 763 ui_page_status_.clear();
753 764
754 if (support_host_) 765 if (support_host_)
755 support_host_->Close(); 766 support_host_->Close();
756 } 767 }
757 768
758 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { 769 void ArcAuthService::SetUIPage(ArcSupportHost::UIPage page,
770 const base::string16& status) {
759 ui_page_ = page; 771 ui_page_ = page;
760 ui_page_status_ = status; 772 ui_page_status_ = status;
761 if (support_host_) 773 if (support_host_)
762 support_host_->ShowPage(ui_page_, ui_page_status_); 774 support_host_->ShowPage(ui_page_, ui_page_status_);
763 } 775 }
764 776
765 // This is the special method to support enterprise mojo API. 777 // This is the special method to support enterprise mojo API.
766 // TODO(hidehiko): Remove this. 778 // TODO(hidehiko): Remove this.
767 void ArcAuthService::StopAndEnableArc() { 779 void ArcAuthService::StopAndEnableArc() {
768 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 780 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 23 matching lines...) Expand all
792 } 804 }
793 805
794 if (state_ != State::FETCHING_CODE) { 806 if (state_ != State::FETCHING_CODE) {
795 ShutdownBridgeAndCloseUI(); 807 ShutdownBridgeAndCloseUI();
796 return; 808 return;
797 } 809 }
798 810
799 sign_in_time_ = base::Time::Now(); 811 sign_in_time_ = base::Time::Now();
800 VLOG(1) << "Starting ARC for first sign in."; 812 VLOG(1) << "Starting ARC for first sign in.";
801 813
802 SetUIPage(UIPage::START_PROGRESS, base::string16()); 814 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16());
803 ShutdownBridge(); 815 ShutdownBridge();
804 auth_code_ = auth_code; 816 auth_code_ = auth_code;
805 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, 817 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout,
806 base::Bind(&ArcAuthService::OnArcSignInTimeout, 818 base::Bind(&ArcAuthService::OnArcSignInTimeout,
807 weak_ptr_factory_.GetWeakPtr())); 819 weak_ptr_factory_.GetWeakPtr()));
808 StartArc(); 820 StartArc();
809 } 821 }
810 822
811 void ArcAuthService::OnArcSignInTimeout() { 823 void ArcAuthService::OnArcSignInTimeout() {
812 LOG(ERROR) << "Timed out waiting for first sign in."; 824 LOG(ERROR) << "Timed out waiting for first sign in.";
813 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); 825 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT);
814 } 826 }
815 827
816 void ArcAuthService::StartLso() { 828 void ArcAuthService::StartLso() {
817 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 829 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
818 830
819 // Terms were accepted 831 // Terms were accepted
820 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); 832 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true);
821 833
822 // Update UMA only if error (with or without feedback) is currently shown. 834 // Update UMA only if error (with or without feedback) is currently shown.
823 if (ui_page_ == UIPage::ERROR) { 835 if (ui_page_ == ArcSupportHost::UIPage::ERROR) {
824 UpdateOptInActionUMA(OptInActionType::RETRY); 836 UpdateOptInActionUMA(OptInActionType::RETRY);
825 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) { 837 } else if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) {
826 UpdateOptInActionUMA(OptInActionType::RETRY); 838 UpdateOptInActionUMA(OptInActionType::RETRY);
827 ShutdownBridge(); 839 ShutdownBridge();
828 } 840 }
829 841
830 DCHECK(arc_bridge_service()->stopped()); 842 DCHECK(arc_bridge_service()->stopped());
831 SetState(State::FETCHING_CODE); 843 SetState(State::FETCHING_CODE);
832 PrepareContextForAuthCodeRequest(); 844 PrepareContextForAuthCodeRequest();
833 } 845 }
834 846
835 void ArcAuthService::CancelAuthCode() { 847 void ArcAuthService::CancelAuthCode() {
836 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 848 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
837 849
838 if (state_ == State::NOT_INITIALIZED) { 850 if (state_ == State::NOT_INITIALIZED) {
839 NOTREACHED(); 851 NOTREACHED();
840 return; 852 return;
841 } 853 }
842 854
843 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means 855 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means
844 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not 856 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not
845 // be started). If Arc is booting normally dont't stop it on progress close. 857 // be started). If Arc is booting normally dont't stop it on progress close.
846 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR && 858 if (state_ != State::FETCHING_CODE &&
847 ui_page_ != UIPage::ERROR_WITH_FEEDBACK) { 859 ui_page_ != ArcSupportHost::UIPage::ERROR &&
860 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) {
848 return; 861 return;
849 } 862 }
850 863
851 // Update UMA with user cancel only if error is not currently shown. 864 // Update UMA with user cancel only if error is not currently shown.
852 if (ui_page_ != UIPage::ERROR && ui_page_ == UIPage::ERROR_WITH_FEEDBACK && 865 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK)
853 ui_page_ != UIPage::NO_PAGE) {
854 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 866 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
855 }
856 867
857 StopArc(); 868 StopArc();
858 869
859 if (IsArcManaged()) 870 if (IsArcManaged())
860 return; 871 return;
861 872
862 DisableArc(); 873 DisableArc();
863 } 874 }
864 875
865 bool ArcAuthService::IsArcManaged() const { 876 bool ArcAuthService::IsArcManaged() const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 if (IsAllowed()) 913 if (IsAllowed())
903 UpdateEnabledStateUMA(IsArcEnabled()); 914 UpdateEnabledStateUMA(IsArcEnabled());
904 } 915 }
905 916
906 void ArcAuthService::StartUI() { 917 void ArcAuthService::StartUI() {
907 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 918 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
908 919
909 if (!arc_bridge_service()->stopped()) { 920 if (!arc_bridge_service()->stopped()) {
910 // If the user attempts to re-enable ARC while the bridge is still running 921 // If the user attempts to re-enable ARC while the bridge is still running
911 // the user should not be able to continue until the bridge has stopped. 922 // the user should not be able to continue until the bridge has stopped.
912 ShowUI(UIPage::ERROR, l10n_util::GetStringUTF16( 923 ShowUI(
913 IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); 924 ArcSupportHost::UIPage::ERROR,
925 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR));
914 return; 926 return;
915 } 927 }
916 928
917 SetState(State::FETCHING_CODE); 929 SetState(State::FETCHING_CODE);
918 ShowUI(UIPage::TERMS, base::string16()); 930 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16());
919 } 931 }
920 932
921 void ArcAuthService::OnPrepareContextFailed() { 933 void ArcAuthService::OnPrepareContextFailed() {
922 DCHECK_EQ(state_, State::FETCHING_CODE); 934 DCHECK_EQ(state_, State::FETCHING_CODE);
923 935
924 ShutdownBridgeAndShowUI( 936 ShutdownBridgeAndShowUI(
925 UIPage::ERROR, 937 ArcSupportHost::UIPage::ERROR,
926 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 938 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
927 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 939 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
928 } 940 }
929 941
930 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { 942 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) {
931 SetAuthCodeAndStartArc(auth_code); 943 SetAuthCodeAndStartArc(auth_code);
932 } 944 }
933 945
934 void ArcAuthService::OnAuthCodeFailed() { 946 void ArcAuthService::OnAuthCodeFailed() {
935 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 947 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
936 DCHECK_EQ(state_, State::FETCHING_CODE); 948 DCHECK_EQ(state_, State::FETCHING_CODE);
937 ShutdownBridgeAndShowUI( 949 ShutdownBridgeAndShowUI(
938 UIPage::ERROR, 950 ArcSupportHost::UIPage::ERROR,
939 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 951 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
940 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 952 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
941 } 953 }
942 954
943 void ArcAuthService::OnAndroidManagementChecked( 955 void ArcAuthService::OnAndroidManagementChecked(
944 policy::AndroidManagementClient::Result result) { 956 policy::AndroidManagementClient::Result result) {
945 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 957 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
946 switch (result) { 958 switch (result) {
947 case policy::AndroidManagementClient::Result::UNMANAGED: 959 case policy::AndroidManagementClient::Result::UNMANAGED:
948 OnAndroidManagementPassed(); 960 OnAndroidManagementPassed();
949 break; 961 break;
950 case policy::AndroidManagementClient::Result::MANAGED: 962 case policy::AndroidManagementClient::Result::MANAGED:
951 ShutdownBridgeAndShowUI( 963 ShutdownBridgeAndShowUI(
952 UIPage::ERROR, 964 ArcSupportHost::UIPage::ERROR,
953 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); 965 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
954 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); 966 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
955 break; 967 break;
956 case policy::AndroidManagementClient::Result::ERROR: 968 case policy::AndroidManagementClient::Result::ERROR:
957 ShutdownBridgeAndShowUI( 969 ShutdownBridgeAndShowUI(
958 UIPage::ERROR, 970 ArcSupportHost::UIPage::ERROR,
959 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 971 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
960 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 972 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
961 break; 973 break;
962 } 974 }
963 } 975 }
964 976
965 void ArcAuthService::OnBackgroundAndroidManagementChecked( 977 void ArcAuthService::OnBackgroundAndroidManagementChecked(
966 policy::AndroidManagementClient::Result result) { 978 policy::AndroidManagementClient::Result result) {
967 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 979 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
968 switch (result) { 980 switch (result) {
(...skipping 18 matching lines...) Expand all
987 std::string auth_endpoint; 999 std::string auth_endpoint;
988 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { 1000 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
989 auth_endpoint = command_line->GetSwitchValueASCII( 1001 auth_endpoint = command_line->GetSwitchValueASCII(
990 chromeos::switches::kArcUseAuthEndpoint); 1002 chromeos::switches::kArcUseAuthEndpoint);
991 } 1003 }
992 1004
993 if (!auth_endpoint.empty()) { 1005 if (!auth_endpoint.empty()) {
994 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( 1006 auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
995 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); 1007 this, context_->GetURLRequestContext(), profile_, auth_endpoint));
996 } else { 1008 } else {
997 ShowUI(UIPage::LSO_PROGRESS, base::string16()); 1009 ShowUI(ArcSupportHost::UIPage::LSO_PROGRESS, base::string16());
998 } 1010 }
999 } 1011 }
1000 1012
1001 void ArcAuthService::OnAndroidManagementPassed() { 1013 void ArcAuthService::OnAndroidManagementPassed() {
1002 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 1014 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1003 1015
1004 if (state_ == State::ACTIVE) { 1016 if (state_ == State::ACTIVE) {
1005 if (IsAuthCodeRequest()) 1017 if (IsAuthCodeRequest())
1006 FetchAuthCode(); 1018 FetchAuthCode();
1007 return; 1019 return;
1008 } 1020 }
1009 1021
1010 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || 1022 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) ||
1011 IsOptInVerificationDisabled()) { 1023 IsOptInVerificationDisabled()) {
1012 StartArc(); 1024 StartArc();
1013 } else { 1025 } else {
1014 FetchAuthCode(); 1026 FetchAuthCode();
1015 } 1027 }
1016 } 1028 }
1017 1029
1030 void ArcAuthService::OnWindowClosed() {
1031 CancelAuthCode();
1032 }
1033
1034 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled,
1035 bool is_backup_and_restore_enabled,
1036 bool is_location_service_enabled) {
1037 // This is ARC support's UI event callback, so this is called only when
1038 // the UI is visible. The condition to open the UI is
1039 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI())
1040 // and in the case, preference_handler_ should be always created (see
1041 // OnPrimaryUserProfilePrepared()),
1042 // TODO(hidehiko): Simplify the logic with the code restructuring.
1043 DCHECK(preference_handler_);
1044 preference_handler_->EnableMetrics(is_metrics_enabled);
1045 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled);
1046 preference_handler_->EnableLocationService(is_location_service_enabled);
1047 StartLso();
1048 }
1049
1050 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) {
1051 SetAuthCodeAndStartArc(auth_code);
1052 }
1053
1054 void ArcAuthService::OnSendFeedbackClicked() {
1055 chrome::OpenFeedbackDialog(nullptr);
1056 }
1057
1058 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) {
1059 if (!support_host_)
1060 return;
1061 support_host_->SetMetricsPreferenceCheckbox(enabled, managed);
1062 }
1063
1064 void ArcAuthService::OnBackupAndRestoreModeChanged(bool enabled, bool managed) {
1065 if (!support_host_)
1066 return;
1067 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed);
1068 }
1069
1070 void ArcAuthService::OnLocationServicesModeChanged(bool enabled, bool managed) {
1071 if (!support_host_)
1072 return;
1073 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed);
1074 }
1075
1018 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { 1076 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
1019 switch (state) { 1077 switch (state) {
1020 case ArcAuthService::State::NOT_INITIALIZED: 1078 case ArcAuthService::State::NOT_INITIALIZED:
1021 return os << "NOT_INITIALIZED"; 1079 return os << "NOT_INITIALIZED";
1022 case ArcAuthService::State::STOPPED: 1080 case ArcAuthService::State::STOPPED:
1023 return os << "STOPPED"; 1081 return os << "STOPPED";
1024 case ArcAuthService::State::FETCHING_CODE: 1082 case ArcAuthService::State::FETCHING_CODE:
1025 return os << "FETCHING_CODE"; 1083 return os << "FETCHING_CODE";
1026 case ArcAuthService::State::ACTIVE: 1084 case ArcAuthService::State::ACTIVE:
1027 return os << "ACTIVE"; 1085 return os << "ACTIVE";
1028 default: 1086 default:
1029 NOTREACHED(); 1087 NOTREACHED();
1030 return os; 1088 return os;
1031 } 1089 }
1032 } 1090 }
1033 1091
1034 } // namespace arc 1092 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.h ('k') | chrome/browser/chromeos/arc/arc_support_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698