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

Side by Side Diff: components/precache/core/precache_fetcher.h

Issue 2335913002: Add daily quota for precache (Closed)
Patch Set: Addressed sclittle@ comments Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_PRECACHE_CORE_PRECACHE_FETCHER_H_ 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_
6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "components/precache/core/fetcher_pool.h" 21 #include "components/precache/core/fetcher_pool.h"
22 #include "components/precache/core/proto/quota.pb.h"
22 #include "net/url_request/url_fetcher.h" 23 #include "net/url_request/url_fetcher.h"
23 #include "net/url_request/url_fetcher_delegate.h" 24 #include "net/url_request/url_fetcher_delegate.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 namespace base { 27 namespace base {
27 class SingleThreadTaskRunner; 28 class SingleThreadTaskRunner;
28 } 29 }
29 30
30 namespace net { 31 namespace net {
31 class URLRequestContextGetter; 32 class URLRequestContextGetter;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // PrecacheFetcher instance. 146 // PrecacheFetcher instance.
146 void Start(); 147 void Start();
147 148
148 // Stops all precaching work. The PreacheFetcher should not be used after 149 // Stops all precaching work. The PreacheFetcher should not be used after
149 // calling this method. 150 // calling this method.
150 std::unique_ptr<PrecacheUnfinishedWork> CancelPrecaching(); 151 std::unique_ptr<PrecacheUnfinishedWork> CancelPrecaching();
151 152
152 private: 153 private:
153 friend class PrecacheFetcherTest; 154 friend class PrecacheFetcherTest;
154 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, FetcherPoolMaxLimitReached); 155 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, FetcherPoolMaxLimitReached);
156 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, DailyQuota);
155 157
156 // Notifies the precache delete that precaching is done, and report 158 // Notifies the precache delete that precaching is done, and report
157 // completion statistics. 159 // completion statistics.
158 void NotifyDone(size_t remaining_manifest_urls_to_fetch, 160 void NotifyDone(size_t remaining_manifest_urls_to_fetch,
159 size_t remaining_resource_urls_to_fetch); 161 size_t remaining_resource_urls_to_fetch);
160 162
161 // Fetches the next resource or manifest URL, if any remain. Fetching is done 163 // Fetches the next resource or manifest URL, if any remain. Fetching is done
162 // sequentially and depth-first: all resources are fetched for a manifest 164 // sequentially and depth-first: all resources are fetched for a manifest
163 // before the next manifest is fetched. This is done to limit the length of 165 // before the next manifest is fetched. This is done to limit the length of
164 // the |resource_urls_to_fetch_| list, reducing the memory usage. 166 // the |resource_urls_to_fetch_| list, reducing the memory usage.
(...skipping 18 matching lines...) Expand all
183 185
184 // Called when a resource has been fetched. 186 // Called when a resource has been fetched.
185 void OnResourceFetchComplete(const Fetcher& source); 187 void OnResourceFetchComplete(const Fetcher& source);
186 188
187 // Adds up the response sizes. 189 // Adds up the response sizes.
188 void UpdateStats(int64_t response_bytes, int64_t network_response_bytes); 190 void UpdateStats(int64_t response_bytes, int64_t network_response_bytes);
189 191
190 // Callback invoked when the manifest info for all the top hosts is retrieved. 192 // Callback invoked when the manifest info for all the top hosts is retrieved.
191 void OnManifestInfoRetrieved(std::deque<ManifestHostInfo> manifests_info); 193 void OnManifestInfoRetrieved(std::deque<ManifestHostInfo> manifests_info);
192 194
195 // Callback invoked when the quota is retrieved.
196 void OnQuotaInfoRetrieved(const PrecacheQuota& quota);
197
193 // The request context used when fetching URLs. 198 // The request context used when fetching URLs.
194 const scoped_refptr<net::URLRequestContextGetter> request_context_; 199 const scoped_refptr<net::URLRequestContextGetter> request_context_;
195 200
196 // The custom URL to use when fetching the config. If not provided, the 201 // The custom URL to use when fetching the config. If not provided, the
197 // default flag-specified URL will be used. 202 // default flag-specified URL will be used.
198 const GURL config_url_; 203 const GURL config_url_;
199 204
200 // The custom URL prefix to use when fetching manifests. If not provided, the 205 // The custom URL prefix to use when fetching manifests. If not provided, the
201 // default flag-specified prefix will be used. 206 // default flag-specified prefix will be used.
202 const std::string manifest_url_prefix_; 207 const std::string manifest_url_prefix_;
203 208
204 // PrecacheDatabase should be accessed on the DB thread. 209 // PrecacheDatabase should be accessed on the DB thread.
205 base::WeakPtr<PrecacheDatabase> precache_database_; 210 base::WeakPtr<PrecacheDatabase> precache_database_;
206 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; 211 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_;
207 212
208 // Non-owning pointer. Should not be NULL. 213 // Non-owning pointer. Should not be NULL.
209 PrecacheDelegate* precache_delegate_; 214 PrecacheDelegate* precache_delegate_;
210 215
211 std::deque<ManifestHostInfo> top_hosts_to_fetch_; 216 std::deque<ManifestHostInfo> top_hosts_to_fetch_;
212 std::deque<std::pair<GURL, std::string>> resources_to_fetch_; 217 std::deque<std::pair<GURL, std::string>> resources_to_fetch_;
213 218
214 FetcherPool<Fetcher> pool_; 219 FetcherPool<Fetcher> pool_;
215 220
216 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; 221 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_;
217 222
223 // Daily quota.
224 PrecacheQuota quota_;
225
218 // The fieldtrial experiment ID. 226 // The fieldtrial experiment ID.
219 uint32_t experiment_id_; 227 uint32_t experiment_id_;
220 228
221 DISALLOW_COPY_AND_ASSIGN(PrecacheFetcher); 229 DISALLOW_COPY_AND_ASSIGN(PrecacheFetcher);
222 }; 230 };
223 231
224 // Class that fetches a URL, and runs the specified callback when the fetch is 232 // Class that fetches a URL, and runs the specified callback when the fetch is
225 // complete. This class exists so that a different method can be run in 233 // complete. This class exists so that a different method can be run in
226 // response to different kinds of fetches, e.g. OnConfigFetchComplete when 234 // response to different kinds of fetches, e.g. OnConfigFetchComplete when
227 // configuration settings are fetched, OnManifestFetchComplete when a manifest 235 // configuration settings are fetched, OnManifestFetchComplete when a manifest
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 int64_t response_bytes_; 294 int64_t response_bytes_;
287 int64_t network_response_bytes_; 295 int64_t network_response_bytes_;
288 bool was_cached_; 296 bool was_cached_;
289 297
290 DISALLOW_COPY_AND_ASSIGN(Fetcher); 298 DISALLOW_COPY_AND_ASSIGN(Fetcher);
291 }; 299 };
292 300
293 } // namespace precache 301 } // namespace precache
294 302
295 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ 303 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698