| Index: chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.cc
|
| diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.cc b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..16580c48e9f11937df05ece4560bc0ac294ad524
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.cc
|
| @@ -0,0 +1,71 @@
|
| +// Copyright 2014 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/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h"
|
| +
|
| +#include "base/memory/singleton.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.h"
|
| +#include "chrome/browser/chromeos/profiles/profile_helper.h"
|
| +#include "chrome/browser/profiles/incognito_helpers.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
| +#include "components/user_manager/user.h"
|
| +
|
| +namespace {
|
| +
|
| +PrefService* GetLocalState() {
|
| + return g_browser_process ? g_browser_process->local_state() : NULL;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +EasyUnlockTpmKeyManagerFactory* EasyUnlockTpmKeyManagerFactory::GetInstance() {
|
| + return Singleton<EasyUnlockTpmKeyManagerFactory>::get();
|
| +}
|
| +
|
| +// static
|
| +EasyUnlockTpmKeyManager* EasyUnlockTpmKeyManagerFactory::Get(
|
| + content::BrowserContext* browser_context) {
|
| + return static_cast<EasyUnlockTpmKeyManager*>(
|
| + EasyUnlockTpmKeyManagerFactory::GetInstance()
|
| + ->GetServiceForBrowserContext(browser_context, true));
|
| +}
|
| +
|
| +EasyUnlockTpmKeyManager* EasyUnlockTpmKeyManagerFactory::GetForUser(
|
| + const std::string& user_id) {
|
| + const user_manager::User* user =
|
| + user_manager::UserManager::Get()->FindUser(user_id);
|
| + if (!user)
|
| + return NULL;
|
| + Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user);
|
| + if (!profile)
|
| + return NULL;
|
| + return EasyUnlockTpmKeyManagerFactory::Get(profile);
|
| +}
|
| +
|
| +EasyUnlockTpmKeyManagerFactory::EasyUnlockTpmKeyManagerFactory()
|
| + : BrowserContextKeyedServiceFactory(
|
| + "EasyUnlockTpmKeyManager",
|
| + BrowserContextDependencyManager::GetInstance()) {
|
| +}
|
| +
|
| +EasyUnlockTpmKeyManagerFactory::~EasyUnlockTpmKeyManagerFactory() {
|
| +}
|
| +
|
| +KeyedService* EasyUnlockTpmKeyManagerFactory::BuildServiceInstanceFor(
|
| + content::BrowserContext* context) const {
|
| + Profile* profile = Profile::FromBrowserContext(context);
|
| + user_manager::User* user = NULL;
|
| + if (!chromeos::ProfileHelper::IsSigninProfile(profile))
|
| + user = chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
|
| + return new EasyUnlockTpmKeyManager(user ? user->email() : std::string(),
|
| + GetLocalState());
|
| +}
|
| +
|
| +content::BrowserContext* EasyUnlockTpmKeyManagerFactory::GetBrowserContextToUse(
|
| + content::BrowserContext* context) const {
|
| + return chrome::GetBrowserContextRedirectedInIncognito(context);
|
| +}
|
|
|