OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/file_stream_context.h" | 5 #include "net/base/file_stream_context.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return OpenResult(file.Pass(), IOResult(OK, 0)); | 175 return OpenResult(file.Pass(), IOResult(OK, 0)); |
176 } | 176 } |
177 | 177 |
178 FileStream::Context::IOResult FileStream::Context::CloseFileImpl() { | 178 FileStream::Context::IOResult FileStream::Context::CloseFileImpl() { |
179 file_.Close(); | 179 file_.Close(); |
180 return IOResult(OK, 0); | 180 return IOResult(OK, 0); |
181 } | 181 } |
182 | 182 |
183 void FileStream::Context::OnOpenCompleted(const CompletionCallback& callback, | 183 void FileStream::Context::OnOpenCompleted(const CompletionCallback& callback, |
184 OpenResult open_result) { | 184 OpenResult open_result) { |
185 if (open_result.file.IsValid() && !orphaned_) { | 185 file_ = open_result.file.Pass(); |
186 file_ = open_result.file.Pass(); | 186 if (file_.IsValid() && !orphaned_) |
187 OnAsyncFileOpened(); | 187 OnAsyncFileOpened(); |
188 } | 188 |
189 OnAsyncCompleted(IntToInt64(callback), open_result.error_code); | 189 OnAsyncCompleted(IntToInt64(callback), open_result.error_code); |
190 } | 190 } |
191 | 191 |
192 void FileStream::Context::CloseAndDelete() { | 192 void FileStream::Context::CloseAndDelete() { |
193 DCHECK(!async_in_progress_); | 193 DCHECK(!async_in_progress_); |
194 | 194 |
195 if (file_.IsValid()) { | 195 if (file_.IsValid()) { |
196 bool posted = task_runner_.get()->PostTask( | 196 bool posted = task_runner_.get()->PostTask( |
197 FROM_HERE, | 197 FROM_HERE, |
198 base::Bind(base::IgnoreResult(&Context::CloseFileImpl), | 198 base::Bind(base::IgnoreResult(&Context::CloseFileImpl), |
(...skipping 16 matching lines...) Expand all Loading... |
215 // should be reset before CloseAsync() because it shouldn't run if any async | 215 // should be reset before CloseAsync() because it shouldn't run if any async |
216 // operation is in progress. | 216 // operation is in progress. |
217 async_in_progress_ = false; | 217 async_in_progress_ = false; |
218 if (orphaned_) | 218 if (orphaned_) |
219 CloseAndDelete(); | 219 CloseAndDelete(); |
220 else | 220 else |
221 callback.Run(result.result); | 221 callback.Run(result.result); |
222 } | 222 } |
223 | 223 |
224 } // namespace net | 224 } // namespace net |
OLD | NEW |