| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 void FileStream::Context::CloseSync() { | 99 void FileStream::Context::CloseSync() { |
| 100 DCHECK(!async_in_progress_); | 100 DCHECK(!async_in_progress_); |
| 101 if (file_ != base::kInvalidPlatformFileValue) { | 101 if (file_ != base::kInvalidPlatformFileValue) { |
| 102 base::ClosePlatformFile(file_); | 102 base::ClosePlatformFile(file_); |
| 103 file_ = base::kInvalidPlatformFileValue; | 103 file_ = base::kInvalidPlatformFileValue; |
| 104 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); | 104 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 void FileStream::Context::CloseAsync(const CompletionCallback& callback) { |
| 109 DCHECK(!async_in_progress_); |
| 110 const bool posted = base::PostTaskAndReplyWithResult( |
| 111 task_runner_.get(), |
| 112 FROM_HERE, |
| 113 base::Bind(&Context::CloseFileImpl, base::Unretained(this)), |
| 114 base::Bind(&Context::ProcessAsyncResult, |
| 115 base::Unretained(this), |
| 116 IntToInt64(callback), |
| 117 FILE_ERROR_SOURCE_CLOSE)); |
| 118 DCHECK(posted); |
| 119 |
| 120 async_in_progress_ = true; |
| 121 } |
| 122 |
| 108 void FileStream::Context::SeekAsync(Whence whence, | 123 void FileStream::Context::SeekAsync(Whence whence, |
| 109 int64 offset, | 124 int64 offset, |
| 110 const Int64CompletionCallback& callback) { | 125 const Int64CompletionCallback& callback) { |
| 111 DCHECK(!async_in_progress_); | 126 DCHECK(!async_in_progress_); |
| 112 | 127 |
| 113 const bool posted = base::PostTaskAndReplyWithResult( | 128 const bool posted = base::PostTaskAndReplyWithResult( |
| 114 task_runner_.get(), | 129 task_runner_.get(), |
| 115 FROM_HERE, | 130 FROM_HERE, |
| 116 base::Bind( | 131 base::Bind( |
| 117 &Context::SeekFileImpl, base::Unretained(this), whence, offset), | 132 &Context::SeekFileImpl, base::Unretained(this), whence, offset), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // operation is in progress. | 266 // operation is in progress. |
| 252 async_in_progress_ = false; | 267 async_in_progress_ = false; |
| 253 if (orphaned_) | 268 if (orphaned_) |
| 254 CloseAndDelete(); | 269 CloseAndDelete(); |
| 255 else | 270 else |
| 256 callback.Run(result); | 271 callback.Run(result); |
| 257 } | 272 } |
| 258 | 273 |
| 259 } // namespace net | 274 } // namespace net |
| 260 | 275 |
| OLD | NEW |