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

Side by Side Diff: chrome/browser/predictors/resource_prefetcher.cc

Issue 2373443002: predictors: Key the resource prefetcher by URL, not navigation. (Closed)
Patch Set: 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 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 #include "chrome/browser/predictors/resource_prefetcher.h" 5 #include "chrome/browser/predictors/resource_prefetcher.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <utility> 8 #include <utility>
9 9
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
13 #include "net/base/request_priority.h" 13 #include "net/base/request_priority.h"
14 #include "net/url_request/url_request_context.h" 14 #include "net/url_request/url_request_context.h"
15 #include "url/origin.h" 15 #include "url/origin.h"
16 16
17 namespace { 17 namespace {
18 18
19 // The size of the buffer used to read the resource. 19 // The size of the buffer used to read the resource.
20 static const size_t kResourceBufferSizeBytes = 50000; 20 static const size_t kResourceBufferSizeBytes = 50000;
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace predictors { 24 namespace predictors {
25 ResourcePrefetcher::ResourcePrefetcher( 25 ResourcePrefetcher::ResourcePrefetcher(
26 Delegate* delegate, 26 Delegate* delegate,
27 const ResourcePrefetchPredictorConfig& config, 27 const ResourcePrefetchPredictorConfig& config,
28 const NavigationID& navigation_id, 28 const GURL& main_frame_url,
29 PrefetchKeyType key_type,
30 const std::vector<GURL>& urls) 29 const std::vector<GURL>& urls)
31 : state_(INITIALIZED), 30 : state_(INITIALIZED),
32 delegate_(delegate), 31 delegate_(delegate),
33 config_(config), 32 config_(config),
34 navigation_id_(navigation_id), 33 main_frame_url_(main_frame_url) {
35 key_type_(key_type) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 34 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
37 35
38 std::copy(urls.begin(), urls.end(), std::back_inserter(request_queue_)); 36 std::copy(urls.begin(), urls.end(), std::back_inserter(request_queue_));
39 } 37 }
40 38
41 ResourcePrefetcher::~ResourcePrefetcher() {} 39 ResourcePrefetcher::~ResourcePrefetcher() {}
42 40
43 void ResourcePrefetcher::Start() { 41 void ResourcePrefetcher::Start() {
44 DCHECK(thread_checker_.CalledOnValidThread()); 42 DCHECK(thread_checker_.CalledOnValidThread());
45 43
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 delegate_->ResourcePrefetcherFinished(this); 99 delegate_->ResourcePrefetcherFinished(this);
102 } 100 }
103 } 101 }
104 102
105 void ResourcePrefetcher::SendRequest(const GURL& url) { 103 void ResourcePrefetcher::SendRequest(const GURL& url) {
106 std::unique_ptr<net::URLRequest> url_request = 104 std::unique_ptr<net::URLRequest> url_request =
107 delegate_->GetURLRequestContext()->CreateRequest(url, net::LOW, this); 105 delegate_->GetURLRequestContext()->CreateRequest(url, net::LOW, this);
108 host_inflight_counts_[url.host()] += 1; 106 host_inflight_counts_[url.host()] += 1;
109 107
110 url_request->set_method("GET"); 108 url_request->set_method("GET");
111 url_request->set_first_party_for_cookies(navigation_id_.main_frame_url); 109 url_request->set_first_party_for_cookies(main_frame_url_);
112 url_request->set_initiator(url::Origin(navigation_id_.main_frame_url)); 110 url_request->set_initiator(url::Origin(main_frame_url_));
113 url_request->SetReferrer(navigation_id_.main_frame_url.spec()); 111 url_request->SetReferrer(main_frame_url_.spec());
114 url_request->SetLoadFlags(url_request->load_flags() | net::LOAD_PREFETCH); 112 url_request->SetLoadFlags(url_request->load_flags() | net::LOAD_PREFETCH);
115 StartURLRequest(url_request.get()); 113 StartURLRequest(url_request.get());
116 inflight_requests_.insert( 114 inflight_requests_.insert(
117 std::make_pair(url_request.get(), std::move(url_request))); 115 std::make_pair(url_request.get(), std::move(url_request)));
118 } 116 }
119 117
120 void ResourcePrefetcher::StartURLRequest(net::URLRequest* request) { 118 void ResourcePrefetcher::StartURLRequest(net::URLRequest* request) {
121 request->Start(); 119 request->Start();
122 } 120 }
123 121
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (!request->status().is_success()) { 203 if (!request->status().is_success()) {
206 FinishRequest(request); 204 FinishRequest(request);
207 return; 205 return;
208 } 206 }
209 207
210 if (ShouldContinueReadingRequest(request, bytes_read)) 208 if (ShouldContinueReadingRequest(request, bytes_read))
211 ReadFullResponse(request); 209 ReadFullResponse(request);
212 } 210 }
213 211
214 } // namespace predictors 212 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetcher.h ('k') | chrome/browser/predictors/resource_prefetcher_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698