diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-24 01:54:05 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-24 01:54:05 +0000 |
commit | 1f8859ad6ec7ea807c0330ddf5559e13be5fb26c (patch) | |
tree | 68887107d0d40f1b22c7a7a07ccd9d7e4caf157a /net/url_request/mime_sniffer_proxy.cc | |
parent | 13dc122db24457653d57ff07791043d518eb05e7 (diff) | |
download | chromium_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 'net/url_request/mime_sniffer_proxy.cc')
-rw-r--r-- | net/url_request/mime_sniffer_proxy.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/net/url_request/mime_sniffer_proxy.cc b/net/url_request/mime_sniffer_proxy.cc index 24b1fbe..3a8d9a9 100644 --- a/net/url_request/mime_sniffer_proxy.cc +++ b/net/url_request/mime_sniffer_proxy.cc @@ -6,10 +6,13 @@ #include "net/base/mime_sniffer.h" +static const int kBufferSize = 1024; + MimeSnifferProxy::MimeSnifferProxy(URLRequest* request, URLRequest::Delegate* delegate) : request_(request), delegate_(delegate), - sniff_content_(false), error_(false) { + sniff_content_(false), error_(false), + buf_(new net::IOBuffer(kBufferSize)) { request->set_delegate(this); } @@ -20,7 +23,7 @@ void MimeSnifferProxy::OnResponseStarted(URLRequest* request) { // We need to read content before we know the mime type, // so we don't call OnResponseStarted. sniff_content_ = true; - if (request_->Read(buf_, sizeof(buf_), &bytes_read_) && bytes_read_) { + if (request_->Read(buf_, kBufferSize, &bytes_read_) && bytes_read_) { OnReadCompleted(request, bytes_read_); } else if (!request_->status().is_io_pending()) { error_ = true; @@ -32,7 +35,8 @@ void MimeSnifferProxy::OnResponseStarted(URLRequest* request) { delegate_->OnResponseStarted(request); } -bool MimeSnifferProxy::Read(char* buf, int max_bytes, int *bytes_read) { +bool MimeSnifferProxy::Read(net::IOBuffer* buf, int max_bytes, + int *bytes_read) { if (sniff_content_) { // This is the first call to Read() after we've sniffed content. // Return our local buffer or the error we ran into. @@ -43,7 +47,7 @@ bool MimeSnifferProxy::Read(char* buf, int max_bytes, int *bytes_read) { return false; } - memcpy(buf, buf_, bytes_read_); + memcpy(buf->data(), buf_->data(), bytes_read_); *bytes_read = bytes_read_; return true; } @@ -57,8 +61,8 @@ void MimeSnifferProxy::OnReadCompleted(URLRequest* request, int bytes_read) { std::string type_hint; request_->GetMimeType(&type_hint); bytes_read_ = bytes_read; - net::SniffMimeType( - buf_, bytes_read_, request_->url(), type_hint, &mime_type_); + net::SniffMimeType(buf_->data(), bytes_read_, request_->url(), + type_hint, &mime_type_); } else { error_ = true; } |