Commit 74c38a06 authored by Kush Sinha's avatar Kush Sinha Committed by Commit Bot

Add Chrome OS AccountManagerFactory

Add a caching factory for Chrome OS |AccountManager|. Cache is keyed on
the basis of Profile path (|Profile::GetPath|).

AccountManager cannot be simply a part of |g_browser_process| because of
Chrome OS Multi Sign In. Accounts participating in Multi Sign In should
see separate instances of |AccountManager|.
Once Multi Sign In has been replaced by Multi Profile,
|AccountManagerFactory| can be removed and |AccountManager| can be made
a part of |g_browser_process|.

Bug: 820046
Change-Id: I8c2f2b2b5d8d61c5a818ab711197840bd605567b
Reviewed-on: https://chromium-review.googlesource.com/1010542Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarLutz Justen <ljusten@chromium.org>
Commit-Queue: Kush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551176}
parent 909d320d
......@@ -4,6 +4,8 @@
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include <utility>
#include "ash/public/interfaces/constants.mojom.h"
#include "base/logging.h"
#include "base/time/default_tick_clock.h"
......@@ -28,6 +30,7 @@
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/account_manager/account_manager_factory.h"
#include "chromeos/geolocation/simple_geolocation_provider.h"
#include "chromeos/timezone/timezone_resolver.h"
#include "components/keep_alive_registry/keep_alive_types.h"
......@@ -45,7 +48,9 @@
#include "services/ui/public/interfaces/constants.mojom.h"
BrowserProcessPlatformPart::BrowserProcessPlatformPart()
: created_profile_helper_(false) {}
: created_profile_helper_(false),
account_manager_factory_(
std::make_unique<chromeos::AccountManagerFactory>()) {}
BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -226,3 +231,8 @@ void BrowserProcessPlatformPart::CreateProfileHelper() {
created_profile_helper_ = true;
profile_helper_.reset(new chromeos::ProfileHelper());
}
chromeos::AccountManagerFactory*
BrowserProcessPlatformPart::GetAccountManagerFactory() {
return account_manager_factory_.get();
}
......@@ -18,7 +18,7 @@ class ChromeSessionManager;
class ChromeUserManager;
class ProfileHelper;
class TimeZoneResolver;
}
} // namespace chromeos
namespace chromeos {
namespace system {
......@@ -27,8 +27,9 @@ class DeviceDisablingManager;
class DeviceDisablingManagerDefaultDelegate;
class SystemClock;
class TimeZoneResolverManager;
}
}
} // namespace system
class AccountManagerFactory;
} // namespace chromeos
namespace policy {
class BrowserPolicyConnectorChromeOS;
......@@ -115,6 +116,8 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase {
ui::InputDeviceControllerClient* GetInputDeviceControllerClient();
chromeos::AccountManagerFactory* GetAccountManagerFactory();
private:
void CreateProfileHelper();
......@@ -144,6 +147,8 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase {
std::unique_ptr<component_updater::CrOSComponentManager>
cros_component_manager_;
std::unique_ptr<chromeos::AccountManagerFactory> account_manager_factory_;
#if defined(USE_OZONE)
std::unique_ptr<ui::InputDeviceControllerClient>
input_device_controller_client_;
......
......@@ -143,6 +143,8 @@
#include "chrome/browser/chromeos/preferences.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chromeos/account_manager/account_manager.h"
#include "chromeos/account_manager/account_manager_factory.h"
#include "chromeos/assistant/buildflags.h"
#include "chromeos/services/multidevice_setup/multidevice_setup_service.h"
#include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h"
......@@ -270,7 +272,7 @@ Profile::ExitType SessionTypePrefValueToExitType(const std::string& value) {
std::string ExitTypeToSessionTypePrefValue(Profile::ExitType type) {
switch (type) {
case Profile::EXIT_NORMAL:
return ProfileImpl::kPrefExitTypeNormal;
return ProfileImpl::kPrefExitTypeNormal;
case Profile::EXIT_SESSION_ENDED:
return kPrefExitTypeSessionEnded;
case Profile::EXIT_CRASHED:
......@@ -411,8 +413,8 @@ ProfileImpl::ProfileImpl(
delegate_(delegate),
predictor_(nullptr) {
TRACE_EVENT0("browser,startup", "ProfileImpl::ctor")
DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
"profile files to the root directory!";
DCHECK(!path.empty()) << "Using an empty path will attempt to write "
<< "profile files to the root directory!";
#if defined(OS_CHROMEOS)
if (!chromeos::ProfileHelper::IsSigninProfile(this) &&
......@@ -427,6 +429,11 @@ ProfileImpl::ProfileImpl(
user->GetAccountId()))
<< "Attempting to construct the profile before starting the user "
"session";
chromeos::AccountManagerFactory* factory =
g_browser_process->platform_part()->GetAccountManagerFactory();
chromeos::AccountManager* account_manager =
factory->GetAccountManager(path.value());
account_manager->Initialize(path);
}
#endif
......
......@@ -65,6 +65,8 @@ component("chromeos") {
"accelerometer/accelerometer_types.h",
"account_manager/account_manager.cc",
"account_manager/account_manager.h",
"account_manager/account_manager_factory.cc",
"account_manager/account_manager_factory.h",
"app_mode/kiosk_oem_manifest_parser.cc",
"app_mode/kiosk_oem_manifest_parser.h",
"attestation/attestation_constants.cc",
......
// Copyright 2018 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 "chromeos/account_manager/account_manager_factory.h"
#include <string>
#include <utility>
#include "base/macros.h"
#include "chromeos/account_manager/account_manager.h"
namespace chromeos {
AccountManagerFactory::AccountManagerFactory() = default;
AccountManagerFactory::~AccountManagerFactory() = default;
AccountManager* AccountManagerFactory::GetAccountManager(
const std::string& profile_path) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = account_managers_.find(profile_path);
if (it == account_managers_.end()) {
it = account_managers_
.emplace(profile_path, std::make_unique<AccountManager>())
.first;
}
return it->second.get();
}
} // namespace chromeos
// Copyright 2018 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 CHROMEOS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_FACTORY_H_
#define CHROMEOS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_FACTORY_H_
#include <memory>
#include <string>
#include <unordered_map>
#include "base/macros.h"
#include "base/sequence_checker.h"
#include "chromeos/account_manager/account_manager.h"
namespace chromeos {
// This factory is needed because of multi signin on Chrome OS. Device Accounts,
// which are simultaneously logged into Chrome OS, should see different
// instances of |AccountManager| and hence |AccountManager| cannot be a part of
// a global like |g_browser_process| (otherwise Device Accounts will start
// sharing |AccountManager| and by extension, their Secondary
// Accounts/Identities, which is undesirable).
// Once multi signin has been removed and multi profile on ChromeOS takes its
// place, remove this class and make |AccountManager| a part of
// |g_browser_process|.
class CHROMEOS_EXPORT AccountManagerFactory {
public:
AccountManagerFactory();
~AccountManagerFactory();
// Returns the |AccountManager| corresponding to the given |profile_path|.
AccountManager* GetAccountManager(const std::string& profile_path);
private:
// A mapping from Profile path to an |AccountManager|. Acts a cache of
// Account Managers.
std::unordered_map<std::string, std::unique_ptr<AccountManager>>
account_managers_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(AccountManagerFactory);
};
} // namespace chromeos
#endif // CHROMEOS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_FACTORY_H_
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