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

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: fix comilation error 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) { 592 if (state_ == State::NOT_INITIALIZED) {
589 ShutdownBridge(); 593 NOTREACHED();
590 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) 594 return;
591 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
592 } 595 }
593 596
597 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means
598 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not
599 // be started). If Arc is booting normally dont't stop it on progress close.
594 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR && 600 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR &&
595 ui_page_ != UIPage::ERROR_WITH_FEEDBACK) 601 ui_page_ != UIPage::ERROR_WITH_FEEDBACK) {
596 return; 602 return;
603 }
597 604
598 // Update UMA with user cancel only if error is not currently shown. 605 // Update UMA with user cancel only if error is not currently shown.
599 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) 606 if (ui_page_ != UIPage::ERROR && ui_page_ == UIPage::ERROR_WITH_FEEDBACK &&
607 ui_page_ != UIPage::NO_PAGE) {
600 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 608 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
609 }
610
611 StopArc();
612
613 if (IsArcManaged())
614 return;
601 615
602 base::AutoReset<bool> auto_reset(&disable_arc_from_ui_, true); 616 base::AutoReset<bool> auto_reset(&disable_arc_from_ui_, true);
603 DisableArc(); 617 DisableArc();
604 } 618 }
605 619
606 bool ArcAuthService::IsArcManaged() const { 620 bool ArcAuthService::IsArcManaged() const {
607 DCHECK(thread_checker.Get().CalledOnValidThread()); 621 DCHECK(thread_checker.Get().CalledOnValidThread());
608 DCHECK(profile_); 622 DCHECK(profile_);
609 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); 623 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled);
610 } 624 }
611 625
612 bool ArcAuthService::IsArcEnabled() const { 626 bool ArcAuthService::IsArcEnabled() const {
613 DCHECK(thread_checker.Get().CalledOnValidThread()); 627 DCHECK(thread_checker.Get().CalledOnValidThread());
614 DCHECK(profile_); 628 DCHECK(profile_);
615 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); 629 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled);
616 } 630 }
617 631
618 void ArcAuthService::EnableArc() { 632 void ArcAuthService::EnableArc() {
619 DCHECK(thread_checker.Get().CalledOnValidThread()); 633 DCHECK(thread_checker.Get().CalledOnValidThread());
620 DCHECK(profile_); 634 DCHECK(profile_);
621 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 635
636 if (!IsArcEnabled()) {
637 if (IsArcManaged())
638 return;
639 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
640 } else {
641 OnOptInPreferenceChanged();
642 }
622 } 643 }
623 644
624 void ArcAuthService::DisableArc() { 645 void ArcAuthService::DisableArc() {
625 DCHECK(thread_checker.Get().CalledOnValidThread()); 646 DCHECK(thread_checker.Get().CalledOnValidThread());
626 DCHECK(profile_); 647 DCHECK(profile_);
627 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 648 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
mtomasz 2016/07/20 03:46:25 Why isn't there a "if (IsArcManaged())" guard like
khmel 2016/07/20 16:50:41 This has no effect for managed Arc. Probably for c
628 } 649 }
629 650
630 void ArcAuthService::StartUI() { 651 void ArcAuthService::StartUI() {
631 DCHECK(thread_checker.Get().CalledOnValidThread()); 652 DCHECK(thread_checker.Get().CalledOnValidThread());
632 653
633 SetState(State::FETCHING_CODE); 654 SetState(State::FETCHING_CODE);
634 655
635 if (initial_opt_in_) { 656 if (initial_opt_in_) {
636 initial_opt_in_ = false; 657 initial_opt_in_ = false;
637 ShowUI(UIPage::START, base::string16()); 658 ShowUI(UIPage::START, base::string16());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 return os << kStateFetchingCode; 739 return os << kStateFetchingCode;
719 case ArcAuthService::State::ACTIVE: 740 case ArcAuthService::State::ACTIVE:
720 return os << kStateActive; 741 return os << kStateActive;
721 default: 742 default:
722 NOTREACHED(); 743 NOTREACHED();
723 return os; 744 return os;
724 } 745 }
725 } 746 }
726 747
727 } // namespace arc 748 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698