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_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ 6 #define WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_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/browser/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 CopyOrMoveOperationDelegate 24 : public RecursiveOperationDelegate { 25 public: 26 enum OperationType { 27 OPERATION_COPY, 28 OPERATION_MOVE 29 }; 30 31 CopyOrMoveOperationDelegate( 32 FileSystemContext* file_system_context, 33 const FileSystemURL& src_root, 34 const FileSystemURL& dest_root, 35 OperationType operation_type, 36 const StatusCallback& callback); 37 virtual ~CopyOrMoveOperationDelegate(); 38 39 // RecursiveOperationDelegate overrides: 40 virtual void Run() OVERRIDE; 41 virtual void RunRecursively() OVERRIDE; 42 virtual void ProcessFile(const FileSystemURL& url, 43 const StatusCallback& callback) OVERRIDE; 44 virtual void ProcessDirectory(const FileSystemURL& url, 45 const StatusCallback& callback) OVERRIDE; 46 47 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); 58 void DidTryRemoveDestRoot(base::PlatformFileError error); 59 void CopyOrMoveFile( 60 const URLPair& url_pair, 61 const StatusCallback& callback); 62 void DidCreateSnapshot( 63 const URLPair& url_pair, 64 const StatusCallback& callback, 65 base::PlatformFileError error, 66 const base::PlatformFileInfo& file_info, 67 const base::FilePath& platform_path, 68 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); 69 void DidValidateFile( 70 const FileSystemURL& dest, 71 const StatusCallback& callback, 72 const base::PlatformFileInfo& file_info, 73 const base::FilePath& platform_path, 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 103 FileSystemURL CreateDestURL(const FileSystemURL& src_url) const; 104 105 FileSystemURL src_root_; 106 FileSystemURL dest_root_; 107 bool same_file_system_; 108 OperationType operation_type_; 109 StatusCallback callback_; 110 111 scoped_refptr<webkit_blob::ShareableFileReference> current_file_ref_; 112 113 scoped_ptr<CopyOrMoveFileValidator> validator_; 114 115 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; 116 117 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); 118 }; 119 120 } // namespace fileapi 121 122 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ 123