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/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 int URLFetcherFileWriter::Initialize(const CompletionCallback& callback) { | 66 int URLFetcherFileWriter::Initialize(const CompletionCallback& callback) { |
67 file_stream_.reset(new FileStream(NULL)); | 67 file_stream_.reset(new FileStream(NULL)); |
68 | 68 |
69 int result = ERR_IO_PENDING; | 69 int result = ERR_IO_PENDING; |
70 if (file_path_.empty()) { | 70 if (file_path_.empty()) { |
71 base::FilePath* temp_file_path = new base::FilePath; | 71 base::FilePath* temp_file_path = new base::FilePath; |
72 base::PostTaskAndReplyWithResult( | 72 base::PostTaskAndReplyWithResult( |
73 file_task_runner_.get(), | 73 file_task_runner_.get(), |
74 FROM_HERE, | 74 FROM_HERE, |
75 base::Bind(&file_util::CreateTemporaryFile, temp_file_path), | 75 base::Bind(&base::CreateTemporaryFile, temp_file_path), |
76 base::Bind(&URLFetcherFileWriter::DidCreateTempFile, | 76 base::Bind(&URLFetcherFileWriter::DidCreateTempFile, |
77 weak_factory_.GetWeakPtr(), | 77 weak_factory_.GetWeakPtr(), |
78 callback, | 78 callback, |
79 base::Owned(temp_file_path))); | 79 base::Owned(temp_file_path))); |
80 } else { | 80 } else { |
81 result = file_stream_->Open( | 81 result = file_stream_->Open( |
82 file_path_, | 82 file_path_, |
83 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC | | 83 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC | |
84 base::PLATFORM_FILE_CREATE_ALWAYS, | 84 base::PLATFORM_FILE_CREATE_ALWAYS, |
85 base::Bind(&URLFetcherFileWriter::DidOpenFile, | 85 base::Bind(&URLFetcherFileWriter::DidOpenFile, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 | 179 |
180 void URLFetcherFileWriter::CloseComplete(const CompletionCallback& callback, | 180 void URLFetcherFileWriter::CloseComplete(const CompletionCallback& callback, |
181 int result) { | 181 int result) { |
182 // Destroy |file_stream_| whether or not the close succeeded. | 182 // Destroy |file_stream_| whether or not the close succeeded. |
183 file_stream_.reset(); | 183 file_stream_.reset(); |
184 callback.Run(result); | 184 callback.Run(result); |
185 } | 185 } |
186 | 186 |
187 } // namespace net | 187 } // namespace net |
OLD | NEW |