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

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

Issue 2005273002: Move MimeTypeResourceHandler before ThrottlingResourceHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/layered_resource_handler.cc
diff --git a/content/browser/loader/layered_resource_handler.cc b/content/browser/loader/layered_resource_handler.cc
index eada59a93f879fd32edf273d8908b96a78296f45..04ba23b88d0a0b74957329f3defd0def1d3435e1 100644
--- a/content/browser/loader/layered_resource_handler.cc
+++ b/content/browser/loader/layered_resource_handler.cc
@@ -7,6 +7,9 @@
#include <utility>
#include "base/logging.h"
+#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
+#include "net/url_request/url_request.h"
namespace content {
@@ -80,4 +83,48 @@ void LayeredResourceHandler::OnDataDownloaded(int bytes_downloaded) {
next_handler_->OnDataDownloaded(bytes_downloaded);
}
+bool LayeredResourceHandler::IsLeafHandler() const {
+ return false;
+}
+
+void LayeredResourceHandler::InstallNewLeafHandler(
+ std::unique_ptr<ResourceHandler> new_handler,
+ const std::string& payload_for_old_handler) {
+ if (!next_handler_->IsLeafHandler()) {
+ next_handler_->InstallNewLeafHandler(std::move(new_handler),
+ payload_for_old_handler);
+ return;
+ }
+
+ // Simulate a read of payload_for_old_handler and the end of the response on
+ // the next handler.
+ bool defer_ignored = false;
+ if (payload_for_old_handler.empty()) {
+ net::URLRequestStatus status(net::URLRequestStatus::CANCELED,
+ net::ERR_ABORTED);
+ next_handler_->OnResponseCompleted(status, std::string(), &defer_ignored);
+ DCHECK(!defer_ignored);
+ } else {
+ scoped_refptr<net::IOBuffer> buf;
+ int size = 0;
+
+ next_handler_->OnWillRead(&buf, &size, -1);
+ CHECK_GE(size, static_cast<int>(payload_for_old_handler.length()));
+
+ memcpy(buf->data(), payload_for_old_handler.c_str(),
+ payload_for_old_handler.length());
+
+ next_handler_->OnReadCompleted(payload_for_old_handler.length(),
+ &defer_ignored);
+ DCHECK(!defer_ignored);
+
+ net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
+ next_handler_->OnResponseCompleted(status, std::string(), &defer_ignored);
+ DCHECK(!defer_ignored);
+ }
+
+ next_handler_ = std::move(new_handler);
+ next_handler_->SetController(controller());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698