| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 // static | 112 // static |
| 113 void ArcSessionManager::RegisterProfilePrefs( | 113 void ArcSessionManager::RegisterProfilePrefs( |
| 114 user_prefs::PrefRegistrySyncable* registry) { | 114 user_prefs::PrefRegistrySyncable* registry) { |
| 115 // TODO(dspaid): Implement a mechanism to allow this to sync on first boot | 115 // TODO(dspaid): Implement a mechanism to allow this to sync on first boot |
| 116 // only. | 116 // only. |
| 117 registry->RegisterBooleanPref(prefs::kArcDataRemoveRequested, false); | 117 registry->RegisterBooleanPref(prefs::kArcDataRemoveRequested, false); |
| 118 registry->RegisterBooleanPref(prefs::kArcEnabled, false); | 118 registry->RegisterBooleanPref(prefs::kArcEnabled, false); |
| 119 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); | 119 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); |
| 120 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); | 120 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); |
| 121 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); | 121 // Note that ArcBackupRestoreEnabled and ArcLocationServiceEnabled prefs have |
| 122 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); | 122 // to be off by default, until an explicit gesture from the user to enable |
| 123 // them is received. This is crucial in the cases when these prefs transition |
| 124 // from a previous managed state to the unmanaged. |
| 125 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, false); |
| 126 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, false); |
| 123 } | 127 } |
| 124 | 128 |
| 125 // static | 129 // static |
| 126 bool ArcSessionManager::IsOobeOptInActive() { | 130 bool ArcSessionManager::IsOobeOptInActive() { |
| 127 // ARC OOBE OptIn is optional for now. Test if it exists and login host is | 131 // ARC OOBE OptIn is optional for now. Test if it exists and login host is |
| 128 // active. | 132 // active. |
| 129 if (!user_manager::UserManager::Get()->IsCurrentUserNew()) | 133 if (!user_manager::UserManager::Get()->IsCurrentUserNew()) |
| 130 return false; | 134 return false; |
| 131 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 135 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 132 chromeos::switches::kEnableArcOOBEOptIn)) | 136 chromeos::switches::kEnableArcOOBEOptIn)) |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } | 499 } |
| 496 ShutdownSession(); | 500 ShutdownSession(); |
| 497 if (support_host_) | 501 if (support_host_) |
| 498 support_host_->Close(); | 502 support_host_->Close(); |
| 499 } | 503 } |
| 500 | 504 |
| 501 void ArcSessionManager::OnOptInPreferenceChanged() { | 505 void ArcSessionManager::OnOptInPreferenceChanged() { |
| 502 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 506 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 503 DCHECK(profile_); | 507 DCHECK(profile_); |
| 504 | 508 |
| 509 PrefService* const prefs = profile_->GetPrefs(); |
| 510 |
| 505 const bool arc_enabled = IsArcEnabled(); | 511 const bool arc_enabled = IsArcEnabled(); |
| 506 if (!IsArcManaged()) { | 512 if (!IsArcManaged()) { |
| 507 // Update UMA only for non-Managed cases. | 513 // Update UMA only for non-Managed cases. |
| 508 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | 514 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN |
| 509 : OptInActionType::OPTED_OUT); | 515 : OptInActionType::OPTED_OUT); |
| 510 | 516 |
| 511 if (!arc_enabled) { | 517 if (!arc_enabled) { |
| 512 // Remove the pinned Play Store icon launcher in Shelf. | 518 // Remove the pinned Play Store icon launcher in Shelf. |
| 513 // This is only for non-Managed cases. In managed cases, it is expected | 519 // This is only for non-Managed cases. In managed cases, it is expected |
| 514 // to be "disabled" rather than "removed", so keep it here. | 520 // to be "disabled" rather than "removed", so keep it here. |
| 515 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | 521 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); |
| 516 if (shelf_delegate) | 522 if (shelf_delegate) |
| 517 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 523 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
| 518 } | 524 } |
| 519 } | 525 } |
| 520 | 526 |
| 521 for (auto& observer : observer_list_) | 527 for (auto& observer : observer_list_) |
| 522 observer.OnArcOptInChanged(arc_enabled); | 528 observer.OnArcOptInChanged(arc_enabled); |
| 523 | 529 |
| 524 // Hide auth notification if it was opened before and arc.enabled pref was | 530 // Hide auth notification if it was opened before and arc.enabled pref was |
| 525 // explicitly set to true or false. | 531 // explicitly set to true or false. |
| 526 if (!g_disable_ui_for_testing && | 532 if (!g_disable_ui_for_testing && prefs->HasPrefPath(prefs::kArcEnabled)) |
| 527 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | |
| 528 ArcAuthNotification::Hide(); | 533 ArcAuthNotification::Hide(); |
| 529 } | |
| 530 | 534 |
| 531 if (!arc_enabled) { | 535 if (!arc_enabled) { |
| 532 // Reset any pending request to re-enable ARC. | 536 // Reset any pending request to re-enable ARC. |
| 533 VLOG(1) << "ARC opt-out. Removing user data."; | 537 VLOG(1) << "ARC opt-out. Removing user data."; |
| 534 reenable_arc_ = false; | 538 reenable_arc_ = false; |
| 535 StopArc(); | 539 StopArc(); |
| 536 RemoveArcData(); | 540 RemoveArcData(); |
| 537 return; | 541 return; |
| 538 } | 542 } |
| 539 | 543 |
| 540 if (state_ == State::ACTIVE) | 544 if (state_ == State::ACTIVE) |
| 541 return; | 545 return; |
| 542 | 546 |
| 543 if (state_ == State::REMOVING_DATA_DIR) { | 547 if (state_ == State::REMOVING_DATA_DIR) { |
| 544 // Data removal request is in progress. Set flag to re-enable Arc once it is | 548 // Data removal request is in progress. Set flag to re-enable Arc once it is |
| 545 // finished. | 549 // finished. |
| 546 reenable_arc_ = true; | 550 reenable_arc_ = true; |
| 547 return; | 551 return; |
| 548 } | 552 } |
| 549 | 553 |
| 550 if (support_host_) | 554 if (support_host_) |
| 551 support_host_->SetArcManaged(IsArcManaged()); | 555 support_host_->SetArcManaged(IsArcManaged()); |
| 552 | 556 |
| 553 // For ARC Kiosk we skip ToS because it is very likely that near the device | 557 // For ARC Kiosk we skip ToS because it is very likely that near the device |
| 554 // there will be no one who is eligible to accept them. | 558 // there will be no one who is eligible to accept them. |
| 555 // TODO(poromov): Move to more Kiosk dedicated set-up phase. | 559 // TODO(poromov): Move to more Kiosk dedicated set-up phase. |
| 556 if (IsArcKioskMode()) | 560 if (IsArcKioskMode()) |
| 557 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 561 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 562 |
| 563 // Skip to show UI asking users to enable/disable their preference for |
| 564 // backup-restore and location-service, if both are managed by the admin |
| 565 // policy. Note that the ToS agreement is anyway not shown in the case of the |
| 566 // managed ARC. |
| 567 if (IsArcManaged() && |
| 568 prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled) && |
| 569 prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) { |
| 570 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 571 } |
| 558 | 572 |
| 559 // If it is marked that sign in has been successfully done, then directly | 573 // If it is marked that sign in has been successfully done, then directly |
| 560 // start ARC. | 574 // start ARC. |
| 561 // For testing, and for Kisok mode, we also skip ToS negotiation procedure. | 575 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. |
| 562 // For backward compatibility, this check needs to be prior to the | 576 // For backward compatibility, this check needs to be prior to the |
| 563 // kArcTermsAccepted check below. | 577 // kArcTermsAccepted check below. |
| 564 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || | 578 if (prefs->GetBoolean(prefs::kArcSignedIn) || |
| 565 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { | 579 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { |
| 566 StartArc(); | 580 StartArc(); |
| 567 | 581 |
| 568 // Skip Android management check for testing. | 582 // Skip Android management check for testing. |
| 569 // We also skip if Android management check for Kiosk mode, | 583 // We also skip if Android management check for Kiosk mode, |
| 570 // because there are no managed human users for Kiosk exist. | 584 // because there are no managed human users for Kiosk exist. |
| 571 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || | 585 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || |
| 572 (g_disable_ui_for_testing && | 586 (g_disable_ui_for_testing && |
| 573 !g_enable_check_android_management_for_testing)) { | 587 !g_enable_check_android_management_for_testing)) { |
| 574 return; | 588 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 588 return; | 602 return; |
| 589 } | 603 } |
| 590 | 604 |
| 591 // If it is marked that the Terms of service is accepted already, | 605 // If it is marked that the Terms of service is accepted already, |
| 592 // just skip the negotiation with user, and start Android management | 606 // just skip the negotiation with user, and start Android management |
| 593 // check directly. | 607 // check directly. |
| 594 // This happens, e.g., when; | 608 // This happens, e.g., when; |
| 595 // 1) User accepted the Terms of service on OOBE flow. | 609 // 1) User accepted the Terms of service on OOBE flow. |
| 596 // 2) User accepted the Terms of service on Opt-in flow, but logged out | 610 // 2) User accepted the Terms of service on Opt-in flow, but logged out |
| 597 // before ARC sign in procedure was done. Then, logs in again. | 611 // before ARC sign in procedure was done. Then, logs in again. |
| 598 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 612 if (prefs->GetBoolean(prefs::kArcTermsAccepted)) { |
| 599 // Don't show UI for this progress if it was not shown. | 613 // Don't show UI for this progress if it was not shown. |
| 600 if (support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) | 614 if (support_host_ && |
| 615 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) { |
| 601 support_host_->ShowArcLoading(); | 616 support_host_->ShowArcLoading(); |
| 617 } |
| 602 StartArcAndroidManagementCheck(); | 618 StartArcAndroidManagementCheck(); |
| 603 return; | 619 return; |
| 604 } | 620 } |
| 605 | 621 |
| 606 // Need user's explicit Terms Of Service agreement. Prevent race condition | 622 // Need user's explicit Terms Of Service agreement. Prevent race condition |
| 607 // when ARC can be enabled before profile is synced. In last case | 623 // when ARC can be enabled before profile is synced. In last case |
| 608 // OnOptInPreferenceChanged is called twice. | 624 // OnOptInPreferenceChanged is called twice. |
| 609 // TODO(crbug.com/687185): Remove the condition. | 625 // TODO(crbug.com/687185): Remove the condition. |
| 610 if (state_ != State::SHOWING_TERMS_OF_SERVICE) | 626 if (state_ != State::SHOWING_TERMS_OF_SERVICE) |
| 611 StartTermsOfServiceNegotiation(); | 627 StartTermsOfServiceNegotiation(); |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 987 |
| 972 #undef MAP_STATE | 988 #undef MAP_STATE |
| 973 | 989 |
| 974 // Some compilers report an error even if all values of an enum-class are | 990 // Some compilers report an error even if all values of an enum-class are |
| 975 // covered exhaustively in a switch statement. | 991 // covered exhaustively in a switch statement. |
| 976 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 992 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 977 return os; | 993 return os; |
| 978 } | 994 } |
| 979 | 995 |
| 980 } // namespace arc | 996 } // namespace arc |
| OLD | NEW |