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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix unittests Created 4 years, 1 month 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/async_resource_handler.cc
diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc
index 69df993843453e1105111ba1193f1c8dc8fe3edd..4a12588ac34727d1b5741092c307f63c0ec7c863 100644
--- a/content/browser/loader/async_resource_handler.cc
+++ b/content/browser/loader/async_resource_handler.cc
@@ -217,6 +217,7 @@ AsyncResourceHandler::AsyncResourceHandler(
waiting_for_upload_progress_ack_(false),
reported_transfer_size_(0),
reported_encoded_body_length_(0) {
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
mmenke 2016/11/17 16:27:19 include base/logging.h
horo 2016/11/17 17:50:27 Already included.
InitializeResourceBufferConstants();
}
@@ -261,6 +262,7 @@ void AsyncResourceHandler::OnUploadProgressACK(int request_id) {
void AsyncResourceHandler::ReportUploadProgress() {
DCHECK(GetRequestInfo()->is_upload_progress_enabled());
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
mmenke 2016/11/17 16:27:19 Is this needed? This is constant for the lifetime
horo 2016/11/17 17:50:26 Done.
if (waiting_for_upload_progress_ack_)
return; // Send one progress event at a time.
@@ -300,8 +302,9 @@ bool AsyncResourceHandler::OnRequestRedirected(
const net::RedirectInfo& redirect_info,
ResourceResponse* response,
bool* defer) {
- const ResourceRequestInfoImpl* info = GetRequestInfo();
- if (!info->filter())
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
+ ResourceMessageFilter* filter = GetFilter();
+ if (!filter)
return false;
*defer = did_defer_ = true;
@@ -316,12 +319,13 @@ bool AsyncResourceHandler::OnRequestRedirected(
// cookies? The only case where it can change is top-level navigation requests
// and hopefully those will eventually all be owned by the browser. It's
// possible this is still needed while renderer-owned ones exist.
- return info->filter()->Send(new ResourceMsg_ReceivedRedirect(
+ return filter->Send(new ResourceMsg_ReceivedRedirect(
GetRequestID(), redirect_info, response->head));
}
bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
bool* defer) {
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
// For changes to the main frame, inform the renderer of the new URL's
// per-host settings before the request actually commits. This way the
// renderer will be able to set these precisely at the time the
@@ -332,7 +336,8 @@ bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
progress_timer_.Stop();
const ResourceRequestInfoImpl* info = GetRequestInfo();
- if (!info->filter())
+ ResourceMessageFilter* filter = GetFilter();
+ if (!filter)
return false;
// We want to send a final upload progress message prior to sending the
@@ -361,16 +366,15 @@ bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
response->head.request_start = request()->creation_time();
response->head.response_start = TimeTicks::Now();
- info->filter()->Send(new ResourceMsg_ReceivedResponse(GetRequestID(),
- response->head));
+ filter->Send(
+ new ResourceMsg_ReceivedResponse(GetRequestID(), response->head));
sent_received_response_msg_ = true;
if (request()->response_info().metadata.get()) {
std::vector<char> copy(request()->response_info().metadata->data(),
request()->response_info().metadata->data() +
request()->response_info().metadata->size());
- info->filter()->Send(new ResourceMsg_ReceivedCachedMetadata(GetRequestID(),
- copy));
+ filter->Send(new ResourceMsg_ReceivedCachedMetadata(GetRequestID(), copy));
}
inlining_helper_->OnResponseReceived(*response);
@@ -378,6 +382,7 @@ bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
}
bool AsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) {
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
if (GetRequestInfo()->is_upload_progress_enabled() &&
request()->has_upload()) {
ReportUploadProgress();
@@ -393,6 +398,7 @@ bool AsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) {
bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
int* buf_size,
int min_size) {
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
DCHECK_EQ(-1, min_size);
if (!CheckForSufficientResource())
@@ -417,6 +423,7 @@ bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
}
bool AsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
DCHECK_GE(bytes_read, 0);
if (!bytes_read)
@@ -468,6 +475,7 @@ bool AsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
}
void AsyncResourceHandler::OnDataDownloaded(int bytes_downloaded) {
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
int encoded_data_length = CalculateEncodedDataLengthToReport();
ResourceMessageFilter* filter = GetFilter();
@@ -480,8 +488,10 @@ void AsyncResourceHandler::OnDataDownloaded(int bytes_downloaded) {
void AsyncResourceHandler::OnResponseCompleted(
const net::URLRequestStatus& status,
bool* defer) {
+ DCHECK(GetRequestInfo()->requester_info().IsRenderer());
const ResourceRequestInfoImpl* info = GetRequestInfo();
- if (!info->filter())
+ ResourceMessageFilter* filter = GetFilter();
+ if (!filter)
return;
// If we crash here, figure out what URL the renderer was requesting.
@@ -514,7 +524,7 @@ void AsyncResourceHandler::OnResponseCompleted(
request_complete_data.completion_time = TimeTicks::Now();
request_complete_data.encoded_data_length =
request()->GetTotalReceivedBytes();
- info->filter()->Send(
+ filter->Send(
new ResourceMsg_RequestComplete(GetRequestID(), request_complete_data));
if (status.is_success())

Powered by Google App Engine
This is Rietveld 408576698