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

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

Issue 2476163003: Refactor ResourceHandler API. (Closed)
Patch Set: Minor cleanups, one real fix 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
« no previous file with comments | « content/browser/loader/sync_resource_handler.h ('k') | content/browser/loader/test_resource_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/sync_resource_handler.cc
diff --git a/content/browser/loader/sync_resource_handler.cc b/content/browser/loader/sync_resource_handler.cc
index b0475ce0db12d7fb4f02e859102b61002a2bb5bd..0acdd1c1f4d71b5911ef34c182564e7a2769ede1 100644
--- a/content/browser/loader/sync_resource_handler.cc
+++ b/content/browser/loader/sync_resource_handler.cc
@@ -11,6 +11,7 @@
#include "content/browser/loader/resource_message_filter.h"
#include "content/browser/loader/resource_request_info_impl.h"
#include "content/common/resource_messages.h"
+#include "content/public/browser/resource_controller.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/browser/resource_request_info.h"
#include "net/base/io_buffer.h"
@@ -36,10 +37,10 @@ SyncResourceHandler::~SyncResourceHandler() {
result_handler_.Run(nullptr);
}
-bool SyncResourceHandler::OnRequestRedirected(
+void SyncResourceHandler::OnRequestRedirected(
const net::RedirectInfo& redirect_info,
ResourceResponse* response,
- bool* defer) {
+ bool* defer_or_cancel) {
if (rdh_->delegate()) {
rdh_->delegate()->OnRequestRedirected(
redirect_info.new_url, request(), GetRequestInfo()->GetContext(),
@@ -52,20 +53,23 @@ bool SyncResourceHandler::OnRequestRedirected(
// WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-(
if (redirect_info.new_url.GetOrigin() != result_.final_url.GetOrigin()) {
LOG(ERROR) << "Cross origin redirect denied";
- return false;
+ *defer_or_cancel = true;
+ controller()->Cancel();
+ return;
}
result_.final_url = redirect_info.new_url;
total_transfer_size_ += request()->GetTotalReceivedBytes();
- return true;
}
-bool SyncResourceHandler::OnResponseStarted(
- ResourceResponse* response,
- bool* defer) {
+void SyncResourceHandler::OnResponseStarted(ResourceResponse* response,
+ bool* defer_or_cancel) {
const ResourceRequestInfoImpl* info = GetRequestInfo();
- if (!info->filter())
- return false;
+ if (!info->filter()) {
+ *defer_or_cancel = true;
+ controller()->Cancel();
+ return;
+ }
if (rdh_->delegate()) {
rdh_->delegate()->OnResponseStarted(request(), info->GetContext(),
@@ -83,12 +87,9 @@ bool SyncResourceHandler::OnResponseStarted(
result_.response_time = response->head.response_time;
result_.load_timing = response->head.load_timing;
result_.devtools_info = response->head.devtools_info;
- return true;
}
-bool SyncResourceHandler::OnWillStart(const GURL& url, bool* defer) {
- return true;
-}
+void SyncResourceHandler::OnWillStart(const GURL& url, bool* defer_or_cancel) {}
bool SyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
int* buf_size,
@@ -99,11 +100,11 @@ bool SyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
return true;
}
-bool SyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
+void SyncResourceHandler::OnReadCompleted(int bytes_read,
+ bool* defer_or_cancel) {
if (!bytes_read)
- return true;
+ return;
result_.data.append(read_buffer_->data(), bytes_read);
- return true;
}
void SyncResourceHandler::OnResponseCompleted(
« no previous file with comments | « content/browser/loader/sync_resource_handler.h ('k') | content/browser/loader/test_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698