OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/download_resource_handler.h" | 8 #include "chrome/browser/renderer_host/download_resource_handler.h" |
8 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
9 | 10 |
10 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( | 11 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( |
11 ResourceDispatcherHost* host, | 12 ResourceDispatcherHost* host, |
12 URLRequest* request, | 13 URLRequest* request, |
13 const GURL& url, | 14 const GURL& url, |
14 int render_process_host_id, | 15 int render_process_host_id, |
15 int render_view_id, | 16 int render_view_id, |
16 int request_id, | 17 int request_id, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 if (download_handler_.get()) | 65 if (download_handler_.get()) |
65 return download_handler_->OnWillRead(request_id, buf, buf_size, min_size); | 66 return download_handler_->OnWillRead(request_id, buf, buf_size, min_size); |
66 | 67 |
67 // We should only have this invoked once, as such we only deal with one | 68 // We should only have this invoked once, as such we only deal with one |
68 // tmp buffer. | 69 // tmp buffer. |
69 DCHECK(!tmp_buffer_.get()); | 70 DCHECK(!tmp_buffer_.get()); |
70 if (min_size < 0) | 71 if (min_size < 0) |
71 min_size = 1024; | 72 min_size = 1024; |
72 tmp_buffer_ = new net::IOBuffer(min_size); | 73 tmp_buffer_ = new net::IOBuffer(min_size); |
73 *buf = tmp_buffer_.get(); | 74 *buf = tmp_buffer_.get(); |
| 75 // TODO(willchan): Remove after debugging bug 16371. |
| 76 CHECK((*buf)->data()); |
74 *buf_size = min_size; | 77 *buf_size = min_size; |
75 return true; | 78 return true; |
76 } | 79 } |
77 | 80 |
78 bool DownloadThrottlingResourceHandler::OnReadCompleted(int request_id, | 81 bool DownloadThrottlingResourceHandler::OnReadCompleted(int request_id, |
79 int* bytes_read) { | 82 int* bytes_read) { |
80 if (ignore_on_read_complete_) { | 83 if (ignore_on_read_complete_) { |
81 // See comments above definition for details on this. | 84 // See comments above definition for details on this. |
82 ignore_on_read_complete_ = false; | 85 ignore_on_read_complete_ = false; |
83 return true; | 86 return true; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 int buf_size; | 149 int buf_size; |
147 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, | 150 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, |
148 tmp_buffer_length_)) { | 151 tmp_buffer_length_)) { |
149 CHECK(buf_size >= tmp_buffer_length_); | 152 CHECK(buf_size >= tmp_buffer_length_); |
150 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); | 153 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); |
151 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); | 154 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); |
152 } | 155 } |
153 tmp_buffer_length_ = 0; | 156 tmp_buffer_length_ = 0; |
154 tmp_buffer_ = NULL; | 157 tmp_buffer_ = NULL; |
155 } | 158 } |
OLD | NEW |