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

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

Issue 2949573002: Move the files related to Android<->Web credentials to a separate folder. (Closed)
Patch Set: Remove includes Created 3 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_
7
8 #include <set>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h"
14 #include "components/password_manager/core/browser/affiliation_service.h"
15 #include "components/password_manager/core/browser/affiliation_utils.h"
16
17 namespace base {
18 class Clock;
19 class TaskRunner;
20 } // namespace base
21
22 namespace password_manager {
23
24 class FacetManagerHost;
25
26 // Encapsulates the state and logic required for handling affiliation requests
27 // concerning a single facet. The AffiliationBackend owns one instance for each
28 // facet that requires attention, and it itself implements the FacetManagerHost
29 // interface to provide shared functionality needed by all FacetManagers.
30 class FacetManager {
31 public:
32 using StrategyOnCacheMiss = AffiliationService::StrategyOnCacheMiss;
33
34 // Both the |backend| and |clock| must outlive this object.
35 FacetManager(const FacetURI& facet_uri,
36 FacetManagerHost* backend,
37 base::Clock* clock);
38 ~FacetManager();
39
40 // Facet-specific implementations for methods in AffiliationService of the
41 // same name. See documentation in affiliation_service.h for details:
42 void GetAffiliations(
43 StrategyOnCacheMiss cache_miss_strategy,
44 const AffiliationService::ResultCallback& callback,
45 const scoped_refptr<base::TaskRunner>& callback_task_runner);
46 void Prefetch(const base::Time& keep_fresh_until);
47 void CancelPrefetch(const base::Time& keep_fresh_until);
48
49 // Called when |affiliation| information regarding this facet has just been
50 // fetched from the Affiliation API.
51 void OnFetchSucceeded(const AffiliatedFacetsWithUpdateTime& affiliation);
52
53 // Called by the backend when the time specified in RequestNotificationAtTime
54 // has come to pass, so that |this| can perform delayed administrative tasks.
55 void NotifyAtRequestedTime();
56
57 // Returns whether this instance has becomes redundant, that is, it has no
58 // more meaningful state than a newly created instance would have.
59 bool CanBeDiscarded() const;
60
61 // Returns whether or not cached data for this facet can be discarded without
62 // harm when trimming the database.
63 bool CanCachedDataBeDiscarded() const;
64
65 // Returns whether or not affiliation information relating to this facet needs
66 // to be fetched right now.
67 bool DoesRequireFetch() const;
68
69 // The members below are made public for the sake of tests.
70
71 // Returns whether or not cached data for this facet is fresh (not stale).
72 bool IsCachedDataFresh() const;
73
74 // Returns whether or not cached data for this facet is near-stale or stale.
75 bool IsCachedDataNearStale() const;
76
77 // The duration after which cached affiliation data is considered near-stale.
78 static const int kCacheSoftExpiryInHours;
79
80 // The duration after which cached affiliation data is considered stale.
81 static const int kCacheHardExpiryInHours;
82
83 private:
84 struct RequestInfo;
85
86 // Returns the time when the cached data for this facet will become stale.
87 // The data is considered stale with the returned time value inclusive.
88 base::Time GetCacheHardExpiryTime() const;
89
90 // Returns the time when cached data for this facet becomes near-stale.
91 // The data is considered near-stale with the returned time value inclusive.
92 base::Time GetCacheSoftExpiryTime() const;
93
94 // Returns the maximum of |keep_fresh_thresholds_|, or the NULL time if the
95 // set is empty.
96 base::Time GetMaximumKeepFreshUntilThreshold() const;
97
98 // Returns the next time affiliation data for this facet needs to be fetched
99 // due to active prefetch requests, or base::Time::Max() if not at all.
100 base::Time GetNextRequiredFetchTimeDueToPrefetch() const;
101
102 // Posts the callback of the request described by |request_info| with success.
103 static void ServeRequestWithSuccess(const RequestInfo& request_info,
104 const AffiliatedFacets& affiliation);
105
106 // Posts the callback of the request described by |request_info| with failure.
107 static void ServeRequestWithFailure(const RequestInfo& request_info);
108
109 FacetURI facet_uri_;
110 FacetManagerHost* backend_;
111 base::Clock* clock_;
112
113 // The last time affiliation information was fetched for this facet, i.e. the
114 // freshness of the data in the cache. If there is no corresponding data in
115 // the database, this will contain the NULL time. Otherwise, the update time
116 // in the database should match this value; it is stored to reduce disk I/O.
117 base::Time last_update_time_;
118
119 // Contains information about the GetAffiliations() requests that are waiting
120 // for the result of looking up this facet.
121 std::vector<RequestInfo> pending_requests_;
122
123 // Keeps track of |keep_fresh_until| thresholds corresponding to Prefetch()
124 // requests for this facet. Affiliation information for this facet must be
125 // kept fresh by periodic refetches until at least the maximum time in this
126 // set (exclusive).
127 //
128 // This is not a single timestamp but rather a multiset so that cancellation
129 // of individual prefetches can be supported even if there are two requests
130 // with the same |keep_fresh_until| threshold.
131 std::multiset<base::Time> keep_fresh_until_thresholds_;
132
133 DISALLOW_COPY_AND_ASSIGN(FacetManager);
134 };
135
136 } // namespace password_manager
137 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_FACET_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698