| 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 21 matching lines...) Expand all Loading... |
| 32 #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/extensions/app_launch_params.h" | 33 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 34 #include "chrome/browser/ui/extensions/application_launch.h" | 34 #include "chrome/browser/ui/extensions/application_launch.h" |
| 35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
| 37 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
| 38 #include "chromeos/cryptohome/cryptohome_parameters.h" | 38 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 39 #include "chromeos/dbus/dbus_thread_manager.h" | 39 #include "chromeos/dbus/dbus_thread_manager.h" |
| 40 #include "chromeos/dbus/session_manager_client.h" | 40 #include "chromeos/dbus/session_manager_client.h" |
| 41 #include "components/arc/arc_bridge_service.h" | 41 #include "components/arc/arc_bridge_service.h" |
| 42 #include "components/policy/core/browser/browser_policy_connector.h" | |
| 43 #include "components/pref_registry/pref_registry_syncable.h" | 42 #include "components/pref_registry/pref_registry_syncable.h" |
| 44 #include "components/prefs/pref_service.h" | 43 #include "components/prefs/pref_service.h" |
| 45 #include "components/syncable_prefs/pref_service_syncable.h" | 44 #include "components/syncable_prefs/pref_service_syncable.h" |
| 46 #include "components/user_manager/user.h" | 45 #include "components/user_manager/user.h" |
| 47 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 48 #include "extensions/browser/app_window/app_window_registry.h" | 47 #include "extensions/browser/app_window/app_window_registry.h" |
| 49 #include "extensions/browser/extension_prefs.h" | 48 #include "extensions/browser/extension_prefs.h" |
| 50 #include "extensions/browser/extension_registry.h" | 49 #include "extensions/browser/extension_registry.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 52 | 51 |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 ArcSupportHost::kHostAppId, profile_)); | 558 ArcSupportHost::kHostAppId, profile_)); |
| 560 OpenApplication(CreateAppLaunchParamsUserContainer( | 559 OpenApplication(CreateAppLaunchParamsUserContainer( |
| 561 profile_, extension, WindowOpenDisposition::NEW_WINDOW, | 560 profile_, extension, WindowOpenDisposition::NEW_WINDOW, |
| 562 extensions::SOURCE_CHROME_INTERNAL)); | 561 extensions::SOURCE_CHROME_INTERNAL)); |
| 563 } | 562 } |
| 564 | 563 |
| 565 void ArcAuthService::OnContextReady() { | 564 void ArcAuthService::OnContextReady() { |
| 566 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 565 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 567 | 566 |
| 568 DCHECK(!initial_opt_in_); | 567 DCHECK(!initial_opt_in_); |
| 569 CheckAndroidManagement(false); | 568 |
| 569 // TODO(hidehiko): The check is not necessary if this is a part of re-auth |
| 570 // flow. Remove this. |
| 571 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 572 profile_, context_->token_service(), context_->account_id(), |
| 573 false /* retry_on_error */)); |
| 574 android_management_checker_->StartCheck( |
| 575 base::Bind(&ArcAuthService::OnAndroidManagementChecked, |
| 576 weak_ptr_factory_.GetWeakPtr())); |
| 570 } | 577 } |
| 571 | 578 |
| 572 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, | 579 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, |
| 573 bool from_sync) { | 580 bool from_sync) { |
| 574 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 581 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 575 | 582 |
| 576 // Update UMA only for local changes | 583 // Update UMA only for local changes |
| 577 if (!from_sync) { | 584 if (!from_sync) { |
| 578 const bool arc_enabled = | 585 const bool arc_enabled = |
| 579 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 586 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 if (state_ == State::ACTIVE) | 623 if (state_ == State::ACTIVE) |
| 617 return; | 624 return; |
| 618 CloseUI(); | 625 CloseUI(); |
| 619 auth_code_.clear(); | 626 auth_code_.clear(); |
| 620 | 627 |
| 621 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 628 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 622 // Need pre-fetch auth code and show OptIn UI if needed. | 629 // Need pre-fetch auth code and show OptIn UI if needed. |
| 623 initial_opt_in_ = true; | 630 initial_opt_in_ = true; |
| 624 StartUI(); | 631 StartUI(); |
| 625 } else { | 632 } else { |
| 626 // Ready to start Arc, but check Android management first. | 633 // Ready to start Arc, but check Android management in parallel. |
| 634 StartArc(); |
| 635 // Note: Because the callback may be called in synchronous way (i.e. called |
| 636 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
| 637 // Otherwise, DisableArc() which may be called in |
| 638 // OnBackgroundAndroidManagementChecked() could be ignored. |
| 627 if (!g_disable_ui_for_testing || | 639 if (!g_disable_ui_for_testing || |
| 628 g_enable_check_android_management_for_testing) { | 640 g_enable_check_android_management_for_testing) { |
| 629 CheckAndroidManagement(true); | 641 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 630 } else { | 642 profile_, context_->token_service(), context_->account_id(), |
| 631 StartArc(); | 643 true /* retry_on_error */)); |
| 644 android_management_checker_->StartCheck( |
| 645 base::Bind(&ArcAuthService::OnBackgroundAndroidManagementChecked, |
| 646 weak_ptr_factory_.GetWeakPtr())); |
| 632 } | 647 } |
| 633 } | 648 } |
| 634 | 649 |
| 635 UpdateEnabledStateUMA(true); | 650 UpdateEnabledStateUMA(true); |
| 636 } | 651 } |
| 637 | 652 |
| 638 void ArcAuthService::ShutdownBridge() { | 653 void ArcAuthService::ShutdownBridge() { |
| 639 arc_sign_in_timer_.Stop(); | 654 arc_sign_in_timer_.Stop(); |
| 640 playstore_launcher_.reset(); | 655 playstore_launcher_.reset(); |
| 641 auth_callback_.Reset(); | 656 auth_callback_.Reset(); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 874 |
| 860 void ArcAuthService::OnAuthCodeFailed() { | 875 void ArcAuthService::OnAuthCodeFailed() { |
| 861 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 876 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 862 DCHECK_EQ(state_, State::FETCHING_CODE); | 877 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 863 ShutdownBridgeAndShowUI( | 878 ShutdownBridgeAndShowUI( |
| 864 UIPage::ERROR, | 879 UIPage::ERROR, |
| 865 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 880 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 866 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 881 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 867 } | 882 } |
| 868 | 883 |
| 869 void ArcAuthService::CheckAndroidManagement(bool background_mode) { | |
| 870 // Do not send requests for Chrome OS managed users. | |
| 871 if (policy_util::IsAccountManaged(profile_)) { | |
| 872 OnAndroidManagementPassed(); | |
| 873 return; | |
| 874 } | |
| 875 | |
| 876 // Do not send requests for well-known consumer domains. | |
| 877 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( | |
| 878 profile_->GetProfileUserName())) { | |
| 879 OnAndroidManagementPassed(); | |
| 880 return; | |
| 881 } | |
| 882 | |
| 883 android_management_checker_.reset( | |
| 884 new ArcAndroidManagementChecker(this, context_->token_service(), | |
| 885 context_->account_id(), background_mode)); | |
| 886 if (background_mode) | |
| 887 OnAndroidManagementPassed(); | |
| 888 } | |
| 889 | |
| 890 void ArcAuthService::OnAndroidManagementChecked( | 884 void ArcAuthService::OnAndroidManagementChecked( |
| 891 policy::AndroidManagementClient::Result result) { | 885 policy::AndroidManagementClient::Result result) { |
| 886 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 892 switch (result) { | 887 switch (result) { |
| 893 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: | 888 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: |
| 894 OnAndroidManagementPassed(); | 889 OnAndroidManagementPassed(); |
| 895 break; | 890 break; |
| 896 case policy::AndroidManagementClient::Result::RESULT_MANAGED: | 891 case policy::AndroidManagementClient::Result::RESULT_MANAGED: |
| 897 if (android_management_checker_->background_mode()) { | |
| 898 DisableArc(); | |
| 899 return; | |
| 900 } | |
| 901 ShutdownBridgeAndShowUI( | 892 ShutdownBridgeAndShowUI( |
| 902 UIPage::ERROR, | 893 UIPage::ERROR, |
| 903 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); | 894 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); |
| 904 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 895 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 905 break; | 896 break; |
| 906 case policy::AndroidManagementClient::Result::RESULT_ERROR: | 897 case policy::AndroidManagementClient::Result::RESULT_ERROR: |
| 907 ShutdownBridgeAndShowUI( | 898 ShutdownBridgeAndShowUI( |
| 908 UIPage::ERROR, | 899 UIPage::ERROR, |
| 909 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 900 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 910 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 901 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 911 break; | 902 break; |
| 912 default: | 903 default: |
| 913 NOTREACHED(); | 904 NOTREACHED(); |
| 914 } | 905 } |
| 915 } | 906 } |
| 916 | 907 |
| 908 void ArcAuthService::OnBackgroundAndroidManagementChecked( |
| 909 policy::AndroidManagementClient::Result result) { |
| 910 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 911 switch (result) { |
| 912 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: |
| 913 // Do nothing. ARC should be started already. |
| 914 break; |
| 915 case policy::AndroidManagementClient::Result::RESULT_MANAGED: |
| 916 DisableArc(); |
| 917 break; |
| 918 case policy::AndroidManagementClient::Result::RESULT_ERROR: |
| 919 // This code should not be reached. For background check, |
| 920 // retry_on_error should be set. |
| 921 NOTREACHED(); |
| 922 } |
| 923 } |
| 924 |
| 917 void ArcAuthService::FetchAuthCode() { | 925 void ArcAuthService::FetchAuthCode() { |
| 918 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 926 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 919 | 927 |
| 920 const base::CommandLine* command_line = | 928 const base::CommandLine* command_line = |
| 921 base::CommandLine::ForCurrentProcess(); | 929 base::CommandLine::ForCurrentProcess(); |
| 922 std::string auth_endpoint; | 930 std::string auth_endpoint; |
| 923 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { | 931 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { |
| 924 auth_endpoint = command_line->GetSwitchValueASCII( | 932 auth_endpoint = command_line->GetSwitchValueASCII( |
| 925 chromeos::switches::kArcUseAuthEndpoint); | 933 chromeos::switches::kArcUseAuthEndpoint); |
| 926 } | 934 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 return os << "FETCHING_CODE"; | 968 return os << "FETCHING_CODE"; |
| 961 case ArcAuthService::State::ACTIVE: | 969 case ArcAuthService::State::ACTIVE: |
| 962 return os << "ACTIVE"; | 970 return os << "ACTIVE"; |
| 963 default: | 971 default: |
| 964 NOTREACHED(); | 972 NOTREACHED(); |
| 965 return os; | 973 return os; |
| 966 } | 974 } |
| 967 } | 975 } |
| 968 | 976 |
| 969 } // namespace arc | 977 } // namespace arc |
| OLD | NEW |