| OLD | NEW |
| 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" |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 784 |
| 785 void ArcAuthService::OnPrepareContextFailed() { | 785 void ArcAuthService::OnPrepareContextFailed() { |
| 786 DCHECK_EQ(state_, State::FETCHING_CODE); | 786 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 787 | 787 |
| 788 ShutdownBridgeAndShowUI( | 788 ShutdownBridgeAndShowUI( |
| 789 UIPage::ERROR, | 789 UIPage::ERROR, |
| 790 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 790 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 791 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 791 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 792 } | 792 } |
| 793 | 793 |
| 794 void ArcAuthService::OnAuthCodeRequested(const std::string& auth_code) { |
| 795 SetAuthCodeAndStartArc(auth_code); |
| 796 } |
| 797 |
| 798 void ArcAuthService::OnAuthCodeFailed() { |
| 799 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 800 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 801 ShutdownBridgeAndShowUI( |
| 802 UIPage::ERROR, |
| 803 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 804 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 805 } |
| 806 |
| 794 void ArcAuthService::CheckAndroidManagement(bool background_mode) { | 807 void ArcAuthService::CheckAndroidManagement(bool background_mode) { |
| 795 // Do not send requests for Chrome OS managed users. | 808 // Do not send requests for Chrome OS managed users. |
| 796 if (IsAccountManaged(profile_)) { | 809 if (IsAccountManaged(profile_)) { |
| 797 StartArcIfSignedIn(); | 810 StartArcIfSignedIn(); |
| 798 return; | 811 return; |
| 799 } | 812 } |
| 800 | 813 |
| 801 // Do not send requests for well-known consumer domains. | 814 // Do not send requests for well-known consumer domains. |
| 802 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( | 815 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( |
| 803 profile_->GetProfileUserName())) { | 816 profile_->GetProfileUserName())) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 833 UIPage::ERROR, | 846 UIPage::ERROR, |
| 834 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 847 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 835 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 848 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 836 break; | 849 break; |
| 837 default: | 850 default: |
| 838 NOTREACHED(); | 851 NOTREACHED(); |
| 839 } | 852 } |
| 840 } | 853 } |
| 841 | 854 |
| 842 void ArcAuthService::StartArcIfSignedIn() { | 855 void ArcAuthService::StartArcIfSignedIn() { |
| 856 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 843 if (state_ == State::ACTIVE) | 857 if (state_ == State::ACTIVE) |
| 844 return; | 858 return; |
| 859 |
| 845 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || | 860 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || |
| 846 IsOptInVerificationDisabled()) { | 861 IsOptInVerificationDisabled()) { |
| 847 StartArc(); | 862 StartArc(); |
| 848 } else { | 863 } else { |
| 849 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | 864 const base::CommandLine* command_line = |
| 865 base::CommandLine::ForCurrentProcess(); |
| 866 std::string auth_endpoint; |
| 867 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { |
| 868 auth_endpoint = command_line->GetSwitchValueASCII( |
| 869 chromeos::switches::kArcUseAuthEndpoint); |
| 870 } |
| 871 |
| 872 if (!auth_endpoint.empty()) |
| 873 context_->FetchAuthCode(auth_endpoint); |
| 874 else |
| 875 ShowUI(UIPage::LSO_PROGRESS, base::string16()); |
| 850 } | 876 } |
| 851 } | 877 } |
| 852 | 878 |
| 853 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 879 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 854 switch (state) { | 880 switch (state) { |
| 855 case ArcAuthService::State::NOT_INITIALIZED: | 881 case ArcAuthService::State::NOT_INITIALIZED: |
| 856 return os << kStateNotInitialized; | 882 return os << kStateNotInitialized; |
| 857 case ArcAuthService::State::STOPPED: | 883 case ArcAuthService::State::STOPPED: |
| 858 return os << kStateStopped; | 884 return os << kStateStopped; |
| 859 case ArcAuthService::State::FETCHING_CODE: | 885 case ArcAuthService::State::FETCHING_CODE: |
| 860 return os << kStateFetchingCode; | 886 return os << kStateFetchingCode; |
| 861 case ArcAuthService::State::ACTIVE: | 887 case ArcAuthService::State::ACTIVE: |
| 862 return os << kStateActive; | 888 return os << kStateActive; |
| 863 default: | 889 default: |
| 864 NOTREACHED(); | 890 NOTREACHED(); |
| 865 return os; | 891 return os; |
| 866 } | 892 } |
| 867 } | 893 } |
| 868 | 894 |
| 869 } // namespace arc | 895 } // namespace arc |
| OLD | NEW |