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

Side by Side Diff: chrome/browser/renderer_host/download_throttling_resource_handler.cc

Issue 6459005: Cancel prerender when we discover a download starting from a page we are prer... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Adding browser test Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer_host/download_throttling_resource_handler.h" 5 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/cert_store.h"
8 #include "chrome/browser/renderer_host/download_resource_handler.h" 9 #include "chrome/browser/renderer_host/download_resource_handler.h"
10 #include "chrome/browser/renderer_host/render_view_host.h"
11 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
9 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 12 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
13 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
14 #include "chrome/browser/renderer_host/resource_request_details.h"
15 #include "chrome/common/notification_service.h"
10 #include "chrome/common/resource_response.h" 16 #include "chrome/common/resource_response.h"
11 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
12 #include "net/base/mime_sniffer.h" 18 #include "net/base/mime_sniffer.h"
13 19
14 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( 20 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler(
15 ResourceDispatcherHost* host, 21 ResourceDispatcherHost* host,
16 net::URLRequest* request, 22 net::URLRequest* request,
17 const GURL& url, 23 const GURL& url,
18 int render_process_host_id, 24 int render_process_host_id,
19 int render_view_id, 25 int render_view_id,
20 int request_id, 26 int request_id,
21 bool in_complete) 27 bool in_complete)
22 : host_(host), 28 : host_(host),
23 request_(request), 29 request_(request),
24 url_(url), 30 url_(url),
25 render_process_host_id_(render_process_host_id), 31 render_process_host_id_(render_process_host_id),
26 render_view_id_(render_view_id), 32 render_view_id_(render_view_id),
27 request_id_(request_id), 33 request_id_(request_id),
28 tmp_buffer_length_(0), 34 tmp_buffer_length_(0),
29 ignore_on_read_complete_(in_complete) { 35 ignore_on_read_complete_(in_complete) {
30 // Pause the request. 36 // Pause the request.
31 host_->PauseRequest(render_process_host_id_, request_id_, true); 37 host_->PauseRequest(render_process_host_id_, request_id_, true);
32 host_->download_request_limiter()->CanDownloadOnIOThread( 38 host_->download_request_limiter()->CanDownloadOnIOThread(
33 render_process_host_id_, render_view_id, this); 39 render_process_host_id_, render_view_id, this);
34 } 40 }
35 41
36 DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() { 42 DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() {
37 } 43 }
38 44
45 ResourceRequestDetails*
46 DownloadThrottlingResourceHandler::GetResourceRequestDetails() {
47 int certID = 0;
48 if (request_->ssl_info().cert) {
49 ResourceDispatcherHostRequestInfo* info =
50 ResourceDispatcherHost::InfoForRequest(request_);
51
52 certID = CertStore::GetInstance()->StoreCert(request_->ssl_info().cert,
cbentzel 2011/02/09 12:11:14 I have no idea what's going on here, but it seems
dominich 2011/02/09 22:33:30 Done.
53 info->child_id());
54 }
55
56 return new ResourceRequestDetails(request_, certID);
57 }
58
59 template<NotificationType::Type T>
60 void DownloadThrottlingResourceHandler::NotifyOnUI(
61 int process_id, int view_id,
62 ResourceRequestDetails* details) {
63 RenderViewHost* rvh = RenderViewHost::FromID(process_id, view_id);
64 if (rvh) {
65 RenderViewHostDelegate* rvhd = rvh->delegate();
66 NotificationService::current()->Notify(T,
67 Source<RenderViewHostDelegate>(rvhd),
68 Details<ResourceRequestDetails>(details));
69 }
70 delete details;
71 }
72
39 bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id, 73 bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id,
40 uint64 position, 74 uint64 position,
41 uint64 size) { 75 uint64 size) {
42 if (download_handler_.get()) 76 if (download_handler_.get())
43 return download_handler_->OnUploadProgress(request_id, position, size); 77 return download_handler_->OnUploadProgress(request_id, position, size);
44 return true; 78 return true;
45 } 79 }
46 80
47 bool DownloadThrottlingResourceHandler::OnRequestRedirected( 81 bool DownloadThrottlingResourceHandler::OnRequestRedirected(
48 int request_id, 82 int request_id,
49 const GURL& url, 83 const GURL& url,
50 ResourceResponse* response, 84 ResourceResponse* response,
51 bool* defer) { 85 bool* defer) {
52 if (download_handler_.get()) { 86 if (download_handler_.get()) {
53 return download_handler_->OnRequestRedirected( 87 return download_handler_->OnRequestRedirected(
54 request_id, url, response, defer); 88 request_id, url, response, defer);
55 } 89 }
56 url_ = url; 90 url_ = url;
57 return true; 91 return true;
58 } 92 }
59 93
60 bool DownloadThrottlingResourceHandler::OnResponseStarted( 94 bool DownloadThrottlingResourceHandler::OnResponseStarted(
61 int request_id, 95 int request_id,
62 ResourceResponse* response) { 96 ResourceResponse* response) {
97 BrowserThread::PostTask(
98 BrowserThread::UI, FROM_HERE,
99 NewRunnableFunction(
100 &DownloadThrottlingResourceHandler::NotifyOnUI
101 <NotificationType::DOWNLOAD_STARTED>,
102 render_process_host_id_, render_view_id_,
103 GetResourceRequestDetails()));
104
63 if (download_handler_.get()) 105 if (download_handler_.get())
64 return download_handler_->OnResponseStarted(request_id, response); 106 return download_handler_->OnResponseStarted(request_id, response);
65 response_ = response; 107 response_ = response;
66 return true; 108 return true;
67 } 109 }
68 110
69 bool DownloadThrottlingResourceHandler::OnWillStart(int request_id, 111 bool DownloadThrottlingResourceHandler::OnWillStart(int request_id,
70 const GURL& url, 112 const GURL& url,
71 bool* defer) { 113 bool* defer) {
72 if (download_handler_.get()) 114 if (download_handler_.get())
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 NOTREACHED(); 176 NOTREACHED();
135 return true; 177 return true;
136 } 178 }
137 179
138 void DownloadThrottlingResourceHandler::OnRequestClosed() { 180 void DownloadThrottlingResourceHandler::OnRequestClosed() {
139 if (download_handler_.get()) 181 if (download_handler_.get())
140 download_handler_->OnRequestClosed(); 182 download_handler_->OnRequestClosed();
141 } 183 }
142 184
143 void DownloadThrottlingResourceHandler::CancelDownload() { 185 void DownloadThrottlingResourceHandler::CancelDownload() {
186 BrowserThread::PostTask(
187 BrowserThread::UI, FROM_HERE,
188 NewRunnableFunction(
189 &DownloadThrottlingResourceHandler::NotifyOnUI
190 <NotificationType::DOWNLOAD_CANCELLED>,
cbentzel 2011/02/09 12:11:14 There are no consumers of DOWNLOAD_CANCELLED right
dominich 2011/02/09 22:33:30 I can. I thought that it would be good to have bot
dominich 2011/02/09 22:33:30 Done.
191 render_process_host_id_, render_view_id_,
192 GetResourceRequestDetails()));
193
144 host_->CancelRequest(render_process_host_id_, request_id_, false); 194 host_->CancelRequest(render_process_host_id_, request_id_, false);
145 } 195 }
146 196
147 void DownloadThrottlingResourceHandler::ContinueDownload() { 197 void DownloadThrottlingResourceHandler::ContinueDownload() {
148 DCHECK(!download_handler_.get()); 198 DCHECK(!download_handler_.get());
149 download_handler_ = 199 download_handler_ =
150 new DownloadResourceHandler(host_, 200 new DownloadResourceHandler(host_,
151 render_process_host_id_, 201 render_process_host_id_,
152 render_view_id_, 202 render_view_id_,
153 request_id_, 203 request_id_,
(...skipping 22 matching lines...) Expand all
176 int buf_size; 226 int buf_size;
177 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, 227 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size,
178 tmp_buffer_length_)) { 228 tmp_buffer_length_)) {
179 CHECK(buf_size >= tmp_buffer_length_); 229 CHECK(buf_size >= tmp_buffer_length_);
180 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); 230 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_);
181 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); 231 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_);
182 } 232 }
183 tmp_buffer_length_ = 0; 233 tmp_buffer_length_ = 0;
184 tmp_buffer_ = NULL; 234 tmp_buffer_ = NULL;
185 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698