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

Unified Diff: chrome/browser/predictors/resource_prefetcher.h

Issue 2365613002: predictors: Refactor the prefetcher in resource_prefetch_predictor. (Closed)
Patch Set: . Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/predictors/resource_prefetcher.h
diff --git a/chrome/browser/predictors/resource_prefetcher.h b/chrome/browser/predictors/resource_prefetcher.h
index 1366d75dc01698213df8f23b3609724f5b9ec653..9a960b32eca7acf7d36f92752b799cbfe9a92189 100644
--- a/chrome/browser/predictors/resource_prefetcher.h
+++ b/chrome/browser/predictors/resource_prefetcher.h
@@ -35,41 +35,6 @@ namespace predictors {
// - Lives entirely on the IO thread.
class ResourcePrefetcher : public net::URLRequest::Delegate {
public:
- // Denotes the prefetch request for a single subresource.
- struct Request {
- explicit Request(const GURL& i_resource_url);
- Request(const Request& other);
-
- enum PrefetchStatus {
- PREFETCH_STATUS_NOT_STARTED,
- PREFETCH_STATUS_STARTED,
-
- // Cancellation reasons.
- PREFETCH_STATUS_REDIRECTED,
- PREFETCH_STATUS_AUTH_REQUIRED,
- PREFETCH_STATUS_CERT_REQUIRED,
- PREFETCH_STATUS_CERT_ERROR,
- PREFETCH_STATUS_CANCELLED,
- PREFETCH_STATUS_FAILED,
-
- // Successful prefetch states.
- PREFETCH_STATUS_FROM_CACHE,
- PREFETCH_STATUS_FROM_NETWORK
- };
-
- enum UsageStatus {
- USAGE_STATUS_NOT_REQUESTED,
- USAGE_STATUS_FROM_CACHE,
- USAGE_STATUS_FROM_NETWORK,
- USAGE_STATUS_NAVIGATION_ABANDONED
- };
-
- GURL resource_url;
- PrefetchStatus prefetch_status;
- UsageStatus usage_status;
- };
- typedef ScopedVector<Request> RequestVector;
-
// Used to communicate when the prefetching is done. All methods are invoked
// on the IO thread.
class Delegate {
@@ -77,21 +42,18 @@ class ResourcePrefetcher : public net::URLRequest::Delegate {
virtual ~Delegate() { }
// Called when the ResourcePrefetcher is finished, i.e. there is nothing
- // pending in flight. Should take ownership of |requests|.
- virtual void ResourcePrefetcherFinished(
- ResourcePrefetcher* prefetcher,
- RequestVector* requests) = 0;
+ // pending in flight.
+ virtual void ResourcePrefetcherFinished(ResourcePrefetcher* prefetcher) = 0;
virtual net::URLRequestContext* GetURLRequestContext() = 0;
};
- // |delegate| has to outlive the ResourcePrefetcher. The ResourcePrefetcher
- // takes ownership of |requests|.
+ // |delegate| has to outlive the ResourcePrefetcher.
ResourcePrefetcher(Delegate* delegate,
const ResourcePrefetchPredictorConfig& config,
const NavigationID& navigation_id,
PrefetchKeyType key_type,
- std::unique_ptr<RequestVector> requests);
+ const std::vector<GURL>& urls);
~ResourcePrefetcher() override;
void Start(); // Kicks off the prefetching. Can only be called once.
@@ -107,15 +69,15 @@ class ResourcePrefetcher : public net::URLRequest::Delegate {
// Launches new prefetch requests if possible.
void TryToLaunchPrefetchRequests();
- // Starts a net::URLRequest for the input |request|.
- void SendRequest(Request* request);
+ // Starts a net::URLRequest for the input |url|.
+ void SendRequest(const GURL& url);
// Called by |SendRequest| to start the |request|. This is necessary to stub
// out the Start() call to net::URLRequest for unittesting.
virtual void StartURLRequest(net::URLRequest* request);
// Marks the request as finished, with the given status.
- void FinishRequest(net::URLRequest* request, Request::PrefetchStatus status);
+ void FinishRequest(net::URLRequest* request);
// Reads the response data from the response - required for the resource to
// be cached correctly. Stubbed out during testing.
@@ -153,12 +115,11 @@ class ResourcePrefetcher : public net::URLRequest::Delegate {
ResourcePrefetchPredictorConfig const config_;
NavigationID navigation_id_;
PrefetchKeyType key_type_;
- std::unique_ptr<RequestVector> request_vector_;
+ std::unique_ptr<GURL> urls_;
- std::map<net::URLRequest*,
- std::pair<std::unique_ptr<net::URLRequest>, Request*>>
+ std::map<net::URLRequest*, std::unique_ptr<net::URLRequest>>
inflight_requests_;
- std::list<Request*> request_queue_;
+ std::list<GURL> request_queue_;
std::map<std::string, size_t> host_inflight_counts_;
DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcher);

Powered by Google App Engine
This is Rietveld 408576698