Commit f24fa5ac authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

[b4p] Refactor: Offload client authentication APIs to dedicated helper

First step to remove the duplication for b4p reauth. The implementation
of methods TriggerReauthForAccount and TriggerSignin are moved to a new
helper class, as they are.

In the next CLs, the class we'll start to internally recover the primary
account id and set the opt in preference for account storage.

Bug: 1070944
Change-Id: Ic6c950d28551a6b624f2c88943f880a961d9e4d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150426
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759301}
parent 01d5f76e
...@@ -220,6 +220,9 @@ ChromePasswordManagerClient::ChromePasswordManagerClient( ...@@ -220,6 +220,9 @@ ChromePasswordManagerClient::ChromePasswordManagerClient(
password_generation_driver_receivers_(web_contents, this), password_generation_driver_receivers_(web_contents, this),
observer_(nullptr), observer_(nullptr),
credentials_filter_(this, base::BindRepeating(&GetSyncService, profile_)), credentials_filter_(this, base::BindRepeating(&GetSyncService, profile_)),
#if !defined(OS_ANDROID)
account_storage_auth_helper_(profile_),
#endif
helper_(this) { helper_(this) {
ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this,
autofill_client); autofill_client);
...@@ -575,41 +578,15 @@ void ChromePasswordManagerClient::TriggerReauthForAccount( ...@@ -575,41 +578,15 @@ void ChromePasswordManagerClient::TriggerReauthForAccount(
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
std::move(reauth_callback).Run(ReauthSucceeded(false)); std::move(reauth_callback).Run(ReauthSucceeded(false));
#else // !defined(OS_ANDROID) #else // !defined(OS_ANDROID)
Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); account_storage_auth_helper_.TriggerOptInReauth(account_id,
if (!browser) { std::move(reauth_callback));
std::move(reauth_callback).Run(ReauthSucceeded(false));
return;
}
SigninViewController* signin_view_controller =
browser->signin_view_controller();
if (!signin_view_controller) {
std::move(reauth_callback).Run(ReauthSucceeded(false));
return;
}
signin_view_controller->ShowReauthPrompt(
account_id,
base::BindOnce(
[](base::OnceCallback<void(ReauthSucceeded)> reauth_callback,
signin::ReauthResult result) {
std::move(reauth_callback)
.Run(ReauthSucceeded(result == signin::ReauthResult::kSuccess));
},
std::move(reauth_callback)));
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
} }
void ChromePasswordManagerClient::TriggerSignIn() { void ChromePasswordManagerClient::TriggerSignIn() {
#if BUILDFLAG(ENABLE_DICE_SUPPORT) #if !defined(OS_ANDROID)
Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); account_storage_auth_helper_.TriggerSignIn();
if (!browser) #endif
return;
if (SigninViewController* signin_controller =
browser->signin_view_controller()) {
signin_controller->ShowDiceAddAccountTab(
signin_metrics::AccessPoint::ACCESS_POINT_AUTOFILL_DROPDOWN,
std::string());
}
#endif // BUILDFLAG(ENABLE_DICE_SUPPORT)
} }
bool ChromePasswordManagerClient::IsIsolationForPasswordSitesEnabled() const { bool ChromePasswordManagerClient::IsIsolationForPasswordSitesEnabled() const {
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/signin/reauth_result.h"
#include "components/autofill/content/common/mojom/autofill_driver.mojom-forward.h" #include "components/autofill/content/common/mojom/autofill_driver.mojom-forward.h"
#include "components/password_manager/content/browser/content_credential_manager.h" #include "components/password_manager/content/browser/content_credential_manager.h"
#include "components/password_manager/content/browser/content_password_manager_driver_factory.h" #include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
...@@ -45,6 +44,8 @@ ...@@ -45,6 +44,8 @@
class PasswordAccessoryController; class PasswordAccessoryController;
class TouchToFillController; class TouchToFillController;
#else
#include "chrome/browser/ui/passwords/account_storage_auth_helper.h"
#endif #endif
class ChromeBiometricAuthenticator; class ChromeBiometricAuthenticator;
...@@ -386,6 +387,10 @@ class ChromePasswordManagerClient ...@@ -386,6 +387,10 @@ class ChromePasswordManagerClient
// Whether OnPaste() was called from this ChromePasswordManagerClient // Whether OnPaste() was called from this ChromePasswordManagerClient
bool was_on_paste_called_ = false; bool was_on_paste_called_ = false;
#if !defined(OS_ANDROID)
AccountStorageAuthHelper account_storage_auth_helper_;
#endif
// Helper for performing logic that is common between // Helper for performing logic that is common between
// ChromePasswordManagerClient and IOSChromePasswordManagerClient. // ChromePasswordManagerClient and IOSChromePasswordManagerClient.
password_manager::PasswordManagerClientHelper helper_; password_manager::PasswordManagerClientHelper helper_;
......
...@@ -2195,6 +2195,8 @@ jumbo_static_library("ui") { ...@@ -2195,6 +2195,8 @@ jumbo_static_library("ui") {
"avatar_button_error_controller_delegate.h", "avatar_button_error_controller_delegate.h",
"frame/window_frame_util.cc", "frame/window_frame_util.cc",
"frame/window_frame_util.h", "frame/window_frame_util.h",
"passwords/account_storage_auth_helper.cc",
"passwords/account_storage_auth_helper.h",
"signin_reauth_popup_delegate.cc", "signin_reauth_popup_delegate.cc",
"signin_reauth_popup_delegate.h", "signin_reauth_popup_delegate.h",
"signin_view_controller.cc", "signin_view_controller.cc",
......
// Copyright 2020 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/passwords/account_storage_auth_helper.h"
#include <string>
#include <utility>
#include "base/bind.h"
#include "build/build_config.h"
#include "chrome/browser/signin/reauth_result.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/signin_view_controller.h"
#include "components/signin/public/base/signin_metrics.h"
#include "google_apis/gaia/core_account_id.h"
namespace {
using ReauthSucceeded =
password_manager::PasswordManagerClient::ReauthSucceeded;
}
AccountStorageAuthHelper::AccountStorageAuthHelper(Profile* profile)
: profile_(profile) {}
void AccountStorageAuthHelper::TriggerOptInReauth(
const CoreAccountId& account_id,
base::OnceCallback<void(ReauthSucceeded)> reauth_callback) {
Browser* browser = chrome::FindBrowserWithProfile(profile_);
if (!browser) {
std::move(reauth_callback).Run(ReauthSucceeded(false));
return;
}
SigninViewController* signin_view_controller =
browser->signin_view_controller();
if (!signin_view_controller) {
std::move(reauth_callback).Run(ReauthSucceeded(false));
return;
}
signin_view_controller->ShowReauthPrompt(
account_id,
base::BindOnce(
[](base::OnceCallback<void(ReauthSucceeded)> reauth_callback,
signin::ReauthResult result) {
std::move(reauth_callback)
.Run(ReauthSucceeded(result == signin::ReauthResult::kSuccess));
},
std::move(reauth_callback)));
}
void AccountStorageAuthHelper::TriggerSignIn() {
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
Browser* browser = chrome::FindBrowserWithProfile(profile_);
if (!browser)
return;
if (SigninViewController* signin_controller =
browser->signin_view_controller()) {
signin_controller->ShowDiceAddAccountTab(
signin_metrics::AccessPoint::ACCESS_POINT_AUTOFILL_DROPDOWN,
std::string());
}
#endif // BUILDFLAG(ENABLE_DICE_SUPPORT)
}
// Copyright 2020 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.
#ifndef CHROME_BROWSER_UI_PASSWORDS_ACCOUNT_STORAGE_AUTH_HELPER_H_
#define CHROME_BROWSER_UI_PASSWORDS_ACCOUNT_STORAGE_AUTH_HELPER_H_
#include "base/callback.h"
#include "components/password_manager/core/browser/password_manager_client.h"
struct CoreAccountId;
class Profile;
// Responsible for triggering authentication flows related to the passwords
// account storage. Used only by desktop.
class AccountStorageAuthHelper {
public:
explicit AccountStorageAuthHelper(Profile* profile);
~AccountStorageAuthHelper() = default;
AccountStorageAuthHelper(const AccountStorageAuthHelper&) = delete;
AccountStorageAuthHelper& operator=(const AccountStorageAuthHelper&) = delete;
// Requests a reauth for the given |account_id|. |reauth_callback| is called
// passing whether the reauth succeeded or not.
// TODO(crbug.com/1070944): Set the opt-in pref internally and update comment.
// TODO(crbug.com/1070944): Retrieve the primary account id internally and
// update method comment.
void TriggerOptInReauth(
const CoreAccountId& account_id,
base::OnceCallback<
void(password_manager::PasswordManagerClient::ReauthSucceeded)>
reauth_callback);
// Redirects the user to a sign-in in a new tab.
void TriggerSignIn();
private:
Profile* const profile_;
};
#endif // CHROME_BROWSER_UI_PASSWORDS_ACCOUNT_STORAGE_AUTH_HELPER_H_
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