Commit c6c35131 authored by Jared Saul's avatar Jared Saul Committed by Commit Bot

[Autofill] Create a singleton instance of Autofill StrikeDatabase

Bug: 884817
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Ifdf444eab32052a9b84d17a9b21ccf14edb78e52
Reviewed-on: https://chromium-review.googlesource.com/c/1255723Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Jared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#597289}
parent b06e9201
...@@ -76,6 +76,10 @@ identity::IdentityManager* AwAutofillClient::GetIdentityManager() { ...@@ -76,6 +76,10 @@ identity::IdentityManager* AwAutofillClient::GetIdentityManager() {
return nullptr; return nullptr;
} }
autofill::StrikeDatabase* AwAutofillClient::GetStrikeDatabase() {
return nullptr;
}
ukm::UkmRecorder* AwAutofillClient::GetUkmRecorder() { ukm::UkmRecorder* AwAutofillClient::GetUkmRecorder() {
return nullptr; return nullptr;
} }
......
...@@ -23,6 +23,7 @@ class CreditCard; ...@@ -23,6 +23,7 @@ class CreditCard;
class FormStructure; class FormStructure;
class MigratableCreditCard; class MigratableCreditCard;
class PersonalDataManager; class PersonalDataManager;
class StrikeDatabase;
} }
namespace content { namespace content {
...@@ -63,6 +64,7 @@ class AwAutofillClient : public autofill::AutofillClient, ...@@ -63,6 +64,7 @@ class AwAutofillClient : public autofill::AutofillClient,
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
syncer::SyncService* GetSyncService() override; syncer::SyncService* GetSyncService() override;
identity::IdentityManager* GetIdentityManager() override; identity::IdentityManager* GetIdentityManager() override;
autofill::StrikeDatabase* GetStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override; ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override; ukm::SourceId GetUkmSourceId() override;
autofill::AddressNormalizer* GetAddressNormalizer() override; autofill::AddressNormalizer* GetAddressNormalizer() override;
......
...@@ -116,6 +116,8 @@ jumbo_split_static_library("browser") { ...@@ -116,6 +116,8 @@ jumbo_split_static_library("browser") {
"autofill/personal_data_manager_factory.h", "autofill/personal_data_manager_factory.h",
"autofill/risk_util.cc", "autofill/risk_util.cc",
"autofill/risk_util.h", "autofill/risk_util.h",
"autofill/strike_database_factory.cc",
"autofill/strike_database_factory.h",
"autofill/validation_rules_storage_factory.cc", "autofill/validation_rules_storage_factory.cc",
"autofill/validation_rules_storage_factory.h", "autofill/validation_rules_storage_factory.h",
"background_fetch/background_fetch_delegate_factory.cc", "background_fetch/background_fetch_delegate_factory.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 "chrome/browser/autofill/strike_database_factory.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/autofill/core/browser/strike_database.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace autofill {
// static
StrikeDatabase* StrikeDatabaseFactory::GetForProfile(Profile* profile) {
return static_cast<StrikeDatabase*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
StrikeDatabaseFactory* StrikeDatabaseFactory::GetInstance() {
return base::Singleton<StrikeDatabaseFactory>::get();
}
StrikeDatabaseFactory::StrikeDatabaseFactory()
: BrowserContextKeyedServiceFactory(
"AutofillStrikeDatabase",
BrowserContextDependencyManager::GetInstance()) {}
StrikeDatabaseFactory::~StrikeDatabaseFactory() {}
KeyedService* StrikeDatabaseFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
// Note: This instance becomes owned by an object that never gets destroyed,
// effectively leaking it until browser close. Only one is created per
// profile, and closing-then-opening a profile returns the same instance.
return new StrikeDatabase(
profile->GetPath().Append(FILE_PATH_LITERAL("AutofillStrikeDatabase")));
}
content::BrowserContext* StrikeDatabaseFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
} // namespace autofill
// 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 CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
#define CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
#include "base/compiler_specific.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
}
class Profile;
namespace autofill {
class StrikeDatabase;
// Singleton that owns all StrikeDatabases and associates them with Profiles.
class StrikeDatabaseFactory : public BrowserContextKeyedServiceFactory {
public:
// Returns the StrikeDatabase for |profile|, creating it if it is not yet
// created.
static StrikeDatabase* GetForProfile(Profile* profile);
static StrikeDatabaseFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<StrikeDatabaseFactory>;
StrikeDatabaseFactory();
~StrikeDatabaseFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(StrikeDatabaseFactory);
};
} // namespace autofill
#endif // CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/autofill/address_normalizer_factory.h" #include "chrome/browser/autofill/address_normalizer_factory.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/autofill/risk_util.h" #include "chrome/browser/autofill/risk_util.h"
#include "chrome/browser/autofill/strike_database_factory.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h" #include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -138,6 +139,18 @@ identity::IdentityManager* ChromeAutofillClient::GetIdentityManager() { ...@@ -138,6 +139,18 @@ identity::IdentityManager* ChromeAutofillClient::GetIdentityManager() {
return IdentityManagerFactory::GetForProfile(profile->GetOriginalProfile()); return IdentityManagerFactory::GetForProfile(profile->GetOriginalProfile());
} }
StrikeDatabase* ChromeAutofillClient::GetStrikeDatabase() {
Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
// No need to return a StrikeDatabase in incognito mode. It is primarily used
// to determine whether or not to offer save of Autofill data. However, we
// don't allow saving of Autofill data while in incognito anyway, so an
// incognito code path should never get far enough to query StrikeDatabase.
return profile->IsOffTheRecord()
? nullptr
: StrikeDatabaseFactory::GetForProfile(profile);
}
ukm::UkmRecorder* ChromeAutofillClient::GetUkmRecorder() { ukm::UkmRecorder* ChromeAutofillClient::GetUkmRecorder() {
return ukm::UkmRecorder::Get(); return ukm::UkmRecorder::Get();
} }
......
...@@ -54,6 +54,7 @@ class ChromeAutofillClient ...@@ -54,6 +54,7 @@ class ChromeAutofillClient
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
syncer::SyncService* GetSyncService() override; syncer::SyncService* GetSyncService() override;
identity::IdentityManager* GetIdentityManager() override; identity::IdentityManager* GetIdentityManager() override;
StrikeDatabase* GetStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override; ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override; ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override; AddressNormalizer* GetAddressNormalizer() override;
......
...@@ -53,6 +53,7 @@ class CreditCard; ...@@ -53,6 +53,7 @@ class CreditCard;
class FormStructure; class FormStructure;
class MigratableCreditCard; class MigratableCreditCard;
class PersonalDataManager; class PersonalDataManager;
class StrikeDatabase;
struct Suggestion; struct Suggestion;
// A client interface that needs to be supplied to the Autofill component by the // A client interface that needs to be supplied to the Autofill component by the
...@@ -113,6 +114,9 @@ class AutofillClient : public RiskDataLoader { ...@@ -113,6 +114,9 @@ class AutofillClient : public RiskDataLoader {
// Gets the IdentityManager associated with the client. // Gets the IdentityManager associated with the client.
virtual identity::IdentityManager* GetIdentityManager() = 0; virtual identity::IdentityManager* GetIdentityManager() = 0;
// Gets the StrikeDatabase associated with the client.
virtual StrikeDatabase* GetStrikeDatabase() = 0;
// Gets the UKM service associated with this client (for metrics). // Gets the UKM service associated with this client (for metrics).
virtual ukm::UkmRecorder* GetUkmRecorder() = 0; virtual ukm::UkmRecorder* GetUkmRecorder() = 0;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/leveldb_proto/proto_database.h" #include "components/leveldb_proto/proto_database.h"
namespace autofill { namespace autofill {
...@@ -19,7 +20,7 @@ class StrikeData; ...@@ -19,7 +20,7 @@ class StrikeData;
// the user. Projects can earn strikes in a number of ways; for instance, if a // the user. Projects can earn strikes in a number of ways; for instance, if a
// user ignores or declines a prompt, or if a user accepts a prompt but the task // user ignores or declines a prompt, or if a user accepts a prompt but the task
// fails. // fails.
class StrikeDatabase { class StrikeDatabase : public KeyedService {
public: public:
using ClearStrikesCallback = base::RepeatingCallback<void(bool success)>; using ClearStrikesCallback = base::RepeatingCallback<void(bool success)>;
...@@ -34,7 +35,7 @@ class StrikeDatabase { ...@@ -34,7 +35,7 @@ class StrikeDatabase {
using StrikeDataProto = leveldb_proto::ProtoDatabase<StrikeData>; using StrikeDataProto = leveldb_proto::ProtoDatabase<StrikeData>;
explicit StrikeDatabase(const base::FilePath& database_dir); explicit StrikeDatabase(const base::FilePath& database_dir);
~StrikeDatabase(); ~StrikeDatabase() override;
// Passes the number of strikes for |key| to |outer_callback|. In the case // Passes the number of strikes for |key| to |outer_callback|. In the case
// that the database fails to retrieve the strike update or if no entry is // that the database fails to retrieve the strike update or if no entry is
......
...@@ -36,6 +36,10 @@ identity::IdentityManager* TestAutofillClient::GetIdentityManager() { ...@@ -36,6 +36,10 @@ identity::IdentityManager* TestAutofillClient::GetIdentityManager() {
return identity_test_env_.identity_manager(); return identity_test_env_.identity_manager();
} }
StrikeDatabase* TestAutofillClient::GetStrikeDatabase() {
return nullptr;
}
ukm::UkmRecorder* TestAutofillClient::GetUkmRecorder() { ukm::UkmRecorder* TestAutofillClient::GetUkmRecorder() {
return ukm::UkmRecorder::Get(); return ukm::UkmRecorder::Get();
} }
......
...@@ -33,6 +33,7 @@ class TestAutofillClient : public AutofillClient { ...@@ -33,6 +33,7 @@ class TestAutofillClient : public AutofillClient {
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
syncer::SyncService* GetSyncService() override; syncer::SyncService* GetSyncService() override;
identity::IdentityManager* GetIdentityManager() override; identity::IdentityManager* GetIdentityManager() override;
StrikeDatabase* GetStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override; ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override; ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override; AddressNormalizer* GetAddressNormalizer() override;
......
...@@ -26,6 +26,8 @@ source_set("autofill") { ...@@ -26,6 +26,8 @@ source_set("autofill") {
"form_suggestion_view_client.h", "form_suggestion_view_client.h",
"personal_data_manager_factory.cc", "personal_data_manager_factory.cc",
"personal_data_manager_factory.h", "personal_data_manager_factory.h",
"strike_database_factory.cc",
"strike_database_factory.h",
"validation_rules_storage_factory.cc", "validation_rules_storage_factory.cc",
"validation_rules_storage_factory.h", "validation_rules_storage_factory.h",
] ]
...@@ -67,6 +69,7 @@ source_set("autofill") { ...@@ -67,6 +69,7 @@ source_set("autofill") {
"//ios/chrome/browser/ui/autofill/manual_fill:manual_fill_ui", "//ios/chrome/browser/ui/autofill/manual_fill:manual_fill_ui",
"//ios/chrome/browser/ui/image_util", "//ios/chrome/browser/ui/image_util",
"//ios/web", "//ios/web",
"//third_party/leveldatabase",
"//third_party/libaddressinput", "//third_party/libaddressinput",
"//ui/base", "//ui/base",
"//url", "//url",
...@@ -116,6 +119,7 @@ source_set("autofill_internal") { ...@@ -116,6 +119,7 @@ source_set("autofill_internal") {
"//ios/chrome/browser/signin", "//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/autofill", "//ios/chrome/browser/ui/autofill",
"//ios/web", "//ios/web",
"//third_party/leveldatabase",
"//ui/gfx/geometry", "//ui/gfx/geometry",
"//url", "//url",
] ]
...@@ -162,6 +166,7 @@ source_set("unit_tests") { ...@@ -162,6 +166,7 @@ source_set("unit_tests") {
"//ios/web", "//ios/web",
"//ios/web/public/test", "//ios/web/public/test",
"//testing/gtest", "//testing/gtest",
"//third_party/leveldatabase",
"//third_party/ocmock", "//third_party/ocmock",
"//ui/base:test_support", "//ui/base:test_support",
] ]
......
// 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 "ios/chrome/browser/autofill/strike_database_factory.h"
#include <utility>
#include "base/memory/singleton.h"
#include "components/autofill/core/browser/strike_database.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
namespace autofill {
// static
StrikeDatabase* StrikeDatabaseFactory::GetForBrowserState(
ios::ChromeBrowserState* browser_state) {
return static_cast<StrikeDatabase*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
StrikeDatabaseFactory* StrikeDatabaseFactory::GetInstance() {
return base::Singleton<StrikeDatabaseFactory>::get();
}
StrikeDatabaseFactory::StrikeDatabaseFactory()
: BrowserStateKeyedServiceFactory(
"AutofillStrikeDatabase",
BrowserStateDependencyManager::GetInstance()) {}
StrikeDatabaseFactory::~StrikeDatabaseFactory() {}
std::unique_ptr<KeyedService> StrikeDatabaseFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
ios::ChromeBrowserState* chrome_browser_state =
ios::ChromeBrowserState::FromBrowserState(context);
return std::make_unique<autofill::StrikeDatabase>(
chrome_browser_state->GetStatePath().Append(
FILE_PATH_LITERAL("AutofillStrikeDatabase")));
}
} // namespace autofill
// 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 IOS_CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
#define IOS_CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
namespace ios {
class ChromeBrowserState;
}
namespace autofill {
class StrikeDatabase;
// Singleton that owns all StrikeDatabases and associates them with
// ios::ChromeBrowserState.
class StrikeDatabaseFactory : public BrowserStateKeyedServiceFactory {
public:
static StrikeDatabase* GetForBrowserState(
ios::ChromeBrowserState* browser_state);
static StrikeDatabaseFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<StrikeDatabaseFactory>;
StrikeDatabaseFactory();
~StrikeDatabaseFactory() override;
// BrowserStateKeyedServiceFactory implementation.
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* context) const override;
DISALLOW_COPY_AND_ASSIGN(StrikeDatabaseFactory);
};
} // namespace autofill
#endif // IOS_CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
...@@ -26,6 +26,7 @@ source_set("autofill") { ...@@ -26,6 +26,7 @@ source_set("autofill") {
"//components/browser_sync", "//components/browser_sync",
"//components/infobars/core", "//components/infobars/core",
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/leveldb_proto",
"//components/password_manager/core/browser", "//components/password_manager/core/browser",
"//components/prefs", "//components/prefs",
"//components/strings", "//components/strings",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/autofill/core/browser/autofill_client.h" #include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/card_unmask_delegate.h" #include "components/autofill/core/browser/card_unmask_delegate.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl.h" #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#import "components/autofill/ios/browser/autofill_client_ios_bridge.h" #import "components/autofill/ios/browser/autofill_client_ios_bridge.h"
...@@ -47,6 +48,7 @@ class ChromeAutofillClientIOS : public AutofillClient { ...@@ -47,6 +48,7 @@ class ChromeAutofillClientIOS : public AutofillClient {
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
syncer::SyncService* GetSyncService() override; syncer::SyncService* GetSyncService() override;
identity::IdentityManager* GetIdentityManager() override; identity::IdentityManager* GetIdentityManager() override;
StrikeDatabase* GetStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override; ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override; ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override; AddressNormalizer* GetAddressNormalizer() override;
...@@ -108,6 +110,7 @@ class ChromeAutofillClientIOS : public AutofillClient { ...@@ -108,6 +110,7 @@ class ChromeAutofillClientIOS : public AutofillClient {
web::WebState* web_state_; web::WebState* web_state_;
__weak id<AutofillClientIOSBridge> bridge_; __weak id<AutofillClientIOSBridge> bridge_;
identity::IdentityManager* identity_manager_; identity::IdentityManager* identity_manager_;
StrikeDatabase* strike_database_;
scoped_refptr<AutofillWebDataService> autofill_web_data_service_; scoped_refptr<AutofillWebDataService> autofill_web_data_service_;
infobars::InfoBarManager* infobar_manager_; infobars::InfoBarManager* infobar_manager_;
password_manager::PasswordGenerationManager* password_generation_manager_; password_manager::PasswordGenerationManager* password_generation_manager_;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/autofill/address_normalizer_factory.h" #include "ios/chrome/browser/autofill/address_normalizer_factory.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h" #include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#include "ios/chrome/browser/autofill/strike_database_factory.h"
#include "ios/chrome/browser/infobars/infobar.h" #include "ios/chrome/browser/infobars/infobar.h"
#include "ios/chrome/browser/infobars/infobar_utils.h" #include "ios/chrome/browser/infobars/infobar_utils.h"
#include "ios/chrome/browser/metrics/ukm_url_recorder.h" #include "ios/chrome/browser/metrics/ukm_url_recorder.h"
...@@ -67,6 +68,8 @@ ChromeAutofillClientIOS::ChromeAutofillClientIOS( ...@@ -67,6 +68,8 @@ ChromeAutofillClientIOS::ChromeAutofillClientIOS(
bridge_(bridge), bridge_(bridge),
identity_manager_(IdentityManagerFactory::GetForBrowserState( identity_manager_(IdentityManagerFactory::GetForBrowserState(
browser_state->GetOriginalChromeBrowserState())), browser_state->GetOriginalChromeBrowserState())),
strike_database_(StrikeDatabaseFactory::GetForBrowserState(
browser_state->GetOriginalChromeBrowserState())),
autofill_web_data_service_( autofill_web_data_service_(
ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState( ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState(
browser_state, browser_state,
...@@ -101,6 +104,10 @@ identity::IdentityManager* ChromeAutofillClientIOS::GetIdentityManager() { ...@@ -101,6 +104,10 @@ identity::IdentityManager* ChromeAutofillClientIOS::GetIdentityManager() {
return identity_manager_; return identity_manager_;
} }
StrikeDatabase* ChromeAutofillClientIOS::GetStrikeDatabase() {
return strike_database_;
}
ukm::UkmRecorder* ChromeAutofillClientIOS::GetUkmRecorder() { ukm::UkmRecorder* ChromeAutofillClientIOS::GetUkmRecorder() {
return GetApplicationContext()->GetUkmRecorder(); return GetApplicationContext()->GetUkmRecorder();
} }
......
...@@ -99,6 +99,8 @@ ios_web_view_sources = [ ...@@ -99,6 +99,8 @@ ios_web_view_sources = [
"internal/autofill/web_view_autofill_client_ios.mm", "internal/autofill/web_view_autofill_client_ios.mm",
"internal/autofill/web_view_personal_data_manager_factory.cc", "internal/autofill/web_view_personal_data_manager_factory.cc",
"internal/autofill/web_view_personal_data_manager_factory.h", "internal/autofill/web_view_personal_data_manager_factory.h",
"internal/autofill/web_view_strike_database_factory.cc",
"internal/autofill/web_view_strike_database_factory.h",
"internal/content_settings/web_view_cookie_settings_factory.cc", "internal/content_settings/web_view_cookie_settings_factory.cc",
"internal/content_settings/web_view_cookie_settings_factory.h", "internal/content_settings/web_view_cookie_settings_factory.h",
"internal/content_settings/web_view_host_content_settings_map_factory.cc", "internal/content_settings/web_view_host_content_settings_map_factory.cc",
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#import "ios/web_view/internal/autofill/cwv_credit_card_verifier_internal.h" #import "ios/web_view/internal/autofill/cwv_credit_card_verifier_internal.h"
#import "ios/web_view/internal/autofill/web_view_autofill_client_ios.h" #import "ios/web_view/internal/autofill/web_view_autofill_client_ios.h"
#include "ios/web_view/internal/autofill/web_view_personal_data_manager_factory.h" #include "ios/web_view/internal/autofill/web_view_personal_data_manager_factory.h"
#include "ios/web_view/internal/autofill/web_view_strike_database_factory.h"
#import "ios/web_view/internal/passwords/cwv_password_controller.h" #import "ios/web_view/internal/passwords/cwv_password_controller.h"
#include "ios/web_view/internal/signin/web_view_identity_manager_factory.h" #include "ios/web_view/internal/signin/web_view_identity_manager_factory.h"
#import "ios/web_view/internal/sync/web_view_profile_sync_service_factory.h" #import "ios/web_view/internal/sync/web_view_profile_sync_service_factory.h"
...@@ -108,6 +109,8 @@ ...@@ -108,6 +109,8 @@
_webState, self, _webState, self,
ios_web_view::WebViewIdentityManagerFactory::GetForBrowserState( ios_web_view::WebViewIdentityManagerFactory::GetForBrowserState(
browserState->GetRecordingBrowserState()), browserState->GetRecordingBrowserState()),
ios_web_view::WebViewStrikeDatabaseFactory::GetForBrowserState(
browserState->GetRecordingBrowserState()),
ios_web_view::WebViewWebDataServiceWrapperFactory:: ios_web_view::WebViewWebDataServiceWrapperFactory::
GetAutofillWebDataForBrowserState( GetAutofillWebDataForBrowserState(
browserState, ServiceAccessType::EXPLICIT_ACCESS), browserState, ServiceAccessType::EXPLICIT_ACCESS),
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/autofill/core/browser/autofill_client.h" #include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/card_unmask_delegate.h" #include "components/autofill/core/browser/card_unmask_delegate.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
...@@ -31,6 +32,7 @@ class WebViewAutofillClientIOS : public AutofillClient { ...@@ -31,6 +32,7 @@ class WebViewAutofillClientIOS : public AutofillClient {
web::WebState* web_state, web::WebState* web_state,
id<CWVAutofillClientIOSBridge> bridge, id<CWVAutofillClientIOSBridge> bridge,
identity::IdentityManager* identity_manager, identity::IdentityManager* identity_manager,
StrikeDatabase* strike_database,
scoped_refptr<AutofillWebDataService> autofill_web_data_service, scoped_refptr<AutofillWebDataService> autofill_web_data_service,
syncer::SyncService* sync_service); syncer::SyncService* sync_service);
~WebViewAutofillClientIOS() override; ~WebViewAutofillClientIOS() override;
...@@ -40,6 +42,7 @@ class WebViewAutofillClientIOS : public AutofillClient { ...@@ -40,6 +42,7 @@ class WebViewAutofillClientIOS : public AutofillClient {
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
syncer::SyncService* GetSyncService() override; syncer::SyncService* GetSyncService() override;
identity::IdentityManager* GetIdentityManager() override; identity::IdentityManager* GetIdentityManager() override;
StrikeDatabase* GetStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override; ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override; ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override; AddressNormalizer* GetAddressNormalizer() override;
...@@ -100,6 +103,7 @@ class WebViewAutofillClientIOS : public AutofillClient { ...@@ -100,6 +103,7 @@ class WebViewAutofillClientIOS : public AutofillClient {
web::WebState* web_state_; web::WebState* web_state_;
__weak id<CWVAutofillClientIOSBridge> bridge_; __weak id<CWVAutofillClientIOSBridge> bridge_;
identity::IdentityManager* identity_manager_; identity::IdentityManager* identity_manager_;
StrikeDatabase* strike_database_;
scoped_refptr<AutofillWebDataService> autofill_web_data_service_; scoped_refptr<AutofillWebDataService> autofill_web_data_service_;
syncer::SyncService* sync_service_ = nullptr; syncer::SyncService* sync_service_ = nullptr;
......
...@@ -23,6 +23,7 @@ WebViewAutofillClientIOS::WebViewAutofillClientIOS( ...@@ -23,6 +23,7 @@ WebViewAutofillClientIOS::WebViewAutofillClientIOS(
web::WebState* web_state, web::WebState* web_state,
id<CWVAutofillClientIOSBridge> bridge, id<CWVAutofillClientIOSBridge> bridge,
identity::IdentityManager* identity_manager, identity::IdentityManager* identity_manager,
StrikeDatabase* strike_database,
scoped_refptr<AutofillWebDataService> autofill_web_data_service, scoped_refptr<AutofillWebDataService> autofill_web_data_service,
syncer::SyncService* sync_service) syncer::SyncService* sync_service)
: pref_service_(pref_service), : pref_service_(pref_service),
...@@ -30,6 +31,7 @@ WebViewAutofillClientIOS::WebViewAutofillClientIOS( ...@@ -30,6 +31,7 @@ WebViewAutofillClientIOS::WebViewAutofillClientIOS(
web_state_(web_state), web_state_(web_state),
bridge_(bridge), bridge_(bridge),
identity_manager_(identity_manager), identity_manager_(identity_manager),
strike_database_(strike_database),
autofill_web_data_service_(autofill_web_data_service), autofill_web_data_service_(autofill_web_data_service),
sync_service_(sync_service) {} sync_service_(sync_service) {}
...@@ -53,6 +55,10 @@ identity::IdentityManager* WebViewAutofillClientIOS::GetIdentityManager() { ...@@ -53,6 +55,10 @@ identity::IdentityManager* WebViewAutofillClientIOS::GetIdentityManager() {
return identity_manager_; return identity_manager_;
} }
StrikeDatabase* WebViewAutofillClientIOS::GetStrikeDatabase() {
return strike_database_;
}
ukm::UkmRecorder* WebViewAutofillClientIOS::GetUkmRecorder() { ukm::UkmRecorder* WebViewAutofillClientIOS::GetUkmRecorder() {
// UKM recording is not supported for WebViews. // UKM recording is not supported for WebViews.
return nullptr; return nullptr;
......
// 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 "ios/web_view/internal/autofill/web_view_strike_database_factory.h"
#include <utility>
#include "base/memory/singleton.h"
#include "components/autofill/core/browser/strike_database.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "ios/web_view/internal/app/application_context.h"
#include "ios/web_view/internal/web_view_browser_state.h"
namespace ios_web_view {
// static
autofill::StrikeDatabase* WebViewStrikeDatabaseFactory::GetForBrowserState(
WebViewBrowserState* browser_state) {
return static_cast<autofill::StrikeDatabase*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
WebViewStrikeDatabaseFactory* WebViewStrikeDatabaseFactory::GetInstance() {
return base::Singleton<WebViewStrikeDatabaseFactory>::get();
}
WebViewStrikeDatabaseFactory::WebViewStrikeDatabaseFactory()
: BrowserStateKeyedServiceFactory(
"AutofillStrikeDatabase",
BrowserStateDependencyManager::GetInstance()) {}
WebViewStrikeDatabaseFactory::~WebViewStrikeDatabaseFactory() {}
std::unique_ptr<KeyedService>
WebViewStrikeDatabaseFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
WebViewBrowserState* browser_state =
WebViewBrowserState::FromBrowserState(context);
return std::make_unique<autofill::StrikeDatabase>(
browser_state->GetStatePath().Append(
FILE_PATH_LITERAL("AutofillStrikeDatabase")));
}
} // namespace ios_web_view
// 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 IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_STRIKE_DATABASE_FACTORY_H_
#define IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_STRIKE_DATABASE_FACTORY_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
namespace autofill {
class StrikeDatabase;
}
namespace ios_web_view {
class WebViewBrowserState;
// Singleton that owns all StrikeDatabases and associates them with
// ios_web_view::WebViewBrowserState.
class WebViewStrikeDatabaseFactory : public BrowserStateKeyedServiceFactory {
public:
static autofill::StrikeDatabase* GetForBrowserState(
WebViewBrowserState* browser_state);
static WebViewStrikeDatabaseFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<WebViewStrikeDatabaseFactory>;
WebViewStrikeDatabaseFactory();
~WebViewStrikeDatabaseFactory() override;
// BrowserStateKeyedServiceFactory implementation.
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* context) const override;
DISALLOW_COPY_AND_ASSIGN(WebViewStrikeDatabaseFactory);
};
} // namespace ios_web_view
#endif // IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_STRIKE_DATABASE_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