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

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

Issue 2623383004: Update InterceptingResourceHandler tests to use MockResourceLoader. (Closed)
Patch Set: Response to comments Created 3 years, 11 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/intercepting_resource_handler.cc
diff --git a/content/browser/loader/intercepting_resource_handler.cc b/content/browser/loader/intercepting_resource_handler.cc
index 7c8f4a998641b711b9f5917198011a99269cad02..733ca71d22de50ef164acb6f184dac791ae4d42a 100644
--- a/content/browser/loader/intercepting_resource_handler.cc
+++ b/content/browser/loader/intercepting_resource_handler.cc
@@ -4,8 +4,10 @@
#include "content/browser/loader/intercepting_resource_handler.h"
+#include "base/location.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "content/public/common/resource_response.h"
#include "net/base/io_buffer.h"
#include "net/url_request/url_request.h"
@@ -15,7 +17,8 @@ namespace content {
InterceptingResourceHandler::InterceptingResourceHandler(
std::unique_ptr<ResourceHandler> next_handler,
net::URLRequest* request)
- : LayeredResourceHandler(request, std::move(next_handler)) {
+ : LayeredResourceHandler(request, std::move(next_handler)),
+ weak_ptr_factory_(this) {
next_handler_->SetController(this);
}
@@ -149,14 +152,12 @@ void InterceptingResourceHandler::Resume() {
controller()->Resume();
return;
}
- bool defer = false;
- if (!DoLoop(&defer)) {
- controller()->Cancel();
- return;
- }
- if (!defer)
- controller()->Resume();
+ // Can't call DoLoop synchronously, as it may call into |next_handler_|
+ // synchronously, which is what called Resume().
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&InterceptingResourceHandler::AdvanceState,
+ weak_ptr_factory_.GetWeakPtr()));
}
void InterceptingResourceHandler::UseNewHandler(
@@ -279,4 +280,15 @@ bool InterceptingResourceHandler::SendFirstReadBufferToNewHandler(bool* defer) {
return true;
}
+void InterceptingResourceHandler::AdvanceState() {
+ bool defer = false;
+ if (!DoLoop(&defer)) {
+ controller()->Cancel();
+ return;
+ }
+
+ if (!defer)
+ controller()->Resume();
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698