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

Unified Diff: content/browser/loader/redirect_to_file_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
Index: content/browser/loader/redirect_to_file_resource_handler.cc
diff --git a/content/browser/loader/redirect_to_file_resource_handler.cc b/content/browser/loader/redirect_to_file_resource_handler.cc
index 7ddcdded6b374369bf5c64b16c58e5ba4c2ca12b..c156e8e705d95e922c2fb26ff639c63514182af8 100644
--- a/content/browser/loader/redirect_to_file_resource_handler.cc
+++ b/content/browser/loader/redirect_to_file_resource_handler.cc
@@ -156,22 +156,23 @@ void RedirectToFileResourceHandler::
create_temporary_file_stream_ = create_temporary_file_stream;
}
-bool RedirectToFileResourceHandler::OnResponseStarted(
+void RedirectToFileResourceHandler::OnResponseStarted(
ResourceResponse* response,
- bool* defer) {
+ bool* defer_or_cancel) {
DCHECK(writer_);
response->head.download_file_path = writer_->path();
- return next_handler_->OnResponseStarted(response, defer);
+ next_handler_->OnResponseStarted(response, defer_or_cancel);
}
-bool RedirectToFileResourceHandler::OnWillStart(const GURL& url, bool* defer) {
+void RedirectToFileResourceHandler::OnWillStart(const GURL& url,
+ bool* defer_or_cancel) {
DCHECK(!writer_);
// Defer starting the request until we have created the temporary file.
// TODO(darin): This is sub-optimal. We should not delay starting the
// network request like this.
will_start_url_ = url;
- did_defer_ = *defer = true;
+ did_defer_ = *defer_or_cancel = true;
if (create_temporary_file_stream_.is_null()) {
CreateTemporaryFileStream(
base::Bind(&RedirectToFileResourceHandler::DidCreateTemporaryFile,
@@ -181,7 +182,6 @@ bool RedirectToFileResourceHandler::OnWillStart(const GURL& url, bool* defer) {
base::Bind(&RedirectToFileResourceHandler::DidCreateTemporaryFile,
weak_factory_.GetWeakPtr()));
}
- return true;
}
bool RedirectToFileResourceHandler::OnWillRead(
@@ -203,8 +203,8 @@ bool RedirectToFileResourceHandler::OnWillRead(
return true;
}
-bool RedirectToFileResourceHandler::OnReadCompleted(int bytes_read,
- bool* defer) {
+void RedirectToFileResourceHandler::OnReadCompleted(int bytes_read,
+ bool* defer_or_cancel) {
DCHECK(buf_write_pending_);
buf_write_pending_ = false;
@@ -214,7 +214,7 @@ bool RedirectToFileResourceHandler::OnReadCompleted(int bytes_read,
buf_->set_offset(new_offset);
if (BufIsFull()) {
- did_defer_ = *defer = true;
+ did_defer_ = *defer_or_cancel = true;
if (buf_->capacity() == bytes_read) {
// The network layer has saturated our buffer in one read. Next time, we
@@ -223,7 +223,10 @@ bool RedirectToFileResourceHandler::OnReadCompleted(int bytes_read,
}
}
- return WriteMore();
+ if (!WriteMore()) {
+ controller()->Cancel();
+ *defer_or_cancel = true;
+ }
}
void RedirectToFileResourceHandler::OnResponseCompleted(
@@ -253,10 +256,9 @@ void RedirectToFileResourceHandler::DidCreateTemporaryFile(
// Resume the request.
DCHECK(did_defer_);
- bool defer = false;
- if (!next_handler_->OnWillStart(will_start_url_, &defer)) {
- controller()->Cancel();
- } else if (!defer) {
+ bool defer_or_cancel = false;
+ next_handler_->OnWillStart(will_start_url_, &defer_or_cancel);
+ if (!defer_or_cancel) {
ResumeIfDeferred();
} else {
did_defer_ = false;
« no previous file with comments | « content/browser/loader/redirect_to_file_resource_handler.h ('k') | content/browser/loader/resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698