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

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

Issue 2702723002: Extract kArcEnabled preference from ArcSessionManager part 1. (Closed)
Patch Set: Created 3 years, 10 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 "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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // TODO(hidehiko): Revisit to think about lazy initialization. 411 // TODO(hidehiko): Revisit to think about lazy initialization.
412 // 412 //
413 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must 413 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must
414 // be the kiosk app. In case of error the UI will be useless as well, because 414 // be the kiosk app. In case of error the UI will be useless as well, because
415 // in typical use case there will be no one nearby the kiosk device, who can 415 // in typical use case there will be no one nearby the kiosk device, who can
416 // do some action to solve the problem be means of UI. 416 // do some action to solve the problem be means of UI.
417 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && 417 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() &&
418 !IsArcKioskMode()) { 418 !IsArcKioskMode()) {
419 DCHECK(!support_host_); 419 DCHECK(!support_host_);
420 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); 420 support_host_ = base::MakeUnique<ArcSupportHost>(profile_);
421 support_host_->SetArcManaged(IsArcManaged()); 421 support_host_->SetArcManaged(IsArcPlayStoreEnabledForProfile(profile_));
Yusuke Sato 2017/02/17 22:27:08 This contradicts with the description of the CL yo
hidehiko 2017/02/20 18:18:44 Good catch! Fixed.
422 support_host_->AddObserver(this); 422 support_host_->AddObserver(this);
423 } 423 }
424 424
425 DCHECK_EQ(State::NOT_INITIALIZED, state_); 425 DCHECK_EQ(State::NOT_INITIALIZED, state_);
426 SetState(State::STOPPED); 426 SetState(State::STOPPED);
427 427
428 context_.reset(new ArcAuthContext(profile_)); 428 context_.reset(new ArcAuthContext(profile_));
429 429
430 if (!g_disable_ui_for_testing || 430 if (!g_disable_ui_for_testing ||
431 g_enable_check_android_management_for_testing) { 431 g_enable_check_android_management_for_testing) {
432 ArcAndroidManagementChecker::StartClient(); 432 ArcAndroidManagementChecker::StartClient();
433 } 433 }
434 434
435 pref_change_registrar_.Init(profile_->GetPrefs()); 435 pref_change_registrar_.Init(profile_->GetPrefs());
436 pref_change_registrar_.Add( 436 pref_change_registrar_.Add(
437 prefs::kArcEnabled, 437 prefs::kArcEnabled,
438 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, 438 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged,
439 weak_ptr_factory_.GetWeakPtr())); 439 weak_ptr_factory_.GetWeakPtr()));
440 440
441 // Chrome may be shut down before completing ARC data removal. 441 // Chrome may be shut down before completing ARC data removal.
442 // In such a case, start removing the data now. 442 // In such a case, start removing the data now.
443 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { 443 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) {
444 VLOG(1) << "ARC data removal requested in previous session."; 444 VLOG(1) << "ARC data removal requested in previous session.";
445 RemoveArcData(); 445 RemoveArcData();
446 } 446 }
447 447
448 if (IsArcPlayStoreEnabled()) { 448 if (IsArcPlayStoreEnabledForProfile(profile_)) {
449 VLOG(1) << "ARC is already enabled."; 449 VLOG(1) << "ARC is already enabled.";
450 DCHECK(!enable_requested_); 450 DCHECK(!enable_requested_);
451 RequestEnable(); 451 RequestEnable();
452 } else { 452 } else {
453 VLOG(1) << "ARC is initially disabled. Removing data."; 453 VLOG(1) << "ARC is initially disabled. Removing data.";
454 RemoveArcData(); 454 RemoveArcData();
455 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); 455 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
456 OnIsSyncingChanged(); 456 OnIsSyncingChanged();
457 } 457 }
458 } 458 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 502 }
503 ShutdownSession(); 503 ShutdownSession();
504 if (support_host_) 504 if (support_host_)
505 support_host_->Close(); 505 support_host_->Close();
506 } 506 }
507 507
508 void ArcSessionManager::OnOptInPreferenceChanged() { 508 void ArcSessionManager::OnOptInPreferenceChanged() {
509 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 509 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
510 DCHECK(profile_); 510 DCHECK(profile_);
511 511
512 const bool arc_enabled = IsArcPlayStoreEnabled(); 512 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_);
513 if (!IsArcManaged()) { 513 const bool is_play_store_managed =
514 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_);
515 if (!is_play_store_managed) {
514 // Update UMA only for non-Managed cases. 516 // Update UMA only for non-Managed cases.
515 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN 517 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN
516 : OptInActionType::OPTED_OUT); 518 : OptInActionType::OPTED_OUT);
517 519
518 if (!arc_enabled) { 520 if (!is_play_store_enabled) {
519 // Remove the pinned Play Store icon launcher in Shelf. 521 // Remove the pinned Play Store icon launcher in Shelf.
520 // This is only for non-Managed cases. In managed cases, it is expected 522 // This is only for non-Managed cases. In managed cases, it is expected
521 // to be "disabled" rather than "removed", so keep it here. 523 // to be "disabled" rather than "removed", so keep it here.
522 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); 524 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate();
523 if (shelf_delegate) 525 if (shelf_delegate)
524 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); 526 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId);
525 } 527 }
526 } 528 }
527 529
528 if (support_host_) 530 if (support_host_)
529 support_host_->SetArcManaged(IsArcManaged()); 531 support_host_->SetArcManaged(is_play_store_managed);
530 532
531 // Hide auth notification if it was opened before and arc.enabled pref was 533 // Hide auth notification if it was opened before and arc.enabled pref was
532 // explicitly set to true or false. 534 // explicitly set to true or false.
533 if (!g_disable_ui_for_testing && 535 if (!g_disable_ui_for_testing &&
534 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { 536 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) {
535 ArcAuthNotification::Hide(); 537 ArcAuthNotification::Hide();
536 } 538 }
537 539
538 if (arc_enabled) 540 if (is_play_store_enabled)
539 RequestEnable(); 541 RequestEnable();
540 else 542 else
541 RequestDisable(); 543 RequestDisable();
542 544
543 for (auto& observer : observer_list_) 545 for (auto& observer : observer_list_)
544 observer.OnArcPlayStoreEnabledChanged(arc_enabled); 546 observer.OnArcPlayStoreEnabledChanged(is_play_store_enabled);
545 } 547 }
546 548
547 void ArcSessionManager::ShutdownSession() { 549 void ArcSessionManager::ShutdownSession() {
548 arc_sign_in_timer_.Stop(); 550 arc_sign_in_timer_.Stop();
549 playstore_launcher_.reset(); 551 playstore_launcher_.reset();
550 terms_of_service_negotiator_.reset(); 552 terms_of_service_negotiator_.reset();
551 android_management_checker_.reset(); 553 android_management_checker_.reset();
552 arc_session_runner_->RequestStop(); 554 arc_session_runner_->RequestStop();
553 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might 555 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might
554 // still be running when we return from this function. Do not set the 556 // still be running when we return from this function. Do not set the
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 } 638 }
637 639
638 // Update UMA with user cancel only if error is not currently shown. 640 // Update UMA with user cancel only if error is not currently shown.
639 if (support_host_ && 641 if (support_host_ &&
640 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE && 642 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE &&
641 support_host_->ui_page() != ArcSupportHost::UIPage::ERROR) { 643 support_host_->ui_page() != ArcSupportHost::UIPage::ERROR) {
642 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 644 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
643 } 645 }
644 646
645 StopArc(); 647 StopArc();
646 SetArcPlayStoreEnabled(false); 648 SetArcPlayStoreEnabledForProfile(profile_, false);
647 }
648
649 bool ArcSessionManager::IsArcManaged() const {
650 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
651 DCHECK(profile_);
652 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled);
653 }
654
655 bool ArcSessionManager::IsArcPlayStoreEnabled() const {
656 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
657 if (!IsAllowed())
658 return false;
659
660 DCHECK(profile_);
661 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled);
662 }
663
664 void ArcSessionManager::SetArcPlayStoreEnabled(bool enabled) {
665 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
666 DCHECK(profile_);
667
668 if (IsArcManaged()) {
669 VLOG(1) << "Whether Google Play Store is enabled is managed. Do nothing.";
670 return;
671 }
672
673 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled);
674 } 649 }
675 650
676 void ArcSessionManager::RecordArcState() { 651 void ArcSessionManager::RecordArcState() {
677 // Only record Enabled state if ARC is allowed in the first place, so we do 652 // Only record Enabled state if ARC is allowed in the first place, so we do
678 // not split the ARC population by devices that cannot run ARC. 653 // not split the ARC population by devices that cannot run ARC.
679 if (IsAllowed()) 654 if (IsAllowed())
680 UpdateEnabledStateUMA(enable_requested_); 655 UpdateEnabledStateUMA(enable_requested_);
681 } 656 }
682 657
683 void ArcSessionManager::RequestEnable() { 658 void ArcSessionManager::RequestEnable() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 // because there are no managed human users for Kiosk exist. 701 // because there are no managed human users for Kiosk exist.
727 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || 702 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() ||
728 (g_disable_ui_for_testing && 703 (g_disable_ui_for_testing &&
729 !g_enable_check_android_management_for_testing)) { 704 !g_enable_check_android_management_for_testing)) {
730 return; 705 return;
731 } 706 }
732 707
733 // Check Android management in parallel. 708 // Check Android management in parallel.
734 // Note: Because the callback may be called in synchronous way (i.e. called 709 // Note: Because the callback may be called in synchronous way (i.e. called
735 // on the same stack), StartCheck() needs to be called *after* StartArc(). 710 // on the same stack), StartCheck() needs to be called *after* StartArc().
736 // Otherwise, SetArcPlayStoreEnabled() which may be called in 711 // Otherwise, SetArcPlayStoreEnabledForProfile() which may be called in
737 // OnBackgroundAndroidManagementChecked() could be ignored. 712 // OnBackgroundAndroidManagementChecked() could be ignored.
738 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( 713 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>(
739 profile_, context_->token_service(), context_->account_id(), 714 profile_, context_->token_service(), context_->account_id(),
740 true /* retry_on_error */); 715 true /* retry_on_error */);
741 android_management_checker_->StartCheck( 716 android_management_checker_->StartCheck(
742 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, 717 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked,
743 weak_ptr_factory_.GetWeakPtr())); 718 weak_ptr_factory_.GetWeakPtr()));
744 return; 719 return;
745 } 720 }
746 721
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 861 }
887 862
888 void ArcSessionManager::OnBackgroundAndroidManagementChecked( 863 void ArcSessionManager::OnBackgroundAndroidManagementChecked(
889 policy::AndroidManagementClient::Result result) { 864 policy::AndroidManagementClient::Result result) {
890 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 865 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
891 switch (result) { 866 switch (result) {
892 case policy::AndroidManagementClient::Result::UNMANAGED: 867 case policy::AndroidManagementClient::Result::UNMANAGED:
893 // Do nothing. ARC should be started already. 868 // Do nothing. ARC should be started already.
894 break; 869 break;
895 case policy::AndroidManagementClient::Result::MANAGED: 870 case policy::AndroidManagementClient::Result::MANAGED:
896 SetArcPlayStoreEnabled(false); 871 SetArcPlayStoreEnabledForProfile(profile_, false);
897 break; 872 break;
898 case policy::AndroidManagementClient::Result::ERROR: 873 case policy::AndroidManagementClient::Result::ERROR:
899 // This code should not be reached. For background check, 874 // This code should not be reached. For background check,
900 // retry_on_error should be set. 875 // retry_on_error should be set.
901 NOTREACHED(); 876 NOTREACHED();
902 } 877 }
903 } 878 }
904 879
905 void ArcSessionManager::OnWindowClosed() { 880 void ArcSessionManager::OnWindowClosed() {
906 DCHECK(support_host_); 881 DCHECK(support_host_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 965
991 #undef MAP_STATE 966 #undef MAP_STATE
992 967
993 // Some compilers report an error even if all values of an enum-class are 968 // Some compilers report an error even if all values of an enum-class are
994 // covered exhaustively in a switch statement. 969 // covered exhaustively in a switch statement.
995 NOTREACHED() << "Invalid value " << static_cast<int>(state); 970 NOTREACHED() << "Invalid value " << static_cast<int>(state);
996 return os; 971 return os;
997 } 972 }
998 973
999 } // namespace arc 974 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698