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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 void ArcSessionManager::SetShelfDelegateForTesting( | 149 void ArcSessionManager::SetShelfDelegateForTesting( |
150 ash::ShelfDelegate* shelf_delegate) { | 150 ash::ShelfDelegate* shelf_delegate) { |
151 g_shelf_delegate_for_testing = shelf_delegate; | 151 g_shelf_delegate_for_testing = shelf_delegate; |
152 } | 152 } |
153 | 153 |
154 // static | 154 // static |
155 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { | 155 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
156 g_enable_check_android_management_for_testing = true; | 156 g_enable_check_android_management_for_testing = true; |
157 } | 157 } |
158 | 158 |
159 // static | |
160 bool ArcSessionManager::IsPersistentArc() { | |
161 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
162 chromeos::switches::kEnableArcPersistently); | |
163 } | |
164 | |
159 void ArcSessionManager::OnSessionReady() { | 165 void ArcSessionManager::OnSessionReady() { |
160 for (auto& observer : arc_session_observer_list_) | 166 for (auto& observer : arc_session_observer_list_) |
161 observer.OnSessionReady(); | 167 observer.OnSessionReady(); |
162 } | 168 } |
163 | 169 |
164 void ArcSessionManager::OnSessionStopped(StopReason reason) { | 170 void ArcSessionManager::OnSessionStopped(StopReason reason) { |
165 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 171 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
166 if (arc_sign_in_timer_.IsRunning()) | 172 if (arc_sign_in_timer_.IsRunning()) |
167 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 173 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
168 | 174 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 | 394 |
389 bool ArcSessionManager::IsAllowed() const { | 395 bool ArcSessionManager::IsAllowed() const { |
390 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
391 return profile_ != nullptr; | 397 return profile_ != nullptr; |
392 } | 398 } |
393 | 399 |
394 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { | 400 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { |
395 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 401 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
396 DCHECK(profile && profile != profile_); | 402 DCHECK(profile && profile != profile_); |
397 | 403 |
404 // TODO(victorhsieh): Keep using the instance from login screen when ready. | |
398 Shutdown(); | 405 Shutdown(); |
399 | 406 |
400 if (!IsArcAllowedForProfile(profile)) | 407 if (!IsArcAllowedForProfile(profile)) |
401 return; | 408 return; |
402 | 409 |
403 // TODO(khmel): Move this to IsArcAllowedForProfile. | 410 // TODO(khmel): Move this to IsArcAllowedForProfile. |
404 if (policy_util::IsArcDisabledForEnterprise() && | 411 if (policy_util::IsArcDisabledForEnterprise() && |
405 policy_util::IsAccountManaged(profile)) { | 412 policy_util::IsAccountManaged(profile)) { |
406 VLOG(2) << "Enterprise users are not supported in ARC."; | 413 VLOG(2) << "Enterprise users are not supported in ARC."; |
407 return; | 414 return; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | 449 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, |
443 weak_ptr_factory_.GetWeakPtr())); | 450 weak_ptr_factory_.GetWeakPtr())); |
444 | 451 |
445 // Chrome may be shut down before completing ARC data removal. | 452 // Chrome may be shut down before completing ARC data removal. |
446 // In such a case, start removing the data now. | 453 // In such a case, start removing the data now. |
447 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 454 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
448 VLOG(1) << "ARC data removal requested in previous session."; | 455 VLOG(1) << "ARC data removal requested in previous session."; |
449 RemoveArcData(); | 456 RemoveArcData(); |
450 } | 457 } |
451 | 458 |
452 if (IsArcPlayStoreEnabled()) { | 459 if (IsPersistentArc() || IsArcPlayStoreEnabled()) { |
453 VLOG(1) << "ARC is already enabled."; | 460 VLOG(1) << "ARC is already enabled."; |
454 DCHECK(!enable_requested_); | 461 DCHECK(!enable_requested_); |
455 RequestEnable(); | 462 RequestEnable(); |
456 } else { | 463 } else { |
457 VLOG(1) << "ARC is initially disabled. Removing data."; | 464 VLOG(1) << "ARC is initially disabled. Removing data."; |
458 RemoveArcData(); | 465 RemoveArcData(); |
459 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 466 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
460 OnIsSyncingChanged(); | 467 OnIsSyncingChanged(); |
461 } | 468 } |
462 } | 469 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 } | 513 } |
507 ShutdownSession(); | 514 ShutdownSession(); |
508 if (support_host_) | 515 if (support_host_) |
509 support_host_->Close(); | 516 support_host_->Close(); |
510 } | 517 } |
511 | 518 |
512 void ArcSessionManager::OnOptInPreferenceChanged() { | 519 void ArcSessionManager::OnOptInPreferenceChanged() { |
513 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 520 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
514 DCHECK(profile_); | 521 DCHECK(profile_); |
515 | 522 |
516 const bool arc_enabled = IsArcPlayStoreEnabled(); | 523 const bool play_enabled = IsArcPlayStoreEnabled(); |
hidehiko
2017/02/23 10:29:16
Could you use "play_store" instead of "play" for c
victorhsieh
2017/02/24 00:44:59
Done.
hidehiko
2017/02/28 19:26:06
There are still many "play" (not "play store") usa
victorhsieh
2017/02/28 21:47:06
Really done. Double checked with `git show | grep
| |
517 if (!IsArcManaged()) { | 524 if (!IsArcManaged()) { |
518 // Update UMA only for non-Managed cases. | 525 // Update UMA only for non-Managed cases. |
519 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | 526 UpdateOptInActionUMA(play_enabled ? OptInActionType::OPTED_IN |
520 : OptInActionType::OPTED_OUT); | 527 : OptInActionType::OPTED_OUT); |
521 | 528 |
522 if (!arc_enabled) { | 529 if (!play_enabled) { |
523 // Remove the pinned Play Store icon launcher in Shelf. | 530 // Remove the pinned Play Store icon launcher in Shelf. |
524 // This is only for non-Managed cases. In managed cases, it is expected | 531 // This is only for non-Managed cases. In managed cases, it is expected |
525 // to be "disabled" rather than "removed", so keep it here. | 532 // to be "disabled" rather than "removed", so keep it here. |
526 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | 533 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); |
527 if (shelf_delegate) | 534 if (shelf_delegate) |
528 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 535 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
529 } | 536 } |
530 } | 537 } |
531 | 538 |
532 if (support_host_) | 539 if (support_host_) |
533 support_host_->SetArcManaged(IsArcManaged()); | 540 support_host_->SetArcManaged(IsArcManaged()); |
534 | 541 |
535 // Hide auth notification if it was opened before and arc.enabled pref was | 542 // Hide auth notification if it was opened before and arc.enabled pref was |
536 // explicitly set to true or false. | 543 // explicitly set to true or false. |
537 if (!g_disable_ui_for_testing && | 544 if (!g_disable_ui_for_testing && |
538 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 545 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
539 ArcAuthNotification::Hide(); | 546 ArcAuthNotification::Hide(); |
540 } | 547 } |
541 | 548 |
542 if (arc_enabled) | 549 if (IsPersistentArc()) { |
hidehiko
2017/02/23 10:29:16
Clarification: Several services expect OnArcPlaySt
victorhsieh
2017/02/24 00:44:59
Fixed. It's not intentional. Thanks.
| |
550 // TODO(victorhsieh): Implement opt-in and opt-out flow. For now, do | |
551 // nothing but keep the existing ARC instance running. | |
552 return; | |
553 } | |
554 | |
555 if (play_enabled) | |
543 RequestEnable(); | 556 RequestEnable(); |
544 else | 557 else |
545 RequestDisable(); | 558 RequestDisable(); |
546 | 559 |
547 for (auto& observer : observer_list_) | 560 for (auto& observer : observer_list_) |
548 observer.OnArcPlayStoreEnabledChanged(arc_enabled); | 561 observer.OnArcPlayStoreEnabledChanged(play_enabled); |
549 } | 562 } |
550 | 563 |
551 void ArcSessionManager::ShutdownSession() { | 564 void ArcSessionManager::ShutdownSession() { |
552 arc_sign_in_timer_.Stop(); | 565 arc_sign_in_timer_.Stop(); |
553 playstore_launcher_.reset(); | 566 playstore_launcher_.reset(); |
554 terms_of_service_negotiator_.reset(); | 567 terms_of_service_negotiator_.reset(); |
555 android_management_checker_.reset(); | 568 android_management_checker_.reset(); |
556 arc_session_runner_->RequestStop(); | 569 arc_session_runner_->RequestStop(); |
557 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 570 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might |
558 // still be running when we return from this function. Do not set the | 571 // still be running when we return from this function. Do not set the |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 // Skip to show UI asking users to enable/disable their preference for | 734 // Skip to show UI asking users to enable/disable their preference for |
722 // backup-restore and location-service, if both are managed by the admin | 735 // backup-restore and location-service, if both are managed by the admin |
723 // policy. Note that the ToS agreement is anyway not shown in the case of the | 736 // policy. Note that the ToS agreement is anyway not shown in the case of the |
724 // managed ARC. | 737 // managed ARC. |
725 if (IsArcManaged() && | 738 if (IsArcManaged() && |
726 prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled) && | 739 prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled) && |
727 prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) { | 740 prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) { |
728 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 741 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
729 } | 742 } |
730 | 743 |
744 if (IsPersistentArc()) { | |
hidehiko
2017/02/23 10:29:16
Maybe merge this into L757?
victorhsieh
2017/02/24 00:44:59
Done.
| |
745 DCHECK(IsArcAllowedForProfile(profile_)); | |
746 StartArc(); | |
747 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) | |
hidehiko
2017/02/23 10:29:16
IIUC, background management check is always needed
victorhsieh
2017/02/24 00:44:59
Done.
| |
748 StartArcAndroidManagementCheckedInBackground(); | |
749 return; | |
750 } | |
751 | |
731 // If it is marked that sign in has been successfully done, then directly | 752 // If it is marked that sign in has been successfully done, then directly |
732 // start ARC. | 753 // start ARC. |
733 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. | 754 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. |
734 // For backward compatibility, this check needs to be prior to the | 755 // For backward compatibility, this check needs to be prior to the |
735 // kArcTermsAccepted check below. | 756 // kArcTermsAccepted check below. |
736 if (prefs->GetBoolean(prefs::kArcSignedIn) || | 757 if (prefs->GetBoolean(prefs::kArcSignedIn) || |
737 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { | 758 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { |
738 StartArc(); | 759 StartArc(); |
739 | 760 |
740 // Skip Android management check for testing. | 761 // Skip Android management check for testing. |
741 // We also skip if Android management check for Kiosk mode, | 762 // We also skip if Android management check for Kiosk mode, |
742 // because there are no managed human users for Kiosk exist. | 763 // because there are no managed human users for Kiosk exist. |
743 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || | 764 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || |
744 (g_disable_ui_for_testing && | 765 (g_disable_ui_for_testing && |
745 !g_enable_check_android_management_for_testing)) { | 766 !g_enable_check_android_management_for_testing)) { |
746 return; | 767 return; |
747 } | 768 } |
748 | 769 |
749 // Check Android management in parallel. | 770 // Check Android management in parallel. |
750 // Note: Because the callback may be called in synchronous way (i.e. called | 771 // Note: Because the callback may be called in synchronous way (i.e. called |
751 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 772 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
752 // Otherwise, SetArcPlayStoreEnabled() which may be called in | 773 // Otherwise, SetArcPlayStoreEnabled() which may be called in |
753 // OnBackgroundAndroidManagementChecked() could be ignored. | 774 // OnBackgroundAndroidManagementChecked() could be ignored. |
754 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( | 775 StartArcAndroidManagementCheckedInBackground(); |
hidehiko
2017/02/23 10:29:16
Maybe: "Check" rather than "Checked"?
victorhsieh
2017/02/24 00:44:59
Done.
| |
755 profile_, context_->token_service(), context_->account_id(), | |
756 true /* retry_on_error */); | |
757 android_management_checker_->StartCheck( | |
758 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, | |
759 weak_ptr_factory_.GetWeakPtr())); | |
760 return; | 776 return; |
761 } | 777 } |
762 | 778 |
763 // If it is marked that the Terms of service is accepted already, | 779 // If it is marked that the Terms of service is accepted already, |
764 // just skip the negotiation with user, and start Android management | 780 // just skip the negotiation with user, and start Android management |
765 // check directly. | 781 // check directly. |
766 // This happens, e.g., when; | 782 // This happens, e.g., when; |
767 // 1) User accepted the Terms of service on OOBE flow. | 783 // 1) User accepted the Terms of service on OOBE flow. |
768 // 2) User accepted the Terms of service on Opt-in flow, but logged out | 784 // 2) User accepted the Terms of service on Opt-in flow, but logged out |
769 // before ARC sign in procedure was done. Then, logs in again. | 785 // before ARC sign in procedure was done. Then, logs in again. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 878 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
863 | 879 |
864 android_management_checker_.reset(new ArcAndroidManagementChecker( | 880 android_management_checker_.reset(new ArcAndroidManagementChecker( |
865 profile_, context_->token_service(), context_->account_id(), | 881 profile_, context_->token_service(), context_->account_id(), |
866 false /* retry_on_error */)); | 882 false /* retry_on_error */)); |
867 android_management_checker_->StartCheck( | 883 android_management_checker_->StartCheck( |
868 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, | 884 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
869 weak_ptr_factory_.GetWeakPtr())); | 885 weak_ptr_factory_.GetWeakPtr())); |
870 } | 886 } |
871 | 887 |
888 void ArcSessionManager::StartArcAndroidManagementCheckedInBackground() { | |
889 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( | |
hidehiko
2017/02/23 10:29:16
Could you add DCHECKs similar to StartArcAndroidMa
victorhsieh
2017/02/24 00:44:59
Reverted this change.
| |
890 profile_, context_->token_service(), context_->account_id(), | |
891 true /* retry_on_error */); | |
892 android_management_checker_->StartCheck( | |
893 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, | |
894 weak_ptr_factory_.GetWeakPtr())); | |
895 } | |
896 | |
872 void ArcSessionManager::OnAndroidManagementChecked( | 897 void ArcSessionManager::OnAndroidManagementChecked( |
873 policy::AndroidManagementClient::Result result) { | 898 policy::AndroidManagementClient::Result result) { |
874 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 899 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
875 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); | 900 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); |
876 | 901 |
877 switch (result) { | 902 switch (result) { |
878 case policy::AndroidManagementClient::Result::UNMANAGED: | 903 case policy::AndroidManagementClient::Result::UNMANAGED: |
879 VLOG(1) << "Starting ARC for first sign in."; | 904 VLOG(1) << "Starting ARC for first sign in."; |
880 sign_in_start_time_ = base::Time::Now(); | 905 sign_in_start_time_ = base::Time::Now(); |
881 arc_sign_in_timer_.Start( | 906 arc_sign_in_timer_.Start( |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1008 | 1033 |
1009 #undef MAP_STATE | 1034 #undef MAP_STATE |
1010 | 1035 |
1011 // Some compilers report an error even if all values of an enum-class are | 1036 // Some compilers report an error even if all values of an enum-class are |
1012 // covered exhaustively in a switch statement. | 1037 // covered exhaustively in a switch statement. |
1013 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 1038 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
1014 return os; | 1039 return os; |
1015 } | 1040 } |
1016 | 1041 |
1017 } // namespace arc | 1042 } // namespace arc |
OLD | NEW |