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

Side by Side Diff: components/password_manager/core/browser/facet_manager.h

Issue 947563002: Add prefetch support to AffiliationBackend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment phrasing. Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_ 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_ 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_
7 7
8 #include <set>
9 #include <vector>
10
8 #include "base/macros.h" 11 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
10 #include "base/time/time.h" 13 #include "base/time/time.h"
11 #include "components/password_manager/core/browser/affiliation_service.h" 14 #include "components/password_manager/core/browser/affiliation_service.h"
12 #include "components/password_manager/core/browser/affiliation_utils.h" 15 #include "components/password_manager/core/browser/affiliation_utils.h"
13 16
14 namespace base { 17 namespace base {
18 class Clock;
15 class TaskRunner; 19 class TaskRunner;
16 } // namespace base 20 } // namespace base
17 21
18 namespace password_manager { 22 namespace password_manager {
19 23
20 class FacetManagerHost; 24 class FacetManagerHost;
21 25
22 // Part of AffiliationBackend that encapsulates the state and logic required for 26 // Part of AffiliationBackend that encapsulates the state and logic required for
23 // handling GetAffiliations() requests in regard to a single facet. 27 // handling requests in regard to a single facet.
24 // 28 //
25 // In contrast, the AffiliationBackend itself implements the FacetManagerHost 29 // In contrast, the AffiliationBackend itself implements the FacetManagerHost
26 // interface to provide shared functionality needed by all FacetManagers. 30 // interface to provide shared functionality needed by all FacetManagers.
27 class FacetManager { 31 class FacetManager {
28 public: 32 public:
29 // The |backend| must outlive this object. 33 // Both the |backend| and |clock| must outlive this object.
30 FacetManager(FacetManagerHost* backend, const FacetURI& facet_uri); 34 FacetManager(const FacetURI& facet_uri,
35 FacetManagerHost* backend,
36 base::Clock* clock);
31 ~FacetManager(); 37 ~FacetManager();
32 38
39 // Facet-specific implementations for methods in AffiliationService of the
40 // same name. See documentation in affiliation_service.h for details:
41 void GetAffiliations(
42 bool cached_only,
43 const AffiliationService::ResultCallback& callback,
44 const scoped_refptr<base::TaskRunner>& callback_task_runner);
45 void Prefetch(const base::Time& keep_fresh_until);
46 void CancelPrefetch(const base::Time& keep_fresh_until);
47
33 // Called when |affiliation| information regarding this facet has just been 48 // Called when |affiliation| information regarding this facet has just been
34 // fetched from the Affiliation API. 49 // fetched from the Affiliation API.
35 void OnFetchSucceeded(const AffiliatedFacetsWithUpdateTime& affiliation); 50 void OnFetchSucceeded(const AffiliatedFacetsWithUpdateTime& affiliation);
36 51
52 // Called by the backend when the time specified in RequestNotificationAtTime
53 // has come to pass, so that |this| can perform delayed administrative tasks.
54 void NotifyAtRequestedTime();
55
37 // Returns whether this instance has becomes redundant, that is, it has no 56 // Returns whether this instance has becomes redundant, that is, it has no
38 // more meaningful state than a newly created instance would have. 57 // more meaningful state than a newly created instance would have.
39 bool CanBeDiscarded() const; 58 bool CanBeDiscarded() const;
40 59
41 // Returns whether or not affiliation information relating to this facet needs 60 // Returns whether or not affiliation information relating to this facet needs
42 // to be fetched right now. 61 // to be fetched right now.
43 bool DoesRequireFetch() const; 62 bool DoesRequireFetch() const;
44 63
45 // Facet-specific implementations for methods in AffiliationService of the
46 // same name. See documentation in affiliation_service.h for details:
47 void GetAffiliations(
48 bool cached_only,
49 const AffiliationService::ResultCallback& callback,
50 const scoped_refptr<base::TaskRunner>& callback_task_runner);
51
52 private: 64 private:
53 struct RequestInfo; 65 struct RequestInfo;
54 66
55 // Returns the time when cached data for this facet will expire. The data is 67 // Returns the time when the cached data for this facet will become stale.
56 // already considered expired at the returned microsecond. 68 // 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.
57 base::Time GetCacheExpirationTime() const; 69 base::Time GetCacheHardExpiryTime() const;
58 70
59 // Returns whether or not the cache has fresh data for this facet. 71 // Returns the time when cached data for this facet becomes near-stale.
72 // The data is considered near-stale already in the returned time quantum.
73 base::Time GetCacheSoftExpiryTime() const;
74
75 // Returns whether or not cached data for this facet is fresh (not stale).
60 bool IsCachedDataFresh() const; 76 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.
61 77
78 // Returns the maximum of |keep_fresh_untils_|, or the NULL time if the set is
79 // empty.
80 base::Time GetMaximumKeepFreshUntil() const;
81
82 // Returns the next time affiliation data for this facet needs to be fetched
83 // due to active prefetch requests, or base::Time::Max() if not at all.
84 base::Time GetNextRequiredFetchTimeDueToPrefetch() const;
85
62 // Posts the callback of the request described by |request_info| with success. 86 // Posts the callback of the request described by |request_info| with success.
63 static void ServeRequestWithSuccess(const RequestInfo& request_info, 87 static void ServeRequestWithSuccess(const RequestInfo& request_info,
64 const AffiliatedFacets& affiliation); 88 const AffiliatedFacets& affiliation);
65 89
66 // Posts the callback of the request described by |request_info| with failure. 90 // Posts the callback of the request described by |request_info| with failure.
67 static void ServeRequestWithFailure(const RequestInfo& request_info); 91 static void ServeRequestWithFailure(const RequestInfo& request_info);
68 92
93 FacetURI facet_uri_;
69 FacetManagerHost* backend_; 94 FacetManagerHost* backend_;
70 FacetURI facet_uri_; 95 base::Clock* clock_;
71 96
72 // The last time affiliation information was fetched for this facet, i.e. the 97 // The last time affiliation information was fetched for this facet, i.e. the
73 // freshness of the data in the cache. If there is no corresponding data in 98 // freshness of the data in the cache. If there is no corresponding data in
74 // the database, this will contain the NULL time. Otherwise, the update time 99 // the database, this will contain the NULL time. Otherwise, the update time
75 // in the database should match this value; it is stored to reduce disk I/O. 100 // in the database should match this value; it is stored to reduce disk I/O.
76 base::Time last_update_time_; 101 base::Time last_update_time_;
77 102
78 // Contains information about the GetAffiliations() requests that are waiting 103 // Contains information about the GetAffiliations() requests that are waiting
79 // for the result of looking up this facet. 104 // for the result of looking up this facet.
80 std::vector<RequestInfo> pending_requests_; 105 std::vector<RequestInfo> pending_requests_;
81 106
107 // Keeps track of |keep_fresh_until| thresholds corresponding to Prefetch()
108 // requests for this facet. Affiliation information for this facet must be
109 // kept fresh by periodic refetches until at least the maximum time in this
110 // set (exclusive).
111 //
112 // This is not a single timestamp but rather a multiset so that cancellation
113 // of individual prefetches can be supported even if there are two requests
114 // with the same |keep_fresh_until| threshold.
115 std::multiset<base::Time> keep_fresh_untils_;
116
82 DISALLOW_COPY_AND_ASSIGN(FacetManager); 117 DISALLOW_COPY_AND_ASSIGN(FacetManager);
83 }; 118 };
84 119
85 } // namespace password_manager 120 } // namespace password_manager
86 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_ 121 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698