Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Unified Diff: components/password_manager/core/browser/affiliation_backend.h

Issue 1008373003: Integrate throttling logic into AffiliationBackend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comment. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/password_manager/core/browser/affiliation_backend.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/password_manager/core/browser/affiliation_backend.h
diff --git a/components/password_manager/core/browser/affiliation_backend.h b/components/password_manager/core/browser/affiliation_backend.h
index 0e1558a08a65857bd106cd1b9eb114b6c2cd503c..29fb0283faa6b32b01d2fca82c97b432302c10bd 100644
--- a/components/password_manager/core/browser/affiliation_backend.h
+++ b/components/password_manager/core/browser/affiliation_backend.h
@@ -12,6 +12,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+#include "components/password_manager/core/browser/affiliation_fetch_throttler_delegate.h"
#include "components/password_manager/core/browser/affiliation_fetcher_delegate.h"
#include "components/password_manager/core/browser/affiliation_service.h"
#include "components/password_manager/core/browser/affiliation_utils.h"
@@ -20,7 +21,9 @@
namespace base {
class Clock;
class FilePath;
+class SingleThreadTaskRunner;
class ThreadChecker;
+class TickClock;
class Time;
} // namespace base
@@ -32,6 +35,7 @@ namespace password_manager {
class AffiliationDatabase;
class AffiliationFetcher;
+class AffiliationFetchThrottler;
class FacetManager;
// The AffiliationBackend is the part of the AffiliationService that lives on a
@@ -43,15 +47,18 @@ class FacetManager;
// and then transfer it to the background thread for the rest of its life.
// Initialize() must be called already on the final (background) thread.
class AffiliationBackend : public FacetManagerHost,
- public AffiliationFetcherDelegate {
+ public AffiliationFetcherDelegate,
+ public AffiliationFetchThrottlerDelegate {
public:
// Constructs an instance that will use |request_context_getter| for all
- // network requests, and will rely on |time_source| to tell the current time,
- // which is expected to always be no less than the Unix epoch.
+ // network requests, use |task_runner| for asynchronous tasks, and will rely
+ // on |time_source| and |time_tick_source| to tell the current time/ticks.
// Construction is very cheap, expensive steps are deferred to Initialize().
AffiliationBackend(
const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
- scoped_ptr<base::Clock> time_source);
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ scoped_ptr<base::Clock> time_source,
+ scoped_ptr<base::TickClock> time_tick_source);
~AffiliationBackend() override;
// Performs the I/O-heavy part of initialization. The database used to cache
@@ -77,10 +84,6 @@ class AffiliationBackend : public FacetManagerHost,
// storing it into |facet_managers_| if it did not exist.
FacetManager* GetOrCreateFacetManager(const FacetURI& facet_uri);
- // Collects facet URIs that require fetching and issues a network request
- // against the Affiliation API to fetch corresponding affiliation information.
- void SendNetworkRequest();
-
// Scheduled by RequestNotificationAtTime() to be called back at times when a
// FacetManager needs to be notified.
void OnSendNotification(const FacetURI& facet_uri);
@@ -99,20 +102,28 @@ class AffiliationBackend : public FacetManagerHost,
void OnFetchFailed() override;
void OnMalformedResponse() override;
- // Used only for testing.
+ // AffiliationFetchThrottlerDelegate:
+ bool OnCanSendNetworkRequest() override;
+
+ // Returns the number of in-memory FacetManagers. Used only for testing.
size_t facet_manager_count_for_testing() { return facet_managers_.size(); }
+ // To be called after Initialize() to use |throttler| instead of the default
+ // one. Used only for testing.
+ void SetThrottlerForTesting(scoped_ptr<AffiliationFetchThrottler> throttler);
+
// Created in Initialize(), and ensures that all subsequent methods are called
// on the same thread.
scoped_ptr<base::ThreadChecker> thread_checker_;
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
-
- // Will always return a Now() that is strictly greater than the NULL time.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
scoped_ptr<base::Clock> clock_;
+ scoped_ptr<base::TickClock> tick_clock_;
scoped_ptr<AffiliationDatabase> cache_;
scoped_ptr<AffiliationFetcher> fetcher_;
+ scoped_ptr<AffiliationFetchThrottler> throttler_;
// Contains a FacetManager for each facet URI that need ongoing attention. To
// save memory, managers are discarded as soon as they become redundant.
« no previous file with comments | « no previous file | components/password_manager/core/browser/affiliation_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698