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

Unified Diff: net/url_request/url_fetcher_response_writer.cc

Issue 2425673006: Make URLFetcherFileWriter::Finish() skip closing file when there is an error (Closed)
Patch Set: Fix another subclass Created 4 years, 2 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: 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 fcc8cbf38ffc4129245cd2cf2ceb63466e112a67..158ac8079ccd5b5350b6dba5c0838b57b82289f4 100644
--- a/net/url_request/url_fetcher_response_writer.cc
+++ b/net/url_request/url_fetcher_response_writer.cc
@@ -40,7 +40,8 @@ int URLFetcherStringWriter::Write(IOBuffer* buffer,
return num_bytes;
}
-int URLFetcherStringWriter::Finish(const CompletionCallback& callback) {
+int URLFetcherStringWriter::Finish(int net_error,
+ const CompletionCallback& callback) {
// Do nothing.
return OK;
}
@@ -67,6 +68,7 @@ int URLFetcherFileWriter::Initialize(const CompletionCallback& callback) {
file_stream_.reset(new FileStream(file_task_runner_));
int result = ERR_IO_PENDING;
+ owns_file_ = true;
if (file_path_.empty()) {
base::FilePath* temp_file_path = new base::FilePath;
base::PostTaskAndReplyWithResult(
@@ -106,7 +108,16 @@ int URLFetcherFileWriter::Write(IOBuffer* buffer,
return result;
}
-int URLFetcherFileWriter::Finish(const CompletionCallback& callback) {
+int URLFetcherFileWriter::Finish(int net_error,
+ const CompletionCallback& callback) {
+ DCHECK_NE(ERR_IO_PENDING, net_error);
+ if (net_error < 0) {
+ // If an error occurred, simply delete the file after any pending operation
+ // is done. Do not call file_stream_->Close() because there might
+ // be an operation pending. See crbug.com/487732.
+ CloseAndDeleteFile();
+ return OK;
+ }
// If the file_stream_ still exists at this point, close it.
if (file_stream_) {
int result = file_stream_->Close(base::Bind(
@@ -159,7 +170,6 @@ void URLFetcherFileWriter::DidCreateTempFile(const CompletionCallback& callback,
return;
}
file_path_ = *temp_file_path;
- owns_file_ = true;
const int result = file_stream_->Open(
file_path_,
base::File::FLAG_WRITE | base::File::FLAG_ASYNC |
@@ -173,9 +183,7 @@ void URLFetcherFileWriter::DidCreateTempFile(const CompletionCallback& callback,
void URLFetcherFileWriter::DidOpenFile(const CompletionCallback& callback,
int result) {
- if (result == OK)
- owns_file_ = true;
- else
+ if (result < OK)
CloseAndDeleteFile();
callback.Run(result);

Powered by Google App Engine
This is Rietveld 408576698