Commit 522b635b authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Migrate ForcedReauthenticationDialogView to the IdentityManager

Use the IdentityManager APIs and update callers accordingly,
including calls from the associated test suite.

Bug: 889879
Change-Id: I69c1c29d033602dd0c37618fefd71c5229ceacbe
Reviewed-on: https://chromium-review.googlesource.com/1251609Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#595407}
parent 4fc8a212
...@@ -9,8 +9,11 @@ ...@@ -9,8 +9,11 @@
#include "base/macros.h" #include "base/macros.h"
namespace identity {
class IdentityManager;
}
class Profile; class Profile;
class SigninManager;
namespace base { namespace base {
class TimeDelta; class TimeDelta;
...@@ -23,12 +26,12 @@ class ForcedReauthenticationDialog { ...@@ -23,12 +26,12 @@ class ForcedReauthenticationDialog {
virtual ~ForcedReauthenticationDialog() {} virtual ~ForcedReauthenticationDialog() {}
// Show the ForcedReauthenticationDialog for |profile|. If there're no opened // Show the ForcedReauthenticationDialog for |profile|. If there're no opened
// browser windows for |profile|, |signin_manager| will be called to signed // browser windows for |profile|, |identity_manager| will be called to signed
// out immediately. Otherwise, dialog will be closed with all browser windows // out immediately. Otherwise, dialog will be closed with all browser windows
// are associated to |profile| after |countdown_duration| if there is no // are associated to |profile| after |countdown_duration| if there is no
// reauth. // reauth.
virtual void ShowDialog(Profile* profile, virtual void ShowDialog(Profile* profile,
SigninManager* signin_manager, identity::IdentityManager* identity_manager,
base::TimeDelta countdown_duration) = 0; base::TimeDelta countdown_duration) = 0;
protected: protected:
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h" #include "components/constrained_window/constrained_window_views.h"
#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h" #include "ui/views/border.h"
...@@ -43,8 +44,9 @@ constexpr int kRefreshTitleTimer = 1; ...@@ -43,8 +44,9 @@ constexpr int kRefreshTitleTimer = 1;
// finish sign in. // finish sign in.
constexpr int kCloseDirectlyTimer = 60; constexpr int kCloseDirectlyTimer = 60;
void Signout(SigninManager* signin_manager) { void Signout(identity::IdentityManager* identity_manager) {
signin_manager->SignOut( identity_manager->ClearPrimaryAccount(
identity::IdentityManager::ClearAccountTokensAction::kDefault,
signin_metrics::AUTHENTICATION_FAILED_WITH_FORCE_SIGNIN, signin_metrics::AUTHENTICATION_FAILED_WITH_FORCE_SIGNIN,
signin_metrics::SignoutDelete::KEEPING); signin_metrics::SignoutDelete::KEEPING);
} }
...@@ -87,10 +89,10 @@ class PromptLabel : public views::StyledLabel { ...@@ -87,10 +89,10 @@ class PromptLabel : public views::StyledLabel {
ForcedReauthenticationDialogView::ForcedReauthenticationDialogView( ForcedReauthenticationDialogView::ForcedReauthenticationDialogView(
Browser* browser, Browser* browser,
SigninManager* signin_manager, identity::IdentityManager* identity_manager,
base::TimeDelta countdown_duration) base::TimeDelta countdown_duration)
: browser_(browser), : browser_(browser),
signin_manager_(signin_manager), identity_manager_(identity_manager),
desired_close_time_(base::TimeTicks::Now() + countdown_duration), desired_close_time_(base::TimeTicks::Now() + countdown_duration),
weak_factory_(this) { weak_factory_(this) {
constrained_window::CreateBrowserModalDialogViews( constrained_window::CreateBrowserModalDialogViews(
...@@ -105,22 +107,22 @@ ForcedReauthenticationDialogView::~ForcedReauthenticationDialogView() {} ...@@ -105,22 +107,22 @@ ForcedReauthenticationDialogView::~ForcedReauthenticationDialogView() {}
// static // static
ForcedReauthenticationDialogView* ForcedReauthenticationDialogView::ShowDialog( ForcedReauthenticationDialogView* ForcedReauthenticationDialogView::ShowDialog(
Profile* profile, Profile* profile,
SigninManager* signin_manager, identity::IdentityManager* identity_manager,
base::TimeDelta countdown_duration) { base::TimeDelta countdown_duration) {
Browser* browser = FindBrowserWithProfile(profile); Browser* browser = FindBrowserWithProfile(profile);
if (browser == nullptr) { // If there is no browser, we can just sign if (browser == nullptr) { // If there is no browser, we can just sign
// out profile directly. // out profile directly.
Signout(signin_manager); Signout(identity_manager);
return nullptr; return nullptr;
} }
return new ForcedReauthenticationDialogView(browser, signin_manager, return new ForcedReauthenticationDialogView(browser, identity_manager,
countdown_duration); countdown_duration);
} }
bool ForcedReauthenticationDialogView::Accept() { bool ForcedReauthenticationDialogView::Accept() {
if (GetTimeRemaining() < base::TimeDelta::FromSeconds(kCloseDirectlyTimer)) { if (GetTimeRemaining() < base::TimeDelta::FromSeconds(kCloseDirectlyTimer)) {
Signout(signin_manager_); Signout(identity_manager_);
} else { } else {
browser_->signin_view_controller()->ShowSignin( browser_->signin_view_controller()->ShowSignin(
profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_REAUTH, browser_, profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_REAUTH, browser_,
...@@ -163,7 +165,7 @@ void ForcedReauthenticationDialogView::AddedToWidget() { ...@@ -163,7 +165,7 @@ void ForcedReauthenticationDialogView::AddedToWidget() {
GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha); GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha);
// Create the prompt label. // Create the prompt label.
size_t offset; size_t offset;
std::string email = signin_manager_->GetAuthenticatedAccountInfo().email; std::string email = identity_manager_->GetPrimaryAccountInfo().email;
const base::string16 domain = const base::string16 domain =
base::ASCIIToUTF16(gaia::ExtractDomainName(email)); base::ASCIIToUTF16(gaia::ExtractDomainName(email));
const base::string16 prompt_text = const base::string16 prompt_text =
...@@ -270,10 +272,10 @@ ForcedReauthenticationDialogImpl::~ForcedReauthenticationDialogImpl() { ...@@ -270,10 +272,10 @@ ForcedReauthenticationDialogImpl::~ForcedReauthenticationDialogImpl() {
void ForcedReauthenticationDialogImpl::ShowDialog( void ForcedReauthenticationDialogImpl::ShowDialog(
Profile* profile, Profile* profile,
SigninManager* signin_manager, identity::IdentityManager* identity_manager,
base::TimeDelta countdown_duration) { base::TimeDelta countdown_duration) {
dialog_view_ = ForcedReauthenticationDialogView::ShowDialog( dialog_view_ = ForcedReauthenticationDialogView::ShowDialog(
profile, signin_manager, countdown_duration) profile, identity_manager, countdown_duration)
->AsWeakPtr(); ->AsWeakPtr();
} }
......
...@@ -16,9 +16,12 @@ ...@@ -16,9 +16,12 @@
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
namespace identity {
class IdentityManager;
}
class Browser; class Browser;
class Profile; class Profile;
class SigninManager;
// A modal dialog that displays a warning message of the auth failure // A modal dialog that displays a warning message of the auth failure
// and ask user to sign in again. // and ask user to sign in again.
...@@ -33,7 +36,7 @@ class ForcedReauthenticationDialogView : public views::DialogDelegateView { ...@@ -33,7 +36,7 @@ class ForcedReauthenticationDialogView : public views::DialogDelegateView {
// Dialog will delete itself after closing. // Dialog will delete itself after closing.
static ForcedReauthenticationDialogView* ShowDialog( static ForcedReauthenticationDialogView* ShowDialog(
Profile* profile, Profile* profile,
SigninManager* signin_manager, identity::IdentityManager* identity_manager,
base::TimeDelta countdown_duration); base::TimeDelta countdown_duration);
// override views::DialogDelegateView // override views::DialogDelegateView
...@@ -57,14 +60,14 @@ class ForcedReauthenticationDialogView : public views::DialogDelegateView { ...@@ -57,14 +60,14 @@ class ForcedReauthenticationDialogView : public views::DialogDelegateView {
private: private:
// Show the dialog for |browser|. The dialog will delete itself after closing. // Show the dialog for |browser|. The dialog will delete itself after closing.
ForcedReauthenticationDialogView(Browser* browser, ForcedReauthenticationDialogView(Browser* browser,
SigninManager* signin_manager, identity::IdentityManager* identity_manager,
base::TimeDelta countdown_duration); base::TimeDelta countdown_duration);
void OnCountDown(); void OnCountDown();
base::TimeDelta GetTimeRemaining() const; base::TimeDelta GetTimeRemaining() const;
Browser* const browser_; Browser* const browser_;
SigninManager* signin_manager_; identity::IdentityManager* identity_manager_;
const base::TimeTicks desired_close_time_; const base::TimeTicks desired_close_time_;
...@@ -84,7 +87,7 @@ class ForcedReauthenticationDialogImpl : public ForcedReauthenticationDialog { ...@@ -84,7 +87,7 @@ class ForcedReauthenticationDialogImpl : public ForcedReauthenticationDialog {
// override ForcedReauthenticationDialog // override ForcedReauthenticationDialog
void ShowDialog(Profile* profile, void ShowDialog(Profile* profile,
SigninManager* signin_manager, identity::IdentityManager* identity_manager,
base::TimeDelta countdown_duration) override; base::TimeDelta countdown_duration) override;
private: private:
......
...@@ -6,12 +6,15 @@ ...@@ -6,12 +6,15 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h" #include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "components/signin/core/browser/signin_manager.h" #include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
class ForcedReauthenticationDialogViewBrowserTest : public DialogBrowserTest { class ForcedReauthenticationDialogViewBrowserTest : public DialogBrowserTest {
...@@ -21,8 +24,14 @@ class ForcedReauthenticationDialogViewBrowserTest : public DialogBrowserTest { ...@@ -21,8 +24,14 @@ class ForcedReauthenticationDialogViewBrowserTest : public DialogBrowserTest {
// override DialogBrowserTest // override DialogBrowserTest
void ShowUi(const std::string& name) override { void ShowUi(const std::string& name) override {
Profile* profile = browser()->profile(); Profile* profile = browser()->profile();
SigninManager* manager = SigninManagerFactory::GetForProfile(profile); identity::IdentityManager* manager =
manager->SetAuthenticatedAccountInfo("test1", "test@xyz.com"); IdentityManagerFactory::GetForProfile(profile);
identity::MakePrimaryAccountAvailable(
SigninManagerFactory::GetForProfile(profile),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile), manager,
"test@xyz.com");
ForcedReauthenticationDialogView::ShowDialog( ForcedReauthenticationDialogView::ShowDialog(
profile, manager, base::TimeDelta::FromSeconds(60)); profile, manager, base::TimeDelta::FromSeconds(60));
} }
...@@ -43,9 +52,10 @@ IN_PROC_BROWSER_TEST_F(ForcedReauthenticationDialogViewBrowserTest, ...@@ -43,9 +52,10 @@ IN_PROC_BROWSER_TEST_F(ForcedReauthenticationDialogViewBrowserTest,
NotOpenDialogDueToNoBrowser) { NotOpenDialogDueToNoBrowser) {
Profile* profile = browser()->profile(); Profile* profile = browser()->profile();
CloseBrowserSynchronously(browser()); CloseBrowserSynchronously(browser());
EXPECT_EQ(nullptr, ForcedReauthenticationDialogView::ShowDialog( EXPECT_EQ(nullptr,
profile, SigninManagerFactory::GetForProfile(profile), ForcedReauthenticationDialogView::ShowDialog(
base::TimeDelta::FromSeconds(60))); profile, IdentityManagerFactory::GetForProfile(profile),
base::TimeDelta::FromSeconds(60)));
} }
IN_PROC_BROWSER_TEST_F(ForcedReauthenticationDialogViewBrowserTest, IN_PROC_BROWSER_TEST_F(ForcedReauthenticationDialogViewBrowserTest,
...@@ -55,7 +65,8 @@ IN_PROC_BROWSER_TEST_F(ForcedReauthenticationDialogViewBrowserTest, ...@@ -55,7 +65,8 @@ IN_PROC_BROWSER_TEST_F(ForcedReauthenticationDialogViewBrowserTest,
ASSERT_EQ(1, model->count()); ASSERT_EQ(1, model->count());
model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
ASSERT_TRUE(model->empty()); ASSERT_TRUE(model->empty());
EXPECT_EQ(nullptr, ForcedReauthenticationDialogView::ShowDialog( EXPECT_EQ(nullptr,
profile, SigninManagerFactory::GetForProfile(profile), ForcedReauthenticationDialogView::ShowDialog(
base::TimeDelta::FromSeconds(60))); profile, IdentityManagerFactory::GetForProfile(profile),
base::TimeDelta::FromSeconds(60)));
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment