summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-24 01:54:05 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-24 01:54:05 +0000
commit1f8859ad6ec7ea807c0330ddf5559e13be5fb26c (patch)
tree68887107d0d40f1b22c7a7a07ccd9d7e4caf157a /chrome/browser/dom_ui
parent13dc122db24457653d57ff07791043d518eb05e7 (diff)
downloadchromium_src-1f8859ad6ec7ea807c0330ddf5559e13be5fb26c.zip
chromium_src-1f8859ad6ec7ea807c0330ddf5559e13be5fb26c.tar.gz
chromium_src-1f8859ad6ec7ea807c0330ddf5559e13be5fb26c.tar.bz2
Change URLRequest to use a ref-counted buffer for actual IO.The ref-counting will prevent the deletion / reuse of memorywhile the buffer is actually being used by pending IO.This seems a very intrusive change, but at least we will be ableto make sure that it works without having to chase every singledestruction of an URLRequest to make sure that any pending IOwas cancelled, and also allows us to avoid blocking onthe object destruction.BUG=5325
Review URL: http://codereview.chromium.org/18390 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8603 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/chrome_url_data_manager.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc
index a180280..ce533dd 100644
--- a/chrome/browser/dom_ui/chrome_url_data_manager.cc
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc
@@ -42,7 +42,7 @@ class URLRequestChromeJob : public URLRequestJob {
// URLRequestJob implementation.
virtual void Start();
virtual void Kill();
- virtual bool ReadRawData(char* buf, int buf_size, int *bytes_read);
+ virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read);
virtual bool GetMimeType(std::string* mime_type);
// Called by ChromeURLDataManager to notify us that the data blob is ready
@@ -60,7 +60,7 @@ class URLRequestChromeJob : public URLRequestJob {
// Do the actual copy from data_ (the data we're serving) into |buf|.
// Separate from ReadRawData so we can handle async I/O.
- void CompleteRead(char* buf, int buf_size, int* bytes_read);
+ void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read);
// The actual data we're serving. NULL until it's been fetched.
scoped_refptr<RefCountedBytes> data_;
@@ -70,7 +70,7 @@ class URLRequestChromeJob : public URLRequestJob {
// For async reads, we keep around a pointer to the buffer that
// we're reading into.
- char* pending_buf_;
+ scoped_refptr<net::IOBuffer> pending_buf_;
int pending_buf_size_;
std::string mime_type_;
@@ -249,7 +249,7 @@ URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request,
}
URLRequestChromeJob::URLRequestChromeJob(URLRequest* request)
- : URLRequestJob(request), data_offset_(0), pending_buf_(NULL) {}
+ : URLRequestJob(request), data_offset_(0) {}
URLRequestChromeJob::~URLRequestChromeJob() {
}
@@ -278,9 +278,10 @@ void URLRequestChromeJob::DataAvailable(RefCountedBytes* bytes) {
data_ = bytes;
int bytes_read;
- if (pending_buf_) {
+ if (pending_buf_.get()) {
CompleteRead(pending_buf_, pending_buf_size_, &bytes_read);
NotifyReadComplete(bytes_read);
+ pending_buf_ = NULL;
}
} else {
// The request failed.
@@ -288,10 +289,11 @@ void URLRequestChromeJob::DataAvailable(RefCountedBytes* bytes) {
}
}
-bool URLRequestChromeJob::ReadRawData(char* buf, int buf_size,
+bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size,
int* bytes_read) {
if (!data_.get()) {
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
+ DCHECK(!pending_buf_.get());
pending_buf_ = buf;
pending_buf_size_ = buf_size;
return false; // Tell the caller we're still waiting for data.
@@ -302,13 +304,13 @@ bool URLRequestChromeJob::ReadRawData(char* buf, int buf_size,
return true;
}
-void URLRequestChromeJob::CompleteRead(char* buf, int buf_size,
+void URLRequestChromeJob::CompleteRead(net::IOBuffer* buf, int buf_size,
int* bytes_read) {
int remaining = static_cast<int>(data_->data.size()) - data_offset_;
if (buf_size > remaining)
buf_size = remaining;
if (buf_size > 0) {
- memcpy(buf, &data_->data[0] + data_offset_, buf_size);
+ memcpy(buf->data(), &data_->data[0] + data_offset_, buf_size);
data_offset_ += buf_size;
}
*bytes_read = buf_size;