| 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);
|
|
|