| 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" |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_android_management_checker.h" | 16 #include "chrome/browser/chromeos/arc/arc_android_management_checker.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_auth_context.h" | 18 #include "chrome/browser/chromeos/arc/arc_auth_context.h" |
| 18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 19 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 20 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 21 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 22 #include "chrome/browser/extensions/extension_util.h" | 23 #include "chrome/browser/extensions/extension_util.h" |
| 23 #include "chrome/browser/policy/profile_policy_connector.h" | 24 #include "chrome/browser/policy/profile_policy_connector.h" |
| 24 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 25 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 25 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 26 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 } | 592 } |
| 592 } | 593 } |
| 593 | 594 |
| 594 UpdateEnabledStateUMA(true); | 595 UpdateEnabledStateUMA(true); |
| 595 } | 596 } |
| 596 | 597 |
| 597 void ArcAuthService::ShutdownBridge() { | 598 void ArcAuthService::ShutdownBridge() { |
| 598 playstore_launcher_.reset(); | 599 playstore_launcher_.reset(); |
| 599 auth_callback_.Reset(); | 600 auth_callback_.Reset(); |
| 600 android_management_checker_.reset(); | 601 android_management_checker_.reset(); |
| 602 auth_code_fetcher_.reset(); |
| 601 arc_bridge_service()->Shutdown(); | 603 arc_bridge_service()->Shutdown(); |
| 602 if (state_ != State::NOT_INITIALIZED) | 604 if (state_ != State::NOT_INITIALIZED) |
| 603 SetState(State::STOPPED); | 605 SetState(State::STOPPED); |
| 604 FOR_EACH_OBSERVER(Observer, observer_list_, OnShutdownBridge()); | 606 FOR_EACH_OBSERVER(Observer, observer_list_, OnShutdownBridge()); |
| 605 } | 607 } |
| 606 | 608 |
| 607 void ArcAuthService::ShutdownBridgeAndCloseUI() { | 609 void ArcAuthService::ShutdownBridgeAndCloseUI() { |
| 608 ShutdownBridge(); | 610 ShutdownBridge(); |
| 609 CloseUI(); | 611 CloseUI(); |
| 610 } | 612 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 786 |
| 785 void ArcAuthService::OnPrepareContextFailed() { | 787 void ArcAuthService::OnPrepareContextFailed() { |
| 786 DCHECK_EQ(state_, State::FETCHING_CODE); | 788 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 787 | 789 |
| 788 ShutdownBridgeAndShowUI( | 790 ShutdownBridgeAndShowUI( |
| 789 UIPage::ERROR, | 791 UIPage::ERROR, |
| 790 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 792 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 791 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 793 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 792 } | 794 } |
| 793 | 795 |
| 796 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { |
| 797 SetAuthCodeAndStartArc(auth_code); |
| 798 } |
| 799 |
| 800 void ArcAuthService::OnAuthCodeFailed() { |
| 801 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 802 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 803 ShutdownBridgeAndShowUI( |
| 804 UIPage::ERROR, |
| 805 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 806 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 807 } |
| 808 |
| 794 void ArcAuthService::CheckAndroidManagement(bool background_mode) { | 809 void ArcAuthService::CheckAndroidManagement(bool background_mode) { |
| 795 // Do not send requests for Chrome OS managed users. | 810 // Do not send requests for Chrome OS managed users. |
| 796 if (IsAccountManaged(profile_)) { | 811 if (IsAccountManaged(profile_)) { |
| 797 StartArcIfSignedIn(); | 812 StartArcIfSignedIn(); |
| 798 return; | 813 return; |
| 799 } | 814 } |
| 800 | 815 |
| 801 // Do not send requests for well-known consumer domains. | 816 // Do not send requests for well-known consumer domains. |
| 802 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( | 817 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( |
| 803 profile_->GetProfileUserName())) { | 818 profile_->GetProfileUserName())) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 833 UIPage::ERROR, | 848 UIPage::ERROR, |
| 834 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 849 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 835 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 850 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 836 break; | 851 break; |
| 837 default: | 852 default: |
| 838 NOTREACHED(); | 853 NOTREACHED(); |
| 839 } | 854 } |
| 840 } | 855 } |
| 841 | 856 |
| 842 void ArcAuthService::StartArcIfSignedIn() { | 857 void ArcAuthService::StartArcIfSignedIn() { |
| 858 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 843 if (state_ == State::ACTIVE) | 859 if (state_ == State::ACTIVE) |
| 844 return; | 860 return; |
| 861 |
| 845 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || | 862 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || |
| 846 IsOptInVerificationDisabled()) { | 863 IsOptInVerificationDisabled()) { |
| 847 StartArc(); | 864 StartArc(); |
| 848 } else { | 865 } else { |
| 849 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | 866 const base::CommandLine* command_line = |
| 867 base::CommandLine::ForCurrentProcess(); |
| 868 std::string auth_endpoint; |
| 869 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { |
| 870 auth_endpoint = command_line->GetSwitchValueASCII( |
| 871 chromeos::switches::kArcUseAuthEndpoint); |
| 872 } |
| 873 |
| 874 if (!auth_endpoint.empty()) { |
| 875 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( |
| 876 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); |
| 877 } else { |
| 878 ShowUI(UIPage::LSO_PROGRESS, base::string16()); |
| 879 } |
| 850 } | 880 } |
| 851 } | 881 } |
| 852 | 882 |
| 853 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 883 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 854 switch (state) { | 884 switch (state) { |
| 855 case ArcAuthService::State::NOT_INITIALIZED: | 885 case ArcAuthService::State::NOT_INITIALIZED: |
| 856 return os << kStateNotInitialized; | 886 return os << kStateNotInitialized; |
| 857 case ArcAuthService::State::STOPPED: | 887 case ArcAuthService::State::STOPPED: |
| 858 return os << kStateStopped; | 888 return os << kStateStopped; |
| 859 case ArcAuthService::State::FETCHING_CODE: | 889 case ArcAuthService::State::FETCHING_CODE: |
| 860 return os << kStateFetchingCode; | 890 return os << kStateFetchingCode; |
| 861 case ArcAuthService::State::ACTIVE: | 891 case ArcAuthService::State::ACTIVE: |
| 862 return os << kStateActive; | 892 return os << kStateActive; |
| 863 default: | 893 default: |
| 864 NOTREACHED(); | 894 NOTREACHED(); |
| 865 return os; | 895 return os; |
| 866 } | 896 } |
| 867 } | 897 } |
| 868 | 898 |
| 869 } // namespace arc | 899 } // namespace arc |
| OLD | NEW |