Commit 5e281d7f authored by Boris Sazonov's avatar Boris Sazonov Committed by Chromium LUCI CQ

[Lacros] Rename AccountManagerFacadeLacros to AccountManagerFacadeImpl

Renames AccountManagerFacadeLacros to AccountManagerFacadeImpl and moves
it to components/account_manager_core so it is accessible by both
Ash and Lacros.

It also renames the corresponding test and moves it to the new
//components/account_manager_core:unit_tests target which runs on
both Ash and Lacros.

This is a preparation step before the upcoming unification of
AccountManagerFacadeLacros and AccountManagerFacadeAsh.

Bug: 1161699
Change-Id: I88486df45685a04540f332031835eec34bf1e11b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601750
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842775}
parent b24f1bec
...@@ -4598,8 +4598,6 @@ static_library("browser") { ...@@ -4598,8 +4598,6 @@ static_library("browser") {
"feedback/show_feedback_page_lacros.cc", "feedback/show_feedback_page_lacros.cc",
"first_run/first_run_internal_lacros.cc", "first_run/first_run_internal_lacros.cc",
"lacros/account_manager_facade_factory_lacros.cc", "lacros/account_manager_facade_factory_lacros.cc",
"lacros/account_manager_facade_lacros.cc",
"lacros/account_manager_facade_lacros.h",
"lacros/account_manager_util.cc", "lacros/account_manager_util.cc",
"lacros/account_manager_util.h", "lacros/account_manager_util.h",
"lacros/cert_db_initializer.h", "lacros/cert_db_initializer.h",
......
...@@ -5,15 +5,15 @@ ...@@ -5,15 +5,15 @@
#include "chrome/browser/account_manager_facade_factory.h" #include "chrome/browser/account_manager_facade_factory.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "chrome/browser/lacros/account_manager_facade_lacros.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h" #include "chromeos/lacros/lacros_chrome_service_impl.h"
#include "components/account_manager_core/account_manager_facade.h" #include "components/account_manager_core/account_manager_facade.h"
#include "components/account_manager_core/account_manager_facade_impl.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
account_manager::AccountManagerFacade* GetAccountManagerFacade( account_manager::AccountManagerFacade* GetAccountManagerFacade(
const std::string& profile_path) { const std::string& profile_path) {
// Multi-Login is disabled with Lacros. Always return the same instance. // Multi-Login is disabled with Lacros. Always return the same instance.
static base::NoDestructor<AccountManagerFacadeLacros> facade([] { static base::NoDestructor<AccountManagerFacadeImpl> facade([] {
auto* lacros_chrome_service_impl = chromeos::LacrosChromeServiceImpl::Get(); auto* lacros_chrome_service_impl = chromeos::LacrosChromeServiceImpl::Get();
DCHECK(lacros_chrome_service_impl); DCHECK(lacros_chrome_service_impl);
if (!lacros_chrome_service_impl->IsAccountManagerAvailable()) { if (!lacros_chrome_service_impl->IsAccountManagerAvailable()) {
......
...@@ -4939,7 +4939,6 @@ test("unit_tests") { ...@@ -4939,7 +4939,6 @@ test("unit_tests") {
if (is_chromeos_lacros) { if (is_chromeos_lacros) {
assert(enable_native_notifications) assert(enable_native_notifications)
sources += [ sources += [
"../browser/lacros/account_manager_facade_lacros_unittest.cc",
"../browser/lacros/client_cert_store_lacros_unittest.cc", "../browser/lacros/client_cert_store_lacros_unittest.cc",
"../browser/lacros/lacros_chrome_service_delegate_impl_unittest.cc", "../browser/lacros/lacros_chrome_service_delegate_impl_unittest.cc",
"../browser/lacros/metrics_reporting_observer_unittest.cc", "../browser/lacros/metrics_reporting_observer_unittest.cc",
......
...@@ -427,6 +427,10 @@ test("components_unittests") { ...@@ -427,6 +427,10 @@ test("components_unittests") {
] ]
} }
if (is_chromeos_ash || is_chromeos_lacros) {
deps += [ "//components/account_manager_core:unit_tests" ]
}
if (is_mac) { if (is_mac) {
deps += [ "//components/metal_util:unit_tests" ] deps += [ "//components/metal_util:unit_tests" ]
} }
......
...@@ -13,6 +13,8 @@ component("account_manager_core") { ...@@ -13,6 +13,8 @@ component("account_manager_core") {
"account.h", "account.h",
"account_manager_facade.cc", "account_manager_facade.cc",
"account_manager_facade.h", "account_manager_facade.h",
"account_manager_facade_impl.cc",
"account_manager_facade_impl.h",
"account_manager_util.cc", "account_manager_util.cc",
"account_manager_util.h", "account_manager_util.h",
] ]
...@@ -21,6 +23,7 @@ component("account_manager_core") { ...@@ -21,6 +23,7 @@ component("account_manager_core") {
"//base", "//base",
"//chromeos/crosapi/mojom", "//chromeos/crosapi/mojom",
"//google_apis:google_apis", "//google_apis:google_apis",
"//mojo/public/cpp/bindings",
] ]
defines = [ "IS_ACCOUNT_MANAGER_CORE_IMPL" ] defines = [ "IS_ACCOUNT_MANAGER_CORE_IMPL" ]
...@@ -36,3 +39,17 @@ source_set("test_support") { ...@@ -36,3 +39,17 @@ source_set("test_support") {
deps = [ ":account_manager_core" ] deps = [ ":account_manager_core" ]
} }
source_set("unit_tests") {
testonly = true
sources = [ "account_manager_facade_impl_unittest.cc" ]
deps = [
":account_manager_core",
":test_support",
"//base/test:test_support",
"//chromeos/crosapi/mojom",
"//testing/gtest",
]
}
include_rules = [ include_rules = [
"+chromeos/crosapi/mojom/account_manager.mojom.h", "+chromeos/crosapi/mojom/account_manager.mojom.h",
"+google_apis/gaia/google_service_auth_error.h", "+google_apis/gaia/google_service_auth_error.h",
"+mojo/public",
] ]
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/lacros/account_manager_facade_lacros.h" #include "components/account_manager_core/account_manager_facade_impl.h"
#include <memory> #include <memory>
#include <utility> #include <utility>
...@@ -17,7 +17,7 @@ constexpr uint32_t kMinVersionWithObserver = 1; ...@@ -17,7 +17,7 @@ constexpr uint32_t kMinVersionWithObserver = 1;
} // namespace } // namespace
AccountManagerFacadeLacros::AccountManagerFacadeLacros( AccountManagerFacadeImpl::AccountManagerFacadeImpl(
mojo::Remote<crosapi::mojom::AccountManager> account_manager_remote, mojo::Remote<crosapi::mojom::AccountManager> account_manager_remote,
base::OnceClosure init_finished) base::OnceClosure init_finished)
: account_manager_remote_(std::move(account_manager_remote)), : account_manager_remote_(std::move(account_manager_remote)),
...@@ -29,39 +29,39 @@ AccountManagerFacadeLacros::AccountManagerFacadeLacros( ...@@ -29,39 +29,39 @@ AccountManagerFacadeLacros::AccountManagerFacadeLacros(
} }
account_manager_remote_.QueryVersion(base::BindOnce( account_manager_remote_.QueryVersion(base::BindOnce(
&AccountManagerFacadeLacros::OnVersionCheck, weak_factory_.GetWeakPtr())); &AccountManagerFacadeImpl::OnVersionCheck, weak_factory_.GetWeakPtr()));
} }
AccountManagerFacadeLacros::~AccountManagerFacadeLacros() = default; AccountManagerFacadeImpl::~AccountManagerFacadeImpl() = default;
bool AccountManagerFacadeLacros::IsInitialized() { bool AccountManagerFacadeImpl::IsInitialized() {
return is_initialized_; return is_initialized_;
} }
void AccountManagerFacadeLacros::ShowAddAccountDialog( void AccountManagerFacadeImpl::ShowAddAccountDialog(
const AccountAdditionSource& source, const AccountAdditionSource& source,
base::OnceCallback<void(const AccountAdditionResult& result)> callback) { base::OnceCallback<void(const AccountAdditionResult& result)> callback) {
// TODO(crbug.com/1140469): implement this. // TODO(crbug.com/1140469): implement this.
} }
void AccountManagerFacadeLacros::ShowReauthAccountDialog( void AccountManagerFacadeImpl::ShowReauthAccountDialog(
const AccountAdditionSource& source, const AccountAdditionSource& source,
const std::string& email) { const std::string& email) {
// TODO(crbug.com/1140469): implement this. // TODO(crbug.com/1140469): implement this.
} }
void AccountManagerFacadeLacros::OnVersionCheck(uint32_t version) { void AccountManagerFacadeImpl::OnVersionCheck(uint32_t version) {
if (version < kMinVersionWithObserver) { if (version < kMinVersionWithObserver) {
std::move(init_finished_).Run(); std::move(init_finished_).Run();
return; return;
} }
account_manager_remote_->AddObserver( account_manager_remote_->AddObserver(
base::BindOnce(&AccountManagerFacadeLacros::OnReceiverReceived, base::BindOnce(&AccountManagerFacadeImpl::OnReceiverReceived,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
void AccountManagerFacadeLacros::OnReceiverReceived( void AccountManagerFacadeImpl::OnReceiverReceived(
mojo::PendingReceiver<AccountManagerObserver> receiver) { mojo::PendingReceiver<AccountManagerObserver> receiver) {
receiver_ = receiver_ =
std::make_unique<mojo::Receiver<crosapi::mojom::AccountManagerObserver>>( std::make_unique<mojo::Receiver<crosapi::mojom::AccountManagerObserver>>(
...@@ -69,19 +69,19 @@ void AccountManagerFacadeLacros::OnReceiverReceived( ...@@ -69,19 +69,19 @@ void AccountManagerFacadeLacros::OnReceiverReceived(
// At this point (|receiver_| exists), we are subscribed to Account Manager. // At this point (|receiver_| exists), we are subscribed to Account Manager.
account_manager_remote_->IsInitialized(base::BindOnce( account_manager_remote_->IsInitialized(base::BindOnce(
&AccountManagerFacadeLacros::OnInitialized, weak_factory_.GetWeakPtr())); &AccountManagerFacadeImpl::OnInitialized, weak_factory_.GetWeakPtr()));
} }
void AccountManagerFacadeLacros::OnInitialized(bool is_initialized) { void AccountManagerFacadeImpl::OnInitialized(bool is_initialized) {
if (is_initialized) if (is_initialized)
is_initialized_ = true; is_initialized_ = true;
// else: We will receive a notification in |OnTokenUpserted|. // else: We will receive a notification in |OnTokenUpserted|.
std::move(init_finished_).Run(); std::move(init_finished_).Run();
} }
void AccountManagerFacadeLacros::OnTokenUpserted( void AccountManagerFacadeImpl::OnTokenUpserted(
crosapi::mojom::AccountPtr account) { crosapi::mojom::AccountPtr account) {
is_initialized_ = true; is_initialized_ = true;
} }
void AccountManagerFacadeLacros::OnAccountRemoved( void AccountManagerFacadeImpl::OnAccountRemoved(
crosapi::mojom::AccountPtr account) {} crosapi::mojom::AccountPtr account) {}
...@@ -2,30 +2,30 @@ ...@@ -2,30 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_LACROS_ACCOUNT_MANAGER_FACADE_LACROS_H_ #ifndef COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_MANAGER_FACADE_IMPL_H_
#define CHROME_BROWSER_LACROS_ACCOUNT_MANAGER_FACADE_LACROS_H_ #define COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_MANAGER_FACADE_IMPL_H_
#include <memory> #include <memory>
#include "base/component_export.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chromeos/crosapi/mojom/account_manager.mojom.h" #include "chromeos/crosapi/mojom/account_manager.mojom.h"
#include "components/account_manager_core/account_manager_facade.h" #include "components/account_manager_core/account_manager_facade.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
// Lacros specific implementation of |AccountManagerFacade| that talks to // ChromeOS-specific implementation of |AccountManagerFacade| that talks to
// |chromeos::AccountManager|, residing in ash-chrome, over Mojo. // |chromeos::AccountManager| over Mojo. Used by both Lacros and Ash.
class AccountManagerFacadeLacros class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountManagerFacadeImpl
: public account_manager::AccountManagerFacade, : public account_manager::AccountManagerFacade,
public crosapi::mojom::AccountManagerObserver { public crosapi::mojom::AccountManagerObserver {
public: public:
AccountManagerFacadeLacros( AccountManagerFacadeImpl(
mojo::Remote<crosapi::mojom::AccountManager> account_manager_remote, mojo::Remote<crosapi::mojom::AccountManager> account_manager_remote,
base::OnceClosure init_finished = base::DoNothing()); base::OnceClosure init_finished = base::DoNothing());
AccountManagerFacadeLacros(const AccountManagerFacadeLacros&) = delete; AccountManagerFacadeImpl(const AccountManagerFacadeImpl&) = delete;
AccountManagerFacadeLacros& operator=(const AccountManagerFacadeLacros&) = AccountManagerFacadeImpl& operator=(const AccountManagerFacadeImpl&) = delete;
delete; ~AccountManagerFacadeImpl() override;
~AccountManagerFacadeLacros() override;
// AccountManagerFacade overrides: // AccountManagerFacade overrides:
bool IsInitialized() override; bool IsInitialized() override;
...@@ -52,7 +52,7 @@ class AccountManagerFacadeLacros ...@@ -52,7 +52,7 @@ class AccountManagerFacadeLacros
std::unique_ptr<mojo::Receiver<crosapi::mojom::AccountManagerObserver>> std::unique_ptr<mojo::Receiver<crosapi::mojom::AccountManagerObserver>>
receiver_; receiver_;
base::WeakPtrFactory<AccountManagerFacadeLacros> weak_factory_{this}; base::WeakPtrFactory<AccountManagerFacadeImpl> weak_factory_{this};
}; };
#endif // CHROME_BROWSER_LACROS_ACCOUNT_MANAGER_FACADE_LACROS_H_ #endif // COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_MANAGER_FACADE_IMPL_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/lacros/account_manager_facade_lacros.h" #include "components/account_manager_core/account_manager_facade_impl.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "chromeos/crosapi/mojom/account_manager.mojom.h" #include "chromeos/crosapi/mojom/account_manager.mojom.h"
...@@ -58,21 +58,20 @@ class FakeAccountManager : public crosapi::mojom::AccountManager { ...@@ -58,21 +58,20 @@ class FakeAccountManager : public crosapi::mojom::AccountManager {
} // namespace } // namespace
class AccountManagerFacadeLacrosTest : public testing::Test { class AccountManagerFacadeImplTest : public testing::Test {
public: public:
AccountManagerFacadeLacrosTest() = default; AccountManagerFacadeImplTest() = default;
AccountManagerFacadeLacrosTest(const AccountManagerFacadeLacrosTest&) = AccountManagerFacadeImplTest(const AccountManagerFacadeImplTest&) = delete;
AccountManagerFacadeImplTest& operator=(const AccountManagerFacadeImplTest&) =
delete; delete;
AccountManagerFacadeLacrosTest& operator=( ~AccountManagerFacadeImplTest() override = default;
const AccountManagerFacadeLacrosTest&) = delete;
~AccountManagerFacadeLacrosTest() override = default;
protected: protected:
FakeAccountManager& account_manager() { return account_manager_; } FakeAccountManager& account_manager() { return account_manager_; }
std::unique_ptr<AccountManagerFacadeLacros> CreateFacade() { std::unique_ptr<AccountManagerFacadeImpl> CreateFacade() {
base::RunLoop run_loop; base::RunLoop run_loop;
auto result = std::make_unique<AccountManagerFacadeLacros>( auto result = std::make_unique<AccountManagerFacadeImpl>(
account_manager().CreateRemote(), run_loop.QuitClosure()); account_manager().CreateRemote(), run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
return result; return result;
...@@ -83,17 +82,17 @@ class AccountManagerFacadeLacrosTest : public testing::Test { ...@@ -83,17 +82,17 @@ class AccountManagerFacadeLacrosTest : public testing::Test {
FakeAccountManager account_manager_; FakeAccountManager account_manager_;
}; };
TEST_F(AccountManagerFacadeLacrosTest, TEST_F(AccountManagerFacadeImplTest,
FacadeIsInitializedOnConnectIfAccountManagerIsInitialized) { FacadeIsInitializedOnConnectIfAccountManagerIsInitialized) {
account_manager().SetIsInitialized(true); account_manager().SetIsInitialized(true);
std::unique_ptr<AccountManagerFacadeLacros> account_manager_facade = std::unique_ptr<AccountManagerFacadeImpl> account_manager_facade =
CreateFacade(); CreateFacade();
EXPECT_TRUE(account_manager_facade->IsInitialized()); EXPECT_TRUE(account_manager_facade->IsInitialized());
} }
TEST_F(AccountManagerFacadeLacrosTest, FacadeIsUninitializedByDefault) { TEST_F(AccountManagerFacadeImplTest, FacadeIsUninitializedByDefault) {
std::unique_ptr<AccountManagerFacadeLacros> account_manager_facade = std::unique_ptr<AccountManagerFacadeImpl> account_manager_facade =
CreateFacade(); CreateFacade();
EXPECT_FALSE(account_manager_facade->IsInitialized()); EXPECT_FALSE(account_manager_facade->IsInitialized());
} }
......
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