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