| Index: chrome/browser/ui/views/profiles/force_signout_dialog.cc
|
| diff --git a/chrome/browser/ui/views/profiles/force_signout_dialog.cc b/chrome/browser/ui/views/profiles/force_signout_dialog.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7255705700f7368edfde3850112cc02442341143
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/profiles/force_signout_dialog.cc
|
| @@ -0,0 +1,112 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/profiles/force_signout_dialog.h"
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/strings/string16.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/browser_list.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/browser/ui/views/frame/browser_view.h"
|
| +#include "chrome/browser/ui/views/profiles/force_signout_dialog_view.h"
|
| +#include "chrome/grit/generated_resources.h"
|
| +#include "components/signin/core/browser/signin_manager.h"
|
| +
|
| +namespace {
|
| +
|
| +void Signout(SigninManager* signin_manager) {
|
| + signin_manager->SignOut(
|
| + signin_metrics::AUTHENTICATION_FAILED_WITH_FORCE_SIGNIN,
|
| + signin_metrics::SignoutDelete::KEEPING);
|
| +}
|
| +
|
| +bool IsMatchingBrowser(Browser* browser, Profile* profile) {
|
| + return browser->profile()->GetOriginalProfile() ==
|
| + profile->GetOriginalProfile() &&
|
| + !browser->tab_strip_model()->empty() &&
|
| + BrowserView::GetBrowserViewForBrowser(browser)->frame()->IsVisible();
|
| +}
|
| +
|
| +// Find a browser that is assoicated with |profile| to show the dialog for
|
| +// Sign out warning.
|
| +Browser* FindBrowserWithProfile(Profile* profile) {
|
| + Browser* browser = BrowserList::GetInstance()->GetLastActive();
|
| + if (browser && IsMatchingBrowser(browser, profile))
|
| + return browser;
|
| + for (auto* browser : *BrowserList::GetInstance()) {
|
| + if (IsMatchingBrowser(browser, profile)) {
|
| + return browser;
|
| + }
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +ForceSignoutDialogView* ForceSignoutDialog::dialog_view_ = nullptr;
|
| +
|
| +// static
|
| +void ForceSignoutDialog::ShowDialog(Profile* profile,
|
| + SigninManager* signin_manager,
|
| + const base::Closure& signout_timer) {
|
| + if (dialog_view_)
|
| + return;
|
| +
|
| + Browser* browser = FindBrowserWithProfile(profile);
|
| + if (browser == nullptr) { // If there is no browser, we can just sign
|
| + // out profile directly.
|
| + Signout(signin_manager);
|
| + return;
|
| + }
|
| + dialog_view_ = new ForceSignoutDialogView(
|
| + browser,
|
| + base::MakeUnique<ForceSignoutDialog>(signin_manager, signout_timer));
|
| +}
|
| +
|
| +void ForceSignoutDialog::ActivateModalDialog() {
|
| + if (dialog_view_)
|
| + dialog_view_->ActivateModalDialog();
|
| +}
|
| +
|
| +bool ForceSignoutDialog::IsShowing() {
|
| + return dialog_view_ && dialog_view_->IsShowing();
|
| +}
|
| +
|
| +void ForceSignoutDialog::OnAccept() {
|
| + Signout(signin_manager_);
|
| +}
|
| +
|
| +void ForceSignoutDialog::OnCancel() {
|
| + if (!signout_timer_.is_null())
|
| + signout_timer_.Run();
|
| +}
|
| +
|
| +std::string ForceSignoutDialog::GetEmail() {
|
| + return signin_manager_->GetAuthenticatedAccountInfo().email;
|
| +}
|
| +
|
| +bool ForceSignoutDialog::IsDelayAllowed() {
|
| + return !signout_timer_.is_null();
|
| +}
|
| +
|
| +void ForceSignoutDialog::OnViewClosing() {
|
| + dialog_view_ = nullptr;
|
| +}
|
| +
|
| +ForceSignoutDialog::~ForceSignoutDialog() {}
|
| +
|
| +ForceSignoutDialog::ForceSignoutDialog(SigninManager* signin_manager,
|
| + const base::Closure& signout_timer)
|
| + : BrowserModalDialog(),
|
| + signin_manager_(signin_manager),
|
| + signout_timer_(signout_timer) {}
|
| +
|
| +// static
|
| +ForceSignoutDialogView* ForceSignoutDialog::GetDialogViewForTesting() {
|
| + return dialog_view_;
|
| +}
|
|
|