OLD | NEW |
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_AFFILIATION_SERVICE_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_SERVICE_H_ |
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_SERVICE_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // private: | 85 // private: |
86 // AffiliationService* service_; | 86 // AffiliationService* service_; |
87 // const FacetURI& y_; | 87 // const FacetURI& y_; |
88 // CancelPrefetchingHandle cancel_handle_; | 88 // CancelPrefetchingHandle cancel_handle_; |
89 // }; | 89 // }; |
90 class AffiliationService : public KeyedService { | 90 class AffiliationService : public KeyedService { |
91 public: | 91 public: |
92 typedef base::Callback<void(const AffiliatedFacets& /* results */, | 92 typedef base::Callback<void(const AffiliatedFacets& /* results */, |
93 bool /* success */)> ResultCallback; | 93 bool /* success */)> ResultCallback; |
94 | 94 |
95 typedef base::Closure CancelPrefetchingHandle; | |
96 | |
97 // The |backend_task_runner| should be a task runner corresponding to a thread | 95 // The |backend_task_runner| should be a task runner corresponding to a thread |
98 // that can take blocking I/O, and is normally Chrome's DB thread. | 96 // that can take blocking I/O, and is normally Chrome's DB thread. |
99 AffiliationService( | 97 AffiliationService( |
100 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner); | 98 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner); |
101 ~AffiliationService() override; | 99 ~AffiliationService() override; |
102 | 100 |
103 // Initializes the service by creating its backend and transferring it to the | 101 // Initializes the service by creating its backend and transferring it to the |
104 // thread corresponding to |backend_task_runner_|. | 102 // thread corresponding to |backend_task_runner_|. |
105 void Initialize(net::URLRequestContextGetter* request_context_getter, | 103 void Initialize(net::URLRequestContextGetter* request_context_getter, |
106 const base::FilePath& db_path); | 104 const base::FilePath& db_path); |
107 | 105 |
108 // Looks up facets affiliated with the facet identified by |facet_uri|. If | 106 // Looks up facets affiliated with the facet identified by |facet_uri|. If |
109 // |cached_only| is true, the results will be based solely on prefetched | 107 // |cached_only| is true, the results will be based solely on prefetched |
110 // information already stored in the cache. Otherwise, on-demand network | 108 // information already stored in the cache. Otherwise, on-demand network |
111 // requests will be issued if there is no up-to-date data in the cache. | 109 // requests will be issued if there is no up-to-date data in the cache. |
112 void GetAffiliations(const FacetURI& facet_uri, | 110 void GetAffiliations(const FacetURI& facet_uri, |
113 bool cached_only, | 111 bool cached_only, |
114 const ResultCallback& result_callback); | 112 const ResultCallback& result_callback); |
115 | 113 |
116 // Prefetches affiliation information for the facet identified by |facet_uri|, | 114 // Prefetches affiliation information for the facet identified by |facet_uri|, |
117 // and keeps the information fresh by periodic re-fetches (as needed) until at | 115 // and keeps the information fresh by periodic re-fetches (as needed) until |
118 // least |keep_fresh_until|, the returned cancel handle is called, or until | 116 // the clock strikes |keep_fresh_until| (exclusive), until a matching call to |
119 // Chrome is shut down, whichever is sooner. It is a supported use-case to | 117 // CancelPrefetch(), or until Chrome is shut down, whichever is sooner. It is |
120 // pass base::Time::Max() as |keep_fresh_until|. | 118 // a supported use-case to pass base::Time::Max() as |keep_fresh_until|. |
121 // | 119 // |
122 // Canceling can be useful when a password is deleted, so that resources are | 120 // Canceling can be useful when a password is deleted, so that resources are |
123 // no longer wasted on repeatedly refreshing affiliation information. Note | 121 // no longer wasted on repeatedly refreshing affiliation information. Note |
124 // that canceling will not blow away data already stored in the cache unless | 122 // that canceling will not blow away data already stored in the cache unless |
125 // it becomes stale. | 123 // it becomes stale. |
126 CancelPrefetchingHandle Prefetch(const FacetURI& facet_uri, | 124 void Prefetch(const FacetURI& facet_uri, const base::Time& keep_fresh_until); |
127 const base::Time& keep_fresh_until); | 125 |
| 126 // Cancels the corresponding prefetch command, i.e., the one issued for the |
| 127 // same |facet_uri| and with the same |keep_fresh_until|. |
| 128 void CancelPrefetch(const FacetURI& facet_uri, |
| 129 const base::Time& keep_fresh_until); |
128 | 130 |
129 // Wipes results of on-demand fetches and expired prefetches from the cache, | 131 // Wipes results of on-demand fetches and expired prefetches from the cache, |
130 // but retains information corresponding to facets that are being kept fresh. | 132 // but retains information corresponding to facets that are being kept fresh. |
131 // As no required data is deleted, there will be no network requests directly | 133 // As no required data is deleted, there will be no network requests directly |
132 // triggered by this call. | 134 // triggered by this call. |
133 void TrimCache(); | 135 void TrimCache(); |
134 | 136 |
135 private: | 137 private: |
136 // Cancels the corresponding prefetch command, i.e., the one issued for the | |
137 // same |facet_uri| and with the same |keep_fresh_until|. | |
138 void CancelPrefetch(const FacetURI& facet_uri, const base::Time&); | |
139 | |
140 // The backend, owned by this AffiliationService instance, but living on the | 138 // The backend, owned by this AffiliationService instance, but living on the |
141 // DB thread. It will be deleted asynchronously during shutdown on the DB | 139 // DB thread. It will be deleted asynchronously during shutdown on the DB |
142 // thread, so it will outlive |this| along with all its in-flight tasks. | 140 // thread, so it will outlive |this| along with all its in-flight tasks. |
143 AffiliationBackend* backend_; | 141 AffiliationBackend* backend_; |
144 | 142 |
145 // TaskRunner to be used to run the |backend_| (usually the DB thread). | 143 // TaskRunner to be used to run the |backend_| (usually the DB thread). |
146 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_; | 144 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_; |
147 | 145 |
148 base::ThreadChecker thread_checker_; | 146 base::ThreadChecker thread_checker_; |
149 base::WeakPtrFactory<AffiliationService> weak_ptr_factory_; | 147 base::WeakPtrFactory<AffiliationService> weak_ptr_factory_; |
150 | 148 |
151 DISALLOW_COPY_AND_ASSIGN(AffiliationService); | 149 DISALLOW_COPY_AND_ASSIGN(AffiliationService); |
152 }; | 150 }; |
153 | 151 |
154 } // namespace password_manager | 152 } // namespace password_manager |
155 | 153 |
156 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_SERVICE_H_ | 154 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_SERVICE_H_ |
OLD | NEW |