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

Unified Diff: chrome/browser/renderer_host/download_resource_handler.cc

Issue 18390: Change URLRequest to use a ref-counted buffer for actual IO.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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/renderer_host/download_resource_handler.cc
===================================================================
--- chrome/browser/renderer_host/download_resource_handler.cc (revision 8565)
+++ chrome/browser/renderer_host/download_resource_handler.cc (working copy)
@@ -7,6 +7,7 @@
#include "chrome/browser/download/download_file.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
+#include "net/base/io_buffer.h"
DownloadResourceHandler::DownloadResourceHandler(ResourceDispatcherHost* rdh,
int render_process_host_id,
@@ -20,7 +21,6 @@
global_id_(ResourceDispatcherHost::GlobalRequestID(render_process_host_id,
request_id)),
render_view_id_(render_view_id),
- read_buffer_(NULL),
url_(UTF8ToWide(url)),
content_length_(0),
download_manager_(manager),
@@ -72,15 +72,14 @@
// Create a new buffer, which will be handed to the download thread for file
// writing and deletion.
-bool DownloadResourceHandler::OnWillRead(int request_id,
- char** buf, int* buf_size,
- int min_size) {
+bool DownloadResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
+ int* buf_size, int min_size) {
DCHECK(buf && buf_size);
if (!read_buffer_) {
*buf_size = min_size < 0 ? kReadBufSize : min_size;
- read_buffer_ = new char[*buf_size];
+ read_buffer_ = new net::IOBuffer(*buf_size);
}
- *buf = read_buffer_;
+ *buf = read_buffer_.get();
return true;
}
@@ -91,7 +90,11 @@
DCHECK(read_buffer_);
AutoLock auto_lock(buffer_->lock);
bool need_update = buffer_->contents.empty();
- buffer_->contents.push_back(std::make_pair(read_buffer_, *bytes_read));
+
+ // We are passing ownership of this buffer to the download file manager.
+ net::IOBuffer* buffer = NULL;
+ read_buffer_.swap(&buffer);
+ buffer_->contents.push_back(std::make_pair(buffer, *bytes_read));
if (need_update) {
download_manager_->file_loop()->PostTask(FROM_HERE,
NewRunnableMethod(download_manager_,
@@ -99,7 +102,6 @@
download_id_,
buffer_));
}
- read_buffer_ = NULL;
// We schedule a pause outside of the read loop if there is too much file
// writing work to do.
@@ -117,7 +119,7 @@
&DownloadFileManager::DownloadFinished,
download_id_,
buffer_));
- delete [] read_buffer_;
+ read_buffer_ = NULL;
// 'buffer_' is deleted by the DownloadFileManager.
buffer_ = NULL;

Powered by Google App Engine
This is Rietveld 408576698