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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 388 |
389 bool ArcSessionManager::IsAllowed() const { | 389 bool ArcSessionManager::IsAllowed() const { |
390 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 390 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
391 return profile_ != nullptr; | 391 return profile_ != nullptr; |
392 } | 392 } |
393 | 393 |
394 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { | 394 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { |
395 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 395 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
396 DCHECK(profile && profile != profile_); | 396 DCHECK(profile && profile != profile_); |
397 | 397 |
| 398 // TODO(victorhsieh): Keep using the instance from login screen when ready. |
398 Shutdown(); | 399 Shutdown(); |
399 | 400 |
400 if (!IsArcAllowedForProfile(profile)) | 401 if (!IsArcAllowedForProfile(profile)) |
401 return; | 402 return; |
402 | 403 |
403 // TODO(khmel): Move this to IsArcAllowedForProfile. | 404 // TODO(khmel): Move this to IsArcAllowedForProfile. |
404 if (policy_util::IsArcDisabledForEnterprise() && | 405 if (policy_util::IsArcDisabledForEnterprise() && |
405 policy_util::IsAccountManaged(profile)) { | 406 policy_util::IsAccountManaged(profile)) { |
406 VLOG(2) << "Enterprise users are not supported in ARC."; | 407 VLOG(2) << "Enterprise users are not supported in ARC."; |
407 return; | 408 return; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | 443 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, |
443 weak_ptr_factory_.GetWeakPtr())); | 444 weak_ptr_factory_.GetWeakPtr())); |
444 | 445 |
445 // Chrome may be shut down before completing ARC data removal. | 446 // Chrome may be shut down before completing ARC data removal. |
446 // In such a case, start removing the data now. | 447 // In such a case, start removing the data now. |
447 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 448 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
448 VLOG(1) << "ARC data removal requested in previous session."; | 449 VLOG(1) << "ARC data removal requested in previous session."; |
449 RemoveArcData(); | 450 RemoveArcData(); |
450 } | 451 } |
451 | 452 |
452 if (IsArcPlayStoreEnabled()) { | 453 if (ShouldArcAlwaysStart() || IsArcPlayStoreEnabled()) { |
453 VLOG(1) << "ARC is already enabled."; | 454 VLOG(1) << "ARC is already enabled."; |
454 DCHECK(!enable_requested_); | 455 DCHECK(!enable_requested_); |
455 RequestEnable(); | 456 RequestEnable(); |
456 } else { | 457 } else { |
457 VLOG(1) << "ARC is initially disabled. Removing data."; | 458 VLOG(1) << "ARC is initially disabled. Removing data."; |
458 RemoveArcData(); | 459 RemoveArcData(); |
459 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 460 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
460 OnIsSyncingChanged(); | 461 OnIsSyncingChanged(); |
461 } | 462 } |
462 } | 463 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 507 } |
507 ShutdownSession(); | 508 ShutdownSession(); |
508 if (support_host_) | 509 if (support_host_) |
509 support_host_->Close(); | 510 support_host_->Close(); |
510 } | 511 } |
511 | 512 |
512 void ArcSessionManager::OnOptInPreferenceChanged() { | 513 void ArcSessionManager::OnOptInPreferenceChanged() { |
513 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 514 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
514 DCHECK(profile_); | 515 DCHECK(profile_); |
515 | 516 |
516 const bool arc_enabled = IsArcPlayStoreEnabled(); | 517 const bool play_store_enabled = IsArcPlayStoreEnabled(); |
517 if (!IsArcManaged()) { | 518 if (!IsArcManaged()) { |
518 // Update UMA only for non-Managed cases. | 519 // Update UMA only for non-Managed cases. |
519 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | 520 UpdateOptInActionUMA(play_store_enabled ? OptInActionType::OPTED_IN |
520 : OptInActionType::OPTED_OUT); | 521 : OptInActionType::OPTED_OUT); |
521 | 522 |
522 if (!arc_enabled) { | 523 if (!play_store_enabled) { |
523 // Remove the pinned Play Store icon launcher in Shelf. | 524 // Remove the pinned Play Store icon launcher in Shelf. |
524 // This is only for non-Managed cases. In managed cases, it is expected | 525 // This is only for non-Managed cases. In managed cases, it is expected |
525 // to be "disabled" rather than "removed", so keep it here. | 526 // to be "disabled" rather than "removed", so keep it here. |
526 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | 527 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); |
527 if (shelf_delegate) | 528 if (shelf_delegate) |
528 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 529 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
529 } | 530 } |
530 } | 531 } |
531 | 532 |
532 if (support_host_) | 533 if (support_host_) |
533 support_host_->SetArcManaged(IsArcManaged()); | 534 support_host_->SetArcManaged(IsArcManaged()); |
534 | 535 |
535 // Hide auth notification if it was opened before and arc.enabled pref was | 536 // Hide auth notification if it was opened before and arc.enabled pref was |
536 // explicitly set to true or false. | 537 // explicitly set to true or false. |
537 if (!g_disable_ui_for_testing && | 538 if (!g_disable_ui_for_testing && |
538 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 539 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
539 ArcAuthNotification::Hide(); | 540 ArcAuthNotification::Hide(); |
540 } | 541 } |
541 | 542 |
542 if (arc_enabled) | 543 if (ShouldArcAlwaysStart()) { |
543 RequestEnable(); | 544 // TODO(victorhsieh): Implement opt-in and opt-out flow. For now, do |
544 else | 545 // nothing but keep the existing ARC instance running. |
545 RequestDisable(); | 546 } else { |
| 547 if (play_store_enabled) |
| 548 RequestEnable(); |
| 549 else |
| 550 RequestDisable(); |
| 551 } |
546 | 552 |
547 for (auto& observer : observer_list_) | 553 for (auto& observer : observer_list_) |
548 observer.OnArcPlayStoreEnabledChanged(arc_enabled); | 554 observer.OnArcPlayStoreEnabledChanged(play_store_enabled); |
549 } | 555 } |
550 | 556 |
551 void ArcSessionManager::ShutdownSession() { | 557 void ArcSessionManager::ShutdownSession() { |
552 arc_sign_in_timer_.Stop(); | 558 arc_sign_in_timer_.Stop(); |
553 playstore_launcher_.reset(); | 559 playstore_launcher_.reset(); |
554 terms_of_service_negotiator_.reset(); | 560 terms_of_service_negotiator_.reset(); |
555 android_management_checker_.reset(); | 561 android_management_checker_.reset(); |
556 arc_session_runner_->RequestStop(); | 562 arc_session_runner_->RequestStop(); |
557 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 563 // 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 | 564 // still be running when we return from this function. Do not set the |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled) && | 732 prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled) && |
727 prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) { | 733 prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) { |
728 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 734 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
729 } | 735 } |
730 | 736 |
731 // If it is marked that sign in has been successfully done, then directly | 737 // If it is marked that sign in has been successfully done, then directly |
732 // start ARC. | 738 // start ARC. |
733 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. | 739 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. |
734 // For backward compatibility, this check needs to be prior to the | 740 // For backward compatibility, this check needs to be prior to the |
735 // kArcTermsAccepted check below. | 741 // kArcTermsAccepted check below. |
736 if (prefs->GetBoolean(prefs::kArcSignedIn) || | 742 if (prefs->GetBoolean(prefs::kArcSignedIn) || ShouldArcAlwaysStart() || |
737 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { | 743 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { |
738 StartArc(); | 744 StartArc(); |
739 | 745 |
740 // Skip Android management check for testing. | 746 // Skip Android management check for testing. |
741 // We also skip if Android management check for Kiosk mode, | 747 // We also skip if Android management check for Kiosk mode, |
742 // because there are no managed human users for Kiosk exist. | 748 // because there are no managed human users for Kiosk exist. |
743 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || | 749 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || |
744 (g_disable_ui_for_testing && | 750 (g_disable_ui_for_testing && |
745 !g_enable_check_android_management_for_testing)) { | 751 !g_enable_check_android_management_for_testing)) { |
746 return; | 752 return; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 | 1014 |
1009 #undef MAP_STATE | 1015 #undef MAP_STATE |
1010 | 1016 |
1011 // Some compilers report an error even if all values of an enum-class are | 1017 // Some compilers report an error even if all values of an enum-class are |
1012 // covered exhaustively in a switch statement. | 1018 // covered exhaustively in a switch statement. |
1013 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 1019 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
1014 return os; | 1020 return os; |
1015 } | 1021 } |
1016 | 1022 |
1017 } // namespace arc | 1023 } // namespace arc |
OLD | NEW |