| 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 class CopyOrMoveImpl; |
| 27 |
| 26 enum OperationType { | 28 enum OperationType { |
| 27 OPERATION_COPY, | 29 OPERATION_COPY, |
| 28 OPERATION_MOVE | 30 OPERATION_MOVE |
| 29 }; | 31 }; |
| 30 | 32 |
| 31 CopyOrMoveOperationDelegate( | 33 CopyOrMoveOperationDelegate( |
| 32 FileSystemContext* file_system_context, | 34 FileSystemContext* file_system_context, |
| 33 const FileSystemURL& src_root, | 35 const FileSystemURL& src_root, |
| 34 const FileSystemURL& dest_root, | 36 const FileSystemURL& dest_root, |
| 35 OperationType operation_type, | 37 OperationType operation_type, |
| 36 const StatusCallback& callback); | 38 const StatusCallback& callback); |
| 37 virtual ~CopyOrMoveOperationDelegate(); | 39 virtual ~CopyOrMoveOperationDelegate(); |
| 38 | 40 |
| 39 // RecursiveOperationDelegate overrides: | 41 // RecursiveOperationDelegate overrides: |
| 40 virtual void Run() OVERRIDE; | 42 virtual void Run() OVERRIDE; |
| 41 virtual void RunRecursively() OVERRIDE; | 43 virtual void RunRecursively() OVERRIDE; |
| 42 virtual void ProcessFile(const FileSystemURL& url, | 44 virtual void ProcessFile(const FileSystemURL& url, |
| 43 const StatusCallback& callback) OVERRIDE; | 45 const StatusCallback& callback) OVERRIDE; |
| 44 virtual void ProcessDirectory(const FileSystemURL& url, | 46 virtual void ProcessDirectory(const FileSystemURL& url, |
| 45 const StatusCallback& callback) OVERRIDE; | 47 const StatusCallback& callback) OVERRIDE; |
| 46 | 48 |
| 47 private: | 49 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); | 50 void DidTryCopyOrMoveFile(base::PlatformFileError error); |
| 58 void DidTryRemoveDestRoot(base::PlatformFileError error); | 51 void DidTryRemoveDestRoot(base::PlatformFileError error); |
| 59 void CopyOrMoveFile( | 52 void DidFinishRecursiveCopyDir(const FileSystemURL& src, |
| 60 const URLPair& url_pair, | 53 const StatusCallback& callback, |
| 61 const StatusCallback& callback); | 54 base::PlatformFileError error); |
| 62 void DidCreateSnapshot( | 55 void DidRemoveSourceForMove(const StatusCallback& callback, |
| 63 const URLPair& url_pair, | 56 base::PlatformFileError error); |
| 64 const StatusCallback& callback, | 57 |
| 65 base::PlatformFileError error, | 58 // Starts Copy (or Move based on |operation_type_|) from |src_url| to |
| 66 const base::PlatformFileInfo& file_info, | 59 // |dest_url|. Upon completion |callback| is invoked. |
| 67 const base::FilePath& platform_path, | 60 // This can be run for multiple files in parallel. |
| 68 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 61 void CopyOrMoveFile(const FileSystemURL& src_url, |
| 69 void DidValidateFile( | 62 const FileSystemURL& dest_url, |
| 70 const FileSystemURL& dest, | 63 const StatusCallback& callback); |
| 71 const StatusCallback& callback, | 64 void DidCopyOrMoveFile(CopyOrMoveImpl* impl, |
| 72 const base::PlatformFileInfo& file_info, | 65 const StatusCallback& callback, |
| 73 const base::FilePath& platform_path, | 66 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 | 67 |
| 103 FileSystemURL CreateDestURL(const FileSystemURL& src_url) const; | 68 FileSystemURL CreateDestURL(const FileSystemURL& src_url) const; |
| 104 | 69 |
| 105 FileSystemURL src_root_; | 70 FileSystemURL src_root_; |
| 106 FileSystemURL dest_root_; | 71 FileSystemURL dest_root_; |
| 107 bool same_file_system_; | 72 bool same_file_system_; |
| 108 OperationType operation_type_; | 73 OperationType operation_type_; |
| 109 StatusCallback callback_; | 74 StatusCallback callback_; |
| 110 | 75 |
| 111 scoped_refptr<webkit_blob::ShareableFileReference> current_file_ref_; | 76 std::set<CopyOrMoveImpl*> running_copy_set_; |
| 112 | |
| 113 scoped_ptr<CopyOrMoveFileValidator> validator_; | |
| 114 | |
| 115 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; | 77 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_; |
| 116 | 78 |
| 117 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); | 79 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); |
| 118 }; | 80 }; |
| 119 | 81 |
| 120 } // namespace fileapi | 82 } // namespace fileapi |
| 121 | 83 |
| 122 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ | 84 #endif // WEBKIT_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_ |
| OLD | NEW |