OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_fetcher_response_writer.h" | 5 #include "net/url_request/url_fetcher_response_writer.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 int URLFetcherFileWriter::Initialize(const CompletionCallback& callback) { | 55 int URLFetcherFileWriter::Initialize(const CompletionCallback& callback) { |
56 DCHECK(!file_stream_); | 56 DCHECK(!file_stream_); |
57 DCHECK(!owns_file_); | 57 DCHECK(!owns_file_); |
58 | 58 |
59 file_stream_.reset(new FileStream(NULL)); | 59 file_stream_.reset(new FileStream(NULL)); |
60 | 60 |
61 int result = ERR_IO_PENDING; | 61 int result = ERR_IO_PENDING; |
62 if (file_path_.empty()) { | 62 if (file_path_.empty()) { |
63 base::FilePath* temp_file_path = new base::FilePath; | 63 base::FilePath* temp_file_path = new base::FilePath; |
64 base::PostTaskAndReplyWithResult( | 64 base::PostTaskAndReplyWithResult( |
65 file_task_runner_, | 65 file_task_runner_.get(), |
66 FROM_HERE, | 66 FROM_HERE, |
67 base::Bind(&file_util::CreateTemporaryFile, | 67 base::Bind(&file_util::CreateTemporaryFile, temp_file_path), |
68 temp_file_path), | |
69 base::Bind(&URLFetcherFileWriter::DidCreateTempFile, | 68 base::Bind(&URLFetcherFileWriter::DidCreateTempFile, |
70 weak_factory_.GetWeakPtr(), | 69 weak_factory_.GetWeakPtr(), |
71 callback, | 70 callback, |
72 base::Owned(temp_file_path))); | 71 base::Owned(temp_file_path))); |
73 } else { | 72 } else { |
74 result = file_stream_->Open( | 73 result = file_stream_->Open( |
75 file_path_, | 74 file_path_, |
76 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC | | 75 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC | |
77 base::PLATFORM_FILE_CREATE_ALWAYS, | 76 base::PLATFORM_FILE_CREATE_ALWAYS, |
78 base::Bind(&URLFetcherFileWriter::DidOpenFile, | 77 base::Bind(&URLFetcherFileWriter::DidOpenFile, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 total_bytes_written_ = 0; | 162 total_bytes_written_ = 0; |
164 owns_file_ = true; | 163 owns_file_ = true; |
165 } else { | 164 } else { |
166 error_code_ = result; | 165 error_code_ = result; |
167 CloseAndDeleteFile(); | 166 CloseAndDeleteFile(); |
168 } | 167 } |
169 callback.Run(result); | 168 callback.Run(result); |
170 } | 169 } |
171 | 170 |
172 } // namespace net | 171 } // namespace net |
OLD | NEW |