OLD | NEW |
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/download/download_throttling_resource_handler.h" | 5 #include "chrome/browser/download/download_throttling_resource_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/download/download_util.h" | 8 #include "content/browser/download/download_stats.h" |
9 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 9 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
10 #include "content/common/resource_response.h" | 10 #include "content/common/resource_response.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/mime_sniffer.h" | 12 #include "net/base/mime_sniffer.h" |
13 | 13 |
14 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( | 14 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( |
15 ResourceHandler* next_handler, | 15 ResourceHandler* next_handler, |
16 ResourceDispatcherHost* host, | 16 ResourceDispatcherHost* host, |
17 DownloadRequestLimiter* limiter, | 17 DownloadRequestLimiter* limiter, |
18 net::URLRequest* request, | 18 net::URLRequest* request, |
19 const GURL& url, | 19 const GURL& url, |
20 int render_process_host_id, | 20 int render_process_host_id, |
21 int render_view_id, | 21 int render_view_id, |
22 int request_id, | 22 int request_id, |
23 bool in_complete) | 23 bool in_complete) |
24 : host_(host), | 24 : host_(host), |
25 request_(request), | 25 request_(request), |
26 url_(url), | 26 url_(url), |
27 render_process_host_id_(render_process_host_id), | 27 render_process_host_id_(render_process_host_id), |
28 render_view_id_(render_view_id), | 28 render_view_id_(render_view_id), |
29 request_id_(request_id), | 29 request_id_(request_id), |
30 next_handler_(next_handler), | 30 next_handler_(next_handler), |
31 request_allowed_(false), | 31 request_allowed_(false), |
32 tmp_buffer_length_(0), | 32 tmp_buffer_length_(0), |
33 ignore_on_read_complete_(in_complete), | 33 ignore_on_read_complete_(in_complete), |
34 request_closed_(false) { | 34 request_closed_(false) { |
35 download_util::RecordDownloadCount( | 35 download_stats::RecordDownloadCount( |
36 download_util::INITIATED_BY_NAVIGATION_COUNT); | 36 download_stats::INITIATED_BY_NAVIGATION_COUNT); |
37 | 37 |
38 // Pause the request. | 38 // Pause the request. |
39 host_->PauseRequest(render_process_host_id_, request_id_, true); | 39 host_->PauseRequest(render_process_host_id_, request_id_, true); |
40 | 40 |
41 // Add a reference to ourselves to keep this object alive until we | 41 // Add a reference to ourselves to keep this object alive until we |
42 // receive a callback from DownloadRequestLimiter. The reference is | 42 // receive a callback from DownloadRequestLimiter. The reference is |
43 // released in ContinueDownload() and CancelDownload(). | 43 // released in ContinueDownload() and CancelDownload(). |
44 AddRef(); | 44 AddRef(); |
45 | 45 |
46 limiter->CanDownloadOnIOThread( | 46 limiter->CanDownloadOnIOThread( |
47 render_process_host_id_, render_view_id, request_id, this); | 47 render_process_host_id_, render_view_id, request_id, this); |
48 BrowserThread::PostTask( | |
49 BrowserThread::UI, FROM_HERE, | |
50 NewRunnableFunction(&download_util::NotifyDownloadInitiated, | |
51 render_process_host_id_, render_view_id_)); | |
52 } | 48 } |
53 | 49 |
54 DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() { | 50 DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() { |
55 } | 51 } |
56 | 52 |
57 bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id, | 53 bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id, |
58 uint64 position, | 54 uint64 position, |
59 uint64 size) { | 55 uint64 size) { |
60 DCHECK(!request_closed_); | 56 DCHECK(!request_closed_); |
61 if (request_allowed_) | 57 if (request_allowed_) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 int buf_size; | 189 int buf_size; |
194 if (next_handler_->OnWillRead(request_id_, &buffer, &buf_size, | 190 if (next_handler_->OnWillRead(request_id_, &buffer, &buf_size, |
195 tmp_buffer_length_)) { | 191 tmp_buffer_length_)) { |
196 CHECK(buf_size >= tmp_buffer_length_); | 192 CHECK(buf_size >= tmp_buffer_length_); |
197 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); | 193 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); |
198 next_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); | 194 next_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); |
199 } | 195 } |
200 tmp_buffer_length_ = 0; | 196 tmp_buffer_length_ = 0; |
201 tmp_buffer_ = NULL; | 197 tmp_buffer_ = NULL; |
202 } | 198 } |
OLD | NEW |