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 <stack> | 8 #include <stack> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/time.h" |
12 #include "webkit/browser/fileapi/recursive_operation_delegate.h" | 13 #include "webkit/browser/fileapi/recursive_operation_delegate.h" |
13 | 14 |
| 15 namespace net { |
| 16 class DrainableIOBuffer; |
| 17 class IOBufferWithSize; |
| 18 } |
| 19 |
14 namespace webkit_blob { | 20 namespace webkit_blob { |
| 21 class FileStreamReader; |
15 class ShareableFileReference; | 22 class ShareableFileReference; |
16 } | 23 } |
17 | 24 |
18 namespace fileapi { | 25 namespace fileapi { |
19 | 26 |
20 class CopyOrMoveFileValidator; | 27 class CopyOrMoveFileValidator; |
| 28 class FileStreamWriter; |
21 | 29 |
22 // A delegate class for recursive copy or move operations. | 30 // A delegate class for recursive copy or move operations. |
23 class CopyOrMoveOperationDelegate | 31 class CopyOrMoveOperationDelegate |
24 : public RecursiveOperationDelegate { | 32 : public RecursiveOperationDelegate { |
25 public: | 33 public: |
26 class CopyOrMoveImpl; | 34 class CopyOrMoveImpl; |
27 typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback; | 35 typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback; |
28 | 36 |
29 enum OperationType { | 37 enum OperationType { |
30 OPERATION_COPY, | 38 OPERATION_COPY, |
31 OPERATION_MOVE | 39 OPERATION_MOVE |
32 }; | 40 }; |
33 | 41 |
| 42 // Helper to copy a file by reader and writer streams. |
| 43 // Export for testing. |
| 44 class WEBKIT_STORAGE_BROWSER_EXPORT StreamCopyHelper { |
| 45 public: |
| 46 StreamCopyHelper( |
| 47 scoped_ptr<webkit_blob::FileStreamReader> reader, |
| 48 scoped_ptr<FileStreamWriter> writer, |
| 49 int buffer_size, |
| 50 const FileSystemOperation::CopyFileProgressCallback& |
| 51 file_progress_callback, |
| 52 const base::TimeDelta& min_progress_callback_invocation_span); |
| 53 ~StreamCopyHelper(); |
| 54 |
| 55 void Run(const StatusCallback& callback); |
| 56 |
| 57 private: |
| 58 // Reads the content from the |reader_|. |
| 59 void Read(const StatusCallback& callback); |
| 60 void DidRead(const StatusCallback& callback, int result); |
| 61 |
| 62 // Writes the content in |buffer| to |writer_|. |
| 63 void Write(const StatusCallback& callback, |
| 64 scoped_refptr<net::DrainableIOBuffer> buffer); |
| 65 void DidWrite(const StatusCallback& callback, |
| 66 scoped_refptr<net::DrainableIOBuffer> buffer, int result); |
| 67 |
| 68 scoped_ptr<webkit_blob::FileStreamReader> reader_; |
| 69 scoped_ptr<FileStreamWriter> writer_; |
| 70 FileSystemOperation::CopyFileProgressCallback file_progress_callback_; |
| 71 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 72 int64 num_copied_bytes_; |
| 73 base::Time last_progress_callback_invocation_time_; |
| 74 base::TimeDelta min_progress_callback_invocation_span_; |
| 75 base::WeakPtrFactory<StreamCopyHelper> weak_factory_; |
| 76 DISALLOW_COPY_AND_ASSIGN(StreamCopyHelper); |
| 77 }; |
| 78 |
34 CopyOrMoveOperationDelegate( | 79 CopyOrMoveOperationDelegate( |
35 FileSystemContext* file_system_context, | 80 FileSystemContext* file_system_context, |
36 const FileSystemURL& src_root, | 81 const FileSystemURL& src_root, |
37 const FileSystemURL& dest_root, | 82 const FileSystemURL& dest_root, |
38 OperationType operation_type, | 83 OperationType operation_type, |
39 const CopyProgressCallback& progress_callback, | 84 const CopyProgressCallback& progress_callback, |
40 const StatusCallback& callback); | 85 const StatusCallback& callback); |
41 virtual ~CopyOrMoveOperationDelegate(); | 86 virtual ~CopyOrMoveOperationDelegate(); |
42 | 87 |
43 // RecursiveOperationDelegate overrides: | 88 // RecursiveOperationDelegate overrides: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 125 |
81 std::set<CopyOrMoveImpl*> running_copy_set_; | 126 std::set<CopyOrMoveImpl*> running_copy_set_; |
82 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; | 127 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; |
83 | 128 |
84 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); | 129 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); |
85 }; | 130 }; |
86 | 131 |
87 } // namespace fileapi | 132 } // namespace fileapi |
88 | 133 |
89 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ | 134 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ |
OLD | NEW |