Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager.cc

Issue 2844383006: Turn ArcSupportHost from Observer model to Delegate (Closed)
Patch Set: git cl try Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 return; 948 return;
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::OnWindowClosedTermsAccepted() {
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_->HasAuthDelegateForTest());
Luis Héctor Chávez 2017/05/30 16:06:27 you shouldn't use ...ForTest() methods outside of
victorhsieh0 2017/05/30 19:52:42 Done.
977 967
978 UpdateOptInActionUMA(OptInActionType::RETRY); 968 UpdateOptInActionUMA(OptInActionType::RETRY);
979 969
980 // TODO(hidehiko): Simplify the retry logic. 970 if (!arc_session_runner_->IsStopped()) {
Luis Héctor Chávez 2017/05/30 16:06:27 nit: maybe invert the order so that the positive c
victorhsieh0 2017/05/30 19:52:42 Done.
981 if (terms_of_service_negotiator_) { 971 // ARC may be kept alive for the user to send feedback during some opt-in
982 // Currently Terms of service is shown. ArcTermsOfServiceNegotiator should 972 // failure, in order to include ARC's internal state into the report. Here,
983 // handle this. 973 // on retry, stop it, then restart.
984 } else if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) {
985 MaybeStartTermsOfServiceNegotiation();
986 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR &&
987 !arc_session_runner_->IsStopped()) {
988 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping
989 // ARC was postponed to contain its internal state into the report.
990 // Here, on retry, stop it, then restart.
991 DCHECK_EQ(State::ACTIVE, state_); 974 DCHECK_EQ(State::ACTIVE, state_);
992 support_host_->ShowArcLoading(); 975 support_host_->ShowArcLoading();
993 ShutdownSession(); 976 ShutdownSession();
994 reenable_arc_ = true; 977 reenable_arc_ = true;
995 } else if (state_ == State::ACTIVE) {
996 // This case is handled in ArcAuthService.
997 // Do nothing.
998 } else { 978 } else {
999 // Otherwise, we restart ARC. Note: this is the first boot case. 979 // Otherwise, we simply start ARC again.
1000 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE
1001 // case must hit.
1002 StartAndroidManagementCheck(); 980 StartAndroidManagementCheck();
1003 } 981 }
1004 } 982 }
1005 983
1006 void ArcSessionManager::OnSendFeedbackClicked() { 984 void ArcSessionManager::OnSendFeedbackClicked() {
1007 DCHECK(support_host_); 985 DCHECK(support_host_);
1008 chrome::OpenFeedbackDialog(nullptr, chrome::kFeedbackSourceArcApp); 986 chrome::OpenFeedbackDialog(nullptr, chrome::kFeedbackSourceArcApp);
1009 } 987 }
1010 988
1011 void ArcSessionManager::SetArcSessionRunnerForTesting( 989 void ArcSessionManager::SetArcSessionRunnerForTesting(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 1028
1051 #undef MAP_STATE 1029 #undef MAP_STATE
1052 1030
1053 // Some compilers report an error even if all values of an enum-class are 1031 // Some compilers report an error even if all values of an enum-class are
1054 // covered exhaustively in a switch statement. 1032 // covered exhaustively in a switch statement.
1055 NOTREACHED() << "Invalid value " << static_cast<int>(state); 1033 NOTREACHED() << "Invalid value " << static_cast<int>(state);
1056 return os; 1034 return os;
1057 } 1035 }
1058 1036
1059 } // namespace arc 1037 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698