| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 FROM_HERE, | 107 FROM_HERE, |
| 108 base::Bind(&Context::CloseFileImpl, base::Unretained(this)), | 108 base::Bind(&Context::CloseFileImpl, base::Unretained(this)), |
| 109 base::Bind(&Context::OnAsyncCompleted, | 109 base::Bind(&Context::OnAsyncCompleted, |
| 110 base::Unretained(this), | 110 base::Unretained(this), |
| 111 IntToInt64(callback))); | 111 IntToInt64(callback))); |
| 112 DCHECK(posted); | 112 DCHECK(posted); |
| 113 | 113 |
| 114 async_in_progress_ = true; | 114 async_in_progress_ = true; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void FileStream::Context::Seek(base::File::Whence whence, | 117 void FileStream::Context::Seek(int64_t offset, |
| 118 int64_t offset, | |
| 119 const Int64CompletionCallback& callback) { | 118 const Int64CompletionCallback& callback) { |
| 120 DCHECK(!async_in_progress_); | 119 DCHECK(!async_in_progress_); |
| 121 | 120 |
| 122 bool posted = base::PostTaskAndReplyWithResult( | 121 bool posted = base::PostTaskAndReplyWithResult( |
| 123 task_runner_.get(), | 122 task_runner_.get(), FROM_HERE, |
| 124 FROM_HERE, | 123 base::Bind(&Context::SeekFileImpl, base::Unretained(this), offset), |
| 125 base::Bind( | 124 base::Bind(&Context::OnAsyncCompleted, base::Unretained(this), callback)); |
| 126 &Context::SeekFileImpl, base::Unretained(this), whence, offset), | |
| 127 base::Bind(&Context::OnAsyncCompleted, | |
| 128 base::Unretained(this), | |
| 129 callback)); | |
| 130 DCHECK(posted); | 125 DCHECK(posted); |
| 131 | 126 |
| 132 async_in_progress_ = true; | 127 async_in_progress_ = true; |
| 133 } | 128 } |
| 134 | 129 |
| 135 void FileStream::Context::Flush(const CompletionCallback& callback) { | 130 void FileStream::Context::Flush(const CompletionCallback& callback) { |
| 136 DCHECK(!async_in_progress_); | 131 DCHECK(!async_in_progress_); |
| 137 | 132 |
| 138 bool posted = base::PostTaskAndReplyWithResult( | 133 bool posted = base::PostTaskAndReplyWithResult( |
| 139 task_runner_.get(), | 134 task_runner_.get(), |
| 140 FROM_HERE, | 135 FROM_HERE, |
| 141 base::Bind(&Context::FlushFileImpl, base::Unretained(this)), | 136 base::Bind(&Context::FlushFileImpl, base::Unretained(this)), |
| 142 base::Bind(&Context::OnAsyncCompleted, | 137 base::Bind(&Context::OnAsyncCompleted, |
| 143 base::Unretained(this), | 138 base::Unretained(this), |
| 144 IntToInt64(callback))); | 139 IntToInt64(callback))); |
| 145 DCHECK(posted); | 140 DCHECK(posted); |
| 146 | 141 |
| 147 async_in_progress_ = true; | 142 async_in_progress_ = true; |
| 148 } | 143 } |
| 149 | 144 |
| 145 bool FileStream::Context::IsOpen() const { |
| 146 return file_.IsValid(); |
| 147 } |
| 148 |
| 150 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( | 149 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( |
| 151 const base::FilePath& path, int open_flags) { | 150 const base::FilePath& path, int open_flags) { |
| 152 #if defined(OS_POSIX) | 151 #if defined(OS_POSIX) |
| 153 // Always use blocking IO. | 152 // Always use blocking IO. |
| 154 open_flags &= ~base::File::FLAG_ASYNC; | 153 open_flags &= ~base::File::FLAG_ASYNC; |
| 155 #endif | 154 #endif |
| 156 base::File file; | 155 base::File file; |
| 157 #if defined(OS_ANDROID) | 156 #if defined(OS_ANDROID) |
| 158 if (path.IsContentUri()) { | 157 if (path.IsContentUri()) { |
| 159 // Check that only Read flags are set. | 158 // Check that only Read flags are set. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // should be reset before Close() because it shouldn't run if any async | 233 // should be reset before Close() because it shouldn't run if any async |
| 235 // operation is in progress. | 234 // operation is in progress. |
| 236 async_in_progress_ = false; | 235 async_in_progress_ = false; |
| 237 if (orphaned_) | 236 if (orphaned_) |
| 238 CloseAndDelete(); | 237 CloseAndDelete(); |
| 239 else | 238 else |
| 240 callback.Run(result.result); | 239 callback.Run(result.result); |
| 241 } | 240 } |
| 242 | 241 |
| 243 } // namespace net | 242 } // namespace net |
| OLD | NEW |