OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_FILEAPI_CROSS_OPERATION_DELEGATE_H_ | |
6 #define WEBKIT_FILEAPI_CROSS_OPERATION_DELEGATE_H_ | |
7 | |
8 #include <stack> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "webkit/fileapi/recursive_operation_delegate.h" | |
13 | |
14 namespace webkit_blob { | |
15 class ShareableFileReference; | |
16 } | |
17 | |
18 namespace fileapi { | |
19 | |
20 class CopyOrMoveFileValidator; | |
21 | |
22 // A delegate class for recursive copy or move operations. | |
23 class CrossOperationDelegate | |
24 : public RecursiveOperationDelegate, | |
25 public base::SupportsWeakPtr<CrossOperationDelegate> { | |
26 public: | |
27 enum OperationType { | |
28 OPERATION_COPY, | |
29 OPERATION_MOVE | |
30 }; | |
31 | |
32 CrossOperationDelegate( | |
33 FileSystemContext* file_system_context, | |
34 scoped_ptr<LocalFileSystemOperation> src_root_operation, | |
35 LocalFileSystemOperation* dest_root_operation, | |
36 const FileSystemURL& src_root, | |
37 const FileSystemURL& dest_root, | |
38 OperationType operation_type, | |
39 const StatusCallback& callback); | |
40 virtual ~CrossOperationDelegate(); | |
41 | |
42 // RecursiveOperationDelegate overrides: | |
43 virtual void Run() OVERRIDE; | |
44 virtual void RunRecursively() OVERRIDE; | |
45 virtual void ProcessFile(const FileSystemURL& url, | |
46 const StatusCallback& callback) OVERRIDE; | |
47 virtual void ProcessDirectory(const FileSystemURL& url, | |
48 const StatusCallback& callback) OVERRIDE; | |
49 | |
50 using base::SupportsWeakPtr<CrossOperationDelegate>::AsWeakPtr; | |
51 | |
52 private: | |
53 struct URLPair { | |
54 URLPair(const FileSystemURL& src, const FileSystemURL& dest) | |
55 : src(src), | |
56 dest(dest) { | |
57 } | |
58 FileSystemURL src; | |
59 FileSystemURL dest; | |
60 }; | |
61 | |
62 void DidTryCopyOrMoveFile(base::PlatformFileError error); | |
63 void DidTryRemoveDestRoot(base::PlatformFileError error); | |
64 void CopyOrMoveFile( | |
65 const URLPair& url_pair, | |
66 const StatusCallback& callback); | |
67 void DidCreateSnapshot( | |
68 const URLPair& url_pair, | |
69 const StatusCallback& callback, | |
70 base::PlatformFileError error, | |
71 const base::PlatformFileInfo& file_info, | |
72 const base::FilePath& platform_path, | |
73 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | |
74 void DidValidateFile( | |
75 const FileSystemURL& dest, | |
76 const StatusCallback& callback, | |
77 const base::PlatformFileInfo& file_info, | |
78 const base::FilePath& platform_path, | |
79 base::PlatformFileError error); | |
80 void DidFinishCopy( | |
81 const FileSystemURL& src, | |
82 const StatusCallback& callback, | |
83 base::PlatformFileError error); | |
84 void DidRemoveSourceForMove( | |
85 const StatusCallback& callback, | |
86 base::PlatformFileError error); | |
87 | |
88 FileSystemURL CreateDestURL(const FileSystemURL& src_url) const; | |
89 | |
90 // Create nested operations for recursive task. | |
91 // When the creation fails it fires callback_ with the | |
92 // error code and returns NULL. | |
93 // | |
94 // - NewDestOperation is basically a thin wrapper of | |
95 // RecursiveOperationDelegate::NewOperation(). | |
96 // - NewSourceOperation also redirects the request to | |
97 // RecursiveOperationDelegate::NewOperation() **iff** same_file_system_ | |
98 // is true. | |
99 // Otherwise it's for cross-filesystem operation and it needs a | |
100 // separate FileSystemOperationContext, so it creates a new operation | |
101 // which inherits context from src_root_operation_. | |
102 // | |
103 LocalFileSystemOperation* NewDestOperation(); | |
104 LocalFileSystemOperation* NewSourceOperation(); | |
105 | |
106 FileSystemURL src_root_; | |
107 FileSystemURL dest_root_; | |
108 bool same_file_system_; | |
109 OperationType operation_type_; | |
110 StatusCallback callback_; | |
111 | |
112 scoped_ptr<LocalFileSystemOperation> src_root_operation_; | |
113 | |
114 scoped_refptr<webkit_blob::ShareableFileReference> current_file_ref_; | |
115 | |
116 scoped_ptr<CopyOrMoveFileValidator> validator_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(CrossOperationDelegate); | |
119 }; | |
120 | |
121 } // namespace fileapi | |
122 | |
123 #endif // WEBKIT_FILEAPI_CROSS_OPERATION_DELEGATE_H_ | |
OLD | NEW |