| 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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.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 "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_optin_uma.h" | 18 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 19 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 20 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_negotiator.h" | 20 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" |
| 21 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_initial_oobe_ne
gotiator_for_managed_user.h" |
| 21 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" | 22 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" |
| 22 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" | 23 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 23 #include "chrome/browser/chromeos/login/user_flow.h" | 24 #include "chrome/browser/chromeos/login/user_flow.h" |
| 24 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 25 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 25 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 26 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 26 #include "chrome/browser/lifetime/application_lifetime.h" | 27 #include "chrome/browser/lifetime/application_lifetime.h" |
| 27 #include "chrome/browser/policy/profile_policy_connector.h" | 28 #include "chrome/browser/policy/profile_policy_connector.h" |
| 28 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 29 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 29 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 30 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 ash::ShelfDelegate* GetShelfDelegate() { | 72 ash::ShelfDelegate* GetShelfDelegate() { |
| 72 if (g_shelf_delegate_for_testing) | 73 if (g_shelf_delegate_for_testing) |
| 73 return g_shelf_delegate_for_testing; | 74 return g_shelf_delegate_for_testing; |
| 74 if (ash::WmShell::HasInstance()) { | 75 if (ash::WmShell::HasInstance()) { |
| 75 DCHECK(ash::WmShell::Get()->shelf_delegate()); | 76 DCHECK(ash::WmShell::Get()->shelf_delegate()); |
| 76 return ash::WmShell::Get()->shelf_delegate(); | 77 return ash::WmShell::Get()->shelf_delegate(); |
| 77 } | 78 } |
| 78 return nullptr; | 79 return nullptr; |
| 79 } | 80 } |
| 80 | 81 |
| 82 // Returns true if this is the first user's login session and Arc OOBE is |
| 83 // enabled. |
| 84 bool IsFirstRunForOobeEnabledUser() { |
| 85 return user_manager::UserManager::Get()->IsCurrentUserNew() && |
| 86 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 87 chromeos::switches::kEnableArcOOBEOptIn); |
| 88 } |
| 89 |
| 81 } // namespace | 90 } // namespace |
| 82 | 91 |
| 83 ArcSessionManager::ArcSessionManager(ArcBridgeService* bridge_service) | 92 ArcSessionManager::ArcSessionManager(ArcBridgeService* bridge_service) |
| 84 : ArcService(bridge_service), | 93 : ArcService(bridge_service), |
| 85 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), | 94 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), |
| 86 weak_ptr_factory_(this) { | 95 weak_ptr_factory_(this) { |
| 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 88 DCHECK(!g_arc_session_manager); | 97 DCHECK(!g_arc_session_manager); |
| 89 g_arc_session_manager = this; | 98 g_arc_session_manager = this; |
| 90 | 99 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 272 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 264 // the ARC user data wipe is still required or not. | 273 // the ARC user data wipe is still required or not. |
| 265 reenable_arc_ = false; | 274 reenable_arc_ = false; |
| 266 VLOG(1) << "Reenable ARC"; | 275 VLOG(1) << "Reenable ARC"; |
| 267 EnableArc(); | 276 EnableArc(); |
| 268 } | 277 } |
| 269 | 278 |
| 270 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { | 279 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { |
| 271 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 272 | 281 |
| 273 // Due asynchronous nature of stopping Arc bridge, OnProvisioningFinished may | 282 // Due asynchronous nature of stopping ARC bridge, OnProvisioningFinished may |
| 274 // arrive after setting the |State::STOPPED| state and |State::Active| is not | 283 // arrive after setting the |State::STOPPED| state and |State::Active| is not |
| 275 // guaranty set here. prefs::kArcDataRemoveRequested is also can be active | 284 // guaranty set here. prefs::kArcDataRemoveRequested is also can be active |
| 276 // for now. | 285 // for now. |
| 277 | 286 |
| 278 if (provisioning_reported_) { | 287 if (provisioning_reported_) { |
| 279 // We don't expect ProvisioningResult::SUCCESS is reported twice or reported | 288 // We don't expect ProvisioningResult::SUCCESS is reported twice or reported |
| 280 // after an error. | 289 // after an error. |
| 281 DCHECK_NE(result, ProvisioningResult::SUCCESS); | 290 DCHECK_NE(result, ProvisioningResult::SUCCESS); |
| 282 // TODO (khmel): Consider changing LOG to NOTREACHED once we guaranty that | 291 // TODO (khmel): Consider changing LOG to NOTREACHED once we guaranty that |
| 283 // no double message can happen in production. | 292 // no double message can happen in production. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 447 |
| 439 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 448 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 440 prefs::kArcEnabled, this); | 449 prefs::kArcEnabled, this); |
| 441 | 450 |
| 442 context_.reset(new ArcAuthContext(profile_)); | 451 context_.reset(new ArcAuthContext(profile_)); |
| 443 | 452 |
| 444 if (!g_disable_ui_for_testing || | 453 if (!g_disable_ui_for_testing || |
| 445 g_enable_check_android_management_for_testing) { | 454 g_enable_check_android_management_for_testing) { |
| 446 ArcAndroidManagementChecker::StartClient(); | 455 ArcAndroidManagementChecker::StartClient(); |
| 447 } | 456 } |
| 457 |
| 448 pref_change_registrar_.Init(profile_->GetPrefs()); | 458 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 449 pref_change_registrar_.Add( | 459 pref_change_registrar_.Add( |
| 450 prefs::kArcEnabled, | 460 prefs::kArcEnabled, |
| 451 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | 461 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, |
| 452 weak_ptr_factory_.GetWeakPtr())); | 462 weak_ptr_factory_.GetWeakPtr(), false /* initial_run */)); |
| 453 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 463 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 454 // Don't start ARC if there is a pending request to remove the data. Restart | 464 // Don't start ARC if there is a pending request to remove the data. Restart |
| 455 // ARC once data removal finishes. | 465 // ARC once data removal finishes. |
| 456 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 466 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 457 reenable_arc_ = true; | 467 reenable_arc_ = true; |
| 458 RemoveArcData(); | 468 RemoveArcData(); |
| 459 } else { | 469 } else { |
| 460 OnOptInPreferenceChanged(); | 470 OnOptInPreferenceChanged(true /* initial_run */); |
| 461 } | 471 } |
| 462 } else { | 472 } else { |
| 463 RemoveArcData(); | 473 RemoveArcData(); |
| 464 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 474 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
| 465 OnIsSyncingChanged(); | 475 OnIsSyncingChanged(); |
| 466 } | 476 } |
| 467 } | 477 } |
| 468 | 478 |
| 469 void ArcSessionManager::OnIsSyncingChanged() { | 479 void ArcSessionManager::OnIsSyncingChanged() { |
| 470 sync_preferences::PrefServiceSyncable* const pref_service_syncable = | 480 sync_preferences::PrefServiceSyncable* const pref_service_syncable = |
| 471 PrefServiceSyncableFromProfile(profile_); | 481 PrefServiceSyncableFromProfile(profile_); |
| 472 if (!pref_service_syncable->IsSyncing()) | 482 if (!pref_service_syncable->IsSyncing()) |
| 473 return; | 483 return; |
| 474 | 484 |
| 475 pref_service_syncable->RemoveObserver(this); | 485 pref_service_syncable->RemoveObserver(this); |
| 476 | 486 |
| 477 if (IsArcEnabled()) | 487 if (IsArcEnabled()) |
| 478 OnOptInPreferenceChanged(); | 488 OnOptInPreferenceChanged(false); |
| 479 } | 489 } |
| 480 | 490 |
| 481 void ArcSessionManager::Shutdown() { | 491 void ArcSessionManager::Shutdown() { |
| 482 ShutdownBridge(); | 492 ShutdownBridge(); |
| 483 if (support_host_) { | 493 if (support_host_) { |
| 484 support_host_->Close(); | 494 support_host_->Close(); |
| 485 support_host_->RemoveObserver(this); | 495 support_host_->RemoveObserver(this); |
| 486 support_host_.reset(); | 496 support_host_.reset(); |
| 487 } | 497 } |
| 488 if (profile_) { | 498 if (profile_) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 519 void ArcSessionManager::StopArc() { | 529 void ArcSessionManager::StopArc() { |
| 520 if (state_ != State::STOPPED) { | 530 if (state_ != State::STOPPED) { |
| 521 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 531 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 522 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); | 532 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); |
| 523 } | 533 } |
| 524 ShutdownBridge(); | 534 ShutdownBridge(); |
| 525 if (support_host_) | 535 if (support_host_) |
| 526 support_host_->Close(); | 536 support_host_->Close(); |
| 527 } | 537 } |
| 528 | 538 |
| 529 void ArcSessionManager::OnOptInPreferenceChanged() { | 539 void ArcSessionManager::OnOptInPreferenceChanged(bool initial_run) { |
| 530 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 540 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 531 DCHECK(profile_); | 541 DCHECK(profile_); |
| 532 | 542 |
| 533 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. | 543 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. |
| 534 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); | 544 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); |
| 535 | 545 |
| 536 const bool arc_enabled = IsArcEnabled(); | 546 const bool arc_enabled = IsArcEnabled(); |
| 537 for (auto& observer : observer_list_) | 547 for (auto& observer : observer_list_) |
| 538 observer.OnArcOptInChanged(arc_enabled); | 548 observer.OnArcOptInChanged(arc_enabled); |
| 539 | 549 |
| 540 if (!arc_enabled) { | 550 if (!arc_enabled) { |
| 541 // Reset any pending request to re-enable Arc. | 551 // Reset any pending request to re-enable Arc. |
| 542 reenable_arc_ = false; | 552 reenable_arc_ = false; |
| 543 StopArc(); | 553 StopArc(); |
| 544 RemoveArcData(); | 554 RemoveArcData(); |
| 545 return; | 555 return; |
| 546 } | 556 } |
| 547 | 557 |
| 548 if (state_ == State::ACTIVE) | 558 if (state_ == State::ACTIVE) |
| 549 return; | 559 return; |
| 550 | 560 |
| 551 if (state_ == State::REMOVING_DATA_DIR) { | 561 if (state_ == State::REMOVING_DATA_DIR) { |
| 552 // Data removal request is in progress. Set flag to re-enable Arc once it is | 562 // Data removal request is in progress. Set flag to re-enable ARC once it is |
| 553 // finished. | 563 // finished. |
| 554 reenable_arc_ = true; | 564 reenable_arc_ = true; |
| 555 return; | 565 return; |
| 556 } | 566 } |
| 557 | 567 |
| 558 if (support_host_) | 568 if (support_host_) |
| 559 support_host_->SetArcManaged(IsArcManaged()); | 569 support_host_->SetArcManaged(IsArcManaged()); |
| 560 | 570 |
| 561 // For ARC Kiosk we skip ToS because it is very likely that near the device | 571 // For ARC Kiosk we skip ToS because it is very likely that near the device |
| 562 // there will be no one who is eligible to accept them. | 572 // there will be no one who is eligible to accept them. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 607 } |
| 598 | 608 |
| 599 // If it is marked that the Terms of service is accepted already, | 609 // If it is marked that the Terms of service is accepted already, |
| 600 // just skip the negotiation with user, and start Android management | 610 // just skip the negotiation with user, and start Android management |
| 601 // check directly. | 611 // check directly. |
| 602 // This happens, e.g., when; | 612 // This happens, e.g., when; |
| 603 // 1) User accepted the Terms of service on OOBE flow. | 613 // 1) User accepted the Terms of service on OOBE flow. |
| 604 // 2) User accepted the Terms of service on Opt-in flow, but logged out | 614 // 2) User accepted the Terms of service on Opt-in flow, but logged out |
| 605 // before ARC sign in procedure was done. Then, logs in again. | 615 // before ARC sign in procedure was done. Then, logs in again. |
| 606 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 616 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 607 support_host_->ShowArcLoading(); | |
| 608 StartArcAndroidManagementCheck(); | 617 StartArcAndroidManagementCheck(); |
| 609 return; | 618 return; |
| 610 } | 619 } |
| 611 | 620 |
| 612 // Need user's explicit Terms Of Service agreement. | 621 // Need user's explicit Terms Of Service acceptance. |
| 613 StartTermsOfServiceNegotiation(); | 622 StartTermsOfServiceNegotiation(initial_run); |
| 614 } | 623 } |
| 615 | 624 |
| 616 void ArcSessionManager::ShutdownBridge() { | 625 void ArcSessionManager::ShutdownBridge() { |
| 617 arc_sign_in_timer_.Stop(); | 626 arc_sign_in_timer_.Stop(); |
| 618 playstore_launcher_.reset(); | 627 playstore_launcher_.reset(); |
| 619 terms_of_service_negotiator_.reset(); | 628 terms_of_service_negotiator_.reset(); |
| 620 android_management_checker_.reset(); | 629 android_management_checker_.reset(); |
| 621 arc_bridge_service()->RequestStop(); | 630 arc_bridge_service()->RequestStop(); |
| 622 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) | 631 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) |
| 623 SetState(State::STOPPED); | 632 SetState(State::STOPPED); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 640 void ArcSessionManager::StopAndEnableArc() { | 649 void ArcSessionManager::StopAndEnableArc() { |
| 641 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 650 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 642 DCHECK(!arc_bridge_service()->stopped()); | 651 DCHECK(!arc_bridge_service()->stopped()); |
| 643 reenable_arc_ = true; | 652 reenable_arc_ = true; |
| 644 StopArc(); | 653 StopArc(); |
| 645 } | 654 } |
| 646 | 655 |
| 647 void ArcSessionManager::StartArc() { | 656 void ArcSessionManager::StartArc() { |
| 648 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 657 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 649 | 658 |
| 650 // Arc must be started only if no pending data removal request exists. | 659 // ARC must be started only if no pending data removal request exists. |
| 651 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 660 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 652 | 661 |
| 653 provisioning_reported_ = false; | 662 provisioning_reported_ = false; |
| 654 | 663 |
| 655 arc_bridge_service()->RequestStart(); | 664 arc_bridge_service()->RequestStart(); |
| 656 SetState(State::ACTIVE); | 665 SetState(State::ACTIVE); |
| 657 } | 666 } |
| 658 | 667 |
| 659 void ArcSessionManager::OnArcSignInTimeout() { | 668 void ArcSessionManager::OnArcSignInTimeout() { |
| 660 LOG(ERROR) << "Timed out waiting for first sign in."; | 669 LOG(ERROR) << "Timed out waiting for first sign in."; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 | 716 |
| 708 DCHECK(profile_); | 717 DCHECK(profile_); |
| 709 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 718 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| 710 } | 719 } |
| 711 | 720 |
| 712 void ArcSessionManager::EnableArc() { | 721 void ArcSessionManager::EnableArc() { |
| 713 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 722 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 714 DCHECK(profile_); | 723 DCHECK(profile_); |
| 715 | 724 |
| 716 if (IsArcEnabled()) { | 725 if (IsArcEnabled()) { |
| 717 OnOptInPreferenceChanged(); | 726 OnOptInPreferenceChanged(false); |
| 718 return; | 727 return; |
| 719 } | 728 } |
| 720 | 729 |
| 721 if (!IsArcManaged()) | 730 if (!IsArcManaged()) |
| 722 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 731 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 723 } | 732 } |
| 724 | 733 |
| 725 void ArcSessionManager::DisableArc() { | 734 void ArcSessionManager::DisableArc() { |
| 726 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 735 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 727 DCHECK(profile_); | 736 DCHECK(profile_); |
| 728 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 737 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| 729 } | 738 } |
| 730 | 739 |
| 731 void ArcSessionManager::RecordArcState() { | 740 void ArcSessionManager::RecordArcState() { |
| 732 // Only record Enabled state if ARC is allowed in the first place, so we do | 741 // Only record Enabled state if ARC is allowed in the first place, so we do |
| 733 // not split the ARC population by devices that cannot run ARC. | 742 // not split the ARC population by devices that cannot run ARC. |
| 734 if (IsAllowed()) | 743 if (IsAllowed()) |
| 735 UpdateEnabledStateUMA(IsArcEnabled()); | 744 UpdateEnabledStateUMA(IsArcEnabled()); |
| 736 } | 745 } |
| 737 | 746 |
| 738 void ArcSessionManager::StartTermsOfServiceNegotiation() { | 747 void ArcSessionManager::StartTermsOfServiceNegotiation(bool initial_run) { |
| 739 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 748 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 740 DCHECK(!terms_of_service_negotiator_); | 749 DCHECK(!terms_of_service_negotiator_); |
| 741 | 750 |
| 742 if (!arc_bridge_service()->stopped()) { | 751 if (!arc_bridge_service()->stopped()) { |
| 743 // If the user attempts to re-enable ARC while the bridge is still running | 752 // If the user attempts to re-enable ARC while the bridge is still running |
| 744 // the user should not be able to continue until the bridge has stopped. | 753 // the user should not be able to continue until the bridge has stopped. |
| 745 if (support_host_) { | 754 if (support_host_) { |
| 746 support_host_->ShowError( | 755 support_host_->ShowError( |
| 747 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | 756 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
| 748 } | 757 } |
| 749 return; | 758 return; |
| 750 } | 759 } |
| 751 | 760 |
| 752 SetState(State::SHOWING_TERMS_OF_SERVICE); | 761 SetState(State::SHOWING_TERMS_OF_SERVICE); |
| 753 if (support_host_) { | 762 if (initial_run && IsFirstRunForOobeEnabledUser() && IsArcManaged()) { |
| 763 terms_of_service_negotiator_ = base::MakeUnique< |
| 764 ArcTermsOfServiceInitialOobeNegotiatorForManagedUser>(); |
| 765 } else if (support_host_) { |
| 754 terms_of_service_negotiator_ = | 766 terms_of_service_negotiator_ = |
| 755 base::MakeUnique<ArcTermsOfServiceNegotiator>(profile_->GetPrefs(), | 767 base::MakeUnique<ArcTermsOfServiceDefaultNegotiator>( |
| 756 support_host_.get()); | 768 profile_->GetPrefs(), support_host_.get()); |
| 757 terms_of_service_negotiator_->StartNegotiation( | 769 } else { |
| 758 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated, | 770 // Happens in unit tests. |
| 759 weak_ptr_factory_.GetWeakPtr())); | 771 return; |
| 760 } | 772 } |
| 773 |
| 774 terms_of_service_negotiator_->StartNegotiation( |
| 775 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated, |
| 776 weak_ptr_factory_.GetWeakPtr())); |
| 761 } | 777 } |
| 762 | 778 |
| 763 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) { | 779 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) { |
| 764 DCHECK(terms_of_service_negotiator_); | 780 DCHECK(terms_of_service_negotiator_); |
| 765 terms_of_service_negotiator_.reset(); | 781 terms_of_service_negotiator_.reset(); |
| 766 | 782 |
| 767 if (!accepted) { | 783 if (!accepted) { |
| 768 // To cancel, user needs to close the window. Note that clicking "Cancel" | 784 // To cancel, user needs to close the window. Note that clicking "Cancel" |
| 769 // button effectively just closes the window. | 785 // button effectively just closes the window. |
| 770 CancelAuthCode(); | 786 CancelAuthCode(); |
| 771 return; | 787 return; |
| 772 } | 788 } |
| 773 | 789 |
| 774 // Terms were accepted. | 790 // Terms were accepted. |
| 775 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 791 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
| 776 | 792 |
| 777 support_host_->ShowArcLoading(); | 793 if (support_host_) |
| 794 support_host_->ShowArcLoading(false); |
| 778 StartArcAndroidManagementCheck(); | 795 StartArcAndroidManagementCheck(); |
| 779 } | 796 } |
| 780 | 797 |
| 781 void ArcSessionManager::StartArcAndroidManagementCheck() { | 798 void ArcSessionManager::StartArcAndroidManagementCheck() { |
| 782 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 799 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 783 DCHECK(arc_bridge_service()->stopped()); | 800 DCHECK(arc_bridge_service()->stopped()); |
| 784 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || | 801 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || |
| 785 state_ == State::CHECKING_ANDROID_MANAGEMENT); | 802 state_ == State::CHECKING_ANDROID_MANAGEMENT || |
| 803 (state_ == State::STOPPED && |
| 804 profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted))); |
| 786 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 805 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 787 | 806 |
| 788 android_management_checker_.reset(new ArcAndroidManagementChecker( | 807 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 789 profile_, context_->token_service(), context_->account_id(), | 808 profile_, context_->token_service(), context_->account_id(), |
| 790 false /* retry_on_error */)); | 809 false /* retry_on_error */)); |
| 791 android_management_checker_->StartCheck( | 810 android_management_checker_->StartCheck( |
| 792 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, | 811 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
| 793 weak_ptr_factory_.GetWeakPtr())); | 812 weak_ptr_factory_.GetWeakPtr())); |
| 794 } | 813 } |
| 795 | 814 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 void ArcSessionManager::OnWindowClosed() { | 866 void ArcSessionManager::OnWindowClosed() { |
| 848 DCHECK(support_host_); | 867 DCHECK(support_host_); |
| 849 if (terms_of_service_negotiator_) { | 868 if (terms_of_service_negotiator_) { |
| 850 // In this case, ArcTermsOfServiceNegotiator should handle the case. | 869 // In this case, ArcTermsOfServiceNegotiator should handle the case. |
| 851 // Do nothing. | 870 // Do nothing. |
| 852 return; | 871 return; |
| 853 } | 872 } |
| 854 CancelAuthCode(); | 873 CancelAuthCode(); |
| 855 } | 874 } |
| 856 | 875 |
| 857 void ArcSessionManager::OnTermsAgreed(bool is_metrics_enabled, | 876 void ArcSessionManager::OnTermsAccepted(bool is_metrics_enabled, |
| 858 bool is_backup_and_restore_enabled, | 877 bool is_backup_and_restore_enabled, |
| 859 bool is_location_service_enabled) { | 878 bool is_location_service_enabled) { |
| 860 DCHECK(support_host_); | 879 DCHECK(support_host_); |
| 861 DCHECK(terms_of_service_negotiator_); | 880 DCHECK(terms_of_service_negotiator_); |
| 862 // This should be handled in ArcTermsOfServiceNegotiator. Do nothing here. | 881 // This should be handled in ArcTermsOfServiceNegotiator. Do nothing here. |
| 863 } | 882 } |
| 864 | 883 |
| 865 void ArcSessionManager::OnRetryClicked() { | 884 void ArcSessionManager::OnRetryClicked() { |
| 866 DCHECK(support_host_); | 885 DCHECK(support_host_); |
| 867 | 886 |
| 868 UpdateOptInActionUMA(OptInActionType::RETRY); | 887 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 869 | 888 |
| 870 // TODO(hidehiko): Simplify the retry logic. | 889 // TODO(hidehiko): Simplify the retry logic. |
| 871 if (terms_of_service_negotiator_) { | 890 if (terms_of_service_negotiator_) { |
| 872 // Currently Terms of service is shown. ArcTermsOfServiceNegotiator should | 891 // Currently Terms of service is shown. ArcTermsOfServiceNegotiator should |
| 873 // handle this. | 892 // handle this. |
| 874 } else if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 893 } else if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 875 StartTermsOfServiceNegotiation(); | 894 StartTermsOfServiceNegotiation(false); |
| 876 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR && | 895 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR && |
| 877 !arc_bridge_service()->stopped()) { | 896 !arc_bridge_service()->stopped()) { |
| 878 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping | 897 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping |
| 879 // ARC was postponed to contain its internal state into the report. | 898 // ARC was postponed to contain its internal state into the report. |
| 880 // Here, on retry, stop it, then restart. | 899 // Here, on retry, stop it, then restart. |
| 881 DCHECK_EQ(State::ACTIVE, state_); | 900 DCHECK_EQ(State::ACTIVE, state_); |
| 882 support_host_->ShowArcLoading(); | 901 support_host_->ShowArcLoading(true); |
| 883 ShutdownBridge(); | 902 ShutdownBridge(); |
| 884 reenable_arc_ = true; | 903 reenable_arc_ = true; |
| 885 } else if (state_ == State::ACTIVE) { | 904 } else if (state_ == State::ACTIVE) { |
| 886 // This case is handled in ArcAuthService. | 905 // This case is handled in ArcAuthService. |
| 887 // Do nothing. | 906 // Do nothing. |
| 888 } else { | 907 } else { |
| 889 // Otherwise, we restart ARC. Note: this is the first boot case. | 908 // Otherwise, we restart ARC. Note: this is the first boot case. |
| 890 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE | 909 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE |
| 891 // case must hit. | 910 // case must hit. |
| 892 support_host_->ShowArcLoading(); | 911 support_host_->ShowArcLoading(true); |
| 893 StartArcAndroidManagementCheck(); | 912 StartArcAndroidManagementCheck(); |
| 894 } | 913 } |
| 895 } | 914 } |
| 896 | 915 |
| 897 void ArcSessionManager::OnSendFeedbackClicked() { | 916 void ArcSessionManager::OnSendFeedbackClicked() { |
| 898 DCHECK(support_host_); | 917 DCHECK(support_host_); |
| 899 chrome::OpenFeedbackDialog(nullptr); | 918 chrome::OpenFeedbackDialog(nullptr); |
| 900 } | 919 } |
| 901 | 920 |
| 902 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( | 921 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 922 return os << "ACTIVE"; | 941 return os << "ACTIVE"; |
| 923 } | 942 } |
| 924 | 943 |
| 925 // Some compiler reports an error even if all values of an enum-class are | 944 // Some compiler reports an error even if all values of an enum-class are |
| 926 // covered indivisually in a switch statement. | 945 // covered indivisually in a switch statement. |
| 927 NOTREACHED(); | 946 NOTREACHED(); |
| 928 return os; | 947 return os; |
| 929 } | 948 } |
| 930 | 949 |
| 931 } // namespace arc | 950 } // namespace arc |
| OLD | NEW |