Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_session_manager.h" | 5 #include "chrome/browser/chromeos/arc/arc_session_manager.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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 default: | 304 default: |
| 305 error = ArcSupportHost::Error::SIGN_IN_UNKNOWN_ERROR; | 305 error = ArcSupportHost::Error::SIGN_IN_UNKNOWN_ERROR; |
| 306 break; | 306 break; |
| 307 } | 307 } |
| 308 | 308 |
| 309 if (result == ProvisioningResult::ARC_STOPPED || | 309 if (result == ProvisioningResult::ARC_STOPPED || |
| 310 result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { | 310 result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { |
| 311 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) | 311 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) |
| 312 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 312 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 313 ShutdownSession(); | 313 ShutdownSession(); |
| 314 if (support_host_) | 314 ShowArcSupportHostError(error, false); |
| 315 support_host_->ShowError(error, false); | |
| 316 return; | 315 return; |
| 317 } | 316 } |
| 318 | 317 |
| 319 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || | 318 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || |
| 320 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || | 319 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || |
| 321 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || | 320 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || |
| 322 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is | 321 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is |
| 323 // fully setup, but Chrome does not. | 322 // fully setup, but Chrome does not. |
| 324 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || | 323 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || |
| 325 // Just to be safe, remove data if we don't know the cause. | 324 // Just to be safe, remove data if we don't know the cause. |
| 326 result == ProvisioningResult::UNKNOWN_ERROR) { | 325 result == ProvisioningResult::UNKNOWN_ERROR) { |
| 327 VLOG(1) << "ARC provisioning failed permanently. Removing user data"; | 326 VLOG(1) << "ARC provisioning failed permanently. Removing user data"; |
| 328 RequestArcDataRemoval(); | 327 RequestArcDataRemoval(); |
| 329 } | 328 } |
| 330 | 329 |
| 331 // We'll delay shutting down the ARC instance in this case to allow people | 330 // We'll delay shutting down the ARC instance in this case to allow people |
| 332 // to send feedback. | 331 // to send feedback. |
| 333 if (support_host_) | 332 ShowArcSupportHostError(error, true /* = show send feedback button */); |
| 334 support_host_->ShowError(error, true /* = show send feedback button */); | |
| 335 } | 333 } |
| 336 | 334 |
| 337 void ArcSessionManager::SetState(State state) { | 335 void ArcSessionManager::SetState(State state) { |
| 338 state_ = state; | 336 state_ = state; |
| 339 } | 337 } |
| 340 | 338 |
| 341 bool ArcSessionManager::IsAllowed() const { | 339 bool ArcSessionManager::IsAllowed() const { |
| 342 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 340 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 343 return profile_ != nullptr; | 341 return profile_ != nullptr; |
| 344 } | 342 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 // For Kiosk mode, skip ToS because it is very likely that near the device | 519 // For Kiosk mode, skip ToS because it is very likely that near the device |
| 522 // there will be no one who is eligible to accept them. | 520 // there will be no one who is eligible to accept them. |
| 523 // If opt-in verification is disabled, skip negotiation, too. This is for | 521 // If opt-in verification is disabled, skip negotiation, too. This is for |
| 524 // testing purpose. | 522 // testing purpose. |
| 525 if (prefs->GetBoolean(prefs::kArcSignedIn) || ShouldArcAlwaysStart() || | 523 if (prefs->GetBoolean(prefs::kArcSignedIn) || ShouldArcAlwaysStart() || |
| 526 IsArcKioskMode() || IsArcOptInVerificationDisabled()) { | 524 IsArcKioskMode() || IsArcOptInVerificationDisabled()) { |
| 527 StartArc(); | 525 StartArc(); |
| 528 // Check Android management in parallel. | 526 // Check Android management in parallel. |
| 529 // Note: StartBackgroundAndroidManagementCheck() may call | 527 // Note: StartBackgroundAndroidManagementCheck() may call |
| 530 // OnBackgroundAndroidManagementChecked() synchronously (or | 528 // OnBackgroundAndroidManagementChecked() synchronously (or |
| 531 // asynchornously). In the callback, Google Play Store enabled preference | 529 // asynchronously). In the callback, Google Play Store enabled preference |
| 532 // can be set to false if managed, and it triggers RequestDisable() via | 530 // can be set to false if managed, and it triggers RequestDisable() via |
| 533 // ArcPlayStoreEnabledPreferenceHandler. | 531 // ArcPlayStoreEnabledPreferenceHandler |
| 534 // Thus, StartArc() should be called so that disabling should work even | 532 // Thus, StartArc() should be called so that disabling should work even |
| 535 // if synchronous call case. | 533 // if synchronous call case. |
| 536 StartBackgroundAndroidManagementCheck(); | 534 StartBackgroundAndroidManagementCheck(); |
| 537 return; | 535 return; |
| 538 } | 536 } |
| 539 | 537 |
| 540 MaybeStartTermsOfServiceNegotiation(); | 538 MaybeStartTermsOfServiceNegotiation(); |
| 541 } | 539 } |
| 542 | 540 |
| 543 void ArcSessionManager::RequestDisable() { | 541 void ArcSessionManager::RequestDisable() { |
| 544 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 542 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 545 DCHECK(profile_); | 543 DCHECK(profile_); |
| 546 | 544 |
| 547 if (!enable_requested_) { | 545 if (!enable_requested_) { |
| 548 VLOG(1) << "ARC is already disabled. Do nothing."; | 546 VLOG(1) << "ARC is already disabled. Do nothing."; |
| 549 return; | 547 return; |
| 550 } | 548 } |
| 551 enable_requested_ = false; | 549 enable_requested_ = false; |
| 552 | 550 |
| 553 // Reset any pending request to re-enable ARC. | 551 // Reset any pending request to re-enable ARC. |
| 554 reenable_arc_ = false; | 552 reenable_arc_ = false; |
| 555 StopArc(); | 553 StopArc(); |
| 556 VLOG(1) << "ARC opt-out. Removing user data."; | 554 VLOG(1) << "ARC opt-out. Removing user data."; |
| 557 RequestArcDataRemoval(); | 555 RequestArcDataRemoval(); |
| 558 } | 556 } |
| 559 | 557 |
| 560 void ArcSessionManager::RequestArcDataRemoval() { | 558 void ArcSessionManager::RequestArcDataRemoval() { |
| 561 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 559 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 562 DCHECK(profile_); | 560 DCHECK(profile_); |
| 563 // TODO(hidehiko): DCHECK the previous state. This is called for three cases; | 561 // TODO(hidehiko): DCHECK the previous state. This is called for four cases; |
|
hidehiko
2017/03/13 05:10:46
Good catch :-)
| |
| 564 // 1) Supporting managed user initial disabled case (Please see also | 562 // 1) Supporting managed user initial disabled case (Please see also |
| 565 // ArcPlayStoreEnabledPreferenceHandler::Start() for details). | 563 // ArcPlayStoreEnabledPreferenceHandler::Start() for details). |
| 566 // 2) Supporting enterprise triggered data removal. | 564 // 2) Supporting enterprise triggered data removal. |
| 567 // 3) One called in OnProvisioningFinished(). | 565 // 3) One called in OnProvisioningFinished(). |
| 568 // 4) On request disabling. | 566 // 4) On request disabling. |
| 569 // After the state machine is fixed, 2) should be replaced by | 567 // After the state machine is fixed, 2) should be replaced by |
| 570 // RequestDisable() immediately followed by RequestEnable(). | 568 // RequestDisable() immediately followed by RequestEnable(). |
| 571 // 3) and 4) are internal state transition. So, as for public interface, 1) | 569 // 3) and 4) are internal state transition. So, as for public interface, 1) |
| 572 // should be the only use case, and the |state_| should be limited to | 570 // should be the only use case, and the |state_| should be limited to |
| 573 // STOPPED, then. | 571 // STOPPED, then. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 592 DCHECK(!IsArcKioskMode()); | 590 DCHECK(!IsArcKioskMode()); |
| 593 // If opt-in verification is disabled, Terms of Service negotiation should | 591 // If opt-in verification is disabled, Terms of Service negotiation should |
| 594 // be skipped, too. See also RequestEnableImpl(). | 592 // be skipped, too. See also RequestEnableImpl(). |
| 595 DCHECK(!IsArcOptInVerificationDisabled()); | 593 DCHECK(!IsArcOptInVerificationDisabled()); |
| 596 | 594 |
| 597 // TODO(hidehiko): Remove this condition, when the state machine is fixed. | 595 // TODO(hidehiko): Remove this condition, when the state machine is fixed. |
| 598 if (!arc_session_runner_->IsStopped()) { | 596 if (!arc_session_runner_->IsStopped()) { |
| 599 // If the user attempts to re-enable ARC while the ARC instance is still | 597 // If the user attempts to re-enable ARC while the ARC instance is still |
| 600 // running the user should not be able to continue until the ARC instance | 598 // running the user should not be able to continue until the ARC instance |
| 601 // has stopped. | 599 // has stopped. |
| 602 if (support_host_) { | 600 ShowArcSupportHostError( |
| 603 support_host_->ShowError( | 601 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
| 604 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | |
| 605 } | |
| 606 return; | 602 return; |
| 607 } | 603 } |
| 608 | 604 |
| 609 // TODO(hidehiko): DCHECK if |state_| is STOPPED, when the state machine | 605 // TODO(hidehiko): DCHECK if |state_| is STOPPED, when the state machine |
| 610 // is fixed. | 606 // is fixed. |
| 611 SetState(State::NEGOTIATING_TERMS_OF_SERVICE); | 607 SetState(State::NEGOTIATING_TERMS_OF_SERVICE); |
| 612 | 608 |
| 613 if (!IsArcTermsOfServiceNegotiationNeeded()) { | 609 if (!IsArcTermsOfServiceNegotiationNeeded()) { |
| 614 // Moves to next state, Android management check, immediately, as if | 610 // Moves to next state, Android management check, immediately, as if |
| 615 // Terms of Service negotiation is done successfully. | 611 // Terms of Service negotiation is done successfully. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 | 688 |
| 693 // Show loading UI only if ARC support app's window is already shown. | 689 // Show loading UI only if ARC support app's window is already shown. |
| 694 // User may not see any ARC support UI if everything needed is done in | 690 // User may not see any ARC support UI if everything needed is done in |
| 695 // background. In such a case, showing loading UI here (then closed sometime | 691 // background. In such a case, showing loading UI here (then closed sometime |
| 696 // soon later) would look just noisy. | 692 // soon later) would look just noisy. |
| 697 if (support_host_ && | 693 if (support_host_ && |
| 698 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) { | 694 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) { |
| 699 support_host_->ShowArcLoading(); | 695 support_host_->ShowArcLoading(); |
| 700 } | 696 } |
| 701 | 697 |
| 698 for (auto& observer : observer_list_) | |
| 699 observer.OnArcStartOptInAndroidManagementCheck(); | |
| 700 | |
| 702 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( | 701 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( |
| 703 profile_, context_->token_service(), context_->account_id(), | 702 profile_, context_->token_service(), context_->account_id(), |
| 704 false /* retry_on_error */); | 703 false /* retry_on_error */); |
| 705 android_management_checker_->StartCheck( | 704 android_management_checker_->StartCheck( |
| 706 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, | 705 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
| 707 weak_ptr_factory_.GetWeakPtr())); | 706 weak_ptr_factory_.GetWeakPtr())); |
| 708 } | 707 } |
| 709 | 708 |
| 710 void ArcSessionManager::OnAndroidManagementChecked( | 709 void ArcSessionManager::OnAndroidManagementChecked( |
| 711 policy::AndroidManagementClient::Result result) { | 710 policy::AndroidManagementClient::Result result) { |
| 712 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 711 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 713 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); | 712 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); |
| 714 DCHECK(android_management_checker_); | 713 DCHECK(android_management_checker_); |
| 715 android_management_checker_.reset(); | 714 android_management_checker_.reset(); |
| 716 | 715 |
| 717 switch (result) { | 716 switch (result) { |
| 718 case policy::AndroidManagementClient::Result::UNMANAGED: | 717 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 719 VLOG(1) << "Starting ARC for first sign in."; | 718 VLOG(1) << "Starting ARC for first sign in."; |
| 720 sign_in_start_time_ = base::Time::Now(); | 719 sign_in_start_time_ = base::Time::Now(); |
| 721 arc_sign_in_timer_.Start( | 720 arc_sign_in_timer_.Start( |
| 722 FROM_HERE, kArcSignInTimeout, | 721 FROM_HERE, kArcSignInTimeout, |
| 723 base::Bind(&ArcSessionManager::OnArcSignInTimeout, | 722 base::Bind(&ArcSessionManager::OnArcSignInTimeout, |
| 724 weak_ptr_factory_.GetWeakPtr())); | 723 weak_ptr_factory_.GetWeakPtr())); |
| 725 StartArc(); | 724 StartArc(); |
| 726 break; | 725 break; |
| 727 case policy::AndroidManagementClient::Result::MANAGED: | 726 case policy::AndroidManagementClient::Result::MANAGED: |
| 728 if (support_host_) { | 727 ShowArcSupportHostError( |
| 729 support_host_->ShowError( | 728 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); |
| 730 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); | |
| 731 } | |
| 732 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 729 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 733 break; | 730 break; |
| 734 case policy::AndroidManagementClient::Result::ERROR: | 731 case policy::AndroidManagementClient::Result::ERROR: |
| 735 if (support_host_) { | 732 ShowArcSupportHostError(ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, |
| 736 support_host_->ShowError( | 733 false); |
| 737 ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, false); | |
| 738 } | |
| 739 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 734 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 740 break; | 735 break; |
| 741 } | 736 } |
| 742 } | 737 } |
| 743 | 738 |
| 744 void ArcSessionManager::StartBackgroundAndroidManagementCheck() { | 739 void ArcSessionManager::StartBackgroundAndroidManagementCheck() { |
| 745 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 740 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 746 DCHECK_EQ(state_, State::ACTIVE); | 741 DCHECK_EQ(state_, State::ACTIVE); |
| 747 DCHECK(!android_management_checker_); | 742 DCHECK(!android_management_checker_); |
| 748 | 743 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 arc_session_runner_ = std::move(arc_session_runner); | 944 arc_session_runner_ = std::move(arc_session_runner); |
| 950 arc_session_runner_->AddObserver(this); | 945 arc_session_runner_->AddObserver(this); |
| 951 } | 946 } |
| 952 | 947 |
| 953 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( | 948 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( |
| 954 const base::Closure& callback) { | 949 const base::Closure& callback) { |
| 955 DCHECK(!callback.is_null()); | 950 DCHECK(!callback.is_null()); |
| 956 attempt_user_exit_callback_ = callback; | 951 attempt_user_exit_callback_ = callback; |
| 957 } | 952 } |
| 958 | 953 |
| 954 void ArcSessionManager::ShowArcSupportHostError( | |
| 955 ArcSupportHost::Error error, | |
| 956 bool should_show_send_feedback) { | |
| 957 if (support_host_) | |
| 958 support_host_->ShowError(error, should_show_send_feedback); | |
| 959 for (auto& observer : observer_list_) | |
| 960 observer.OnArcSupportHostErrorShown(error); | |
|
hidehiko
2017/03/13 05:10:46
Notifying when |support_host_| is null looks weird
emaxx
2017/03/16 18:32:12
Done.
Renamed to OnArcShowingErrorRequested, do yo
| |
| 961 } | |
| 962 | |
| 959 std::ostream& operator<<(std::ostream& os, | 963 std::ostream& operator<<(std::ostream& os, |
| 960 const ArcSessionManager::State& state) { | 964 const ArcSessionManager::State& state) { |
| 961 #define MAP_STATE(name) \ | 965 #define MAP_STATE(name) \ |
| 962 case ArcSessionManager::State::name: \ | 966 case ArcSessionManager::State::name: \ |
| 963 return os << #name | 967 return os << #name |
| 964 | 968 |
| 965 switch (state) { | 969 switch (state) { |
| 966 MAP_STATE(NOT_INITIALIZED); | 970 MAP_STATE(NOT_INITIALIZED); |
| 967 MAP_STATE(STOPPED); | 971 MAP_STATE(STOPPED); |
| 968 MAP_STATE(NEGOTIATING_TERMS_OF_SERVICE); | 972 MAP_STATE(NEGOTIATING_TERMS_OF_SERVICE); |
| 969 MAP_STATE(CHECKING_ANDROID_MANAGEMENT); | 973 MAP_STATE(CHECKING_ANDROID_MANAGEMENT); |
| 970 MAP_STATE(REMOVING_DATA_DIR); | 974 MAP_STATE(REMOVING_DATA_DIR); |
| 971 MAP_STATE(ACTIVE); | 975 MAP_STATE(ACTIVE); |
| 972 } | 976 } |
| 973 | 977 |
| 974 #undef MAP_STATE | 978 #undef MAP_STATE |
| 975 | 979 |
| 976 // Some compilers report an error even if all values of an enum-class are | 980 // Some compilers report an error even if all values of an enum-class are |
| 977 // covered exhaustively in a switch statement. | 981 // covered exhaustively in a switch statement. |
| 978 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 982 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 979 return os; | 983 return os; |
| 980 } | 984 } |
| 981 | 985 |
| 982 } // namespace arc | 986 } // namespace arc |
| OLD | NEW |