| 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_proxy.h" | 8 #include "base/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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 void FileStream::Context::OpenAsync(const base::FilePath& path, | 65 void FileStream::Context::OpenAsync(const base::FilePath& path, |
| 66 int open_flags, | 66 int open_flags, |
| 67 const CompletionCallback& callback) { | 67 const CompletionCallback& callback) { |
| 68 DCHECK(!async_in_progress_); | 68 DCHECK(!async_in_progress_); |
| 69 | 69 |
| 70 BeginOpenEvent(path); | 70 BeginOpenEvent(path); |
| 71 | 71 |
| 72 const bool posted = base::PostTaskAndReplyWithResult( | 72 const bool posted = base::PostTaskAndReplyWithResult( |
| 73 base::WorkerPool::GetTaskRunner(true /* task_is_slow */), | 73 base::WorkerPool::GetTaskRunner(true /* task_is_slow */).get(), |
| 74 FROM_HERE, | 74 FROM_HERE, |
| 75 base::Bind(&Context::OpenFileImpl, | 75 base::Bind( |
| 76 base::Unretained(this), path, open_flags), | 76 &Context::OpenFileImpl, base::Unretained(this), path, open_flags), |
| 77 base::Bind(&Context::OnOpenCompleted, | 77 base::Bind(&Context::OnOpenCompleted, base::Unretained(this), callback)); |
| 78 base::Unretained(this), callback)); | |
| 79 DCHECK(posted); | 78 DCHECK(posted); |
| 80 | 79 |
| 81 async_in_progress_ = true; | 80 async_in_progress_ = true; |
| 82 } | 81 } |
| 83 | 82 |
| 84 int FileStream::Context::OpenSync(const base::FilePath& path, int open_flags) { | 83 int FileStream::Context::OpenSync(const base::FilePath& path, int open_flags) { |
| 85 DCHECK(!async_in_progress_); | 84 DCHECK(!async_in_progress_); |
| 86 | 85 |
| 87 BeginOpenEvent(path); | 86 BeginOpenEvent(path); |
| 88 OpenResult result = OpenFileImpl(path, open_flags); | 87 OpenResult result = OpenFileImpl(path, open_flags); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 106 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); | 105 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); |
| 107 } | 106 } |
| 108 } | 107 } |
| 109 | 108 |
| 110 void FileStream::Context::SeekAsync(Whence whence, | 109 void FileStream::Context::SeekAsync(Whence whence, |
| 111 int64 offset, | 110 int64 offset, |
| 112 const Int64CompletionCallback& callback) { | 111 const Int64CompletionCallback& callback) { |
| 113 DCHECK(!async_in_progress_); | 112 DCHECK(!async_in_progress_); |
| 114 | 113 |
| 115 const bool posted = base::PostTaskAndReplyWithResult( | 114 const bool posted = base::PostTaskAndReplyWithResult( |
| 116 base::WorkerPool::GetTaskRunner(true /* task is slow */), | 115 base::WorkerPool::GetTaskRunner(true /* task is slow */).get(), |
| 117 FROM_HERE, | 116 FROM_HERE, |
| 118 base::Bind(&Context::SeekFileImpl, | 117 base::Bind( |
| 119 base::Unretained(this), whence, offset), | 118 &Context::SeekFileImpl, base::Unretained(this), whence, offset), |
| 120 base::Bind(&Context::ProcessAsyncResult, | 119 base::Bind(&Context::ProcessAsyncResult, |
| 121 base::Unretained(this), callback, FILE_ERROR_SOURCE_SEEK)); | 120 base::Unretained(this), |
| 121 callback, |
| 122 FILE_ERROR_SOURCE_SEEK)); |
| 122 DCHECK(posted); | 123 DCHECK(posted); |
| 123 | 124 |
| 124 async_in_progress_ = true; | 125 async_in_progress_ = true; |
| 125 } | 126 } |
| 126 | 127 |
| 127 int64 FileStream::Context::SeekSync(Whence whence, int64 offset) { | 128 int64 FileStream::Context::SeekSync(Whence whence, int64 offset) { |
| 128 IOResult result = SeekFileImpl(whence, offset); | 129 IOResult result = SeekFileImpl(whence, offset); |
| 129 RecordError(result, FILE_ERROR_SOURCE_SEEK); | 130 RecordError(result, FILE_ERROR_SOURCE_SEEK); |
| 130 return result.result; | 131 return result.result; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void FileStream::Context::FlushAsync(const CompletionCallback& callback) { | 134 void FileStream::Context::FlushAsync(const CompletionCallback& callback) { |
| 134 DCHECK(!async_in_progress_); | 135 DCHECK(!async_in_progress_); |
| 135 | 136 |
| 136 const bool posted = base::PostTaskAndReplyWithResult( | 137 const bool posted = base::PostTaskAndReplyWithResult( |
| 137 base::WorkerPool::GetTaskRunner(true /* task is slow */), | 138 base::WorkerPool::GetTaskRunner(true /* task is slow */).get(), |
| 138 FROM_HERE, | 139 FROM_HERE, |
| 139 base::Bind(&Context::FlushFileImpl, | 140 base::Bind(&Context::FlushFileImpl, base::Unretained(this)), |
| 140 base::Unretained(this)), | |
| 141 base::Bind(&Context::ProcessAsyncResult, | 141 base::Bind(&Context::ProcessAsyncResult, |
| 142 base::Unretained(this), IntToInt64(callback), | 142 base::Unretained(this), |
| 143 IntToInt64(callback), |
| 143 FILE_ERROR_SOURCE_FLUSH)); | 144 FILE_ERROR_SOURCE_FLUSH)); |
| 144 DCHECK(posted); | 145 DCHECK(posted); |
| 145 | 146 |
| 146 async_in_progress_ = true; | 147 async_in_progress_ = true; |
| 147 } | 148 } |
| 148 | 149 |
| 149 int FileStream::Context::FlushSync() { | 150 int FileStream::Context::FlushSync() { |
| 150 IOResult result = FlushFileImpl(); | 151 IOResult result = FlushFileImpl(); |
| 151 RecordError(result, FILE_ERROR_SOURCE_FLUSH); | 152 RecordError(result, FILE_ERROR_SOURCE_FLUSH); |
| 152 return result.result; | 153 return result.result; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // operation is in progress. | 253 // operation is in progress. |
| 253 async_in_progress_ = false; | 254 async_in_progress_ = false; |
| 254 if (orphaned_) | 255 if (orphaned_) |
| 255 CloseAndDelete(); | 256 CloseAndDelete(); |
| 256 else | 257 else |
| 257 callback.Run(result); | 258 callback.Run(result); |
| 258 } | 259 } |
| 259 | 260 |
| 260 } // namespace net | 261 } // namespace net |
| 261 | 262 |
| OLD | NEW |