OLD | NEW |
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 <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/optional.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "components/precache/core/fetcher_pool.h" | 23 #include "components/precache/core/fetcher_pool.h" |
23 #include "components/precache/core/proto/precache.pb.h" | 24 #include "components/precache/core/proto/precache.pb.h" |
24 #include "components/precache/core/proto/quota.pb.h" | 25 #include "components/precache/core/proto/quota.pb.h" |
25 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
26 #include "net/url_request/url_fetcher_delegate.h" | 27 #include "net/url_request/url_fetcher_delegate.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 namespace base { | 30 namespace base { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // called, then precaching will be canceled and OnDone will not be called. | 130 // called, then precaching will be canceled and OnDone will not be called. |
130 virtual void OnDone() = 0; | 131 virtual void OnDone() = 0; |
131 }; | 132 }; |
132 | 133 |
133 // Visible for testing. | 134 // Visible for testing. |
134 class Fetcher; | 135 class Fetcher; |
135 | 136 |
136 static void RecordCompletionStatistics( | 137 static void RecordCompletionStatistics( |
137 const PrecacheUnfinishedWork& unfinished_work, | 138 const PrecacheUnfinishedWork& unfinished_work, |
138 size_t remaining_manifest_urls_to_fetch, | 139 size_t remaining_manifest_urls_to_fetch, |
139 size_t remaining_resource_urls_to_fetch); | 140 size_t remaining_resource_urls_to_fetch, |
| 141 base::Optional<double> min_weight_fetched); |
140 | 142 |
141 static std::string GetResourceURLBase64HashForTesting( | 143 static std::string GetResourceURLBase64HashForTesting( |
142 const std::vector<GURL>& urls); | 144 const std::vector<GURL>& urls); |
143 | 145 |
144 // Constructs a new PrecacheFetcher. The |unfinished_work| contains the | 146 // Constructs a new PrecacheFetcher. The |unfinished_work| contains the |
145 // prioritized list of hosts that the user commonly visits. These hosts are | 147 // prioritized list of hosts that the user commonly visits. These hosts are |
146 // used by a server side component to construct a list of resource URLs that | 148 // used by a server side component to construct a list of resource URLs that |
147 // the user is likely to fetch. Takes ownership of |unfinished_work|. | 149 // the user is likely to fetch. Takes ownership of |unfinished_work|. |
148 // |precache_database| should be accessed only in |db_task_runner|. | 150 // |precache_database| should be accessed only in |db_task_runner|. |
149 PrecacheFetcher( | 151 PrecacheFetcher( |
(...skipping 22 matching lines...) Expand all Loading... |
172 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, | 174 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, |
173 GloballyRankResourcesAfterPauseResume); | 175 GloballyRankResourcesAfterPauseResume); |
174 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, FetcherPoolMaxLimitReached); | 176 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, FetcherPoolMaxLimitReached); |
175 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, | 177 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, |
176 CancelPrecachingAfterAllManifestFetch); | 178 CancelPrecachingAfterAllManifestFetch); |
177 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, DailyQuota); | 179 FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, DailyQuota); |
178 | 180 |
179 // Notifies the precache delete that precaching is done, and report | 181 // Notifies the precache delete that precaching is done, and report |
180 // completion statistics. | 182 // completion statistics. |
181 void NotifyDone(size_t remaining_manifest_urls_to_fetch, | 183 void NotifyDone(size_t remaining_manifest_urls_to_fetch, |
182 size_t remaining_resource_urls_to_fetch); | 184 size_t remaining_resource_urls_to_fetch, |
| 185 base::Optional<double> min_weight_fetched); |
183 | 186 |
184 // Fetches the next resource or manifest URL, if any remain. Fetching is done | 187 // Fetches the next resource or manifest URL, if any remain. Fetching is done |
185 // sequentially and depth-first: all resources are fetched for a manifest | 188 // sequentially and depth-first: all resources are fetched for a manifest |
186 // before the next manifest is fetched. This is done to limit the length of | 189 // before the next manifest is fetched. This is done to limit the length of |
187 // the |resource_urls_to_fetch_| list, reducing the memory usage. | 190 // the |resource_urls_to_fetch_| list, reducing the memory usage. |
188 void StartNextFetch(); | 191 void StartNextFetch(); |
189 | 192 |
190 void StartNextManifestFetches(); | 193 void StartNextManifestFetches(); |
191 void StartNextResourceFetch(); | 194 void StartNextResourceFetch(); |
192 | 195 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 int64_t response_bytes_; | 359 int64_t response_bytes_; |
357 int64_t network_response_bytes_; | 360 int64_t network_response_bytes_; |
358 bool was_cached_; | 361 bool was_cached_; |
359 | 362 |
360 DISALLOW_COPY_AND_ASSIGN(Fetcher); | 363 DISALLOW_COPY_AND_ASSIGN(Fetcher); |
361 }; | 364 }; |
362 | 365 |
363 } // namespace precache | 366 } // namespace precache |
364 | 367 |
365 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ | 368 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ |
OLD | NEW |