Commit 75c22c91 authored by Florian Uunk's avatar Florian Uunk Committed by Commit Bot

Create a second, account scoped autofill database

And expose it on WebDataServiceWrapper.

Bug: 854643
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I6c7f121f2004d952591ee9a3bd5178cb592d6877
Reviewed-on: https://chromium-review.googlesource.com/1086930
Commit-Queue: Florian Uunk <feuunk@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570019}
parent 9d1e56f9
...@@ -22,6 +22,7 @@ enum class ProfileErrorType { ...@@ -22,6 +22,7 @@ enum class ProfileErrorType {
CREATE_FAILURE_SPECIFIED, CREATE_FAILURE_SPECIFIED,
CREATE_FAILURE_ALL, CREATE_FAILURE_ALL,
DB_PAYMENT_MANIFEST_WEB_DATA, DB_PAYMENT_MANIFEST_WEB_DATA,
DB_ACCOUNT_AUTOFILL_WEB_DATA,
END END
}; };
......
...@@ -37,6 +37,9 @@ ProfileErrorType ProfileErrorFromWebDataServiceWrapperError( ...@@ -37,6 +37,9 @@ ProfileErrorType ProfileErrorFromWebDataServiceWrapperError(
case WebDataServiceWrapper::ERROR_LOADING_AUTOFILL: case WebDataServiceWrapper::ERROR_LOADING_AUTOFILL:
return ProfileErrorType::DB_AUTOFILL_WEB_DATA; return ProfileErrorType::DB_AUTOFILL_WEB_DATA;
case WebDataServiceWrapper::ERROR_LOADING_ACCOUNT_AUTOFILL:
return ProfileErrorType::DB_ACCOUNT_AUTOFILL_WEB_DATA;
case WebDataServiceWrapper::ERROR_LOADING_KEYWORD: case WebDataServiceWrapper::ERROR_LOADING_KEYWORD:
return ProfileErrorType::DB_KEYWORD_WEB_DATA; return ProfileErrorType::DB_KEYWORD_WEB_DATA;
...@@ -109,7 +112,19 @@ WebDataServiceFactory::GetAutofillWebDataForProfile( ...@@ -109,7 +112,19 @@ WebDataServiceFactory::GetAutofillWebDataForProfile(
WebDataServiceWrapper* wrapper = WebDataServiceWrapper* wrapper =
WebDataServiceFactory::GetForProfile(profile, access_type); WebDataServiceFactory::GetForProfile(profile, access_type);
// |wrapper| can be null in Incognito mode. // |wrapper| can be null in Incognito mode.
return wrapper ? wrapper->GetAutofillWebData() return wrapper ? wrapper->GetProfileAutofillWebData()
: scoped_refptr<autofill::AutofillWebDataService>(nullptr);
}
// static
scoped_refptr<autofill::AutofillWebDataService>
WebDataServiceFactory::GetAutofillWebDataForAccount(
Profile* profile,
ServiceAccessType access_type) {
WebDataServiceWrapper* wrapper =
WebDataServiceFactory::GetForProfile(profile, access_type);
// |wrapper| can be null in Incognito mode.
return wrapper ? wrapper->GetAccountAutofillWebData()
: scoped_refptr<autofill::AutofillWebDataService>(nullptr); : scoped_refptr<autofill::AutofillWebDataService>(nullptr);
} }
......
...@@ -49,6 +49,11 @@ class WebDataServiceFactory : public BrowserContextKeyedServiceFactory { ...@@ -49,6 +49,11 @@ class WebDataServiceFactory : public BrowserContextKeyedServiceFactory {
static scoped_refptr<autofill::AutofillWebDataService> static scoped_refptr<autofill::AutofillWebDataService>
GetAutofillWebDataForProfile(Profile* profile, ServiceAccessType access_type); GetAutofillWebDataForProfile(Profile* profile, ServiceAccessType access_type);
// Returns the account-scoped AutofillWebDataService associated with the
// |profile|.
static scoped_refptr<autofill::AutofillWebDataService>
GetAutofillWebDataForAccount(Profile* profile, ServiceAccessType access_type);
// Returns the KeywordWebDataService associated with the |profile|. // Returns the KeywordWebDataService associated with the |profile|.
static scoped_refptr<KeywordWebDataService> GetKeywordWebDataForProfile( static scoped_refptr<KeywordWebDataService> GetKeywordWebDataForProfile(
Profile* profile, Profile* profile,
......
...@@ -359,7 +359,7 @@ class ProfileSyncServiceAutofillTest ...@@ -359,7 +359,7 @@ class ProfileSyncServiceAutofillTest
new TokenWebDataServiceFake(base::ThreadTaskRunnerHandle::Get(), new TokenWebDataServiceFake(base::ThreadTaskRunnerHandle::Get(),
data_type_thread()->task_runner())); data_type_thread()->task_runner()));
web_data_service_ = static_cast<WebDataServiceFake*>( web_data_service_ = static_cast<WebDataServiceFake*>(
web_data_wrapper_->GetAutofillWebData().get()); web_data_wrapper_->GetProfileAutofillWebData().get());
web_data_service_->SetDatabase(web_database_.get()); web_data_service_->SetDatabase(web_database_.get());
personal_data_manager_ = std::make_unique<MockPersonalDataManager>(); personal_data_manager_ = std::make_unique<MockPersonalDataManager>();
......
...@@ -17,6 +17,9 @@ const int WebDatabase::kCurrentVersionNumber = 78; ...@@ -17,6 +17,9 @@ const int WebDatabase::kCurrentVersionNumber = 78;
const int WebDatabase::kDeprecatedVersionNumber = 51; const int WebDatabase::kDeprecatedVersionNumber = 51;
const base::FilePath::CharType WebDatabase::kInMemoryPath[] =
FILE_PATH_LITERAL(":memory");
namespace { namespace {
const int kCompatibleVersionNumber = 78; const int kCompatibleVersionNumber = 78;
...@@ -89,8 +92,10 @@ sql::InitStatus WebDatabase::Init(const base::FilePath& db_name) { ...@@ -89,8 +92,10 @@ sql::InitStatus WebDatabase::Init(const base::FilePath& db_name) {
// database while we're running, and this will give somewhat improved perf. // database while we're running, and this will give somewhat improved perf.
db_.set_exclusive_locking(); db_.set_exclusive_locking();
if (!db_.Open(db_name)) if ((db_name.value() == kInMemoryPath) ? !db_.OpenInMemory()
: !db_.Open(db_name)) {
return sql::INIT_FAILURE; return sql::INIT_FAILURE;
}
// Clobber really old databases. // Clobber really old databases.
static_assert(kDeprecatedVersionNumber < kCurrentVersionNumber, static_assert(kDeprecatedVersionNumber < kCurrentVersionNumber,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/webdata/common/web_database_table.h" #include "components/webdata/common/web_database_table.h"
#include "components/webdata/common/webdata_export.h" #include "components/webdata/common/webdata_export.h"
...@@ -15,10 +16,6 @@ ...@@ -15,10 +16,6 @@
#include "sql/init_status.h" #include "sql/init_status.h"
#include "sql/meta_table.h" #include "sql/meta_table.h"
namespace base {
class FilePath;
}
// This class manages a SQLite database that stores various web page meta data. // This class manages a SQLite database that stores various web page meta data.
class WEBDATA_EXPORT WebDatabase { class WEBDATA_EXPORT WebDatabase {
public: public:
...@@ -30,6 +27,8 @@ class WEBDATA_EXPORT WebDatabase { ...@@ -30,6 +27,8 @@ class WEBDATA_EXPORT WebDatabase {
static const int kCurrentVersionNumber; static const int kCurrentVersionNumber;
// The newest version of the database Chrome will NOT try to migrate. // The newest version of the database Chrome will NOT try to migrate.
static const int kDeprecatedVersionNumber; static const int kDeprecatedVersionNumber;
// Use this as a path to create an in-memory database.
static const base::FilePath::CharType kInMemoryPath[];
WebDatabase(); WebDatabase();
virtual ~WebDatabase(); virtual ~WebDatabase();
......
...@@ -30,10 +30,16 @@ MockWebDataServiceWrapper::~MockWebDataServiceWrapper() { ...@@ -30,10 +30,16 @@ MockWebDataServiceWrapper::~MockWebDataServiceWrapper() {
} }
scoped_refptr<AutofillWebDataService> scoped_refptr<AutofillWebDataService>
MockWebDataServiceWrapper::GetAutofillWebData() { MockWebDataServiceWrapper::GetProfileAutofillWebData() {
return fake_autofill_web_data_; return fake_autofill_web_data_;
} }
scoped_refptr<AutofillWebDataService>
MockWebDataServiceWrapper::GetAccountAutofillWebData() {
// TODO(feuunk): Implement when there are tests covering account data.
return nullptr;
}
scoped_refptr<TokenWebData> MockWebDataServiceWrapper::GetTokenWebData() { scoped_refptr<TokenWebData> MockWebDataServiceWrapper::GetTokenWebData() {
return fake_token_web_data_; return fake_token_web_data_;
} }
...@@ -32,7 +32,11 @@ class MockWebDataServiceWrapper : public MockWebDataServiceWrapperBase { ...@@ -32,7 +32,11 @@ class MockWebDataServiceWrapper : public MockWebDataServiceWrapperBase {
~MockWebDataServiceWrapper() override; ~MockWebDataServiceWrapper() override;
scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData() override; scoped_refptr<autofill::AutofillWebDataService> GetProfileAutofillWebData()
override;
scoped_refptr<autofill::AutofillWebDataService> GetAccountAutofillWebData()
override;
scoped_refptr<TokenWebData> GetTokenWebData() override; scoped_refptr<TokenWebData> GetTokenWebData() override;
......
...@@ -87,63 +87,76 @@ WebDataServiceWrapper::WebDataServiceWrapper( ...@@ -87,63 +87,76 @@ WebDataServiceWrapper::WebDataServiceWrapper(
auto db_task_runner = base::CreateSingleThreadTaskRunnerWithTraits( auto db_task_runner = base::CreateSingleThreadTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
web_database_ = new WebDatabaseService(path, ui_task_runner, db_task_runner); profile_database_ =
new WebDatabaseService(path, ui_task_runner, db_task_runner);
// All tables objects that participate in managing the database must // All tables objects that participate in managing the database must
// be added here. // be added here.
web_database_->AddTable(std::make_unique<autofill::AutofillTable>()); profile_database_->AddTable(std::make_unique<autofill::AutofillTable>());
web_database_->AddTable(std::make_unique<KeywordTable>()); profile_database_->AddTable(std::make_unique<KeywordTable>());
// TODO(mdm): We only really need the LoginsTable on Windows for IE7 password // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
// access, but for now, we still create it on all platforms since it deletes // access, but for now, we still create it on all platforms since it deletes
// the old logins table. We can remove this after a while, e.g. in M22 or so. // the old logins table. We can remove this after a while, e.g. in M22 or so.
web_database_->AddTable(std::make_unique<LoginsTable>()); profile_database_->AddTable(std::make_unique<LoginsTable>());
web_database_->AddTable(std::make_unique<TokenServiceTable>()); profile_database_->AddTable(std::make_unique<TokenServiceTable>());
#if !defined(OS_IOS) #if !defined(OS_IOS)
web_database_->AddTable( profile_database_->AddTable(
std::make_unique<payments::PaymentMethodManifestTable>()); std::make_unique<payments::PaymentMethodManifestTable>());
web_database_->AddTable( profile_database_->AddTable(
std::make_unique<payments::WebAppManifestSectionTable>()); std::make_unique<payments::WebAppManifestSectionTable>());
#endif #endif
web_database_->LoadDatabase(); profile_database_->LoadDatabase();
autofill_web_data_ = new autofill::AutofillWebDataService( profile_autofill_web_data_ = new autofill::AutofillWebDataService(
web_database_, ui_task_runner, db_task_runner, profile_database_, ui_task_runner, db_task_runner,
base::Bind(show_error_callback, ERROR_LOADING_AUTOFILL)); base::Bind(show_error_callback, ERROR_LOADING_AUTOFILL));
autofill_web_data_->Init(); profile_autofill_web_data_->Init();
keyword_web_data_ = new KeywordWebDataService( keyword_web_data_ = new KeywordWebDataService(
web_database_, ui_task_runner, profile_database_, ui_task_runner,
base::Bind(show_error_callback, ERROR_LOADING_KEYWORD)); base::Bind(show_error_callback, ERROR_LOADING_KEYWORD));
keyword_web_data_->Init(); keyword_web_data_->Init();
token_web_data_ = token_web_data_ =
new TokenWebData(web_database_, ui_task_runner, db_task_runner, new TokenWebData(profile_database_, ui_task_runner, db_task_runner,
base::Bind(show_error_callback, ERROR_LOADING_TOKEN)); base::Bind(show_error_callback, ERROR_LOADING_TOKEN));
token_web_data_->Init(); token_web_data_->Init();
#if defined(OS_WIN) #if defined(OS_WIN)
password_web_data_ = new PasswordWebDataService( password_web_data_ = new PasswordWebDataService(
web_database_, ui_task_runner, profile_database_, ui_task_runner,
base::Bind(show_error_callback, ERROR_LOADING_PASSWORD)); base::Bind(show_error_callback, ERROR_LOADING_PASSWORD));
password_web_data_->Init(); password_web_data_->Init();
#endif #endif
#if !defined(OS_IOS) #if !defined(OS_IOS)
payment_manifest_web_data_ = new payments::PaymentManifestWebDataService( payment_manifest_web_data_ = new payments::PaymentManifestWebDataService(
web_database_, profile_database_,
base::Bind(show_error_callback, ERROR_LOADING_PAYMENT_MANIFEST), base::Bind(show_error_callback, ERROR_LOADING_PAYMENT_MANIFEST),
ui_task_runner); ui_task_runner);
#endif #endif
autofill_web_data_->GetAutofillBackend( profile_autofill_web_data_->GetAutofillBackend(
base::Bind(&InitSyncableServicesOnDBSequence, db_task_runner, flare, base::Bind(&InitSyncableServicesOnDBSequence, db_task_runner, flare,
autofill_web_data_, context_path, application_locale)); profile_autofill_web_data_, context_path, application_locale));
account_database_ =
new WebDatabaseService(base::FilePath(WebDatabase::kInMemoryPath),
ui_task_runner, db_task_runner);
account_database_->AddTable(std::make_unique<autofill::AutofillTable>());
account_database_->LoadDatabase();
account_autofill_web_data_ = new autofill::AutofillWebDataService(
account_database_, ui_task_runner, db_task_runner,
base::Bind(show_error_callback, ERROR_LOADING_ACCOUNT_AUTOFILL));
account_autofill_web_data_->Init();
} }
WebDataServiceWrapper::~WebDataServiceWrapper() {} WebDataServiceWrapper::~WebDataServiceWrapper() {}
void WebDataServiceWrapper::Shutdown() { void WebDataServiceWrapper::Shutdown() {
autofill_web_data_->ShutdownOnUISequence(); profile_autofill_web_data_->ShutdownOnUISequence();
account_autofill_web_data_->ShutdownOnUISequence();
keyword_web_data_->ShutdownOnUISequence(); keyword_web_data_->ShutdownOnUISequence();
token_web_data_->ShutdownOnUISequence(); token_web_data_->ShutdownOnUISequence();
...@@ -155,12 +168,18 @@ void WebDataServiceWrapper::Shutdown() { ...@@ -155,12 +168,18 @@ void WebDataServiceWrapper::Shutdown() {
payment_manifest_web_data_->ShutdownOnUISequence(); payment_manifest_web_data_->ShutdownOnUISequence();
#endif #endif
web_database_->ShutdownDatabase(); profile_database_->ShutdownDatabase();
account_database_->ShutdownDatabase();
} }
scoped_refptr<autofill::AutofillWebDataService> scoped_refptr<autofill::AutofillWebDataService>
WebDataServiceWrapper::GetAutofillWebData() { WebDataServiceWrapper::GetProfileAutofillWebData() {
return autofill_web_data_.get(); return profile_autofill_web_data_.get();
}
scoped_refptr<autofill::AutofillWebDataService>
WebDataServiceWrapper::GetAccountAutofillWebData() {
return account_autofill_web_data_.get();
} }
scoped_refptr<KeywordWebDataService> scoped_refptr<KeywordWebDataService>
......
...@@ -45,6 +45,7 @@ class WebDataServiceWrapper : public KeyedService { ...@@ -45,6 +45,7 @@ class WebDataServiceWrapper : public KeyedService {
// ErrorType indicates which service encountered an error loading its data. // ErrorType indicates which service encountered an error loading its data.
enum ErrorType { enum ErrorType {
ERROR_LOADING_AUTOFILL, ERROR_LOADING_AUTOFILL,
ERROR_LOADING_ACCOUNT_AUTOFILL,
ERROR_LOADING_KEYWORD, ERROR_LOADING_KEYWORD,
ERROR_LOADING_TOKEN, ERROR_LOADING_TOKEN,
ERROR_LOADING_PASSWORD, ERROR_LOADING_PASSWORD,
...@@ -73,6 +74,7 @@ class WebDataServiceWrapper : public KeyedService { ...@@ -73,6 +74,7 @@ class WebDataServiceWrapper : public KeyedService {
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const syncer::SyncableService::StartSyncFlare& flare, const syncer::SyncableService::StartSyncFlare& flare,
const ShowErrorCallback& show_error_callback); const ShowErrorCallback& show_error_callback);
~WebDataServiceWrapper() override; ~WebDataServiceWrapper() override;
// KeyedService: // KeyedService:
...@@ -80,7 +82,10 @@ class WebDataServiceWrapper : public KeyedService { ...@@ -80,7 +82,10 @@ class WebDataServiceWrapper : public KeyedService {
// Create the various types of service instances. These methods are virtual // Create the various types of service instances. These methods are virtual
// for testing purpose. // for testing purpose.
virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData(); virtual scoped_refptr<autofill::AutofillWebDataService>
GetProfileAutofillWebData();
virtual scoped_refptr<autofill::AutofillWebDataService>
GetAccountAutofillWebData();
virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData(); virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData();
virtual scoped_refptr<TokenWebData> GetTokenWebData(); virtual scoped_refptr<TokenWebData> GetTokenWebData();
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -96,9 +101,11 @@ class WebDataServiceWrapper : public KeyedService { ...@@ -96,9 +101,11 @@ class WebDataServiceWrapper : public KeyedService {
WebDataServiceWrapper(); WebDataServiceWrapper();
private: private:
scoped_refptr<WebDatabaseService> web_database_; scoped_refptr<WebDatabaseService> profile_database_;
scoped_refptr<WebDatabaseService> account_database_;
scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_; scoped_refptr<autofill::AutofillWebDataService> profile_autofill_web_data_;
scoped_refptr<autofill::AutofillWebDataService> account_autofill_web_data_;
scoped_refptr<KeywordWebDataService> keyword_web_data_; scoped_refptr<KeywordWebDataService> keyword_web_data_;
scoped_refptr<TokenWebData> token_web_data_; scoped_refptr<TokenWebData> token_web_data_;
......
...@@ -49,7 +49,7 @@ WebDataServiceFactory::GetAutofillWebDataForBrowserState( ...@@ -49,7 +49,7 @@ WebDataServiceFactory::GetAutofillWebDataForBrowserState(
ServiceAccessType access_type) { ServiceAccessType access_type) {
WebDataServiceWrapper* wrapper = WebDataServiceWrapper* wrapper =
GetForBrowserState(browser_state, access_type); GetForBrowserState(browser_state, access_type);
return wrapper ? wrapper->GetAutofillWebData() : nullptr; return wrapper ? wrapper->GetProfileAutofillWebData() : nullptr;
} }
// static // static
......
...@@ -38,7 +38,7 @@ WebViewWebDataServiceWrapperFactory::GetAutofillWebDataForBrowserState( ...@@ -38,7 +38,7 @@ WebViewWebDataServiceWrapperFactory::GetAutofillWebDataForBrowserState(
ServiceAccessType access_type) { ServiceAccessType access_type) {
WebDataServiceWrapper* wrapper = WebDataServiceWrapper* wrapper =
GetForBrowserState(browser_state, access_type); GetForBrowserState(browser_state, access_type);
return wrapper ? wrapper->GetAutofillWebData() : nullptr; return wrapper ? wrapper->GetProfileAutofillWebData() : nullptr;
} }
// static // static
......
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