Commit 0cd72d99 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Allow multiple consumers in ExistingUserController

Support having multiple AuthStatusConsumer's in
ExistingUserController.

This is a preparation CL for implementing a browsertest that needs to
subscribe itself as a "consumer" without suppressing the default
consumer functionality (LoginDisplayHostMojo).

Bug: 1033936
Change-Id: I97e6869c105bcddc6263f6bc201ff370a03d41dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315336Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791260}
parent a5dd78eb
......@@ -1017,8 +1017,8 @@ void ExistingUserController::OnAuthFailure(const AuthFailure& failure) {
// attempt.
ChromeUserManager::Get()->ResetUserFlow(last_login_attempt_account_id_);
if (auth_status_consumer_)
auth_status_consumer_->OnAuthFailure(failure);
for (auto& auth_status_consumer : auth_status_consumers_)
auth_status_consumer.OnAuthFailure(failure);
ClearActiveDirectoryState();
ClearRecordedNames();
......@@ -1167,11 +1167,10 @@ void ExistingUserController::OnProfilePrepared(Profile* profile,
user_manager::known_user::SetIsEnterpriseManaged(user_context.GetAccountId(),
is_enterprise_managed);
// Inform |auth_status_consumer_| about successful login.
// Inform |auth_status_consumers_| about successful login.
// TODO(nkostylev): Pass UserContext back crbug.com/424550
if (auth_status_consumer_) {
auth_status_consumer_->OnAuthSuccess(user_context);
}
for (auto& auth_status_consumer : auth_status_consumers_)
auth_status_consumer.OnAuthSuccess(user_context);
}
void ExistingUserController::OnOffTheRecordAuthSuccess() {
......@@ -1183,8 +1182,8 @@ void ExistingUserController::OnOffTheRecordAuthSuccess() {
UserSessionManager::GetInstance()->CompleteGuestSessionLogin(guest_mode_url_);
if (auth_status_consumer_)
auth_status_consumer_->OnOffTheRecordAuthSuccess();
for (auto& auth_status_consumer : auth_status_consumers_)
auth_status_consumer.OnOffTheRecordAuthSuccess();
}
void ExistingUserController::OnPasswordChangeDetected(
......@@ -1201,8 +1200,8 @@ void ExistingUserController::OnPasswordChangeDetected(
return;
}
if (auth_status_consumer_)
auth_status_consumer_->OnPasswordChangeDetected(user_context);
for (auto& auth_status_consumer : auth_status_consumers_)
auth_status_consumer.OnPasswordChangeDetected(user_context);
ShowPasswordChangedDialog(user_context);
}
......@@ -1356,8 +1355,8 @@ void ExistingUserController::WhiteListCheckFailed(const std::string& email) {
GetLoginDisplay()->ShowWhitelistCheckFailedError();
if (auth_status_consumer_) {
auth_status_consumer_->OnAuthFailure(
for (auto& auth_status_consumer : auth_status_consumers_) {
auth_status_consumer.OnAuthFailure(
AuthFailure(AuthFailure::WHITELIST_CHECK_FAILED));
}
......@@ -1396,6 +1395,16 @@ void ExistingUserController::DeviceSettingsChanged() {
}
}
void ExistingUserController::AddLoginStatusConsumer(
AuthStatusConsumer* consumer) {
auth_status_consumers_.AddObserver(consumer);
}
void ExistingUserController::RemoveLoginStatusConsumer(
const AuthStatusConsumer* consumer) {
auth_status_consumers_.RemoveObserver(consumer);
}
LoginPerformer::AuthorizationMode ExistingUserController::auth_mode() const {
if (login_performer_)
return login_performer_->auth_mode();
......
......@@ -15,6 +15,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
......@@ -126,10 +127,9 @@ class ExistingUserController : public LoginDisplay::Delegate,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// Set a delegate that we will pass AuthStatusConsumer events to.
void set_login_status_consumer(AuthStatusConsumer* consumer) {
auth_status_consumer_ = consumer;
}
// Add/remove a delegate that we will pass AuthStatusConsumer events to.
void AddLoginStatusConsumer(AuthStatusConsumer* consumer);
void RemoveLoginStatusConsumer(const AuthStatusConsumer* consumer);
// Returns value of LoginPerformer::auth_mode() (cached if performer is
// destroyed).
......@@ -339,9 +339,9 @@ class ExistingUserController : public LoginDisplay::Delegate,
// Used to execute login operations.
std::unique_ptr<LoginPerformer> login_performer_;
// Delegate to forward all authentication status events to.
// Delegates to forward all authentication status events to.
// Tests can use this to receive authentication status events.
AuthStatusConsumer* auth_status_consumer_ = nullptr;
base::ObserverList<AuthStatusConsumer> auth_status_consumers_;
// AccountId of the last login attempt.
AccountId last_login_attempt_account_id_ = EmptyAccountId();
......
......@@ -121,16 +121,15 @@ class ChallengeResponseFakeCryptohomeClient : public FakeCryptohomeClient {
class AuthFailureWaiter final : public AuthStatusConsumer {
public:
AuthFailureWaiter() {
ExistingUserController::current_controller()->set_login_status_consumer(
this);
ExistingUserController::current_controller()->AddLoginStatusConsumer(this);
}
AuthFailureWaiter(const AuthFailureWaiter&) = delete;
AuthFailureWaiter& operator=(const AuthFailureWaiter&) = delete;
~AuthFailureWaiter() override {
ExistingUserController::current_controller()->set_login_status_consumer(
nullptr);
ExistingUserController::current_controller()->RemoveLoginStatusConsumer(
this);
}
AuthFailure::FailureReason Wait() {
......
......@@ -572,7 +572,7 @@ void LoginDisplayHostMojo::CreateExistingUserController() {
login_display_->set_delegate(existing_user_controller_.get());
// We need auth attempt results to notify views-based login screen.
existing_user_controller_->set_login_status_consumer(this);
existing_user_controller_->AddLoginStatusConsumer(this);
}
} // namespace chromeos
......@@ -2062,7 +2062,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, TermsOfServiceWithLocaleSwitch) {
chromeos::ExistingUserController* controller =
chromeos::ExistingUserController::current_controller();
ASSERT_TRUE(controller);
controller->set_login_status_consumer(&login_status_consumer);
controller->AddLoginStatusConsumer(&login_status_consumer);
// Manually select a different keyboard layout and click the enter button to
// start the session.
......@@ -2073,7 +2073,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, TermsOfServiceWithLocaleSwitch) {
// Spin the loop until the login observer fires. Then, unregister the
// observer.
login_wait_run_loop.Run();
controller->set_login_status_consumer(NULL);
controller->RemoveLoginStatusConsumer(&login_status_consumer);
// Verify that the Terms of Service screen is being shown.
chromeos::WizardController* wizard_controller =
......@@ -2649,9 +2649,9 @@ IN_PROC_BROWSER_TEST_P(TermsOfServiceDownloadTest, TermsOfServiceScreen) {
chromeos::ExistingUserController* controller =
chromeos::ExistingUserController::current_controller();
ASSERT_TRUE(controller);
controller->set_login_status_consumer(&login_status_consumer);
controller->AddLoginStatusConsumer(&login_status_consumer);
login_wait_run_loop.Run();
controller->set_login_status_consumer(NULL);
controller->RemoveLoginStatusConsumer(&login_status_consumer);
// Verify that the Terms of Service screen is being shown.
chromeos::WizardController* wizard_controller =
......@@ -2765,9 +2765,9 @@ IN_PROC_BROWSER_TEST_P(TermsOfServiceDownloadTest, DeclineTermsOfService) {
chromeos::ExistingUserController* controller =
chromeos::ExistingUserController::current_controller();
ASSERT_TRUE(controller);
controller->set_login_status_consumer(&login_status_consumer);
controller->AddLoginStatusConsumer(&login_status_consumer);
login_wait_run_loop.Run();
controller->set_login_status_consumer(NULL);
controller->RemoveLoginStatusConsumer(&login_status_consumer);
// Verify that the Terms of Service screen is being shown.
chromeos::WizardController* wizard_controller =
......
......@@ -10,6 +10,7 @@
#include "base/component_export.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/observer_list_types.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/net_errors.h"
......@@ -128,9 +129,10 @@ enum SuccessReason {
// An interface that defines the callbacks for objects that the
// Authenticator class will call to report the success/failure of
// authentication for Chromium OS.
class COMPONENT_EXPORT(CHROMEOS_LOGIN_AUTH) AuthStatusConsumer {
class COMPONENT_EXPORT(CHROMEOS_LOGIN_AUTH) AuthStatusConsumer
: public base::CheckedObserver {
public:
virtual ~AuthStatusConsumer() {}
~AuthStatusConsumer() override = default;
// The current login attempt has ended in failure, with error |error|.
virtual void OnAuthFailure(const AuthFailure& error) = 0;
......
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