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

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

Issue 2111733002: arc: Handle closing OptIn window for managed Arc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_auth_service.h" 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/shelf/shelf_delegate.h" 9 #include "ash/shelf/shelf_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 : OptInActionType::OPTED_OUT); 445 : OptInActionType::OPTED_OUT);
446 446
447 if (!disable_arc_from_ui_ && !arc_enabled && !IsArcManaged()) { 447 if (!disable_arc_from_ui_ && !arc_enabled && !IsArcManaged()) {
448 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); 448 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate();
449 if (shelf_delegate) 449 if (shelf_delegate)
450 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); 450 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId);
451 } 451 }
452 } 452 }
453 } 453 }
454 454
455 void ArcAuthService::StopArc() {
456 if (state_ != State::STOPPED) {
457 UpdateEnabledStateUMA(false);
458 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
459 }
460 ShutdownBridgeAndCloseUI();
461 }
462
455 void ArcAuthService::OnOptInPreferenceChanged() { 463 void ArcAuthService::OnOptInPreferenceChanged() {
456 DCHECK(thread_checker.Get().CalledOnValidThread()); 464 DCHECK(thread_checker.Get().CalledOnValidThread());
457 DCHECK(profile_); 465 DCHECK(profile_);
458 466
459 const bool arc_enabled = IsArcEnabled(); 467 const bool arc_enabled = IsArcEnabled();
460 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); 468 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled));
461 469
462 if (!arc_enabled) { 470 if (!arc_enabled) {
463 if (state_ != State::STOPPED) { 471 StopArc();
464 UpdateEnabledStateUMA(false);
465 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
466 }
467 ShutdownBridgeAndCloseUI();
468 return; 472 return;
469 } 473 }
470 474
471 if (state_ == State::ACTIVE) 475 if (state_ == State::ACTIVE)
472 return; 476 return;
473 CloseUI(); 477 CloseUI();
474 auth_code_.clear(); 478 auth_code_.clear();
475 479
476 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 480 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
477 // Need pre-fetch auth code and show OptIn UI if needed. 481 // Need pre-fetch auth code and show OptIn UI if needed.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 ShutdownBridge(); 582 ShutdownBridge();
579 } 583 }
580 584
581 initial_opt_in_ = false; 585 initial_opt_in_ = false;
582 StartUI(); 586 StartUI();
583 } 587 }
584 588
585 void ArcAuthService::CancelAuthCode() { 589 void ArcAuthService::CancelAuthCode() {
586 DCHECK(thread_checker.Get().CalledOnValidThread()); 590 DCHECK(thread_checker.Get().CalledOnValidThread());
587 591
588 if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) {
589 ShutdownBridge();
khmel 2016/06/29 23:53:55 This is handled in StopArc and by adding check on
590 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn))
591 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
592 }
593
594 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR && 592 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR &&
Luis Héctor Chávez 2016/06/30 17:04:13 Given that silent opt-in is now off the table, can
khmel 2016/06/30 17:41:50 I added State::NOT_INITIALIZED handling and commen
Luis Héctor Chávez 2016/06/30 20:46:46 Discussed this with mitsuji@. He was also of the i
595 ui_page_ != UIPage::ERROR_WITH_FEEDBACK) 593 ui_page_ != UIPage::ERROR_WITH_FEEDBACK)
596 return; 594 return;
597 595
598 // Update UMA with user cancel only if error is not currently shown. 596 // Update UMA with user cancel only if error is not currently shown.
599 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) 597 if (ui_page_ != UIPage::ERROR && ui_page_ == UIPage::ERROR_WITH_FEEDBACK &&
598 ui_page_ != UIPage::NO_PAGE) {
600 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 599 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
600 }
601
602 StopArc();
603
604 if (IsArcManaged())
605 return;
601 606
602 base::AutoReset<bool> auto_reset(&disable_arc_from_ui_, true); 607 base::AutoReset<bool> auto_reset(&disable_arc_from_ui_, true);
603 DisableArc(); 608 DisableArc();
604 } 609 }
605 610
606 bool ArcAuthService::IsArcManaged() const { 611 bool ArcAuthService::IsArcManaged() const {
607 DCHECK(thread_checker.Get().CalledOnValidThread()); 612 DCHECK(thread_checker.Get().CalledOnValidThread());
608 DCHECK(profile_); 613 DCHECK(profile_);
609 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); 614 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled);
610 } 615 }
611 616
612 bool ArcAuthService::IsArcEnabled() const { 617 bool ArcAuthService::IsArcEnabled() const {
613 DCHECK(thread_checker.Get().CalledOnValidThread()); 618 DCHECK(thread_checker.Get().CalledOnValidThread());
614 DCHECK(profile_); 619 DCHECK(profile_);
615 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); 620 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled);
616 } 621 }
617 622
618 void ArcAuthService::EnableArc() { 623 void ArcAuthService::EnableArc() {
619 DCHECK(thread_checker.Get().CalledOnValidThread()); 624 DCHECK(thread_checker.Get().CalledOnValidThread());
620 DCHECK(profile_); 625 DCHECK(profile_);
621 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 626
627 if (!IsArcEnabled()) {
628 if (IsArcManaged())
629 return;
630 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
631 } else {
632 OnOptInPreferenceChanged();
633 }
622 } 634 }
623 635
624 void ArcAuthService::DisableArc() { 636 void ArcAuthService::DisableArc() {
625 DCHECK(thread_checker.Get().CalledOnValidThread()); 637 DCHECK(thread_checker.Get().CalledOnValidThread());
626 DCHECK(profile_); 638 DCHECK(profile_);
627 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 639 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
628 } 640 }
629 641
630 void ArcAuthService::StartUI() { 642 void ArcAuthService::StartUI() {
631 DCHECK(thread_checker.Get().CalledOnValidThread()); 643 DCHECK(thread_checker.Get().CalledOnValidThread());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 return os << kStateFetchingCode; 730 return os << kStateFetchingCode;
719 case ArcAuthService::State::ACTIVE: 731 case ArcAuthService::State::ACTIVE:
720 return os << kStateActive; 732 return os << kStateActive;
721 default: 733 default:
722 NOTREACHED(); 734 NOTREACHED();
723 return os; 735 return os;
724 } 736 }
725 } 737 }
726 738
727 } // namespace arc 739 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698