Commit 3afd9645 authored by Nela Kaczmarek's avatar Nela Kaczmarek Committed by Commit Bot

AffiliationService class renamed to AndroidAffiliationService to match updated filename.

Bug: 1108279
Change-Id: I4984ea492a3274f02bca3b251cca1ff9014e36c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339661Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Nela Kaczmarek <nelakaczmarek@google.com>
Cr-Commit-Position: refs/heads/master@{#795454}
parent 77f324ac
......@@ -37,7 +37,7 @@ constexpr base::TimeDelta AffiliatedMatchHelper::kInitializationDelayOnStartup;
AffiliatedMatchHelper::AffiliatedMatchHelper(
PasswordStore* password_store,
std::unique_ptr<AffiliationService> affiliation_service)
std::unique_ptr<AndroidAffiliationService> affiliation_service)
: password_store_(password_store),
affiliation_service_(std::move(affiliation_service)) {}
......@@ -63,7 +63,7 @@ void AffiliatedMatchHelper::GetAffiliatedAndroidRealms(
FacetURI facet_uri(
FacetURI::FromPotentiallyInvalidSpec(observed_form.signon_realm));
affiliation_service_->GetAffiliationsAndBranding(
facet_uri, AffiliationService::StrategyOnCacheMiss::FAIL,
facet_uri, AndroidAffiliationService::StrategyOnCacheMiss::FAIL,
base::BindOnce(
&AffiliatedMatchHelper::CompleteGetAffiliatedAndroidRealms,
weak_ptr_factory_.GetWeakPtr(), facet_uri,
......@@ -79,7 +79,7 @@ void AffiliatedMatchHelper::GetAffiliatedWebRealms(
if (IsValidAndroidCredential(android_form)) {
affiliation_service_->GetAffiliationsAndBranding(
FacetURI::FromPotentiallyInvalidSpec(android_form.signon_realm),
AffiliationService::StrategyOnCacheMiss::FETCH_OVER_NETWORK,
AndroidAffiliationService::StrategyOnCacheMiss::FETCH_OVER_NETWORK,
base::BindOnce(&AffiliatedMatchHelper::CompleteGetAffiliatedWebRealms,
weak_ptr_factory_.GetWeakPtr(),
std::move(result_callback)));
......@@ -103,7 +103,7 @@ void AffiliatedMatchHelper::InjectAffiliationAndBrandingInformation(
for (auto* form : android_credentials) {
affiliation_service_->GetAffiliationsAndBranding(
FacetURI::FromPotentiallyInvalidSpec(form->signon_realm),
AffiliationService::StrategyOnCacheMiss::FAIL,
AndroidAffiliationService::StrategyOnCacheMiss::FAIL,
base::BindOnce(&AffiliatedMatchHelper::
CompleteInjectAffiliationAndBrandingInformation,
weak_ptr_factory_.GetWeakPtr(), base::Unretained(form),
......
......@@ -23,17 +23,17 @@ struct PasswordForm;
namespace password_manager {
class AffiliationService;
class AndroidAffiliationService;
// Interacts with the AffiliationService on behalf of the PasswordStore.
// Interacts with the AndroidAffiliationService on behalf of the PasswordStore.
// For each GetLogins() request, it provides the PasswordStore with a list of
// additional realms that are affiliation-based matches to the observed realm.
//
// Currently, the only supported use-case is obtaining Android applications
// affiliated with the web site containing the observed form. This is achieved
// by implementing the "proactive fetching" strategy for interacting with the
// AffiliationService (see android_affiliation_service.h for details), with
// Android applications playing the role of facet Y.
// AndroidAffiliationService (see android_affiliation_service.h for details),
// with Android applications playing the role of facet Y.
//
// More specifically, this class prefetches affiliation information on start-up
// for all Android applications that the PasswordStore has credentials stored
......@@ -55,7 +55,7 @@ class AffiliatedMatchHelper : public PasswordStore::Observer,
// except in tests which do not Initialize() the object.
AffiliatedMatchHelper(
PasswordStore* password_store,
std::unique_ptr<AffiliationService> affiliation_service);
std::unique_ptr<AndroidAffiliationService> affiliation_service);
~AffiliatedMatchHelper() override;
// Schedules deferred initialization.
......@@ -109,27 +109,27 @@ class AffiliatedMatchHelper : public PasswordStore::Observer,
// observing the store for future changes.
void DoDeferredInitialization();
// Called back by AffiliationService to supply the list of facets affiliated
// with |original_facet_uri| so that a GetAffiliatedAndroidRealms() call can
// be completed.
// Called back by AndroidAffiliationService to supply the list of facets
// affiliated with |original_facet_uri| so that a GetAffiliatedAndroidRealms()
// call can be completed.
void CompleteGetAffiliatedAndroidRealms(
const FacetURI& original_facet_uri,
AffiliatedRealmsCallback result_callback,
const AffiliatedFacets& results,
bool success);
// Called back by AffiliationService to supply the list of facets affiliated
// with the Android application that GetAffiliatedWebRealms() was called with,
// so that the call can be completed.
// Called back by AndroidAffiliationService to supply the list of facets
// affiliated with the Android application that GetAffiliatedWebRealms() was
// called with, so that the call can be completed.
void CompleteGetAffiliatedWebRealms(AffiliatedRealmsCallback result_callback,
const AffiliatedFacets& results,
bool success);
// Called back by AffiliationService to supply the list of facets affiliated
// with the Android credential in |form|. Injects affiliation and branding
// information by setting |affiliated_web_realm|, |app_display_name| and
// |app_icon_url| on |form| if |success| is true and |results| is non-empty.
// Invokes |barrier_closure|.
// Called back by AndroidAffiliationService to supply the list of facets
// affiliated with the Android credential in |form|. Injects affiliation and
// branding information by setting |affiliated_web_realm|, |app_display_name|
// and |app_icon_url| on |form| if |success| is true and |results| is
// non-empty. Invokes |barrier_closure|.
void CompleteInjectAffiliationAndBrandingInformation(
autofill::PasswordForm* form,
base::OnceClosure barrier_closure,
......@@ -145,8 +145,9 @@ class AffiliatedMatchHelper : public PasswordStore::Observer,
PasswordStore* const password_store_;
// Being the sole consumer of AffiliationService, |this| owns the service.
std::unique_ptr<AffiliationService> affiliation_service_;
// Being the sole consumer of AndroidAffiliationService, |this| owns the
// service.
std::unique_ptr<AndroidAffiliationService> affiliation_service_;
base::WeakPtrFactory<AffiliatedMatchHelper> weak_ptr_factory_{this};
......
......@@ -27,11 +27,13 @@ namespace password_manager {
namespace {
using StrategyOnCacheMiss = AffiliationService::StrategyOnCacheMiss;
using StrategyOnCacheMiss = AndroidAffiliationService::StrategyOnCacheMiss;
class MockAffiliationService : public testing::StrictMock<AffiliationService> {
class MockAffiliationService
: public testing::StrictMock<AndroidAffiliationService> {
public:
MockAffiliationService() : testing::StrictMock<AffiliationService>(nullptr) {
MockAffiliationService()
: testing::StrictMock<AndroidAffiliationService>(nullptr) {
testing::DefaultValue<AffiliatedFacets>::Set(AffiliatedFacets());
}
......
......@@ -63,7 +63,7 @@ void AffiliationBackend::Initialize(
void AffiliationBackend::GetAffiliationsAndBranding(
const FacetURI& facet_uri,
StrategyOnCacheMiss cache_miss_strategy,
AffiliationService::ResultCallback callback,
AndroidAffiliationService::ResultCallback callback,
const scoped_refptr<base::TaskRunner>& callback_task_runner) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
......@@ -44,10 +44,11 @@ class AffiliationFetcher;
class AffiliationFetchThrottler;
class FacetManager;
// The AffiliationBackend is the part of the AffiliationService that lives on a
// background thread suitable for performing blocking I/O. As most tasks require
// I/O, the backend ends up doing most of the work for the AffiliationService;
// the latter being just a thin layer that delegates most tasks to the backend.
// The AffiliationBackend is the part of the AndroidAffiliationService that
// lives on a background thread suitable for performing blocking I/O. As most
// tasks require I/O, the backend ends up doing most of the work for the
// AndroidAffiliationService; the latter being just a thin layer that delegates
// most tasks to the backend.
//
// This class is not thread-safe, but it is fine to construct it on one thread
// and then transfer it to the background thread for the rest of its life.
......@@ -56,7 +57,7 @@ class AffiliationBackend : public FacetManagerHost,
public AffiliationFetcherDelegate,
public AffiliationFetchThrottlerDelegate {
public:
using StrategyOnCacheMiss = AffiliationService::StrategyOnCacheMiss;
using StrategyOnCacheMiss = AndroidAffiliationService::StrategyOnCacheMiss;
// Constructs an instance that will use |url_loader_factory| for all
// network requests, use |task_runner| for asynchronous tasks, and will rely
......@@ -75,13 +76,13 @@ class AffiliationBackend : public FacetManagerHost,
network::NetworkConnectionTracker* network_connection_tracker,
const base::FilePath& db_path);
// Implementations for methods of the same name in AffiliationService. They
// are not documented here again. See android_affiliation_service.h for
// Implementations for methods of the same name in AndroidAffiliationService.
// They are not documented here again. See android_affiliation_service.h for
// details:
void GetAffiliationsAndBranding(
const FacetURI& facet_uri,
StrategyOnCacheMiss cache_miss_strategy,
AffiliationService::ResultCallback callback,
AndroidAffiliationService::ResultCallback callback,
const scoped_refptr<base::TaskRunner>& callback_task_runner);
void Prefetch(const FacetURI& facet_uri, const base::Time& keep_fresh_until);
void CancelPrefetch(const FacetURI& facet_uri,
......
......@@ -19,11 +19,11 @@
namespace password_manager {
AffiliationService::AffiliationService(
AndroidAffiliationService::AndroidAffiliationService(
scoped_refptr<base::SequencedTaskRunner> backend_task_runner)
: backend_(nullptr), backend_task_runner_(backend_task_runner) {}
AffiliationService::~AffiliationService() {
AndroidAffiliationService::~AndroidAffiliationService() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (backend_) {
backend_task_runner_->DeleteSoon(FROM_HERE, backend_);
......@@ -31,7 +31,7 @@ AffiliationService::~AffiliationService() {
}
}
void AffiliationService::Initialize(
void AndroidAffiliationService::Initialize(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
network::NetworkConnectionTracker* network_connection_tracker,
const base::FilePath& db_path) {
......@@ -48,7 +48,7 @@ void AffiliationService::Initialize(
base::Unretained(network_connection_tracker), db_path));
}
void AffiliationService::GetAffiliationsAndBranding(
void AndroidAffiliationService::GetAffiliationsAndBranding(
const FacetURI& facet_uri,
StrategyOnCacheMiss cache_miss_strategy,
ResultCallback result_callback) {
......@@ -61,8 +61,8 @@ void AffiliationService::GetAffiliationsAndBranding(
base::SequencedTaskRunnerHandle::Get()));
}
void AffiliationService::Prefetch(const FacetURI& facet_uri,
const base::Time& keep_fresh_until) {
void AndroidAffiliationService::Prefetch(const FacetURI& facet_uri,
const base::Time& keep_fresh_until) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(backend_);
backend_task_runner_->PostTask(
......@@ -71,8 +71,9 @@ void AffiliationService::Prefetch(const FacetURI& facet_uri,
facet_uri, keep_fresh_until));
}
void AffiliationService::CancelPrefetch(const FacetURI& facet_uri,
const base::Time& keep_fresh_until) {
void AndroidAffiliationService::CancelPrefetch(
const FacetURI& facet_uri,
const base::Time& keep_fresh_until) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(backend_);
backend_task_runner_->PostTask(
......@@ -81,7 +82,8 @@ void AffiliationService::CancelPrefetch(const FacetURI& facet_uri,
base::Unretained(backend_), facet_uri, keep_fresh_until));
}
void AffiliationService::TrimCacheForFacetURI(const FacetURI& facet_uri) {
void AndroidAffiliationService::TrimCacheForFacetURI(
const FacetURI& facet_uri) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(backend_);
backend_task_runner_->PostTask(
......
......@@ -62,7 +62,7 @@ class AffiliationBackend;
// class ExampleAffiliatedCredentialFiller
// : public base::SupportsWeakPtr<...> {
// public:
// ExampleAffiliatedCredentialFiller(AffiliationService* service,
// ExampleAffiliatedCredentialFiller(AndroidAffiliationService* service,
// const FacetURI& y)
// : service_(service), y_(y) {
// cancel_handle_ = service_->Prefetch(y_, base::Time::Max());
......@@ -86,11 +86,11 @@ class AffiliationBackend;
// }
//
// private:
// AffiliationService* service_;
// AndroidAffiliationService* service_;
// const FacetURI& y_;
// CancelPrefetchingHandle cancel_handle_;
// };
class AffiliationService : public KeyedService {
class AndroidAffiliationService : public KeyedService {
public:
using ResultCallback =
base::OnceCallback<void(const AffiliatedFacets& /* results */,
......@@ -101,9 +101,9 @@ class AffiliationService : public KeyedService {
// The |backend_task_runner| should be a task runner corresponding to a thread
// that can take blocking I/O, and is normally Chrome's DB thread.
explicit AffiliationService(
explicit AndroidAffiliationService(
scoped_refptr<base::SequencedTaskRunner> backend_task_runner);
~AffiliationService() override;
~AndroidAffiliationService() override;
// Initializes the service by creating its backend and transferring it to the
// thread corresponding to |backend_task_runner_|.
......@@ -153,18 +153,18 @@ class AffiliationService : public KeyedService {
virtual void TrimCacheForFacetURI(const FacetURI& facet_uri);
private:
// The backend, owned by this AffiliationService instance, but living on the
// DB thread. It will be deleted asynchronously during shutdown on the DB
// thread, so it will outlive |this| along with all its in-flight tasks.
// The backend, owned by this AndroidAffiliationService instance, but living
// on the DB thread. It will be deleted asynchronously during shutdown on the
// DB thread, so it will outlive |this| along with all its in-flight tasks.
AffiliationBackend* backend_;
// TaskRunner to be used to run the |backend_|.
scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<AffiliationService> weak_ptr_factory_{this};
base::WeakPtrFactory<AndroidAffiliationService> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(AffiliationService);
DISALLOW_COPY_AND_ASSIGN(AndroidAffiliationService);
};
} // namespace password_manager
......
......@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Note: This test focuses on functionality implemented in AffiliationService
// itself. More thorough The AffiliationBackend is tested in-depth separarately.
// Note: This test focuses on functionality implemented in
// AndroidAffiliationService itself. More thorough The AffiliationBackend is
// tested in-depth separarately.
#include "components/password_manager/core/browser/android_affiliation/android_affiliation_service.h"
......@@ -31,7 +32,7 @@ namespace password_manager {
namespace {
using StrategyOnCacheMiss = AffiliationService::StrategyOnCacheMiss;
using StrategyOnCacheMiss = AndroidAffiliationService::StrategyOnCacheMiss;
const char kTestFacetURIAlpha1[] = "https://one.alpha.example.com";
const char kTestFacetURIAlpha2[] = "https://two.alpha.example.com";
......@@ -48,14 +49,14 @@ AffiliatedFacets GetTestEquivalenceClassAlpha() {
} // namespace
class AffiliationServiceTest : public testing::Test {
class AndroidAffiliationServiceTest : public testing::Test {
public:
AffiliationServiceTest() = default;
AndroidAffiliationServiceTest() = default;
protected:
void DestroyService() { service_.reset(); }
AffiliationService* service() { return service_.get(); }
AndroidAffiliationService* service() { return service_.get(); }
MockAffiliationConsumer* mock_consumer() { return &mock_consumer_; }
base::TestMockTimeTaskRunner* background_task_runner() {
......@@ -77,7 +78,8 @@ class AffiliationServiceTest : public testing::Test {
network::TestNetworkConnectionTracker::GetInstance();
network_connection_tracker->SetConnectionType(
network::mojom::ConnectionType::CONNECTION_ETHERNET);
service_ = std::make_unique<AffiliationService>(background_task_runner());
service_ =
std::make_unique<AndroidAffiliationService>(background_task_runner());
service_->Initialize(test_shared_loader_factory_,
network_connection_tracker, database_path);
// Note: the background task runner is purposely not pumped here, so that
......@@ -104,12 +106,12 @@ class AffiliationServiceTest : public testing::Test {
ScopedFakeAffiliationAPI fake_affiliation_api_;
MockAffiliationConsumer mock_consumer_;
std::unique_ptr<AffiliationService> service_;
std::unique_ptr<AndroidAffiliationService> service_;
DISALLOW_COPY_AND_ASSIGN(AffiliationServiceTest);
DISALLOW_COPY_AND_ASSIGN(AndroidAffiliationServiceTest);
};
TEST_F(AffiliationServiceTest, GetAffiliationsAndBranding) {
TEST_F(AndroidAffiliationServiceTest, GetAffiliationsAndBranding) {
// The first request allows on-demand fetching, and should trigger a fetch.
// Then, it should succeed after the fetch is complete.
service()->GetAffiliationsAndBranding(
......@@ -157,7 +159,7 @@ TEST_F(AffiliationServiceTest, GetAffiliationsAndBranding) {
testing::Mock::VerifyAndClearExpectations(mock_consumer());
}
TEST_F(AffiliationServiceTest, ShutdownWhileTasksArePosted) {
TEST_F(AndroidAffiliationServiceTest, ShutdownWhileTasksArePosted) {
service()->GetAffiliationsAndBranding(
FacetURI::FromCanonicalSpec(kTestFacetURIAlpha1),
StrategyOnCacheMiss::FETCH_OVER_NETWORK,
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Note: Read the class comment of AffiliationService for the definition of the
// terms used below.
// Note: Read the class comment of AndroidAffiliationService for the definition
// of the terms used below.
//
// On-demand fetching strategy
//
......@@ -89,7 +89,7 @@ static_assert(
// Encapsulates the details of a pending GetAffiliationsAndBranding() request.
struct FacetManager::RequestInfo {
AffiliationService::ResultCallback callback;
AndroidAffiliationService::ResultCallback callback;
scoped_refptr<base::TaskRunner> callback_task_runner;
};
......@@ -112,7 +112,7 @@ FacetManager::~FacetManager() {
void FacetManager::GetAffiliationsAndBranding(
StrategyOnCacheMiss cache_miss_strategy,
AffiliationService::ResultCallback callback,
AndroidAffiliationService::ResultCallback callback,
const scoped_refptr<base::TaskRunner>& callback_task_runner) {
RequestInfo request_info;
request_info.callback = std::move(callback);
......
......@@ -29,7 +29,7 @@ class FacetManagerHost;
// interface to provide shared functionality needed by all FacetManagers.
class FacetManager {
public:
using StrategyOnCacheMiss = AffiliationService::StrategyOnCacheMiss;
using StrategyOnCacheMiss = AndroidAffiliationService::StrategyOnCacheMiss;
// Both the |backend| and |clock| must outlive this object.
FacetManager(const FacetURI& facet_uri,
......@@ -37,11 +37,12 @@ class FacetManager {
base::Clock* clock);
~FacetManager();
// Facet-specific implementations for methods in AffiliationService of the
// same name. See documentation in android_affiliation_service.h for details:
// Facet-specific implementations for methods in AndroidAffiliationService of
// the same name. See documentation in android_affiliation_service.h for
// details:
void GetAffiliationsAndBranding(
StrategyOnCacheMiss cache_miss_strategy,
AffiliationService::ResultCallback callback,
AndroidAffiliationService::ResultCallback callback,
const scoped_refptr<base::TaskRunner>& callback_task_runner);
void Prefetch(const base::Time& keep_fresh_until);
void CancelPrefetch(const base::Time& keep_fresh_until);
......
......@@ -27,7 +27,7 @@ void MockAffiliationConsumer::ExpectFailure() {
.Times(1);
}
AffiliationService::ResultCallback
AndroidAffiliationService::ResultCallback
MockAffiliationConsumer::GetResultCallback() {
return base::BindOnce(&MockAffiliationConsumer::OnResultCallback,
base::Unretained(this));
......
......@@ -12,7 +12,7 @@
namespace password_manager {
// A mock consumer of AffiliationService::GetAffiliationsAndBranding().
// A mock consumer of AndroidAffiliationService::GetAffiliationsAndBranding().
class MockAffiliationConsumer {
public:
MockAffiliationConsumer();
......@@ -26,7 +26,7 @@ class MockAffiliationConsumer {
// will indicate a failed lookup.
void ExpectFailure();
AffiliationService::ResultCallback GetResultCallback();
AndroidAffiliationService::ResultCallback GetResultCallback();
private:
MOCK_METHOD2(OnResultCallback, void(const AffiliatedFacets&, bool));
......
......@@ -34,21 +34,22 @@ void ActivateAffiliationBasedMatching(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
network::NetworkConnectionTracker* network_connection_tracker,
const base::FilePath& db_path) {
// Subsequent instances of the AffiliationService must use the same sequenced
// task runner for their backends. This guarantees that the backend of the
// first instance will have closed the affiliation database before the second
// instance attempts to open it again. See: https://crbug.com/786157.
// Subsequent instances of the AndroidAffiliationService must use the same
// sequenced task runner for their backends. This guarantees that the backend
// of the first instance will have closed the affiliation database before the
// second instance attempts to open it again. See: https://crbug.com/786157.
//
// Task priority is USER_VISIBLE, because AffiliationService-related tasks
// block obtaining credentials from PasswordStore, hence password autofill.
// Task priority is USER_VISIBLE, because AndroidAffiliationService-related
// tasks block obtaining credentials from PasswordStore, hence password
// autofill.
static auto backend_task_runner = base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE});
// The PasswordStore is so far the only consumer of the AffiliationService,
// therefore the service is owned by the AffiliatedMatchHelper, which in turn
// is owned by the PasswordStore.
std::unique_ptr<AffiliationService> affiliation_service(
new AffiliationService(backend_task_runner));
// The PasswordStore is so far the only consumer of the
// AndroidAffiliationService, therefore the service is owned by the
// AffiliatedMatchHelper, which in turn is owned by the PasswordStore.
std::unique_ptr<AndroidAffiliationService> affiliation_service(
new AndroidAffiliationService(backend_task_runner));
affiliation_service->Initialize(std::move(url_loader_factory),
network_connection_tracker, db_path);
std::unique_ptr<AffiliatedMatchHelper> affiliated_match_helper(
......
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