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

Unified Diff: content/browser/loader/buffered_resource_handler.cc

Issue 25536005: Clean up ResourceHandler API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 2 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: content/browser/loader/buffered_resource_handler.cc
diff --git a/content/browser/loader/buffered_resource_handler.cc b/content/browser/loader/buffered_resource_handler.cc
index beb3228003d257fb821f4b3236fb617f42eb89cc..0d7ad70968dcf491fd24e0c295d5dca4ceccbc86 100644
--- a/content/browser/loader/buffered_resource_handler.cc
+++ b/content/browser/loader/buffered_resource_handler.cc
@@ -80,10 +80,9 @@ BufferedResourceHandler::BufferedResourceHandler(
scoped_ptr<ResourceHandler> next_handler,
ResourceDispatcherHostImpl* host,
net::URLRequest* request)
- : LayeredResourceHandler(next_handler.Pass()),
+ : LayeredResourceHandler(request, next_handler.Pass()),
state_(STATE_STARTING),
host_(host),
- request_(request),
read_buffer_size_(0),
bytes_read_(0),
must_download_(false),
@@ -147,8 +146,10 @@ bool BufferedResourceHandler::OnResponseStarted(
// We'll let the original event handler provide a buffer, and reuse it for
// subsequent reads until we're done buffering.
-bool BufferedResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
- int* buf_size, int min_size) {
+bool BufferedResourceHandler::OnWillRead(int request_id,
+ scoped_refptr<net::IOBuffer>* buf,
+ int* buf_size,
+ int min_size) {
if (state_ == STATE_STREAMING)
return next_handler_->OnWillRead(request_id, buf, buf_size, min_size);
@@ -240,8 +241,7 @@ bool BufferedResourceHandler::ProcessResponse(bool* defer) {
state_ = STATE_REPLAYING;
- int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID();
- if (!next_handler_->OnResponseStarted(request_id, response_.get(), defer))
+ if (!next_handler_->OnResponseStarted(GetRequestID(), response_.get(), defer))
return false;
if (!read_buffer_.get()) {
@@ -259,13 +259,13 @@ bool BufferedResourceHandler::ShouldSniffContent() {
const std::string& mime_type = response_->head.mime_type;
std::string content_type_options;
- request_->GetResponseHeaderByName("x-content-type-options",
- &content_type_options);
+ request()->GetResponseHeaderByName("x-content-type-options",
+ &content_type_options);
bool sniffing_blocked =
LowerCaseEqualsASCII(content_type_options, "nosniff");
bool we_would_like_to_sniff =
- net::ShouldSniffMimeType(request_->url(), mime_type);
+ net::ShouldSniffMimeType(request()->url(), mime_type);
RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type);
@@ -273,7 +273,7 @@ bool BufferedResourceHandler::ShouldSniffContent() {
// We're going to look at the data before deciding what the content type
// is. That means we need to delay sending the ResponseStarted message
// over the IPC channel.
- VLOG(1) << "To buffer: " << request_->url().spec();
+ VLOG(1) << "To buffer: " << request()->url().spec();
return true;
}
@@ -287,7 +287,7 @@ bool BufferedResourceHandler::DetermineMimeType() {
std::string new_type;
bool made_final_decision =
- net::SniffMimeType(read_buffer_->data(), bytes_read_, request_->url(),
+ net::SniffMimeType(read_buffer_->data(), bytes_read_, request()->url(),
type_hint, &new_type);
// SniffMimeType() returns false if there is not enough data to determine
@@ -301,13 +301,13 @@ bool BufferedResourceHandler::DetermineMimeType() {
bool BufferedResourceHandler::SelectNextHandler(bool* defer) {
DCHECK(!response_->head.mime_type.empty());
- ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_);
+ ResourceRequestInfoImpl* info = GetRequestInfo();
const std::string& mime_type = response_->head.mime_type;
if (net::IsSupportedCertificateMimeType(mime_type)) {
// Install certificate file.
scoped_ptr<ResourceHandler> handler(
- new CertificateResourceHandler(request_));
+ new CertificateResourceHandler(request()));
return UseAlternateNextHandler(handler.Pass());
}
@@ -320,7 +320,7 @@ bool BufferedResourceHandler::SelectNextHandler(bool* defer) {
return true;
scoped_ptr<ResourceHandler> handler(
- host_->MaybeInterceptAsStream(request_, response_.get()));
+ host_->MaybeInterceptAsStream(request(), response_.get()));
if (handler)
return UseAlternateNextHandler(handler.Pass());
@@ -344,7 +344,7 @@ bool BufferedResourceHandler::SelectNextHandler(bool* defer) {
info->set_is_download(true);
scoped_ptr<ResourceHandler> handler(
host_->CreateResourceHandlerForDownload(
- request_,
+ request(),
true, // is_content_initiated
must_download,
content::DownloadItem::kInvalidId,
@@ -362,11 +362,11 @@ bool BufferedResourceHandler::UseAlternateNextHandler(
// own error page instead of triggering a download.
// TODO(abarth): We should abstract the response_code test, but this kind
// of check is scattered throughout our codebase.
- request_->CancelWithError(net::ERR_FILE_NOT_FOUND);
+ request()->CancelWithError(net::ERR_FILE_NOT_FOUND);
return false;
}
- int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID();
+ int request_id = GetRequestID();
// Inform the original ResourceHandler that this will be handled entirely by
// the new ResourceHandler.
@@ -389,8 +389,8 @@ bool BufferedResourceHandler::UseAlternateNextHandler(
bool BufferedResourceHandler::ReplayReadCompleted(bool* defer) {
DCHECK(read_buffer_.get());
- int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID();
- bool result = next_handler_->OnReadCompleted(request_id, bytes_read_, defer);
+ bool result = next_handler_->OnReadCompleted(GetRequestID(), bytes_read_,
+ defer);
read_buffer_ = NULL;
read_buffer_size_ = 0;
@@ -418,13 +418,13 @@ bool BufferedResourceHandler::MustDownload() {
must_download_is_set_ = true;
std::string disposition;
- request_->GetResponseHeaderByName("content-disposition", &disposition);
+ request()->GetResponseHeaderByName("content-disposition", &disposition);
if (!disposition.empty() &&
net::HttpContentDisposition(disposition, std::string()).is_attachment()) {
must_download_ = true;
} else if (host_->delegate() &&
host_->delegate()->ShouldForceDownloadResource(
- request_->url(), response_->head.mime_type)) {
+ request()->url(), response_->head.mime_type)) {
must_download_ = true;
} else {
must_download_ = false;
@@ -434,13 +434,13 @@ bool BufferedResourceHandler::MustDownload() {
}
bool BufferedResourceHandler::HasSupportingPlugin(bool* stale) {
- ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_);
+ ResourceRequestInfoImpl* info = GetRequestInfo();
bool allow_wildcard = false;
WebPluginInfo plugin;
return PluginServiceImpl::GetInstance()->GetPluginInfo(
info->GetChildID(), info->GetRouteID(), info->GetContext(),
- request_->url(), GURL(), response_->head.mime_type, allow_wildcard,
+ request()->url(), GURL(), response_->head.mime_type, allow_wildcard,
stale, &plugin, NULL);
}
@@ -448,7 +448,7 @@ bool BufferedResourceHandler::CopyReadBufferToNextHandler(int request_id) {
if (!bytes_read_)
return true;
- net::IOBuffer* buf = NULL;
+ scoped_refptr<net::IOBuffer> buf;
int buf_len = 0;
if (!next_handler_->OnWillRead(request_id, &buf, &buf_len, bytes_read_))
return false;
« no previous file with comments | « content/browser/loader/buffered_resource_handler.h ('k') | content/browser/loader/certificate_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698