| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ | 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ |
| 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ | 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "chrome/browser/predictors/resource_prefetch_common.h" | |
| 21 #include "net/url_request/redirect_info.h" | 20 #include "net/url_request/redirect_info.h" |
| 22 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
| 23 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 24 | 23 |
| 25 namespace net { | 24 namespace net { |
| 26 class URLRequestContext; | 25 class URLRequestContext; |
| 27 } | 26 } |
| 28 | 27 |
| 29 namespace predictors { | 28 namespace predictors { |
| 30 | 29 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // pending in flight. | 75 // pending in flight. |
| 77 virtual void ResourcePrefetcherFinished( | 76 virtual void ResourcePrefetcherFinished( |
| 78 ResourcePrefetcher* prefetcher, | 77 ResourcePrefetcher* prefetcher, |
| 79 std::unique_ptr<PrefetcherStats> stats) = 0; | 78 std::unique_ptr<PrefetcherStats> stats) = 0; |
| 80 | 79 |
| 81 virtual net::URLRequestContext* GetURLRequestContext() = 0; | 80 virtual net::URLRequestContext* GetURLRequestContext() = 0; |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 // |delegate| has to outlive the ResourcePrefetcher. | 83 // |delegate| has to outlive the ResourcePrefetcher. |
| 85 ResourcePrefetcher(Delegate* delegate, | 84 ResourcePrefetcher(Delegate* delegate, |
| 86 const ResourcePrefetchPredictorConfig& config, | 85 size_t max_concurrent_requests, |
| 86 size_t max_concurrent_requests_per_host, |
| 87 const GURL& main_frame_url, | 87 const GURL& main_frame_url, |
| 88 const std::vector<GURL>& urls); | 88 const std::vector<GURL>& urls); |
| 89 ~ResourcePrefetcher() override; | 89 ~ResourcePrefetcher() override; |
| 90 | 90 |
| 91 void Start(); // Kicks off the prefetching. Can only be called once. | 91 void Start(); // Kicks off the prefetching. Can only be called once. |
| 92 void Stop(); // No additional prefetches will be queued after this. | 92 void Stop(); // No additional prefetches will be queued after this. |
| 93 | 93 |
| 94 const GURL& main_frame_url() const { return main_frame_url_; } | 94 const GURL& main_frame_url() const { return main_frame_url_; } |
| 95 | 95 |
| 96 private: | 96 private: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 enum PrefetcherState { | 135 enum PrefetcherState { |
| 136 INITIALIZED = 0, // Prefetching hasn't started. | 136 INITIALIZED = 0, // Prefetching hasn't started. |
| 137 RUNNING = 1, // Prefetching started, allowed to add more requests. | 137 RUNNING = 1, // Prefetching started, allowed to add more requests. |
| 138 STOPPED = 2, // Prefetching started, not allowed to add more requests. | 138 STOPPED = 2, // Prefetching started, not allowed to add more requests. |
| 139 FINISHED = 3 // No more inflight request, new requests not possible. | 139 FINISHED = 3 // No more inflight request, new requests not possible. |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 base::ThreadChecker thread_checker_; | 142 base::ThreadChecker thread_checker_; |
| 143 PrefetcherState state_; | 143 PrefetcherState state_; |
| 144 Delegate* const delegate_; | 144 Delegate* const delegate_; |
| 145 ResourcePrefetchPredictorConfig const config_; | 145 size_t max_concurrent_requests_; |
| 146 size_t max_concurrent_requests_per_host_; |
| 146 GURL main_frame_url_; | 147 GURL main_frame_url_; |
| 147 | 148 |
| 148 // For histogram reports. | 149 // For histogram reports. |
| 149 size_t prefetched_count_; | 150 size_t prefetched_count_; |
| 150 int64_t prefetched_bytes_; | 151 int64_t prefetched_bytes_; |
| 151 | 152 |
| 152 std::map<net::URLRequest*, std::unique_ptr<net::URLRequest>> | 153 std::map<net::URLRequest*, std::unique_ptr<net::URLRequest>> |
| 153 inflight_requests_; | 154 inflight_requests_; |
| 154 std::list<GURL> request_queue_; | 155 std::list<GURL> request_queue_; |
| 155 std::map<std::string, size_t> host_inflight_counts_; | 156 std::map<std::string, size_t> host_inflight_counts_; |
| 156 std::unique_ptr<PrefetcherStats> stats_; | 157 std::unique_ptr<PrefetcherStats> stats_; |
| 157 | 158 |
| 158 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcher); | 159 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcher); |
| 159 }; | 160 }; |
| 160 | 161 |
| 161 } // namespace predictors | 162 } // namespace predictors |
| 162 | 163 |
| 163 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ | 164 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ |
| OLD | NEW |