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_runner.h" | 5 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 operation->TouchFile( | 332 operation->TouchFile( |
333 url, last_access_time, last_modified_time, | 333 url, last_access_time, last_modified_time, |
334 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 334 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
335 handle, callback)); | 335 handle, callback)); |
336 return handle.id; | 336 return handle.id; |
337 } | 337 } |
338 | 338 |
339 OperationID FileSystemOperationRunner::OpenFile( | 339 OperationID FileSystemOperationRunner::OpenFile( |
340 const FileSystemURL& url, | 340 const FileSystemURL& url, |
341 int file_flags, | 341 int file_flags, |
342 base::ProcessHandle peer_handle, | |
343 const OpenFileCallback& callback) { | 342 const OpenFileCallback& callback) { |
344 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 343 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
345 FileSystemOperation* operation = | 344 FileSystemOperation* operation = |
346 file_system_context_->CreateFileSystemOperation(url, &error); | 345 file_system_context_->CreateFileSystemOperation(url, &error); |
347 BeginOperationScoper scope; | 346 BeginOperationScoper scope; |
348 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 347 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); |
349 if (!operation) { | 348 if (!operation) { |
350 DidOpenFile(handle, callback, error, base::kInvalidPlatformFileValue, | 349 DidOpenFile(handle, callback, error, base::kInvalidPlatformFileValue, |
351 base::Closure(), base::ProcessHandle()); | 350 base::Closure()); |
352 return handle.id; | 351 return handle.id; |
353 } | 352 } |
354 if (file_flags & | 353 if (file_flags & |
355 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 354 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
356 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 355 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
357 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 356 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
358 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 357 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
359 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 358 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
360 PrepareForWrite(handle.id, url); | 359 PrepareForWrite(handle.id, url); |
361 } else { | 360 } else { |
362 PrepareForRead(handle.id, url); | 361 PrepareForRead(handle.id, url); |
363 } | 362 } |
364 operation->OpenFile( | 363 operation->OpenFile( |
365 url, file_flags, peer_handle, | 364 url, file_flags, |
366 base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), | 365 base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), |
367 handle, callback)); | 366 handle, callback)); |
368 return handle.id; | 367 return handle.id; |
369 } | 368 } |
370 | 369 |
371 OperationID FileSystemOperationRunner::CreateSnapshotFile( | 370 OperationID FileSystemOperationRunner::CreateSnapshotFile( |
372 const FileSystemURL& url, | 371 const FileSystemURL& url, |
373 const SnapshotFileCallback& callback) { | 372 const SnapshotFileCallback& callback) { |
374 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 373 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
375 FileSystemOperation* operation = | 374 FileSystemOperation* operation = |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 callback.Run(rv, bytes, complete); | 570 callback.Run(rv, bytes, complete); |
572 if (rv != base::PLATFORM_FILE_OK || complete) | 571 if (rv != base::PLATFORM_FILE_OK || complete) |
573 FinishOperation(handle.id); | 572 FinishOperation(handle.id); |
574 } | 573 } |
575 | 574 |
576 void FileSystemOperationRunner::DidOpenFile( | 575 void FileSystemOperationRunner::DidOpenFile( |
577 const OperationHandle& handle, | 576 const OperationHandle& handle, |
578 const OpenFileCallback& callback, | 577 const OpenFileCallback& callback, |
579 base::PlatformFileError rv, | 578 base::PlatformFileError rv, |
580 base::PlatformFile file, | 579 base::PlatformFile file, |
581 const base::Closure& on_close_callback, | 580 const base::Closure& on_close_callback) { |
582 base::ProcessHandle peer_handle) { | |
583 if (handle.scope) { | 581 if (handle.scope) { |
584 finished_operations_.insert(handle.id); | 582 finished_operations_.insert(handle.id); |
585 base::MessageLoopProxy::current()->PostTask( | 583 base::MessageLoopProxy::current()->PostTask( |
586 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, | 584 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, |
587 AsWeakPtr(), handle, callback, rv, file, | 585 AsWeakPtr(), handle, callback, rv, file, |
588 on_close_callback, peer_handle)); | 586 on_close_callback)); |
589 return; | 587 return; |
590 } | 588 } |
591 callback.Run(rv, file, on_close_callback, peer_handle); | 589 callback.Run(rv, file, on_close_callback); |
592 FinishOperation(handle.id); | 590 FinishOperation(handle.id); |
593 } | 591 } |
594 | 592 |
595 void FileSystemOperationRunner::DidCreateSnapshot( | 593 void FileSystemOperationRunner::DidCreateSnapshot( |
596 const OperationHandle& handle, | 594 const OperationHandle& handle, |
597 const SnapshotFileCallback& callback, | 595 const SnapshotFileCallback& callback, |
598 base::PlatformFileError rv, | 596 base::PlatformFileError rv, |
599 const base::PlatformFileInfo& file_info, | 597 const base::PlatformFileInfo& file_info, |
600 const base::FilePath& platform_path, | 598 const base::FilePath& platform_path, |
601 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 599 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 stray_cancel_callbacks_.find(id); | 678 stray_cancel_callbacks_.find(id); |
681 if (found_cancel != stray_cancel_callbacks_.end()) { | 679 if (found_cancel != stray_cancel_callbacks_.end()) { |
682 // This cancel has been requested after the operation has finished, | 680 // This cancel has been requested after the operation has finished, |
683 // so report that we failed to stop it. | 681 // so report that we failed to stop it. |
684 found_cancel->second.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 682 found_cancel->second.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
685 stray_cancel_callbacks_.erase(found_cancel); | 683 stray_cancel_callbacks_.erase(found_cancel); |
686 } | 684 } |
687 } | 685 } |
688 | 686 |
689 } // namespace fileapi | 687 } // namespace fileapi |
OLD | NEW |