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 @@
namespace crosapi {
AccountManagerAsh::AccountManagerAsh(
chromeos::AccountManager* account_manager,
mojo::PendingReceiver<mojom::AccountManager> receiver)
: account_manager_(account_manager), receiver_(this, std::move(receiver)) {
AccountManagerAsh::AccountManagerAsh(chromeos::AccountManager* account_manager)
: account_manager_(account_manager) {
DCHECK(account_manager_);
account_manager_->AddObserver(this);
}
......@@ -25,6 +23,11 @@ AccountManagerAsh::~AccountManagerAsh() {
account_manager_->RemoveObserver(this);
}
void AccountManagerAsh::BindReceiver(
mojo::PendingReceiver<mojom::AccountManager> receiver) {
receivers_.Add(this, std::move(receiver));
}
void AccountManagerAsh::IsInitialized(IsInitializedCallback callback) {
std::move(callback).Run(account_manager_->IsInitialized());
}
......
......@@ -10,7 +10,7 @@
#include "chromeos/crosapi/mojom/account_manager.mojom.h"
#include "components/account_manager_core/account.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"
namespace crosapi {
......@@ -21,12 +21,13 @@ namespace crosapi {
class AccountManagerAsh : public mojom::AccountManager,
public chromeos::AccountManager::Observer {
public:
AccountManagerAsh(chromeos::AccountManager* account_manager,
mojo::PendingReceiver<mojom::AccountManager> receiver);
explicit AccountManagerAsh(chromeos::AccountManager* account_manager);
AccountManagerAsh(const AccountManagerAsh&) = delete;
AccountManagerAsh& operator=(const AccountManagerAsh&) = delete;
~AccountManagerAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::AccountManager> receiver);
// crosapi::mojom::AccountManager:
void IsInitialized(IsInitializedCallback callback) override;
void AddObserver(AddObserverCallback callback) override;
......@@ -42,7 +43,7 @@ class AccountManagerAsh : public mojom::AccountManager,
void FlushMojoForTesting();
chromeos::AccountManager* const account_manager_;
mojo::Receiver<mojom::AccountManager> receiver_;
mojo::ReceiverSet<mojom::AccountManager> receivers_;
mojo::RemoteSet<mojom::AccountManagerObserver> observers_;
};
......
......@@ -93,8 +93,9 @@ class AccountManagerAshTest : public ::testing::Test {
protected:
void SetUp() override {
account_manager_ash_ = std::make_unique<AccountManagerAsh>(
&account_manager_, remote_.BindNewPipeAndPassReceiver());
account_manager_ash_ =
std::make_unique<AccountManagerAsh>(&account_manager_);
account_manager_ash_->BindReceiver(remote_.BindNewPipeAndPassReceiver());
account_manager_async_waiter_ =
std::make_unique<mojom::AccountManagerAsyncWaiter>(
account_manager_ash_.get());
......
......@@ -62,35 +62,38 @@ AshChromeServiceImpl::~AshChromeServiceImpl() = default;
void AshChromeServiceImpl::BindAccountManager(
mojo::PendingReceiver<mojom::AccountManager> receiver) {
DVLOG(1) << "Binding AccountManager receiver";
// Assumptions:
// 1. TODO(https://crbug.com/1102768): Multi-Signin / Fast-User-Switching is
// disabled.
// 2. ash-chrome has 1 and only 1 "regular" |Profile|.
// TODO(https://crrev.com/c/2601750): Move AccountManagerAsh ownership to
// chromeos::AccountManager.
if (!account_manager_ash_) {
// Assumptions:
// 1. TODO(https://crbug.com/1102768): Multi-Signin / Fast-User-Switching is
// disabled.
// 2. ash-chrome has 1 and only 1 "regular" |Profile|.
#if DCHECK_IS_ON()
int num_regular_profiles = 0;
for (const Profile* profile :
g_browser_process->profile_manager()->GetLoadedProfiles()) {
if (chromeos::ProfileHelper::IsRegularProfile(profile))
num_regular_profiles++;
}
DCHECK_EQ(1, num_regular_profiles);
int num_regular_profiles = 0;
for (const Profile* profile :
g_browser_process->profile_manager()->GetLoadedProfiles()) {
if (chromeos::ProfileHelper::IsRegularProfile(profile))
num_regular_profiles++;
}
DCHECK_EQ(1, num_regular_profiles);
#endif // DCHECK_IS_ON()
// Given these assumptions, there is 1 and only 1 Account Manager that
// can/should be contacted - the one attached to the regular |Profile| in
// ash-chrome, for the current |User|.
const user_manager::User* const user =
user_manager::UserManager::Get()->GetActiveUser();
const Profile* const profile =
chromeos::ProfileHelper::Get()->GetProfileByUser(user);
chromeos::AccountManager* const account_manager =
g_browser_process->platform_part()
->GetAccountManagerFactory()
->GetAccountManager(/* profile_path = */ profile->GetPath().value());
// TODO(https://crbug.com/1148448): Convert this to allow multiple,
// simultaneous crosapi clients. See BindScreenManager for an example.
account_manager_ash_ = std::make_unique<crosapi::AccountManagerAsh>(
account_manager, std::move(receiver));
// Given these assumptions, there is 1 and only 1 Account Manager that
// can/should be contacted - the one attached to the regular |Profile| in
// ash-chrome, for the current |User|.
const user_manager::User* const user =
user_manager::UserManager::Get()->GetActiveUser();
const Profile* const profile =
chromeos::ProfileHelper::Get()->GetProfileByUser(user);
chromeos::AccountManager* const account_manager =
g_browser_process->platform_part()
->GetAccountManagerFactory()
->GetAccountManager(
/* profile_path = */ profile->GetPath().value());
account_manager_ash_ =
std::make_unique<crosapi::AccountManagerAsh>(account_manager);
}
account_manager_ash_->BindReceiver(std::move(receiver));
}
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