Commit 909ea96d authored by Boris Sazonov's avatar Boris Sazonov Committed by Chromium LUCI CQ

Revise AccountManagerAsh to support multiple receivers

Changes AccountManagerAsh to use ReceiverSet instead of a single
Receiver. This allows having multiple clients talking to the same
AccountManagerAsh instance and also prepares the upcoming unification of
AccountManagerFacade implementations. AccountManagerAsh ownership will
be revised in subsequent CLs.

Bug: 1161699, 1148448
Change-Id: Ida66bce494df802bf5ce4fd99f78d081a9540b95
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2614788Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841428}
parent a927adf8
...@@ -13,10 +13,8 @@ ...@@ -13,10 +13,8 @@
namespace crosapi { namespace crosapi {
AccountManagerAsh::AccountManagerAsh( AccountManagerAsh::AccountManagerAsh(chromeos::AccountManager* account_manager)
chromeos::AccountManager* account_manager, : account_manager_(account_manager) {
mojo::PendingReceiver<mojom::AccountManager> receiver)
: account_manager_(account_manager), receiver_(this, std::move(receiver)) {
DCHECK(account_manager_); DCHECK(account_manager_);
account_manager_->AddObserver(this); account_manager_->AddObserver(this);
} }
...@@ -25,6 +23,11 @@ AccountManagerAsh::~AccountManagerAsh() { ...@@ -25,6 +23,11 @@ AccountManagerAsh::~AccountManagerAsh() {
account_manager_->RemoveObserver(this); account_manager_->RemoveObserver(this);
} }
void AccountManagerAsh::BindReceiver(
mojo::PendingReceiver<mojom::AccountManager> receiver) {
receivers_.Add(this, std::move(receiver));
}
void AccountManagerAsh::IsInitialized(IsInitializedCallback callback) { void AccountManagerAsh::IsInitialized(IsInitializedCallback callback) {
std::move(callback).Run(account_manager_->IsInitialized()); std::move(callback).Run(account_manager_->IsInitialized());
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "chromeos/crosapi/mojom/account_manager.mojom.h" #include "chromeos/crosapi/mojom/account_manager.mojom.h"
#include "components/account_manager_core/account.h" #include "components/account_manager_core/account.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h" #include "mojo/public/cpp/bindings/remote_set.h"
namespace crosapi { namespace crosapi {
...@@ -21,12 +21,13 @@ namespace crosapi { ...@@ -21,12 +21,13 @@ namespace crosapi {
class AccountManagerAsh : public mojom::AccountManager, class AccountManagerAsh : public mojom::AccountManager,
public chromeos::AccountManager::Observer { public chromeos::AccountManager::Observer {
public: public:
AccountManagerAsh(chromeos::AccountManager* account_manager, explicit AccountManagerAsh(chromeos::AccountManager* account_manager);
mojo::PendingReceiver<mojom::AccountManager> receiver);
AccountManagerAsh(const AccountManagerAsh&) = delete; AccountManagerAsh(const AccountManagerAsh&) = delete;
AccountManagerAsh& operator=(const AccountManagerAsh&) = delete; AccountManagerAsh& operator=(const AccountManagerAsh&) = delete;
~AccountManagerAsh() override; ~AccountManagerAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::AccountManager> receiver);
// crosapi::mojom::AccountManager: // crosapi::mojom::AccountManager:
void IsInitialized(IsInitializedCallback callback) override; void IsInitialized(IsInitializedCallback callback) override;
void AddObserver(AddObserverCallback callback) override; void AddObserver(AddObserverCallback callback) override;
...@@ -42,7 +43,7 @@ class AccountManagerAsh : public mojom::AccountManager, ...@@ -42,7 +43,7 @@ class AccountManagerAsh : public mojom::AccountManager,
void FlushMojoForTesting(); void FlushMojoForTesting();
chromeos::AccountManager* const account_manager_; chromeos::AccountManager* const account_manager_;
mojo::Receiver<mojom::AccountManager> receiver_; mojo::ReceiverSet<mojom::AccountManager> receivers_;
mojo::RemoteSet<mojom::AccountManagerObserver> observers_; mojo::RemoteSet<mojom::AccountManagerObserver> observers_;
}; };
......
...@@ -93,8 +93,9 @@ class AccountManagerAshTest : public ::testing::Test { ...@@ -93,8 +93,9 @@ class AccountManagerAshTest : public ::testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
account_manager_ash_ = std::make_unique<AccountManagerAsh>( account_manager_ash_ =
&account_manager_, remote_.BindNewPipeAndPassReceiver()); std::make_unique<AccountManagerAsh>(&account_manager_);
account_manager_ash_->BindReceiver(remote_.BindNewPipeAndPassReceiver());
account_manager_async_waiter_ = account_manager_async_waiter_ =
std::make_unique<mojom::AccountManagerAsyncWaiter>( std::make_unique<mojom::AccountManagerAsyncWaiter>(
account_manager_ash_.get()); account_manager_ash_.get());
......
...@@ -62,7 +62,9 @@ AshChromeServiceImpl::~AshChromeServiceImpl() = default; ...@@ -62,7 +62,9 @@ AshChromeServiceImpl::~AshChromeServiceImpl() = default;
void AshChromeServiceImpl::BindAccountManager( void AshChromeServiceImpl::BindAccountManager(
mojo::PendingReceiver<mojom::AccountManager> receiver) { mojo::PendingReceiver<mojom::AccountManager> receiver) {
DVLOG(1) << "Binding AccountManager receiver"; // TODO(https://crrev.com/c/2601750): Move AccountManagerAsh ownership to
// chromeos::AccountManager.
if (!account_manager_ash_) {
// Assumptions: // Assumptions:
// 1. TODO(https://crbug.com/1102768): Multi-Signin / Fast-User-Switching is // 1. TODO(https://crbug.com/1102768): Multi-Signin / Fast-User-Switching is
// disabled. // disabled.
...@@ -86,11 +88,12 @@ void AshChromeServiceImpl::BindAccountManager( ...@@ -86,11 +88,12 @@ void AshChromeServiceImpl::BindAccountManager(
chromeos::AccountManager* const account_manager = chromeos::AccountManager* const account_manager =
g_browser_process->platform_part() g_browser_process->platform_part()
->GetAccountManagerFactory() ->GetAccountManagerFactory()
->GetAccountManager(/* profile_path = */ profile->GetPath().value()); ->GetAccountManager(
// TODO(https://crbug.com/1148448): Convert this to allow multiple, /* profile_path = */ profile->GetPath().value());
// simultaneous crosapi clients. See BindScreenManager for an example. account_manager_ash_ =
account_manager_ash_ = std::make_unique<crosapi::AccountManagerAsh>( std::make_unique<crosapi::AccountManagerAsh>(account_manager);
account_manager, std::move(receiver)); }
account_manager_ash_->BindReceiver(std::move(receiver));
} }
void AshChromeServiceImpl::BindFileManager( void AshChromeServiceImpl::BindFileManager(
......
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