| 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 "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.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_auth_notification.h" | 18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_migration_guide_notification.h" | 20 #include "chrome/browser/chromeos/arc/arc_migration_guide_notification.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 21 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 22 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 22 #include "chrome/browser/chromeos/arc/arc_util.h" | 23 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 23 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" | 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" |
| 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator
.h" | 25 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator
.h" |
| 25 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" | 26 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" |
| 26 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" | 27 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 27 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 28 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // TODO(hidehiko): Revisit to think about lazy initialization. | 410 // TODO(hidehiko): Revisit to think about lazy initialization. |
| 410 // | 411 // |
| 411 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must | 412 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must |
| 412 // be the kiosk app. In case of error the UI will be useless as well, because | 413 // be the kiosk app. In case of error the UI will be useless as well, because |
| 413 // in typical use case there will be no one nearby the kiosk device, who can | 414 // in typical use case there will be no one nearby the kiosk device, who can |
| 414 // do some action to solve the problem be means of UI. | 415 // do some action to solve the problem be means of UI. |
| 415 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && | 416 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && |
| 416 !IsArcKioskMode()) { | 417 !IsArcKioskMode()) { |
| 417 DCHECK(!support_host_); | 418 DCHECK(!support_host_); |
| 418 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); | 419 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); |
| 419 support_host_->AddObserver(this); | 420 support_host_->SetErrorDelegate(this); |
| 420 } | 421 } |
| 421 | 422 |
| 422 DCHECK_EQ(State::NOT_INITIALIZED, state_); | 423 DCHECK_EQ(State::NOT_INITIALIZED, state_); |
| 423 SetState(State::STOPPED); | 424 SetState(State::STOPPED); |
| 424 | 425 |
| 425 context_ = base::MakeUnique<ArcAuthContext>(profile_); | 426 context_ = base::MakeUnique<ArcAuthContext>(profile_); |
| 426 | 427 |
| 427 if (!g_disable_ui_for_testing || | 428 if (!g_disable_ui_for_testing || |
| 428 g_enable_check_android_management_for_testing) { | 429 g_enable_check_android_management_for_testing) { |
| 429 ArcAndroidManagementChecker::StartClient(); | 430 ArcAndroidManagementChecker::StartClient(); |
| 430 } | 431 } |
| 431 | 432 |
| 432 // Chrome may be shut down before completing ARC data removal. | 433 // Chrome may be shut down before completing ARC data removal. |
| 433 // For such a case, start removing the data now, if necessary. | 434 // For such a case, start removing the data now, if necessary. |
| 434 MaybeStartArcDataRemoval(); | 435 MaybeStartArcDataRemoval(); |
| 435 } | 436 } |
| 436 | 437 |
| 437 void ArcSessionManager::Shutdown() { | 438 void ArcSessionManager::Shutdown() { |
| 438 enable_requested_ = false; | 439 enable_requested_ = false; |
| 439 ShutdownSession(); | 440 ShutdownSession(); |
| 440 if (support_host_) { | 441 if (support_host_) { |
| 442 support_host_->SetErrorDelegate(nullptr); |
| 441 support_host_->Close(); | 443 support_host_->Close(); |
| 442 support_host_->RemoveObserver(this); | |
| 443 support_host_.reset(); | 444 support_host_.reset(); |
| 444 } | 445 } |
| 445 context_.reset(); | 446 context_.reset(); |
| 446 profile_ = nullptr; | 447 profile_ = nullptr; |
| 447 SetState(State::NOT_INITIALIZED); | 448 SetState(State::NOT_INITIALIZED); |
| 448 if (scoped_opt_in_tracker_) { | 449 if (scoped_opt_in_tracker_) { |
| 449 scoped_opt_in_tracker_->TrackShutdown(); | 450 scoped_opt_in_tracker_->TrackShutdown(); |
| 450 scoped_opt_in_tracker_.reset(); | 451 scoped_opt_in_tracker_.reset(); |
| 451 } | 452 } |
| 452 } | 453 } |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 } | 949 } |
| 949 | 950 |
| 950 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 951 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 951 // the ARC user data wipe is still required or not. | 952 // the ARC user data wipe is still required or not. |
| 952 reenable_arc_ = false; | 953 reenable_arc_ = false; |
| 953 VLOG(1) << "Reenable ARC"; | 954 VLOG(1) << "Reenable ARC"; |
| 954 RequestEnableImpl(); | 955 RequestEnableImpl(); |
| 955 } | 956 } |
| 956 | 957 |
| 957 void ArcSessionManager::OnWindowClosed() { | 958 void ArcSessionManager::OnWindowClosed() { |
| 958 DCHECK(support_host_); | |
| 959 if (terms_of_service_negotiator_) { | |
| 960 // In this case, ArcTermsOfServiceNegotiator should handle the case. | |
| 961 // Do nothing. | |
| 962 return; | |
| 963 } | |
| 964 CancelAuthCode(); | 959 CancelAuthCode(); |
| 965 } | 960 } |
| 966 | 961 |
| 967 void ArcSessionManager::OnTermsAgreed(bool is_metrics_enabled, | |
| 968 bool is_backup_and_restore_enabled, | |
| 969 bool is_location_service_enabled) { | |
| 970 DCHECK(support_host_); | |
| 971 DCHECK(terms_of_service_negotiator_); | |
| 972 // This should be handled in ArcTermsOfServiceNegotiator. Do nothing here. | |
| 973 } | |
| 974 | |
| 975 void ArcSessionManager::OnRetryClicked() { | 962 void ArcSessionManager::OnRetryClicked() { |
| 976 DCHECK(support_host_); | 963 DCHECK(support_host_); |
| 964 DCHECK_EQ(support_host_->ui_page(), ArcSupportHost::UIPage::ERROR); |
| 965 DCHECK(!terms_of_service_negotiator_); |
| 966 DCHECK(!support_host_->HasAuthDelegate()); |
| 977 | 967 |
| 978 UpdateOptInActionUMA(OptInActionType::RETRY); | 968 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 979 | 969 |
| 980 // TODO(hidehiko): Simplify the retry logic. | 970 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 981 if (terms_of_service_negotiator_) { | 971 // This can currently happen when an error page is shown when re-opt-in |
| 982 // Currently Terms of service is shown. ArcTermsOfServiceNegotiator should | 972 // right after opt-out (this is a bug as it should not show an error). When |
| 983 // handle this. | 973 // the user click the retry button on this error page, we may start terms of |
| 984 } else if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 974 // service negotiation instead of recreating the instance. |
| 975 // TODO(hidehiko): consider removing this case after fixing the bug. |
| 985 MaybeStartTermsOfServiceNegotiation(); | 976 MaybeStartTermsOfServiceNegotiation(); |
| 986 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR && | 977 } else if (!arc_session_runner_->IsStopped()) { |
| 987 !arc_session_runner_->IsStopped()) { | |
| 988 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping | 978 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping |
| 989 // ARC was postponed to contain its internal state into the report. | 979 // ARC was postponed to contain its internal state into the report. |
| 990 // Here, on retry, stop it, then restart. | 980 // Here, on retry, stop it, then restart. |
| 991 DCHECK_EQ(State::ACTIVE, state_); | 981 DCHECK_EQ(State::ACTIVE, state_); |
| 992 support_host_->ShowArcLoading(); | 982 support_host_->ShowArcLoading(); |
| 993 ShutdownSession(); | 983 ShutdownSession(); |
| 994 reenable_arc_ = true; | 984 reenable_arc_ = true; |
| 995 } else if (state_ == State::ACTIVE) { | |
| 996 // This case is handled in ArcAuthService. | |
| 997 // Do nothing. | |
| 998 } else { | 985 } else { |
| 999 // Otherwise, we restart ARC. Note: this is the first boot case. | 986 // Otherwise, we restart ARC. Note: this is the first boot case. |
| 1000 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE | 987 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE |
| 1001 // case must hit. | 988 // case must hit. |
| 1002 StartAndroidManagementCheck(); | 989 StartAndroidManagementCheck(); |
| 1003 } | 990 } |
| 1004 } | 991 } |
| 1005 | 992 |
| 1006 void ArcSessionManager::OnSendFeedbackClicked() { | 993 void ArcSessionManager::OnSendFeedbackClicked() { |
| 1007 DCHECK(support_host_); | 994 DCHECK(support_host_); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 | 1037 |
| 1051 #undef MAP_STATE | 1038 #undef MAP_STATE |
| 1052 | 1039 |
| 1053 // Some compilers report an error even if all values of an enum-class are | 1040 // Some compilers report an error even if all values of an enum-class are |
| 1054 // covered exhaustively in a switch statement. | 1041 // covered exhaustively in a switch statement. |
| 1055 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 1042 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 1056 return os; | 1043 return os; |
| 1057 } | 1044 } |
| 1058 | 1045 |
| 1059 } // namespace arc | 1046 } // namespace arc |
| OLD | NEW |