OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webkit/browser/fileapi/file_system_operation_impl.h" | 5 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 DCHECK(SetPendingOperationType(kOperationTouchFile)); | 192 DCHECK(SetPendingOperationType(kOperationTouchFile)); |
193 async_file_util_->Touch( | 193 async_file_util_->Touch( |
194 operation_context_.Pass(), url, | 194 operation_context_.Pass(), url, |
195 last_access_time, last_modified_time, | 195 last_access_time, last_modified_time, |
196 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 196 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
197 weak_factory_.GetWeakPtr(), callback)); | 197 weak_factory_.GetWeakPtr(), callback)); |
198 } | 198 } |
199 | 199 |
200 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, | 200 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, |
201 int file_flags, | 201 int file_flags, |
| 202 base::ProcessHandle peer_handle, |
202 const OpenFileCallback& callback) { | 203 const OpenFileCallback& callback) { |
203 DCHECK(SetPendingOperationType(kOperationOpenFile)); | 204 DCHECK(SetPendingOperationType(kOperationOpenFile)); |
| 205 peer_handle_ = peer_handle; |
204 | 206 |
205 if (file_flags & | 207 if (file_flags & |
206 (base::PLATFORM_FILE_TEMPORARY | base::PLATFORM_FILE_HIDDEN)) { | 208 (base::PLATFORM_FILE_TEMPORARY | base::PLATFORM_FILE_HIDDEN)) { |
207 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, | 209 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, |
208 base::kInvalidPlatformFileValue, | 210 base::kInvalidPlatformFileValue, |
209 base::Closure()); | 211 base::Closure(), |
| 212 base::kNullProcessHandle); |
210 return; | 213 return; |
211 } | 214 } |
212 GetUsageAndQuotaThenRunTask( | 215 GetUsageAndQuotaThenRunTask( |
213 url, | 216 url, |
214 base::Bind(&FileSystemOperationImpl::DoOpenFile, | 217 base::Bind(&FileSystemOperationImpl::DoOpenFile, |
215 weak_factory_.GetWeakPtr(), | 218 weak_factory_.GetWeakPtr(), |
216 url, callback, file_flags), | 219 url, callback, file_flags), |
217 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, | 220 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, |
218 base::kInvalidPlatformFileValue, | 221 base::kInvalidPlatformFileValue, |
219 base::Closure())); | 222 base::Closure(), |
| 223 base::kNullProcessHandle)); |
220 } | 224 } |
221 | 225 |
222 // We can only get here on a write or truncate that's not yet completed. | 226 // We can only get here on a write or truncate that's not yet completed. |
223 // We don't support cancelling any other operation at this time. | 227 // We don't support cancelling any other operation at this time. |
224 void FileSystemOperationImpl::Cancel(const StatusCallback& cancel_callback) { | 228 void FileSystemOperationImpl::Cancel(const StatusCallback& cancel_callback) { |
225 DCHECK(cancel_callback_.is_null()); | 229 DCHECK(cancel_callback_.is_null()); |
226 cancel_callback_ = cancel_callback; | 230 cancel_callback_ = cancel_callback; |
227 | 231 |
228 if (file_writer_delegate_.get()) { | 232 if (file_writer_delegate_.get()) { |
229 DCHECK_EQ(kOperationWrite, pending_operation_); | 233 DCHECK_EQ(kOperationWrite, pending_operation_); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 return base::PLATFORM_FILE_OK; | 328 return base::PLATFORM_FILE_OK; |
325 } | 329 } |
326 | 330 |
327 FileSystemOperationImpl::FileSystemOperationImpl( | 331 FileSystemOperationImpl::FileSystemOperationImpl( |
328 const FileSystemURL& url, | 332 const FileSystemURL& url, |
329 FileSystemContext* file_system_context, | 333 FileSystemContext* file_system_context, |
330 scoped_ptr<FileSystemOperationContext> operation_context) | 334 scoped_ptr<FileSystemOperationContext> operation_context) |
331 : file_system_context_(file_system_context), | 335 : file_system_context_(file_system_context), |
332 operation_context_(operation_context.Pass()), | 336 operation_context_(operation_context.Pass()), |
333 async_file_util_(NULL), | 337 async_file_util_(NULL), |
| 338 peer_handle_(base::kNullProcessHandle), |
334 pending_operation_(kOperationNone), | 339 pending_operation_(kOperationNone), |
335 weak_factory_(this) { | 340 weak_factory_(this) { |
336 DCHECK(operation_context_.get()); | 341 DCHECK(operation_context_.get()); |
337 operation_context_->DetachUserDataThread(); | 342 operation_context_->DetachUserDataThread(); |
338 async_file_util_ = file_system_context_->GetAsyncFileUtil(url.type()); | 343 async_file_util_ = file_system_context_->GetAsyncFileUtil(url.type()); |
339 DCHECK(async_file_util_); | 344 DCHECK(async_file_util_); |
340 } | 345 } |
341 | 346 |
342 void FileSystemOperationImpl::GetUsageAndQuotaThenRunTask( | 347 void FileSystemOperationImpl::GetUsageAndQuotaThenRunTask( |
343 const FileSystemURL& url, | 348 const FileSystemURL& url, |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 write_callback.Run(rv, bytes, complete); | 546 write_callback.Run(rv, bytes, complete); |
542 if (!cancel_callback.is_null()) | 547 if (!cancel_callback.is_null()) |
543 cancel_callback.Run(base::PLATFORM_FILE_OK); | 548 cancel_callback.Run(base::PLATFORM_FILE_OK); |
544 } | 549 } |
545 | 550 |
546 void FileSystemOperationImpl::DidOpenFile( | 551 void FileSystemOperationImpl::DidOpenFile( |
547 const OpenFileCallback& callback, | 552 const OpenFileCallback& callback, |
548 base::PlatformFileError rv, | 553 base::PlatformFileError rv, |
549 base::PassPlatformFile file, | 554 base::PassPlatformFile file, |
550 const base::Closure& on_close_callback) { | 555 const base::Closure& on_close_callback) { |
551 callback.Run(rv, file.ReleaseValue(), on_close_callback); | 556 if (rv == base::PLATFORM_FILE_OK) |
| 557 CHECK_NE(base::kNullProcessHandle, peer_handle_); |
| 558 callback.Run(rv, file.ReleaseValue(), on_close_callback, peer_handle_); |
552 } | 559 } |
553 | 560 |
554 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { | 561 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { |
555 if (pending_operation_ != kOperationNone) | 562 if (pending_operation_ != kOperationNone) |
556 return false; | 563 return false; |
557 pending_operation_ = type; | 564 pending_operation_ = type; |
558 return true; | 565 return true; |
559 } | 566 } |
560 | 567 |
561 } // namespace fileapi | 568 } // namespace fileapi |
OLD | NEW |