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 "webkit/browser/fileapi/recursive_operation_delegate.h" | 12 #include "webkit/browser/fileapi/recursive_operation_delegate.h" |
13 | 13 |
14 namespace webkit_blob { | 14 namespace webkit_blob { |
15 class ShareableFileReference; | 15 class ShareableFileReference; |
16 } | 16 } |
17 | 17 |
18 namespace fileapi { | 18 namespace fileapi { |
19 | 19 |
20 class CopyOrMoveFileValidator; | 20 class CopyOrMoveFileValidator; |
21 | 21 |
22 // A delegate class for recursive copy or move operations. | 22 // A delegate class for recursive copy or move operations. |
23 class CopyOrMoveOperationDelegate | 23 class CopyOrMoveOperationDelegate |
24 : public RecursiveOperationDelegate { | 24 : public RecursiveOperationDelegate { |
25 public: | 25 public: |
26 // Implementation of Copy file. | |
kinuko
2013/09/09 16:12:38
nit: this comment is probably not necessary (not a
hidehiko
2013/09/09 16:55:35
Removed.
| |
27 class CopyOrMoveImpl; | |
28 | |
26 enum OperationType { | 29 enum OperationType { |
27 OPERATION_COPY, | 30 OPERATION_COPY, |
28 OPERATION_MOVE | 31 OPERATION_MOVE |
29 }; | 32 }; |
30 | 33 |
31 CopyOrMoveOperationDelegate( | 34 CopyOrMoveOperationDelegate( |
32 FileSystemContext* file_system_context, | 35 FileSystemContext* file_system_context, |
33 const FileSystemURL& src_root, | 36 const FileSystemURL& src_root, |
34 const FileSystemURL& dest_root, | 37 const FileSystemURL& dest_root, |
35 OperationType operation_type, | 38 OperationType operation_type, |
36 const StatusCallback& callback); | 39 const StatusCallback& callback); |
37 virtual ~CopyOrMoveOperationDelegate(); | 40 virtual ~CopyOrMoveOperationDelegate(); |
38 | 41 |
39 // RecursiveOperationDelegate overrides: | 42 // RecursiveOperationDelegate overrides: |
40 virtual void Run() OVERRIDE; | 43 virtual void Run() OVERRIDE; |
41 virtual void RunRecursively() OVERRIDE; | 44 virtual void RunRecursively() OVERRIDE; |
42 virtual void ProcessFile(const FileSystemURL& url, | 45 virtual void ProcessFile(const FileSystemURL& url, |
43 const StatusCallback& callback) OVERRIDE; | 46 const StatusCallback& callback) OVERRIDE; |
44 virtual void ProcessDirectory(const FileSystemURL& url, | 47 virtual void ProcessDirectory(const FileSystemURL& url, |
45 const StatusCallback& callback) OVERRIDE; | 48 const StatusCallback& callback) OVERRIDE; |
46 | 49 |
47 private: | 50 private: |
48 struct URLPair { | |
49 URLPair(const FileSystemURL& src, const FileSystemURL& dest) | |
50 : src(src), | |
51 dest(dest) { | |
52 } | |
53 FileSystemURL src; | |
54 FileSystemURL dest; | |
55 }; | |
56 | |
57 void DidTryCopyOrMoveFile(base::PlatformFileError error); | 51 void DidTryCopyOrMoveFile(base::PlatformFileError error); |
58 void DidTryRemoveDestRoot(base::PlatformFileError error); | 52 void DidTryRemoveDestRoot(base::PlatformFileError error); |
59 void CopyOrMoveFile( | 53 void DidFinishRecursiveCopyDir(const FileSystemURL& src, |
60 const URLPair& url_pair, | 54 const StatusCallback& callback, |
61 const StatusCallback& callback); | 55 base::PlatformFileError error); |
62 void DidCreateSnapshot( | 56 void DidRemoveSourceForMove(const StatusCallback& callback, |
63 const URLPair& url_pair, | 57 base::PlatformFileError error); |
64 const StatusCallback& callback, | 58 |
65 base::PlatformFileError error, | 59 // Starts Copy (or Move based on |operation_type_|) from |src_url| to |
66 const base::PlatformFileInfo& file_info, | 60 // |dest_url|. Upon completion |callback| is invoked. |
67 const base::FilePath& platform_path, | 61 // This can be run for multiple files in parallel. |
68 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 62 void CopyOrMoveFile(const FileSystemURL& src_url, |
69 void DidValidateFile( | 63 const FileSystemURL& dest_url, |
70 const FileSystemURL& dest, | 64 const StatusCallback& callback); |
71 const StatusCallback& callback, | 65 void DidCopyOrMoveFile(CopyOrMoveImpl* impl, |
72 const base::PlatformFileInfo& file_info, | 66 const StatusCallback& callback, |
73 const base::FilePath& platform_path, | 67 base::PlatformFileError error); |
74 base::PlatformFileError error); | |
75 void DidFinishRecursiveCopyDir( | |
76 const FileSystemURL& src, | |
77 const StatusCallback& callback, | |
78 base::PlatformFileError error); | |
79 void DidFinishCopy( | |
80 const URLPair& url_pair, | |
81 const StatusCallback& callback, | |
82 base::PlatformFileError error); | |
83 void DoPostWriteValidation( | |
84 const URLPair& url_pair, | |
85 const StatusCallback& callback, | |
86 base::PlatformFileError error, | |
87 const base::PlatformFileInfo& file_info, | |
88 const base::FilePath& platform_path, | |
89 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | |
90 void DidPostWriteValidation( | |
91 const URLPair& url_pair, | |
92 const StatusCallback& callback, | |
93 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, | |
94 base::PlatformFileError error); | |
95 void DidRemoveSourceForMove( | |
96 const StatusCallback& callback, | |
97 base::PlatformFileError error); | |
98 void DidRemoveDestForError( | |
99 base::PlatformFileError prior_error, | |
100 const StatusCallback& callback, | |
101 base::PlatformFileError error); | |
102 | 68 |
103 FileSystemURL CreateDestURL(const FileSystemURL& src_url) const; | 69 FileSystemURL CreateDestURL(const FileSystemURL& src_url) const; |
104 | 70 |
105 FileSystemURL src_root_; | 71 FileSystemURL src_root_; |
106 FileSystemURL dest_root_; | 72 FileSystemURL dest_root_; |
107 bool same_file_system_; | 73 bool same_file_system_; |
108 OperationType operation_type_; | 74 OperationType operation_type_; |
109 StatusCallback callback_; | 75 StatusCallback callback_; |
110 | 76 |
111 scoped_refptr<webkit_blob::ShareableFileReference> current_file_ref_; | 77 std::set<CopyOrMoveImpl*> running_copy_set_; |
112 | |
113 scoped_ptr<CopyOrMoveFileValidator> validator_; | |
114 | |
115 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; | 78 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; |
116 | 79 |
117 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); | 80 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); |
118 }; | 81 }; |
119 | 82 |
120 } // namespace fileapi | 83 } // namespace fileapi |
121 | 84 |
122 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ | 85 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ |
OLD | NEW |