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.
5 #ifndef WEBKIT_FILEAPI_CROSS_OPERATION_DELEGATE_H_
6 #define WEBKIT_FILEAPI_CROSS_OPERATION_DELEGATE_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "webkit/fileapi/recursive_operation_delegate.h"
14 namespace webkit_blob
{
15 class ShareableFileReference
;
20 class CopyOrMoveFileValidator
;
22 // A delegate class for recursive copy or move operations.
23 class CrossOperationDelegate
24 : public RecursiveOperationDelegate
,
25 public base::SupportsWeakPtr
<CrossOperationDelegate
> {
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();
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
;
50 using base::SupportsWeakPtr
<CrossOperationDelegate
>::AsWeakPtr
;
53 void DidTryCopyOrMoveFile(base::PlatformFileError error
);
54 void DidTryRemoveDestRoot(base::PlatformFileError error
);
56 const FileSystemURL
& src
,
57 const FileSystemURL
& dest
,
58 const StatusCallback
& callback
);
59 void DidCreateSnapshot(
60 const FileSystemURL
& dest
,
61 const StatusCallback
& callback
,
62 base::PlatformFileError error
,
63 const base::PlatformFileInfo
& file_info
,
64 const base::FilePath
& platform_path
,
65 const scoped_refptr
<webkit_blob::ShareableFileReference
>& file_ref
);
67 const FileSystemURL
& dest
,
68 const StatusCallback
& callback
,
69 const base::PlatformFileInfo
& file_info
,
70 const base::FilePath
& platform_path
,
71 base::PlatformFileError error
);
73 const FileSystemURL
& src
,
74 const StatusCallback
& callback
,
75 base::PlatformFileError error
);
76 void DidRemoveSourceForMove(
77 const StatusCallback
& callback
,
78 base::PlatformFileError error
);
80 FileSystemURL
CreateDestURL(const FileSystemURL
& src_url
) const;
82 // Create nested operations for recursive task.
83 // When the creation fails it fires callback_ with the
84 // error code and returns NULL.
86 // - NewDestOperation is basically a thin wrapper of
87 // RecursiveOperationDelegate::NewOperation().
88 // - NewSourceOperation also redirects the request to
89 // RecursiveOperationDelegate::NewOperation() **iff** same_file_system_
91 // Otherwise it's for cross-filesystem operation and it needs a
92 // separate FileSystemOperationContext, so it creates a new operation
93 // which inherits context from src_root_operation_.
95 LocalFileSystemOperation
* NewDestOperation();
96 LocalFileSystemOperation
* NewSourceOperation();
98 FileSystemURL src_root_
;
99 FileSystemURL dest_root_
;
100 bool same_file_system_
;
101 OperationType operation_type_
;
102 StatusCallback callback_
;
104 scoped_ptr
<LocalFileSystemOperation
> src_root_operation_
;
106 scoped_refptr
<webkit_blob::ShareableFileReference
> current_file_ref_
;
108 scoped_ptr
<CopyOrMoveFileValidator
> validator_
;
110 DISALLOW_COPY_AND_ASSIGN(CrossOperationDelegate
);
113 } // namespace fileapi
115 #endif // WEBKIT_FILEAPI_CROSS_OPERATION_DELEGATE_H_