Commit 6b21580a authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Introduce AccountPasswordStoreFactory

It creates a second instance of a PasswordStore, which will be used to
store Gaia-account-scoped passwords. So far, it is not hooked up to
anything at all.

TBR=jzw@chromium.org
TBRing a purely mechanical change in web_view_password_store_factory.mm

Bug: 998455
Change-Id: I775aa7ed66c0ee712e57370fc85d35f7c8e8474a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771911
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691662}
parent 75395842
......@@ -1052,6 +1052,8 @@ jumbo_split_static_library("browser") {
"page_load_metrics/protocol_util.h",
"page_load_metrics/resource_tracker.cc",
"page_load_metrics/resource_tracker.h",
"password_manager/account_storage/account_password_store_factory.cc",
"password_manager/account_storage/account_password_store_factory.h",
"password_manager/chrome_password_manager_client.cc",
"password_manager/chrome_password_manager_client.h",
"password_manager/password_manager_util_mac.h",
......
// Copyright 2019 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/password_manager/account_storage/account_password_store_factory.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/web_data_service_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/password_manager/core/browser/login_database.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/browser/password_store_default.h"
#include "components/password_manager/core/browser/password_store_factory_util.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/storage_partition.h"
using password_manager::PasswordStore;
// static
scoped_refptr<PasswordStore> AccountPasswordStoreFactory::GetForProfile(
Profile* profile,
ServiceAccessType access_type) {
if (!base::FeatureList::IsEnabled(
password_manager::features::kEnablePasswordsAccountStorage)) {
return nullptr;
}
// |profile| gets always redirected to a non-Incognito profile below, so
// Incognito & IMPLICIT_ACCESS means that incognito browsing session would
// result in traces in the normal profile without the user knowing it.
if (access_type == ServiceAccessType::IMPLICIT_ACCESS &&
profile->IsOffTheRecord()) {
return nullptr;
}
return base::WrapRefCounted(static_cast<password_manager::PasswordStore*>(
GetInstance()->GetServiceForBrowserContext(profile, true).get()));
}
// static
AccountPasswordStoreFactory* AccountPasswordStoreFactory::GetInstance() {
return base::Singleton<AccountPasswordStoreFactory>::get();
}
AccountPasswordStoreFactory::AccountPasswordStoreFactory()
: RefcountedBrowserContextKeyedServiceFactory(
"AccountPasswordStore",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(WebDataServiceFactory::GetInstance());
}
AccountPasswordStoreFactory::~AccountPasswordStoreFactory() {}
scoped_refptr<RefcountedKeyedService>
AccountPasswordStoreFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
DCHECK(base::FeatureList::IsEnabled(
password_manager::features::kEnablePasswordsAccountStorage));
Profile* profile = Profile::FromBrowserContext(context);
std::unique_ptr<password_manager::LoginDatabase> login_db(
password_manager::CreateLoginDatabaseForAccountStorage(
profile->GetPath()));
scoped_refptr<PasswordStore> ps =
new password_manager::PasswordStoreDefault(std::move(login_db));
if (!ps->Init(/*flare=*/base::DoNothing(), profile->GetPrefs())) {
// TODO(crbug.com/479725): Remove the LOG once this error is visible in the
// UI.
LOG(WARNING) << "Could not initialize password store.";
return nullptr;
}
auto network_context_getter = base::BindRepeating(
[](Profile* profile) -> network::mojom::NetworkContext* {
if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return nullptr;
return content::BrowserContext::GetDefaultStoragePartition(profile)
->GetNetworkContext();
},
profile);
password_manager_util::RemoveUselessCredentials(ps, profile->GetPrefs(), 60,
network_context_getter);
return ps;
}
content::BrowserContext* AccountPasswordStoreFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
bool AccountPasswordStoreFactory::ServiceIsNULLWhileTesting() const {
return true;
}
// Copyright 2019 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_PASSWORD_MANAGER_ACCOUNT_STORAGE_ACCOUNT_PASSWORD_STORE_FACTORY_H_
#define CHROME_BROWSER_PASSWORD_MANAGER_ACCOUNT_STORAGE_ACCOUNT_PASSWORD_STORE_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/service_access_type.h"
class Profile;
namespace password_manager {
class PasswordStore;
}
// Singleton that owns all Gaia-account-scoped PasswordStores and associates
// them with Profiles.
class AccountPasswordStoreFactory
: public RefcountedBrowserContextKeyedServiceFactory {
public:
static scoped_refptr<password_manager::PasswordStore> GetForProfile(
Profile* profile,
ServiceAccessType set);
static AccountPasswordStoreFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<AccountPasswordStoreFactory>;
AccountPasswordStoreFactory();
~AccountPasswordStoreFactory() override;
// RefcountedBrowserContextKeyedServiceFactory:
scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsNULLWhileTesting() const override;
DISALLOW_COPY_AND_ASSIGN(AccountPasswordStoreFactory);
};
#endif // CHROME_BROWSER_PASSWORD_MANAGER_ACCOUNT_STORAGE_ACCOUNT_PASSWORD_STORE_FACTORY_H_
......@@ -129,7 +129,8 @@ PasswordStoreFactory::BuildServiceInstanceFor(
Profile* profile = static_cast<Profile*>(context);
std::unique_ptr<password_manager::LoginDatabase> login_db(
password_manager::CreateLoginDatabase(profile->GetPath()));
password_manager::CreateLoginDatabaseForProfileStorage(
profile->GetPath()));
#if defined(OS_MACOSX)
PrefService* local_state = g_browser_process->local_state();
DCHECK(local_state);
......
......@@ -8,8 +8,10 @@ namespace password_manager {
const base::FilePath::CharType kAffiliationDatabaseFileName[] =
FILE_PATH_LITERAL("Affiliation Database");
const base::FilePath::CharType kLoginDataFileName[] =
const base::FilePath::CharType kLoginDataForProfileFileName[] =
FILE_PATH_LITERAL("Login Data");
const base::FilePath::CharType kLoginDataForAccountFileName[] =
FILE_PATH_LITERAL("Login Data For Account");
const char kPasswordManagerAccountDashboardURL[] =
"https://passwords.google.com";
......
......@@ -10,7 +10,8 @@
namespace password_manager {
extern const base::FilePath::CharType kAffiliationDatabaseFileName[];
extern const base::FilePath::CharType kLoginDataFileName[];
extern const base::FilePath::CharType kLoginDataForProfileFileName[];
extern const base::FilePath::CharType kLoginDataForAccountFileName[];
// URL to the password manager account dashboard.
extern const char kPasswordManagerAccountDashboardURL[];
......
......@@ -85,9 +85,17 @@ void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState(
}
}
std::unique_ptr<LoginDatabase> CreateLoginDatabase(
std::unique_ptr<LoginDatabase> CreateLoginDatabaseForProfileStorage(
const base::FilePath& profile_path) {
base::FilePath login_db_file_path = profile_path.Append(kLoginDataFileName);
base::FilePath login_db_file_path =
profile_path.Append(kLoginDataForProfileFileName);
return std::make_unique<LoginDatabase>(login_db_file_path);
}
std::unique_ptr<LoginDatabase> CreateLoginDatabaseForAccountStorage(
const base::FilePath& profile_path) {
base::FilePath login_db_file_path =
profile_path.Append(kLoginDataForAccountFileName);
return std::make_unique<LoginDatabase>(login_db_file_path);
}
......
......@@ -38,7 +38,9 @@ void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState(
// Creates a LoginDatabase. Looks in |profile_path| for the database file.
// Does not call LoginDatabase::Init() -- to avoid UI jank, that needs to be
// called by PasswordStore::Init() on the background thread.
std::unique_ptr<LoginDatabase> CreateLoginDatabase(
std::unique_ptr<LoginDatabase> CreateLoginDatabaseForProfileStorage(
const base::FilePath& profile_path);
std::unique_ptr<LoginDatabase> CreateLoginDatabaseForAccountStorage(
const base::FilePath& profile_path);
} // namespace password_manager
......
......@@ -79,7 +79,8 @@ scoped_refptr<RefcountedKeyedService>
IOSChromePasswordStoreFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
std::unique_ptr<password_manager::LoginDatabase> login_db(
password_manager::CreateLoginDatabase(context->GetStatePath()));
password_manager::CreateLoginDatabaseForProfileStorage(
context->GetStatePath()));
scoped_refptr<base::SequencedTaskRunner> main_task_runner(
base::SequencedTaskRunnerHandle::Get());
......
......@@ -82,7 +82,8 @@ scoped_refptr<RefcountedKeyedService>
WebViewPasswordStoreFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
std::unique_ptr<password_manager::LoginDatabase> login_db(
password_manager::CreateLoginDatabase(context->GetStatePath()));
password_manager::CreateLoginDatabaseForProfileStorage(
context->GetStatePath()));
scoped_refptr<base::SequencedTaskRunner> main_task_runner(
base::SequencedTaskRunnerHandle::Get());
......
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