Commit 176a3a31 authored by Mark Pilgrim's avatar Mark Pilgrim Committed by Commit Bot

Migrate AffiliationFetcher to SimpleURLLoader

Bug: 844947
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I08b3921d4a6e8ad2489a175cea5a5b883af32bbb
Reviewed-on: https://chromium-review.googlesource.com/1129322
Commit-Queue: Mark Pilgrim <pilgrim@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574627}
parent 9ebcff16
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/browser/password_manager/password_manager_util_win.h" #include "chrome/browser/password_manager/password_manager_util_win.h"
...@@ -106,11 +109,11 @@ void PasswordStoreFactory::OnPasswordsSyncedStatePotentiallyChanged( ...@@ -106,11 +109,11 @@ void PasswordStoreFactory::OnPasswordsSyncedStatePotentiallyChanged(
return; return;
syncer::SyncService* sync_service = syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
net::URLRequestContextGetter* request_context_getter =
profile->GetRequestContext();
password_manager::ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState( password_manager::ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState(
password_store.get(), sync_service, request_context_getter, password_store.get(), sync_service,
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetURLLoaderFactoryForBrowserProcess(),
profile->GetPath()); profile->GetPath());
} }
......
...@@ -205,6 +205,7 @@ static_library("browser") { ...@@ -205,6 +205,7 @@ static_library("browser") {
"//net", "//net",
"//services/metrics/public/cpp:metrics_cpp", "//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders", "//services/metrics/public/cpp:ukm_builders",
"//services/network/public/cpp",
"//sql", "//sql",
"//third_party/protobuf:protobuf_lite", "//third_party/protobuf:protobuf_lite",
"//third_party/re2", "//third_party/re2",
...@@ -296,6 +297,7 @@ static_library("test_support") { ...@@ -296,6 +297,7 @@ static_library("test_support") {
":browser", ":browser",
":hash_password_manager", ":hash_password_manager",
"//components/ukm", "//components/ukm",
"//services/network/public/cpp",
"//testing/gmock", "//testing/gmock",
"//url:url", "//url:url",
] ]
...@@ -439,8 +441,11 @@ source_set("unit_tests") { ...@@ -439,8 +441,11 @@ source_set("unit_tests") {
"//components/sync:test_support_model", "//components/sync:test_support_model",
"//components/ukm:test_support", "//components/ukm:test_support",
"//components/variations", "//components/variations",
"//google_apis:google_apis",
"//net:test_support", "//net:test_support",
"//services/metrics/public/cpp:ukm_builders", "//services/metrics/public/cpp:ukm_builders",
"//services/network:test_support",
"//services/network/public/cpp",
"//sql:test_support", "//sql:test_support",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
......
...@@ -15,6 +15,8 @@ include_rules = [ ...@@ -15,6 +15,8 @@ include_rules = [
"+grit", "+grit",
"+net", "+net",
"+services/metrics/public/cpp", "+services/metrics/public/cpp",
"+services/network/public/cpp",
"+services/network/test",
] ]
specific_include_rules = { specific_include_rules = {
......
...@@ -21,16 +21,15 @@ ...@@ -21,16 +21,15 @@
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher.h" #include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher.h"
#include "components/password_manager/core/browser/android_affiliation/facet_manager.h" #include "components/password_manager/core/browser/android_affiliation/facet_manager.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace password_manager { namespace password_manager {
AffiliationBackend::AffiliationBackend( AffiliationBackend::AffiliationBackend(
const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
const scoped_refptr<base::SequencedTaskRunner>& task_runner, const scoped_refptr<base::SequencedTaskRunner>& task_runner,
base::Clock* time_source, base::Clock* time_source,
const base::TickClock* time_tick_source) const base::TickClock* time_tick_source)
: request_context_getter_(request_context_getter), : task_runner_(task_runner),
task_runner_(task_runner),
clock_(time_source), clock_(time_source),
tick_clock_(time_tick_source), tick_clock_(time_tick_source),
construction_time_(clock_->Now()), construction_time_(clock_->Now()),
...@@ -42,7 +41,10 @@ AffiliationBackend::AffiliationBackend( ...@@ -42,7 +41,10 @@ AffiliationBackend::AffiliationBackend(
AffiliationBackend::~AffiliationBackend() { AffiliationBackend::~AffiliationBackend() {
} }
void AffiliationBackend::Initialize(const base::FilePath& db_path) { void AffiliationBackend::Initialize(
std::unique_ptr<network::SharedURLLoaderFactoryInfo>
url_loader_factory_info,
const base::FilePath& db_path) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!throttler_); DCHECK(!throttler_);
throttler_.reset( throttler_.reset(
...@@ -54,6 +56,10 @@ void AffiliationBackend::Initialize(const base::FilePath& db_path) { ...@@ -54,6 +56,10 @@ void AffiliationBackend::Initialize(const base::FilePath& db_path) {
// return value here. See: https://crbug.com/478831. // return value here. See: https://crbug.com/478831.
cache_.reset(new AffiliationDatabase()); cache_.reset(new AffiliationDatabase());
cache_->Init(db_path); cache_->Init(db_path);
DCHECK(url_loader_factory_info);
DCHECK(!url_loader_factory_);
url_loader_factory_ = network::SharedURLLoaderFactory::Create(
std::move(url_loader_factory_info));
} }
void AffiliationBackend::GetAffiliationsAndBranding( void AffiliationBackend::GetAffiliationsAndBranding(
...@@ -252,7 +258,7 @@ bool AffiliationBackend::OnCanSendNetworkRequest() { ...@@ -252,7 +258,7 @@ bool AffiliationBackend::OnCanSendNetworkRequest() {
if (requested_facet_uris.empty()) if (requested_facet_uris.empty())
return false; return false;
fetcher_.reset(AffiliationFetcher::Create(request_context_getter_.get(), fetcher_.reset(AffiliationFetcher::Create(url_loader_factory_,
requested_facet_uris, this)); requested_facet_uris, this));
fetcher_->StartRequest(); fetcher_->StartRequest();
ReportStatistics(requested_facet_uris.size()); ReportStatistics(requested_facet_uris.size());
......
...@@ -32,9 +32,9 @@ class TickClock; ...@@ -32,9 +32,9 @@ class TickClock;
class Time; class Time;
} // namespace base } // namespace base
namespace net { namespace network {
class URLRequestContextGetter; class SharedURLLoaderFactoryInfo;
} // namespace net } // namespace network
namespace password_manager { namespace password_manager {
...@@ -57,12 +57,11 @@ class AffiliationBackend : public FacetManagerHost, ...@@ -57,12 +57,11 @@ class AffiliationBackend : public FacetManagerHost,
public: public:
using StrategyOnCacheMiss = AffiliationService::StrategyOnCacheMiss; using StrategyOnCacheMiss = AffiliationService::StrategyOnCacheMiss;
// Constructs an instance that will use |request_context_getter| for all // Constructs an instance that will use |url_loader_factory| for all
// network requests, use |task_runner| for asynchronous tasks, and will rely // network requests, use |task_runner| for asynchronous tasks, and will rely
// on |time_source| and |time_tick_source| to tell the current time/ticks. // on |time_source| and |time_tick_source| to tell the current time/ticks.
// Construction is very cheap, expensive steps are deferred to Initialize(). // Construction is very cheap, expensive steps are deferred to Initialize().
AffiliationBackend( AffiliationBackend(
const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
const scoped_refptr<base::SequencedTaskRunner>& task_runner, const scoped_refptr<base::SequencedTaskRunner>& task_runner,
base::Clock* time_source, base::Clock* time_source,
const base::TickClock* time_tick_source); const base::TickClock* time_tick_source);
...@@ -70,7 +69,9 @@ class AffiliationBackend : public FacetManagerHost, ...@@ -70,7 +69,9 @@ class AffiliationBackend : public FacetManagerHost,
// Performs the I/O-heavy part of initialization. The database used to cache // Performs the I/O-heavy part of initialization. The database used to cache
// affiliation information locally will be opened/created at |db_path|. // affiliation information locally will be opened/created at |db_path|.
void Initialize(const base::FilePath& db_path); void Initialize(std::unique_ptr<network::SharedURLLoaderFactoryInfo>
url_loader_factory_info,
const base::FilePath& db_path);
// Implementations for methods of the same name in AffiliationService. They // Implementations for methods of the same name in AffiliationService. They
// are not documented here again. See affiliation_service.h for details: // are not documented here again. See affiliation_service.h for details:
...@@ -140,7 +141,7 @@ class AffiliationBackend : public FacetManagerHost, ...@@ -140,7 +141,7 @@ class AffiliationBackend : public FacetManagerHost,
// sequence. // sequence.
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<net::URLRequestContextGetter> request_context_getter_; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
base::Clock* clock_; base::Clock* clock_;
const base::TickClock* tick_clock_; const base::TickClock* tick_clock_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/test_mock_time_task_runner.h" #include "base/test/test_mock_time_task_runner.h"
#include "base/test/test_simple_task_runner.h" #include "base/test/test_simple_task_runner.h"
#include "base/time/clock.h" #include "base/time/clock.h"
...@@ -23,6 +24,9 @@ ...@@ -23,6 +24,9 @@
#include "components/password_manager/core/browser/android_affiliation/fake_affiliation_api.h" #include "components/password_manager/core/browser/android_affiliation/fake_affiliation_api.h"
#include "components/password_manager/core/browser/android_affiliation/mock_affiliation_consumer.h" #include "components/password_manager/core/browser/android_affiliation/mock_affiliation_consumer.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -333,9 +337,12 @@ class AffiliationBackendTest : public testing::Test { ...@@ -333,9 +337,12 @@ class AffiliationBackendTest : public testing::Test {
void SetUp() override { void SetUp() override {
ASSERT_TRUE(CreateTemporaryFile(&db_path_)); ASSERT_TRUE(CreateTemporaryFile(&db_path_));
backend_.reset(new AffiliationBackend( backend_.reset(new AffiliationBackend(
nullptr, backend_task_runner_, backend_task_runner_->GetMockClock(), backend_task_runner_, backend_task_runner_->GetMockClock(),
backend_task_runner_->GetMockTickClock())); backend_task_runner_->GetMockTickClock()));
backend_->Initialize(db_path()); auto test_shared_loader_factory =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_);
backend_->Initialize(test_shared_loader_factory->Clone(), db_path());
auto mock_fetch_throttler = auto mock_fetch_throttler =
std::make_unique<MockAffiliationFetchThrottler>(backend_.get()); std::make_unique<MockAffiliationFetchThrottler>(backend_.get());
mock_fetch_throttler_ = mock_fetch_throttler.get(); mock_fetch_throttler_ = mock_fetch_throttler.get();
...@@ -349,6 +356,7 @@ class AffiliationBackendTest : public testing::Test { ...@@ -349,6 +356,7 @@ class AffiliationBackendTest : public testing::Test {
GetTestEquivalenceClassGamma()); GetTestEquivalenceClassGamma());
} }
base::test::ScopedTaskEnvironment scoped_task_environment_;
scoped_refptr<base::TestMockTimeTaskRunner> backend_task_runner_; scoped_refptr<base::TestMockTimeTaskRunner> backend_task_runner_;
scoped_refptr<base::TestSimpleTaskRunner> consumer_task_runner_; scoped_refptr<base::TestSimpleTaskRunner> consumer_task_runner_;
...@@ -356,6 +364,7 @@ class AffiliationBackendTest : public testing::Test { ...@@ -356,6 +364,7 @@ class AffiliationBackendTest : public testing::Test {
ScopedFakeAffiliationAPI fake_affiliation_api_; ScopedFakeAffiliationAPI fake_affiliation_api_;
MockAffiliationConsumer mock_consumer_; MockAffiliationConsumer mock_consumer_;
std::unique_ptr<AffiliationBackend> backend_; std::unique_ptr<AffiliationBackend> backend_;
network::TestURLLoaderFactory test_url_loader_factory_;
MockAffiliationFetchThrottler* mock_fetch_throttler_; // Owned by |backend_|. MockAffiliationFetchThrottler* mock_fetch_throttler_; // Owned by |backend_|.
DISALLOW_COPY_AND_ASSIGN(AffiliationBackendTest); DISALLOW_COPY_AND_ASSIGN(AffiliationBackendTest);
......
...@@ -21,14 +21,13 @@ ...@@ -21,14 +21,13 @@
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_fetcher.h" #include "services/network/public/cpp/resource_request.h"
#include "net/url_request/url_request_context_getter.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace password_manager { namespace password_manager {
namespace {
// Enumeration listing the possible outcomes of fetching affiliation information // Enumeration listing the possible outcomes of fetching affiliation information
// from the Affiliation API. This is used in UMA histograms, so do not change // from the Affiliation API. This is used in UMA histograms, so do not change
// existing values, only add new values at the end. // existing values, only add new values at the end.
...@@ -39,32 +38,13 @@ enum AffiliationFetchResult { ...@@ -39,32 +38,13 @@ enum AffiliationFetchResult {
AFFILIATION_FETCH_RESULT_MAX AFFILIATION_FETCH_RESULT_MAX
}; };
// Records the given fetch |result| into the respective UMA histogram, as well
// as the response and error codes of |fetcher| if it is non-null.
void ReportStatistics(AffiliationFetchResult result,
const net::URLFetcher* fetcher) {
UMA_HISTOGRAM_ENUMERATION("PasswordManager.AffiliationFetcher.FetchResult",
result, AFFILIATION_FETCH_RESULT_MAX);
if (fetcher) {
base::UmaHistogramSparse(
"PasswordManager.AffiliationFetcher.FetchHttpResponseCode",
fetcher->GetResponseCode());
// Network error codes are negative. See: src/net/base/net_error_list.h.
base::UmaHistogramSparse(
"PasswordManager.AffiliationFetcher.FetchErrorCode",
-fetcher->GetStatus().error());
}
}
} // namespace
static TestAffiliationFetcherFactory* g_testing_factory = nullptr; static TestAffiliationFetcherFactory* g_testing_factory = nullptr;
AffiliationFetcher::AffiliationFetcher( AffiliationFetcher::AffiliationFetcher(
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_uris, const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate) AffiliationFetcherDelegate* delegate)
: request_context_getter_(request_context_getter), : url_loader_factory_(std::move(url_loader_factory)),
requested_facet_uris_(facet_uris), requested_facet_uris_(facet_uris),
delegate_(delegate) { delegate_(delegate) {
for (const FacetURI& uri : requested_facet_uris_) { for (const FacetURI& uri : requested_facet_uris_) {
...@@ -72,19 +52,19 @@ AffiliationFetcher::AffiliationFetcher( ...@@ -72,19 +52,19 @@ AffiliationFetcher::AffiliationFetcher(
} }
} }
AffiliationFetcher::~AffiliationFetcher() { AffiliationFetcher::~AffiliationFetcher() = default;
}
// static // static
AffiliationFetcher* AffiliationFetcher::Create( AffiliationFetcher* AffiliationFetcher::Create(
net::URLRequestContextGetter* context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_uris, const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate) { AffiliationFetcherDelegate* delegate) {
if (g_testing_factory) { if (g_testing_factory) {
return g_testing_factory->CreateInstance(context_getter, facet_uris, return g_testing_factory->CreateInstance(std::move(url_loader_factory),
delegate); facet_uris, delegate);
} }
return new AffiliationFetcher(context_getter, facet_uris, delegate); return new AffiliationFetcher(std::move(url_loader_factory), facet_uris,
delegate);
} }
// static // static
...@@ -94,7 +74,7 @@ void AffiliationFetcher::SetFactoryForTesting( ...@@ -94,7 +74,7 @@ void AffiliationFetcher::SetFactoryForTesting(
} }
void AffiliationFetcher::StartRequest() { void AffiliationFetcher::StartRequest() {
DCHECK(!fetcher_); DCHECK(!simple_url_loader_);
net::NetworkTrafficAnnotationTag traffic_annotation = net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("affiliation_lookup", R"( net::DefineNetworkTrafficAnnotation("affiliation_lookup", R"(
...@@ -127,20 +107,25 @@ void AffiliationFetcher::StartRequest() { ...@@ -127,20 +107,25 @@ void AffiliationFetcher::StartRequest() {
} }
} }
})"); })");
fetcher_ = net::URLFetcher::Create(BuildQueryURL(), net::URLFetcher::POST, auto resource_request = std::make_unique<network::ResourceRequest>();
this, traffic_annotation); resource_request->url = BuildQueryURL();
fetcher_->SetRequestContext(request_context_getter_.get()); resource_request->load_flags =
fetcher_->SetUploadData("application/x-protobuf", PreparePayload()); net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES |
fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA | net::LOAD_BYPASS_CACHE |
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DISABLE_CACHE;
net::LOAD_DO_NOT_SEND_AUTH_DATA | resource_request->method = "POST";
net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE); simple_url_loader_ = network::SimpleURLLoader::Create(
fetcher_->SetAutomaticallyRetryOn5xx(false); std::move(resource_request), traffic_annotation);
fetcher_->SetAutomaticallyRetryOnNetworkChanges(0); simple_url_loader_->AttachStringForUpload(PreparePayload(),
fetcher_->Start(); "application/x-protobuf");
simple_url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(),
base::BindOnce(&AffiliationFetcher::OnSimpleLoaderComplete,
base::Unretained(this)));
} }
GURL AffiliationFetcher::BuildQueryURL() const { // static
GURL AffiliationFetcher::BuildQueryURL() {
return net::AppendQueryParameter( return net::AppendQueryParameter(
GURL("https://www.googleapis.com/affiliation/v1/affiliation:lookup"), GURL("https://www.googleapis.com/affiliation/v1/affiliation:lookup"),
"key", google_apis::GetAPIKey()); "key", google_apis::GetAPIKey());
...@@ -163,6 +148,7 @@ std::string AffiliationFetcher::PreparePayload() const { ...@@ -163,6 +148,7 @@ std::string AffiliationFetcher::PreparePayload() const {
} }
bool AffiliationFetcher::ParseResponse( bool AffiliationFetcher::ParseResponse(
const std::string& serialized_response,
AffiliationFetcherDelegate::Result* result) const { AffiliationFetcherDelegate::Result* result) const {
// This function parses the response protocol buffer message for a list of // This function parses the response protocol buffer message for a list of
// equivalence classes, and stores them into |results| after performing some // equivalence classes, and stores them into |results| after performing some
...@@ -178,11 +164,6 @@ bool AffiliationFetcher::ParseResponse( ...@@ -178,11 +164,6 @@ bool AffiliationFetcher::ParseResponse(
// case so the caller can be notified and it can act accordingly. // case so the caller can be notified and it can act accordingly.
// * The |result| will be free of duplicate or empty equivalence classes. // * The |result| will be free of duplicate or empty equivalence classes.
std::string serialized_response;
if (!fetcher_->GetResponseAsString(&serialized_response)) {
NOTREACHED();
}
affiliation_pb::LookupAffiliationResponse response; affiliation_pb::LookupAffiliationResponse response;
if (!response.ParseFromString(serialized_response)) if (!response.ParseFromString(serialized_response))
return false; return false;
...@@ -238,24 +219,41 @@ bool AffiliationFetcher::ParseResponse( ...@@ -238,24 +219,41 @@ bool AffiliationFetcher::ParseResponse(
return true; return true;
} }
void AffiliationFetcher::OnURLFetchComplete(const net::URLFetcher* source) { void AffiliationFetcher::OnSimpleLoaderComplete(
DCHECK_EQ(source, fetcher_.get()); std::unique_ptr<std::string> response_body) {
// Note that invoking the |delegate_| may destroy |this| synchronously, so the // Note that invoking the |delegate_| may destroy |this| synchronously, so the
// invocation must happen last. // invocation must happen last.
std::unique_ptr<AffiliationFetcherDelegate::Result> result_data( std::unique_ptr<AffiliationFetcherDelegate::Result> result_data(
new AffiliationFetcherDelegate::Result); new AffiliationFetcherDelegate::Result);
if (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS && if (response_body) {
fetcher_->GetResponseCode() == net::HTTP_OK) { if (ParseResponse(*response_body, result_data.get())) {
if (ParseResponse(result_data.get())) { UMA_HISTOGRAM_ENUMERATION(
ReportStatistics(AFFILIATION_FETCH_RESULT_SUCCESS, nullptr); "PasswordManager.AffiliationFetcher.FetchResult",
AFFILIATION_FETCH_RESULT_SUCCESS, AFFILIATION_FETCH_RESULT_MAX);
delegate_->OnFetchSucceeded(std::move(result_data)); delegate_->OnFetchSucceeded(std::move(result_data));
} else { } else {
ReportStatistics(AFFILIATION_FETCH_RESULT_MALFORMED, nullptr); UMA_HISTOGRAM_ENUMERATION(
"PasswordManager.AffiliationFetcher.FetchResult",
AFFILIATION_FETCH_RESULT_MALFORMED, AFFILIATION_FETCH_RESULT_MAX);
delegate_->OnMalformedResponse(); delegate_->OnMalformedResponse();
} }
} else { } else {
ReportStatistics(AFFILIATION_FETCH_RESULT_FAILURE, fetcher_.get()); UMA_HISTOGRAM_ENUMERATION("PasswordManager.AffiliationFetcher.FetchResult",
AFFILIATION_FETCH_RESULT_FAILURE,
AFFILIATION_FETCH_RESULT_MAX);
int response_code = -1;
if (simple_url_loader_->ResponseInfo() &&
simple_url_loader_->ResponseInfo()->headers) {
response_code =
simple_url_loader_->ResponseInfo()->headers->response_code();
}
base::UmaHistogramSparse(
"PasswordManager.AffiliationFetcher.FetchHttpResponseCode",
response_code);
// Network error codes are negative. See: src/net/base/net_error_list.h.
base::UmaHistogramSparse(
"PasswordManager.AffiliationFetcher.FetchErrorCode",
-simple_url_loader_->NetError());
delegate_->OnFetchFailed(); delegate_->OnFetchFailed();
} }
} }
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher_delegate.h" #include "components/password_manager/core/browser/android_affiliation/affiliation_fetcher_delegate.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h" #include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
#include "net/url_request/url_fetcher_delegate.h"
class GURL; class GURL;
namespace net { namespace network {
class URLRequestContextGetter; class SharedURLLoaderFactory;
} // namespace net class SimpleURLLoader;
} // namespace network
namespace password_manager { namespace password_manager {
...@@ -31,18 +31,21 @@ class TestAffiliationFetcherFactory; ...@@ -31,18 +31,21 @@ class TestAffiliationFetcherFactory;
// //
// An instance is good for exactly one fetch, and may be used from any thread // An instance is good for exactly one fetch, and may be used from any thread
// that runs a message loop (i.e. not a worker pool thread). // that runs a message loop (i.e. not a worker pool thread).
class AffiliationFetcher : net::URLFetcherDelegate { class AffiliationFetcher {
public: public:
~AffiliationFetcher() override; ~AffiliationFetcher();
// Constructs a fetcher to retrieve affiliations for each facet in |facet_ids| // Constructs a fetcher to retrieve affiliations for each facet in |facet_ids|
// using the specified |request_context_getter|, and will provide the results // using the specified |url_loader_factory|, and will provide the results
// to the |delegate| on the same thread that creates the instance. // to the |delegate| on the same thread that creates the instance.
static AffiliationFetcher* Create( static AffiliationFetcher* Create(
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_uris, const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate); AffiliationFetcherDelegate* delegate);
// Builds the URL for the Affiliation API's lookup method.
static GURL BuildQueryURL();
// Sets the |factory| to be used by Create() to construct AffiliationFetcher // Sets the |factory| to be used by Create() to construct AffiliationFetcher
// instances. To be used only for testing. // instances. To be used only for testing.
// //
...@@ -57,7 +60,7 @@ class AffiliationFetcher : net::URLFetcherDelegate { ...@@ -57,7 +60,7 @@ class AffiliationFetcher : net::URLFetcherDelegate {
// * No cookies are sent/saved with the request. // * No cookies are sent/saved with the request.
// * In case of network/server errors, the request will not be retried. // * In case of network/server errors, the request will not be retried.
// * Results are guaranteed to be always fresh and will never be cached. // * Results are guaranteed to be always fresh and will never be cached.
virtual void StartRequest(); void StartRequest();
const std::vector<FacetURI>& requested_facet_uris() const { const std::vector<FacetURI>& requested_facet_uris() const {
return requested_facet_uris_; return requested_facet_uris_;
...@@ -66,14 +69,12 @@ class AffiliationFetcher : net::URLFetcherDelegate { ...@@ -66,14 +69,12 @@ class AffiliationFetcher : net::URLFetcherDelegate {
AffiliationFetcherDelegate* delegate() const { return delegate_; } AffiliationFetcherDelegate* delegate() const { return delegate_; }
protected: protected:
AffiliationFetcher(net::URLRequestContextGetter* request_context_getter, AffiliationFetcher(
const std::vector<FacetURI>& facet_uris, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
AffiliationFetcherDelegate* delegate); const std::vector<FacetURI>& facet_uris,
AffiliationFetcherDelegate* delegate);
private: private:
// Builds the URL for the Affiliation API's lookup method.
GURL BuildQueryURL() const;
// Prepares and returns the serialized protocol buffer message that will be // Prepares and returns the serialized protocol buffer message that will be
// the payload of the POST request. // the payload of the POST request.
std::string PreparePayload() const; std::string PreparePayload() const;
...@@ -84,16 +85,16 @@ class AffiliationFetcher : net::URLFetcherDelegate { ...@@ -84,16 +85,16 @@ class AffiliationFetcher : net::URLFetcherDelegate {
// member of exactly one returned equivalence class. // member of exactly one returned equivalence class.
// Returns false if the response was gravely ill-formed or self-inconsistent. // Returns false if the response was gravely ill-formed or self-inconsistent.
// Unknown kinds of facet URIs and new protocol buffer fields will be ignored. // Unknown kinds of facet URIs and new protocol buffer fields will be ignored.
bool ParseResponse(AffiliationFetcherDelegate::Result* result) const; bool ParseResponse(const std::string& serialized_response,
AffiliationFetcherDelegate::Result* result) const;
// net::URLFetcherDelegate: void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body);
void OnURLFetchComplete(const net::URLFetcher* source) override;
const scoped_refptr<net::URLRequestContextGetter> request_context_getter_; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
const std::vector<FacetURI> requested_facet_uris_; const std::vector<FacetURI> requested_facet_uris_;
AffiliationFetcherDelegate* const delegate_; AffiliationFetcherDelegate* const delegate_;
std::unique_ptr<net::URLFetcher> fetcher_; std::unique_ptr<network::SimpleURLLoader> simple_url_loader_;
DISALLOW_COPY_AND_ASSIGN(AffiliationFetcher); DISALLOW_COPY_AND_ASSIGN(AffiliationFetcher);
}; };
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
#include "base/time/default_tick_clock.h" #include "base/time/default_tick_clock.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_backend.h" #include "components/password_manager/core/browser/android_affiliation/affiliation_backend.h"
#include "net/url_request/url_request_context_getter.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace password_manager { namespace password_manager {
...@@ -34,17 +34,18 @@ AffiliationService::~AffiliationService() { ...@@ -34,17 +34,18 @@ AffiliationService::~AffiliationService() {
} }
void AffiliationService::Initialize( void AffiliationService::Initialize(
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const base::FilePath& db_path) { const base::FilePath& db_path) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!backend_); DCHECK(!backend_);
backend_ = new AffiliationBackend( backend_ = new AffiliationBackend(backend_task_runner_,
request_context_getter, backend_task_runner_, base::DefaultClock::GetInstance(),
base::DefaultClock::GetInstance(), base::DefaultTickClock::GetInstance()); base::DefaultTickClock::GetInstance());
backend_task_runner_->PostTask( backend_task_runner_->PostTask(
FROM_HERE, base::Bind(&AffiliationBackend::Initialize, FROM_HERE, base::BindOnce(&AffiliationBackend::Initialize,
base::Unretained(backend_), db_path)); base::Unretained(backend_),
url_loader_factory->Clone(), db_path));
} }
void AffiliationService::GetAffiliationsAndBranding( void AffiliationService::GetAffiliationsAndBranding(
......
...@@ -20,9 +20,9 @@ class FilePath; ...@@ -20,9 +20,9 @@ class FilePath;
class SequencedTaskRunner; class SequencedTaskRunner;
} // namespace base } // namespace base
namespace net { namespace network {
class URLRequestContextGetter; class SharedURLLoaderFactory;
} // namespace net } // namespace network
namespace password_manager { namespace password_manager {
...@@ -105,8 +105,9 @@ class AffiliationService : public KeyedService { ...@@ -105,8 +105,9 @@ class AffiliationService : public KeyedService {
// Initializes the service by creating its backend and transferring it to the // Initializes the service by creating its backend and transferring it to the
// thread corresponding to |backend_task_runner_|. // thread corresponding to |backend_task_runner_|.
void Initialize(net::URLRequestContextGetter* request_context_getter, void Initialize(
const base::FilePath& db_path); scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const base::FilePath& db_path);
// Looks up facets affiliated with the facet identified by |facet_uri| and // Looks up facets affiliated with the facet identified by |facet_uri| and
// branding information, and invokes |result_callback| with the results. It is // branding information, and invokes |result_callback| with the results. It is
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/password_manager/core/browser/android_affiliation/fake_affiliation_api.h" #include "components/password_manager/core/browser/android_affiliation/fake_affiliation_api.h"
#include "components/password_manager/core/browser/android_affiliation/mock_affiliation_consumer.h" #include "components/password_manager/core/browser/android_affiliation/mock_affiliation_consumer.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -47,7 +50,10 @@ class AffiliationServiceTest : public testing::Test { ...@@ -47,7 +50,10 @@ class AffiliationServiceTest : public testing::Test {
AffiliationServiceTest() AffiliationServiceTest()
: main_task_runner_(new base::TestSimpleTaskRunner), : main_task_runner_(new base::TestSimpleTaskRunner),
main_task_runner_handle_(main_task_runner_), main_task_runner_handle_(main_task_runner_),
background_task_runner_(new base::TestMockTimeTaskRunner) {} background_task_runner_(new base::TestMockTimeTaskRunner),
test_shared_loader_factory_(
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_)) {}
~AffiliationServiceTest() override {} ~AffiliationServiceTest() override {}
protected: protected:
...@@ -74,7 +80,7 @@ class AffiliationServiceTest : public testing::Test { ...@@ -74,7 +80,7 @@ class AffiliationServiceTest : public testing::Test {
base::FilePath database_path; base::FilePath database_path;
ASSERT_TRUE(CreateTemporaryFile(&database_path)); ASSERT_TRUE(CreateTemporaryFile(&database_path));
service_.reset(new AffiliationService(background_task_runner())); service_.reset(new AffiliationService(background_task_runner()));
service_->Initialize(nullptr, database_path); service_->Initialize(test_shared_loader_factory_, database_path);
// Note: the background task runner is purposely not pumped here, so that // Note: the background task runner is purposely not pumped here, so that
// the tests also verify that the service can be used synchronously right // the tests also verify that the service can be used synchronously right
// away after having been constructed. // away after having been constructed.
...@@ -92,6 +98,8 @@ class AffiliationServiceTest : public testing::Test { ...@@ -92,6 +98,8 @@ class AffiliationServiceTest : public testing::Test {
scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_;
base::ThreadTaskRunnerHandle main_task_runner_handle_; base::ThreadTaskRunnerHandle main_task_runner_handle_;
scoped_refptr<base::TestMockTimeTaskRunner> background_task_runner_; scoped_refptr<base::TestMockTimeTaskRunner> background_task_runner_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_;
ScopedFakeAffiliationAPI fake_affiliation_api_; ScopedFakeAffiliationAPI fake_affiliation_api_;
MockAffiliationConsumer mock_consumer_; MockAffiliationConsumer mock_consumer_;
......
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "components/password_manager/core/browser/android_affiliation/fake_affiliation_fetcher.h" #include "components/password_manager/core/browser/android_affiliation/fake_affiliation_fetcher.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include <utility> #include <utility>
namespace password_manager { namespace password_manager {
password_manager::FakeAffiliationFetcher::FakeAffiliationFetcher( password_manager::FakeAffiliationFetcher::FakeAffiliationFetcher(
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids, const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) AffiliationFetcherDelegate* delegate)
: AffiliationFetcher(request_context_getter, facet_ids, delegate) { : AffiliationFetcher(std::move(url_loader_factory), facet_ids, delegate) {}
}
password_manager::FakeAffiliationFetcher::~FakeAffiliationFetcher() { password_manager::FakeAffiliationFetcher::~FakeAffiliationFetcher() {
} }
...@@ -27,10 +27,6 @@ void password_manager::FakeAffiliationFetcher::SimulateFailure() { ...@@ -27,10 +27,6 @@ void password_manager::FakeAffiliationFetcher::SimulateFailure() {
delegate()->OnFetchFailed(); delegate()->OnFetchFailed();
} }
void password_manager::FakeAffiliationFetcher::StartRequest() {
// Fake. Does nothing.
}
password_manager::ScopedFakeAffiliationFetcherFactory:: password_manager::ScopedFakeAffiliationFetcherFactory::
ScopedFakeAffiliationFetcherFactory() { ScopedFakeAffiliationFetcherFactory() {
AffiliationFetcher::SetFactoryForTesting(this); AffiliationFetcher::SetFactoryForTesting(this);
...@@ -54,11 +50,11 @@ FakeAffiliationFetcher* ScopedFakeAffiliationFetcherFactory::PeekNextFetcher() { ...@@ -54,11 +50,11 @@ FakeAffiliationFetcher* ScopedFakeAffiliationFetcherFactory::PeekNextFetcher() {
} }
AffiliationFetcher* ScopedFakeAffiliationFetcherFactory::CreateInstance( AffiliationFetcher* ScopedFakeAffiliationFetcherFactory::CreateInstance(
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids, const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) { AffiliationFetcherDelegate* delegate) {
FakeAffiliationFetcher* fetcher = FakeAffiliationFetcher* fetcher = new FakeAffiliationFetcher(
new FakeAffiliationFetcher(request_context_getter, facet_ids, delegate); std::move(url_loader_factory), facet_ids, delegate);
pending_fetchers_.push(fetcher); pending_fetchers_.push(fetcher);
return fetcher; return fetcher;
} }
......
...@@ -19,10 +19,11 @@ namespace password_manager { ...@@ -19,10 +19,11 @@ namespace password_manager {
// responses to users of AffiliationFetcher. // responses to users of AffiliationFetcher.
class FakeAffiliationFetcher : public AffiliationFetcher { class FakeAffiliationFetcher : public AffiliationFetcher {
public: public:
FakeAffiliationFetcher(net::URLRequestContextGetter* request_context_getter, FakeAffiliationFetcher(
const std::vector<FacetURI>& facet_ids, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
AffiliationFetcherDelegate* delegate); const std::vector<FacetURI>& facet_ids,
~FakeAffiliationFetcher() override; AffiliationFetcherDelegate* delegate);
~FakeAffiliationFetcher();
// Simulates successful completion of the request with |fake_result|. Note // Simulates successful completion of the request with |fake_result|. Note
// that the consumer may choose to destroy |this| from within this call. // that the consumer may choose to destroy |this| from within this call.
...@@ -34,8 +35,6 @@ class FakeAffiliationFetcher : public AffiliationFetcher { ...@@ -34,8 +35,6 @@ class FakeAffiliationFetcher : public AffiliationFetcher {
void SimulateFailure(); void SimulateFailure();
private: private:
void StartRequest() override;
DISALLOW_COPY_AND_ASSIGN(FakeAffiliationFetcher); DISALLOW_COPY_AND_ASSIGN(FakeAffiliationFetcher);
}; };
...@@ -66,7 +65,7 @@ class ScopedFakeAffiliationFetcherFactory ...@@ -66,7 +65,7 @@ class ScopedFakeAffiliationFetcherFactory
// AffiliationFetcherFactory: // AffiliationFetcherFactory:
AffiliationFetcher* CreateInstance( AffiliationFetcher* CreateInstance(
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids, const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) override; AffiliationFetcherDelegate* delegate) override;
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include <vector> #include <vector>
namespace net { namespace network {
class URLRequestContextGetter; class SharedURLLoaderFactory;
} // namespace net } // namespace network
namespace password_manager { namespace password_manager {
...@@ -23,10 +23,10 @@ class AffiliationFetcherDelegate; ...@@ -23,10 +23,10 @@ class AffiliationFetcherDelegate;
class TestAffiliationFetcherFactory { class TestAffiliationFetcherFactory {
public: public:
// Constructs a fetcher to retrieve affiliations for each facet in |facet_ids| // Constructs a fetcher to retrieve affiliations for each facet in |facet_ids|
// using the specified |request_context_getter|, and will provide the results // using the specified |url_loader_factory|, and will provide the results
// to the |delegate| on the same thread that creates the instance. // to the |delegate| on the same thread that creates the instance.
virtual AffiliationFetcher* CreateInstance( virtual AffiliationFetcher* CreateInstance(
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<FacetURI>& facet_ids, const std::vector<FacetURI>& facet_ids,
AffiliationFetcherDelegate* delegate) = 0; AffiliationFetcherDelegate* delegate) = 0;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h" #include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
#include "components/password_manager/core/browser/password_manager_constants.h" #include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace password_manager { namespace password_manager {
...@@ -28,7 +29,7 @@ bool ShouldAffiliationBasedMatchingBeActive(syncer::SyncService* sync_service) { ...@@ -28,7 +29,7 @@ bool ShouldAffiliationBasedMatchingBeActive(syncer::SyncService* sync_service) {
void ActivateAffiliationBasedMatching( void ActivateAffiliationBasedMatching(
PasswordStore* password_store, PasswordStore* password_store,
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const base::FilePath& db_path) { const base::FilePath& db_path) {
// Subsequent instances of the AffiliationService must use the same sequenced // Subsequent instances of the AffiliationService must use the same sequenced
// task runner for their backends. This guarantees that the backend of the // task runner for their backends. This guarantees that the backend of the
...@@ -45,7 +46,7 @@ void ActivateAffiliationBasedMatching( ...@@ -45,7 +46,7 @@ void ActivateAffiliationBasedMatching(
// is owned by the PasswordStore. // is owned by the PasswordStore.
std::unique_ptr<AffiliationService> affiliation_service( std::unique_ptr<AffiliationService> affiliation_service(
new AffiliationService(backend_task_runner)); new AffiliationService(backend_task_runner));
affiliation_service->Initialize(request_context_getter, db_path); affiliation_service->Initialize(std::move(url_loader_factory), db_path);
std::unique_ptr<AffiliatedMatchHelper> affiliated_match_helper( std::unique_ptr<AffiliatedMatchHelper> affiliated_match_helper(
new AffiliatedMatchHelper(password_store, new AffiliatedMatchHelper(password_store,
std::move(affiliation_service))); std::move(affiliation_service)));
...@@ -65,7 +66,7 @@ base::FilePath GetAffiliationDatabasePath(const base::FilePath& profile_path) { ...@@ -65,7 +66,7 @@ base::FilePath GetAffiliationDatabasePath(const base::FilePath& profile_path) {
void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState( void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState(
PasswordStore* password_store, PasswordStore* password_store,
syncer::SyncService* sync_service, syncer::SyncService* sync_service,
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const base::FilePath& profile_path) { const base::FilePath& profile_path) {
DCHECK(password_store); DCHECK(password_store);
...@@ -75,7 +76,8 @@ void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState( ...@@ -75,7 +76,8 @@ void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState(
password_store->affiliated_match_helper() != nullptr; password_store->affiliated_match_helper() != nullptr;
if (matching_should_be_active && !matching_is_active) { if (matching_should_be_active && !matching_is_active) {
ActivateAffiliationBasedMatching(password_store, request_context_getter, ActivateAffiliationBasedMatching(password_store,
std::move(url_loader_factory),
GetAffiliationDatabasePath(profile_path)); GetAffiliationDatabasePath(profile_path));
} else if (!matching_should_be_active && matching_is_active) { } else if (!matching_should_be_active && matching_is_active) {
password_store->SetAffiliatedMatchHelper(nullptr); password_store->SetAffiliatedMatchHelper(nullptr);
......
...@@ -15,19 +15,19 @@ ...@@ -15,19 +15,19 @@
#include "components/password_manager/core/browser/password_store.h" #include "components/password_manager/core/browser/password_store.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
#include "components/sync/model/syncable_service.h" #include "components/sync/model/syncable_service.h"
#include "net/url_request/url_request_context_getter.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace password_manager { namespace password_manager {
// Activates or deactivates affiliation-based matching for |password_store|, // Activates or deactivates affiliation-based matching for |password_store|,
// depending on whether or not the |sync_service| is syncing passwords stored // depending on whether or not the |sync_service| is syncing passwords stored
// therein. The AffiliationService will use |request_context_getter| to fetch // therein. The AffiliationService will use |url_loader_factory| to fetch
// affiliation information. This function should be called whenever there is a // affiliation information. This function should be called whenever there is a
// possibility that syncing passwords has just started or ended. // possibility that syncing passwords has just started or ended.
void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState( void ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState(
PasswordStore* password_store, PasswordStore* password_store,
syncer::SyncService* sync_service, syncer::SyncService* sync_service,
net::URLRequestContextGetter* request_context_getter, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const base::FilePath& profile_path); const base::FilePath& profile_path);
// Creates a LoginDatabase. Looks in |profile_path| for the database file. // Creates a LoginDatabase. Looks in |profile_path| for the database file.
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ios/chrome/browser/sync/glue/sync_start_util.h" #include "ios/chrome/browser/sync/glue/sync_start_util.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h" #include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#include "ios/chrome/browser/web_data_service_factory.h" #include "ios/chrome/browser/web_data_service_factory.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
// static // static
scoped_refptr<password_manager::PasswordStore> scoped_refptr<password_manager::PasswordStore>
...@@ -55,10 +56,9 @@ void IOSChromePasswordStoreFactory::OnPasswordsSyncedStatePotentiallyChanged( ...@@ -55,10 +56,9 @@ void IOSChromePasswordStoreFactory::OnPasswordsSyncedStatePotentiallyChanged(
GetForBrowserState(browser_state, ServiceAccessType::EXPLICIT_ACCESS); GetForBrowserState(browser_state, ServiceAccessType::EXPLICIT_ACCESS);
syncer::SyncService* sync_service = syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetForBrowserStateIfExists(browser_state); ProfileSyncServiceFactory::GetForBrowserStateIfExists(browser_state);
net::URLRequestContextGetter* request_context_getter =
browser_state->GetRequestContext();
password_manager::ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState( password_manager::ToggleAffiliationBasedMatchingBasedOnPasswordSyncedState(
password_store.get(), sync_service, request_context_getter, password_store.get(), sync_service,
browser_state->GetSharedURLLoaderFactory(),
browser_state->GetStatePath()); browser_state->GetStatePath());
} }
......
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