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