Commit fc925a60 authored by Kushagra Sinha's avatar Kushagra Sinha Committed by Commit Bot

Lacros: Add AccountManager interface

Add a Mojo interface - AccountManager - for lacros-chrome to talk to
Chrome OS Account Manager residing in ash-chrome.

Implement a method in this interface:
- |IsInitialized@0() => (bool is_initialized);|
which returns |true| when Chrome OS Account Manager has been fully
initialized, and |false| otherwise.

Bug: 1117478
Test: unit_tests --gtest_filter="*AccountManagerAshTest*"
Change-Id: Ia67a51f0d9051af6c0bd311ff5a63155385741a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363748Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Commit-Queue: Kush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811154}
parent 46b6ff75
...@@ -949,6 +949,8 @@ source_set("chromeos") { ...@@ -949,6 +949,8 @@ source_set("chromeos") {
"chrome_content_browser_client_chromeos_part.h", "chrome_content_browser_client_chromeos_part.h",
"concierge_helper_service.cc", "concierge_helper_service.cc",
"concierge_helper_service.h", "concierge_helper_service.h",
"crosapi/account_manager_ash.cc",
"crosapi/account_manager_ash.h",
"crosapi/ash_chrome_service_impl.cc", "crosapi/ash_chrome_service_impl.cc",
"crosapi/ash_chrome_service_impl.h", "crosapi/ash_chrome_service_impl.h",
"crosapi/browser_loader.cc", "crosapi/browser_loader.cc",
...@@ -3206,6 +3208,7 @@ source_set("unit_tests") { ...@@ -3206,6 +3208,7 @@ source_set("unit_tests") {
"child_accounts/usage_time_state_notifier_unittest.cc", "child_accounts/usage_time_state_notifier_unittest.cc",
"chrome_content_browser_client_chromeos_part_unittest.cc", "chrome_content_browser_client_chromeos_part_unittest.cc",
"concierge_helper_service_unittest.cc", "concierge_helper_service_unittest.cc",
"crosapi/account_manager_ash_unittest.cc",
"crosapi/browser_util_unittest.cc", "crosapi/browser_util_unittest.cc",
"crosapi/message_center_ash_unittest.cc", "crosapi/message_center_ash_unittest.cc",
"crosapi/test_mojo_connection_manager_unittest.cc", "crosapi/test_mojo_connection_manager_unittest.cc",
......
...@@ -5,4 +5,4 @@ functionality which lacros-chrome requires. ...@@ -5,4 +5,4 @@ functionality which lacros-chrome requires.
There are currently two types of files in this directory: There are currently two types of files in this directory:
* Files for launching and connecting to lacros-chrome. These are named * Files for launching and connecting to lacros-chrome. These are named
lacros_foo. lacros_foo.
* Files that implement the crosapi. These are named foo_crosapi. * Files that implement the crosapi. These are named foo_ash.
// 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/chromeos/crosapi/account_manager_ash.h"
#include <utility>
#include "chromeos/components/account_manager/account_manager.h"
namespace crosapi {
AccountManagerAsh::AccountManagerAsh(
chromeos::AccountManager* account_manager,
mojo::PendingReceiver<mojom::AccountManager> receiver)
: account_manager_(account_manager), receiver_(this, std::move(receiver)) {
DCHECK(account_manager_);
}
AccountManagerAsh::~AccountManagerAsh() = default;
void AccountManagerAsh::IsInitialized(IsInitializedCallback callback) {
std::move(callback).Run(account_manager_->IsInitialized());
}
} // namespace crosapi
// 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_CHROMEOS_CROSAPI_ACCOUNT_MANAGER_ASH_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_ACCOUNT_MANAGER_ASH_H_
#include "chromeos/crosapi/mojom/account_manager.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace chromeos {
class AccountManager;
} // namespace chromeos
namespace crosapi {
// Implements the |crosapi::mojom::AccountManager| interface in ash-chrome.
// It enables lacros-chrome to interact with accounts stored in the Chrome OS
// Account Manager.
class AccountManagerAsh : public mojom::AccountManager {
public:
AccountManagerAsh(chromeos::AccountManager* account_manager,
mojo::PendingReceiver<mojom::AccountManager> receiver);
AccountManagerAsh(const AccountManagerAsh&) = delete;
AccountManagerAsh& operator=(const AccountManagerAsh&) = delete;
~AccountManagerAsh() override;
// crosapi::mojom::AccountManager:
void IsInitialized(IsInitializedCallback callback) override;
private:
chromeos::AccountManager* const account_manager_;
mojo::Receiver<mojom::AccountManager> receiver_;
};
} // namespace crosapi
#endif // CHROME_BROWSER_CHROMEOS_CROSAPI_ACCOUNT_MANAGER_ASH_H_
// 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/chromeos/crosapi/account_manager_ash.h"
#include <memory>
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "chromeos/components/account_manager/account_manager.h"
#include "chromeos/crosapi/mojom/account_manager.mojom-test-utils.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace crosapi {
class AccountManagerAshTest : public ::testing::Test {
public:
AccountManagerAshTest() = default;
AccountManagerAshTest(const AccountManagerAshTest&) = delete;
AccountManagerAshTest& operator=(const AccountManagerAshTest&) = delete;
~AccountManagerAshTest() override = default;
protected:
void SetUp() override {
account_manager_ash_ = std::make_unique<AccountManagerAsh>(
&account_manager_, remote_.BindNewPipeAndPassReceiver());
account_manager_async_waiter_ =
std::make_unique<mojom::AccountManagerAsyncWaiter>(
account_manager_ash_.get());
}
// Returns |true| if initialization was successful.
bool InitializeAccountManager() {
base::RunLoop run_loop;
account_manager_.InitializeInEphemeralMode(
test_url_loader_factory_.GetSafeWeakWrapper(), run_loop.QuitClosure());
run_loop.Run();
return account_manager_.IsInitialized();
}
mojom::AccountManagerAsyncWaiter* account_manager_async_waiter() {
return account_manager_async_waiter_.get();
}
private:
base::test::SingleThreadTaskEnvironment task_environment_;
network::TestURLLoaderFactory test_url_loader_factory_;
chromeos::AccountManager account_manager_;
mojo::Remote<mojom::AccountManager> remote_;
std::unique_ptr<AccountManagerAsh> account_manager_ash_;
std::unique_ptr<mojom::AccountManagerAsyncWaiter>
account_manager_async_waiter_;
};
TEST_F(AccountManagerAshTest,
IsInitializedReturnsFalseForUninitializedAccountManager) {
bool is_initialized = true;
account_manager_async_waiter()->IsInitialized(&is_initialized);
EXPECT_FALSE(is_initialized);
}
TEST_F(AccountManagerAshTest,
IsInitializedReturnsTrueForInitializedAccountManager) {
bool is_initialized = true;
account_manager_async_waiter()->IsInitialized(&is_initialized);
EXPECT_FALSE(is_initialized);
ASSERT_TRUE(InitializeAccountManager());
account_manager_async_waiter()->IsInitialized(&is_initialized);
EXPECT_TRUE(is_initialized);
}
} // namespace crosapi
...@@ -6,6 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -6,6 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") { mojom("mojom") {
sources = [ sources = [
"account_manager.mojom",
"bitmap.mojom", "bitmap.mojom",
"crosapi.mojom", "crosapi.mojom",
"keystore_service.mojom", "keystore_service.mojom",
......
// 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.
module crosapi.mojom;
// Interface for Chrome OS Account Manager.
// Chrome OS Account Manager is the source of truth for accounts on Chrome OS -
// including ARC, and Chrome content area. It supports Google accounts and
// Microsoft Active Directory accounts, as of this writing.
// This interface is implemented by ash-chrome, and is used by lacros-chrome to
// query accounts residing in the Chrome OS Account Manager.
// ARC++ uses components/arc/mojom/auth.mojom to talk to the Chrome OS Account
// Manager.
[Stable]
interface AccountManager {
// Returns |true| if Chrome OS Account Manager has been fully initialized, and
// |false| otherwise.
IsInitialized@0() => (bool is_initialized);
};
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