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

Unified Diff: net/url_request/url_fetcher_response_writer.cc

Issue 15711003: net: Move write flush responsiblity from URLFetcherResponseWriter to URLFetcherCore (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 7 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
« no previous file with comments | « net/url_request/url_fetcher_response_writer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_fetcher_response_writer.cc
diff --git a/net/url_request/url_fetcher_response_writer.cc b/net/url_request/url_fetcher_response_writer.cc
index efbff40d338db82ddda839d4f6654f869a223d14..fcf6075fcc844c167cd8685e55d4fb473be79a4e 100644
--- a/net/url_request/url_fetcher_response_writer.cc
+++ b/net/url_request/url_fetcher_response_writer.cc
@@ -91,8 +91,15 @@ int URLFetcherFileWriter::Write(IOBuffer* buffer,
DCHECK(file_stream_);
DCHECK(owns_file_);
- ContinueWrite(new DrainableIOBuffer(buffer, num_bytes), callback, OK);
- return ERR_IO_PENDING;
+ int result = file_stream_->Write(buffer, num_bytes,
+ base::Bind(&URLFetcherFileWriter::DidWrite,
+ weak_factory_.GetWeakPtr(),
+ callback));
+ if (result < 0 && result != ERR_IO_PENDING) {
+ error_code_ = result;
+ CloseAndDeleteFile();
+ }
+ return result;
}
int URLFetcherFileWriter::Finish(const CompletionCallback& callback) {
@@ -100,33 +107,13 @@ int URLFetcherFileWriter::Finish(const CompletionCallback& callback) {
return OK;
}
-void URLFetcherFileWriter::ContinueWrite(
- scoped_refptr<DrainableIOBuffer> buffer,
- const CompletionCallback& callback,
- int result) {
- // |file_stream_| should be alive when write is in progress.
- DCHECK(file_stream_);
-
+void URLFetcherFileWriter::DidWrite(const CompletionCallback& callback,
+ int result) {
if (result < 0) {
error_code_ = result;
CloseAndDeleteFile();
- callback.Run(result);
- return;
- }
-
- total_bytes_written_ += result;
- buffer->DidConsume(result);
-
- if (buffer->BytesRemaining() > 0) {
- file_stream_->Write(buffer, buffer->BytesRemaining(),
- base::Bind(&URLFetcherFileWriter::ContinueWrite,
- weak_factory_.GetWeakPtr(),
- buffer,
- callback));
- } else {
- // Finished writing buffer to the file.
- callback.Run(buffer->size());
}
+ callback.Run(result);
}
void URLFetcherFileWriter::DisownFile() {
« no previous file with comments | « net/url_request/url_fetcher_response_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698