mesa gn build: suppress -Wstring-conversion warnings
[chromium-blink-merge.git] / storage / browser / fileapi / copy_or_move_operation_delegate.h
blob7860e1e95f19d3d0facf3f13a6def34294c9f194
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 STORAGE_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_
6 #define STORAGE_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_
8 #include <set>
9 #include <stack>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "storage/browser/fileapi/recursive_operation_delegate.h"
16 namespace net {
17 class DrainableIOBuffer;
18 class IOBufferWithSize;
21 namespace storage {
22 class FileStreamReader;
23 class ShareableFileReference;
26 namespace storage {
28 class CopyOrMoveFileValidator;
29 class FileStreamWriter;
31 // A delegate class for recursive copy or move operations.
32 class CopyOrMoveOperationDelegate
33 : public RecursiveOperationDelegate {
34 public:
35 class CopyOrMoveImpl;
36 typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback;
37 typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption;
39 enum OperationType {
40 OPERATION_COPY,
41 OPERATION_MOVE
44 // Helper to copy a file by reader and writer streams.
45 // Export for testing.
46 class STORAGE_EXPORT StreamCopyHelper {
47 public:
48 StreamCopyHelper(
49 scoped_ptr<storage::FileStreamReader> reader,
50 scoped_ptr<FileStreamWriter> writer,
51 bool need_flush,
52 int buffer_size,
53 const FileSystemOperation::CopyFileProgressCallback&
54 file_progress_callback,
55 const base::TimeDelta& min_progress_callback_invocation_span);
56 ~StreamCopyHelper();
58 void Run(const StatusCallback& callback);
60 // Requests cancelling. After the cancelling is done, |callback| passed to
61 // Run will be called.
62 void Cancel();
64 private:
65 // Reads the content from the |reader_|.
66 void Read(const StatusCallback& callback);
67 void DidRead(const StatusCallback& callback, int result);
69 // Writes the content in |buffer| to |writer_|.
70 void Write(const StatusCallback& callback,
71 scoped_refptr<net::DrainableIOBuffer> buffer);
72 void DidWrite(const StatusCallback& callback,
73 scoped_refptr<net::DrainableIOBuffer> buffer, int result);
75 // Flushes the written content in |writer_|.
76 void Flush(const StatusCallback& callback, bool is_eof);
77 void DidFlush(const StatusCallback& callback, bool is_eof, int result);
79 scoped_ptr<storage::FileStreamReader> reader_;
80 scoped_ptr<FileStreamWriter> writer_;
81 const bool need_flush_;
82 FileSystemOperation::CopyFileProgressCallback file_progress_callback_;
83 scoped_refptr<net::IOBufferWithSize> io_buffer_;
84 int64 num_copied_bytes_;
85 int64 previous_flush_offset_;
86 base::Time last_progress_callback_invocation_time_;
87 base::TimeDelta min_progress_callback_invocation_span_;
88 bool cancel_requested_;
89 base::WeakPtrFactory<StreamCopyHelper> weak_factory_;
90 DISALLOW_COPY_AND_ASSIGN(StreamCopyHelper);
93 CopyOrMoveOperationDelegate(
94 FileSystemContext* file_system_context,
95 const FileSystemURL& src_root,
96 const FileSystemURL& dest_root,
97 OperationType operation_type,
98 CopyOrMoveOption option,
99 const CopyProgressCallback& progress_callback,
100 const StatusCallback& callback);
101 ~CopyOrMoveOperationDelegate() override;
103 // RecursiveOperationDelegate overrides:
104 void Run() override;
105 void RunRecursively() override;
106 void ProcessFile(const FileSystemURL& url,
107 const StatusCallback& callback) override;
108 void ProcessDirectory(const FileSystemURL& url,
109 const StatusCallback& callback) override;
110 void PostProcessDirectory(const FileSystemURL& url,
111 const StatusCallback& callback) override;
113 protected:
114 void OnCancel() override;
116 private:
117 void DidCopyOrMoveFile(const FileSystemURL& src_url,
118 const FileSystemURL& dest_url,
119 const StatusCallback& callback,
120 CopyOrMoveImpl* impl,
121 base::File::Error error);
122 void DidTryRemoveDestRoot(const StatusCallback& callback,
123 base::File::Error error);
124 void ProcessDirectoryInternal(const FileSystemURL& src_url,
125 const FileSystemURL& dest_url,
126 const StatusCallback& callback);
127 void DidCreateDirectory(const FileSystemURL& src_url,
128 const FileSystemURL& dest_url,
129 const StatusCallback& callback,
130 base::File::Error error);
131 void PostProcessDirectoryAfterGetMetadata(
132 const FileSystemURL& src_url,
133 const StatusCallback& callback,
134 base::File::Error error,
135 const base::File::Info& file_info);
136 void PostProcessDirectoryAfterTouchFile(const FileSystemURL& src_url,
137 const StatusCallback& callback,
138 base::File::Error error);
139 void DidRemoveSourceForMove(const StatusCallback& callback,
140 base::File::Error error);
142 void OnCopyFileProgress(const FileSystemURL& src_url, int64 size);
143 FileSystemURL CreateDestURL(const FileSystemURL& src_url) const;
145 FileSystemURL src_root_;
146 FileSystemURL dest_root_;
147 bool same_file_system_;
148 OperationType operation_type_;
149 CopyOrMoveOption option_;
150 CopyProgressCallback progress_callback_;
151 StatusCallback callback_;
153 std::set<CopyOrMoveImpl*> running_copy_set_;
154 base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_;
156 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate);
159 } // namespace storage
161 #endif // STORAGE_BROWSER_FILEAPI_COPY_OR_MOVE_OPERATION_DELEGATE_H_