Chromium Code Reviews| Index: components/password_manager/core/browser/facet_manager.h |
| diff --git a/components/password_manager/core/browser/facet_manager.h b/components/password_manager/core/browser/facet_manager.h |
| index f27e9f23ae97507f26d6266888719a903db0b4e5..e3a76a9a999a66ff7e7ca1992cad73e1fe0a49ec 100644 |
| --- a/components/password_manager/core/browser/facet_manager.h |
| +++ b/components/password_manager/core/browser/facet_manager.h |
| @@ -5,6 +5,9 @@ |
| #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_ |
| #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_ |
| +#include <set> |
| +#include <vector> |
| + |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/time/time.h" |
| @@ -12,6 +15,7 @@ |
| #include "components/password_manager/core/browser/affiliation_utils.h" |
| namespace base { |
| +class Clock; |
| class TaskRunner; |
| } // namespace base |
| @@ -20,20 +24,35 @@ namespace password_manager { |
| class FacetManagerHost; |
| // Part of AffiliationBackend that encapsulates the state and logic required for |
| -// handling GetAffiliations() requests in regard to a single facet. |
| +// handling requests in regard to a single facet. |
| // |
| // In contrast, the AffiliationBackend itself implements the FacetManagerHost |
| // interface to provide shared functionality needed by all FacetManagers. |
| class FacetManager { |
| public: |
| - // The |backend| must outlive this object. |
| - FacetManager(FacetManagerHost* backend, const FacetURI& facet_uri); |
| + // Both the |backend| and |clock| must outlive this object. |
| + FacetManager(const FacetURI& facet_uri, |
| + FacetManagerHost* backend, |
| + base::Clock* clock); |
| ~FacetManager(); |
| + // Facet-specific implementations for methods in AffiliationService of the |
| + // same name. See documentation in affiliation_service.h for details: |
| + void GetAffiliations( |
| + bool cached_only, |
| + const AffiliationService::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); |
| + |
| // Called when |affiliation| information regarding this facet has just been |
| // fetched from the Affiliation API. |
| void OnFetchSucceeded(const AffiliatedFacetsWithUpdateTime& affiliation); |
| + // Called by the backend when the time specified in RequestNotificationAtTime |
| + // has come to pass, so that |this| can perform delayed administrative tasks. |
| + void NotifyAtRequestedTime(); |
| + |
| // Returns whether this instance has becomes redundant, that is, it has no |
| // more meaningful state than a newly created instance would have. |
| bool CanBeDiscarded() const; |
| @@ -42,23 +61,28 @@ class FacetManager { |
| // to be fetched right now. |
| bool DoesRequireFetch() const; |
| - // Facet-specific implementations for methods in AffiliationService of the |
| - // same name. See documentation in affiliation_service.h for details: |
| - void GetAffiliations( |
| - bool cached_only, |
| - const AffiliationService::ResultCallback& callback, |
| - const scoped_refptr<base::TaskRunner>& callback_task_runner); |
| - |
| private: |
| struct RequestInfo; |
| - // Returns the time when cached data for this facet will expire. The data is |
| - // already considered expired at the returned microsecond. |
| - base::Time GetCacheExpirationTime() const; |
| + // Returns the time when the cached data for this facet will become stale. |
| + // The data is considered stale already in the time quantum. |
|
Mike West
2015/02/25 10:33:06
What is a "time quantum"?
engedy
2015/03/10 11:01:00
That was a typo. Rephrased entirely.
|
| + base::Time GetCacheHardExpiryTime() const; |
| + |
| + // Returns the time when cached data for this facet becomes near-stale. |
| + // The data is considered near-stale already in the returned time quantum. |
| + base::Time GetCacheSoftExpiryTime() const; |
| - // Returns whether or not the cache has fresh data for this facet. |
| + // Returns whether or not cached data for this facet is fresh (not stale). |
| bool IsCachedDataFresh() const; |
|
Mike West
2015/02/25 10:33:06
It might be worthwhile to add a public accessor fo
engedy
2015/03/10 11:01:00
Done.
|
| + // Returns the maximum of |keep_fresh_untils_|, or the NULL time if the set is |
| + // empty. |
| + base::Time GetMaximumKeepFreshUntil() const; |
| + |
| + // Returns the next time affiliation data for this facet needs to be fetched |
| + // due to active prefetch requests, or base::Time::Max() if not at all. |
| + base::Time GetNextRequiredFetchTimeDueToPrefetch() const; |
| + |
| // Posts the callback of the request described by |request_info| with success. |
| static void ServeRequestWithSuccess(const RequestInfo& request_info, |
| const AffiliatedFacets& affiliation); |
| @@ -66,8 +90,9 @@ class FacetManager { |
| // Posts the callback of the request described by |request_info| with failure. |
| static void ServeRequestWithFailure(const RequestInfo& request_info); |
| - FacetManagerHost* backend_; |
| FacetURI facet_uri_; |
| + FacetManagerHost* backend_; |
| + base::Clock* clock_; |
| // The last time affiliation information was fetched for this facet, i.e. the |
| // freshness of the data in the cache. If there is no corresponding data in |
| @@ -79,6 +104,16 @@ class FacetManager { |
| // for the result of looking up this facet. |
| std::vector<RequestInfo> pending_requests_; |
| + // Keeps track of |keep_fresh_until| thresholds corresponding to Prefetch() |
| + // requests for this facet. Affiliation information for this facet must be |
| + // kept fresh by periodic refetches until at least the maximum time in this |
| + // set (exclusive). |
| + // |
| + // This is not a single timestamp but rather a multiset so that cancellation |
| + // of individual prefetches can be supported even if there are two requests |
| + // with the same |keep_fresh_until| threshold. |
| + std::multiset<base::Time> keep_fresh_untils_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(FacetManager); |
| }; |