| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <stack> | 9 #include <stack> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "webkit/browser/fileapi/recursive_operation_delegate.h" | 14 #include "webkit/browser/fileapi/recursive_operation_delegate.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class DrainableIOBuffer; | 17 class DrainableIOBuffer; |
| 18 class IOBufferWithSize; | 18 class IOBufferWithSize; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace webkit_blob { | 21 namespace storage { |
| 22 class FileStreamReader; | 22 class FileStreamReader; |
| 23 class ShareableFileReference; | 23 class ShareableFileReference; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace fileapi { | 26 namespace storage { |
| 27 | 27 |
| 28 class CopyOrMoveFileValidator; | 28 class CopyOrMoveFileValidator; |
| 29 class FileStreamWriter; | 29 class FileStreamWriter; |
| 30 | 30 |
| 31 // A delegate class for recursive copy or move operations. | 31 // A delegate class for recursive copy or move operations. |
| 32 class CopyOrMoveOperationDelegate | 32 class CopyOrMoveOperationDelegate |
| 33 : public RecursiveOperationDelegate { | 33 : public RecursiveOperationDelegate { |
| 34 public: | 34 public: |
| 35 class CopyOrMoveImpl; | 35 class CopyOrMoveImpl; |
| 36 typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback; | 36 typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback; |
| 37 typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption; | 37 typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption; |
| 38 | 38 |
| 39 enum OperationType { | 39 enum OperationType { |
| 40 OPERATION_COPY, | 40 OPERATION_COPY, |
| 41 OPERATION_MOVE | 41 OPERATION_MOVE |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // Helper to copy a file by reader and writer streams. | 44 // Helper to copy a file by reader and writer streams. |
| 45 // Export for testing. | 45 // Export for testing. |
| 46 class WEBKIT_STORAGE_BROWSER_EXPORT StreamCopyHelper { | 46 class WEBKIT_STORAGE_BROWSER_EXPORT StreamCopyHelper { |
| 47 public: | 47 public: |
| 48 StreamCopyHelper( | 48 StreamCopyHelper( |
| 49 scoped_ptr<webkit_blob::FileStreamReader> reader, | 49 scoped_ptr<storage::FileStreamReader> reader, |
| 50 scoped_ptr<FileStreamWriter> writer, | 50 scoped_ptr<FileStreamWriter> writer, |
| 51 bool need_flush, | 51 bool need_flush, |
| 52 int buffer_size, | 52 int buffer_size, |
| 53 const FileSystemOperation::CopyFileProgressCallback& | 53 const FileSystemOperation::CopyFileProgressCallback& |
| 54 file_progress_callback, | 54 file_progress_callback, |
| 55 const base::TimeDelta& min_progress_callback_invocation_span); | 55 const base::TimeDelta& min_progress_callback_invocation_span); |
| 56 ~StreamCopyHelper(); | 56 ~StreamCopyHelper(); |
| 57 | 57 |
| 58 void Run(const StatusCallback& callback); | 58 void Run(const StatusCallback& callback); |
| 59 | 59 |
| 60 // Requests cancelling. After the cancelling is done, |callback| passed to | 60 // Requests cancelling. After the cancelling is done, |callback| passed to |
| 61 // Run will be called. | 61 // Run will be called. |
| 62 void Cancel(); | 62 void Cancel(); |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 // Reads the content from the |reader_|. | 65 // Reads the content from the |reader_|. |
| 66 void Read(const StatusCallback& callback); | 66 void Read(const StatusCallback& callback); |
| 67 void DidRead(const StatusCallback& callback, int result); | 67 void DidRead(const StatusCallback& callback, int result); |
| 68 | 68 |
| 69 // Writes the content in |buffer| to |writer_|. | 69 // Writes the content in |buffer| to |writer_|. |
| 70 void Write(const StatusCallback& callback, | 70 void Write(const StatusCallback& callback, |
| 71 scoped_refptr<net::DrainableIOBuffer> buffer); | 71 scoped_refptr<net::DrainableIOBuffer> buffer); |
| 72 void DidWrite(const StatusCallback& callback, | 72 void DidWrite(const StatusCallback& callback, |
| 73 scoped_refptr<net::DrainableIOBuffer> buffer, int result); | 73 scoped_refptr<net::DrainableIOBuffer> buffer, int result); |
| 74 | 74 |
| 75 // Flushes the written content in |writer_|. | 75 // Flushes the written content in |writer_|. |
| 76 void Flush(const StatusCallback& callback, bool is_eof); | 76 void Flush(const StatusCallback& callback, bool is_eof); |
| 77 void DidFlush(const StatusCallback& callback, bool is_eof, int result); | 77 void DidFlush(const StatusCallback& callback, bool is_eof, int result); |
| 78 | 78 |
| 79 scoped_ptr<webkit_blob::FileStreamReader> reader_; | 79 scoped_ptr<storage::FileStreamReader> reader_; |
| 80 scoped_ptr<FileStreamWriter> writer_; | 80 scoped_ptr<FileStreamWriter> writer_; |
| 81 const bool need_flush_; | 81 const bool need_flush_; |
| 82 FileSystemOperation::CopyFileProgressCallback file_progress_callback_; | 82 FileSystemOperation::CopyFileProgressCallback file_progress_callback_; |
| 83 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 83 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 84 int64 num_copied_bytes_; | 84 int64 num_copied_bytes_; |
| 85 int64 previous_flush_offset_; | 85 int64 previous_flush_offset_; |
| 86 base::Time last_progress_callback_invocation_time_; | 86 base::Time last_progress_callback_invocation_time_; |
| 87 base::TimeDelta min_progress_callback_invocation_span_; | 87 base::TimeDelta min_progress_callback_invocation_span_; |
| 88 bool cancel_requested_; | 88 bool cancel_requested_; |
| 89 base::WeakPtrFactory<StreamCopyHelper> weak_factory_; | 89 base::WeakPtrFactory<StreamCopyHelper> weak_factory_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 CopyOrMoveOption option_; | 150 CopyOrMoveOption option_; |
| 151 CopyProgressCallback progress_callback_; | 151 CopyProgressCallback progress_callback_; |
| 152 StatusCallback callback_; | 152 StatusCallback callback_; |
| 153 | 153 |
| 154 std::set<CopyOrMoveImpl*> running_copy_set_; | 154 std::set<CopyOrMoveImpl*> running_copy_set_; |
| 155 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; | 155 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; |
| 156 | 156 |
| 157 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); | 157 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 } // namespace fileapi | 160 } // namespace storage |
| 161 | 161 |
| 162 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ | 162 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ |
| OLD | NEW |