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 STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ | 5 #ifndef STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
6 #define STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ | 6 #define STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <stack> | 9 #include <stack> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // A base class for recursive operation delegates. | 22 // A base class for recursive operation delegates. |
23 // | 23 // |
24 // In short, each subclass should override ProcessFile and ProcessDirectory | 24 // In short, each subclass should override ProcessFile and ProcessDirectory |
25 // to process a directory or a file. To start the recursive operation it | 25 // to process a directory or a file. To start the recursive operation it |
26 // should also call StartRecursiveOperation. | 26 // should also call StartRecursiveOperation. |
27 class STORAGE_EXPORT RecursiveOperationDelegate | 27 class STORAGE_EXPORT RecursiveOperationDelegate |
28 : public base::SupportsWeakPtr<RecursiveOperationDelegate> { | 28 : public base::SupportsWeakPtr<RecursiveOperationDelegate> { |
29 public: | 29 public: |
30 typedef FileSystemOperation::StatusCallback StatusCallback; | 30 typedef FileSystemOperation::StatusCallback StatusCallback; |
31 typedef FileSystemOperation::ErrorCallback ErrorCallback; | |
32 typedef FileSystemOperation::FileEntryList FileEntryList; | 31 typedef FileSystemOperation::FileEntryList FileEntryList; |
| 32 typedef FileSystemOperation::ErrorBehavior ErrorBehavior; |
33 | 33 |
34 virtual ~RecursiveOperationDelegate(); | 34 virtual ~RecursiveOperationDelegate(); |
35 | 35 |
36 // This is called when the consumer of this instance starts a non-recursive | 36 // This is called when the consumer of this instance starts a non-recursive |
37 // operation. | 37 // operation. |
38 virtual void Run() = 0; | 38 virtual void Run() = 0; |
39 | 39 |
40 // This is called when the consumer of this instance starts a recursive | 40 // This is called when the consumer of this instance starts a recursive |
41 // operation. | 41 // operation. |
42 virtual void RunRecursively() = 0; | 42 virtual void RunRecursively() = 0; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // ProcessDirectory(c1_dir). | 97 // ProcessDirectory(c1_dir). |
98 // ProcessFile(d1_file), ProcessFile(d2_file). (in parallel). | 98 // ProcessFile(d1_file), ProcessFile(d2_file). (in parallel). |
99 // PostProcessDirectory(c1_dir) | 99 // PostProcessDirectory(c1_dir) |
100 // PostProcessDirectory(b1_dir). | 100 // PostProcessDirectory(b1_dir). |
101 // ProcessDirectory(b2_dir) | 101 // ProcessDirectory(b2_dir) |
102 // ProcessDirectory(e_dir) | 102 // ProcessDirectory(e_dir) |
103 // PostProcessDirectory(e_dir) | 103 // PostProcessDirectory(e_dir) |
104 // PostProcessDirectory(b2_dir) | 104 // PostProcessDirectory(b2_dir) |
105 // PostProcessDirectory(a_dir) | 105 // PostProcessDirectory(a_dir) |
106 // | 106 // |
| 107 // |error_behavior| is to specify how this behaves when an operation have |
| 108 // failed. |
107 // |callback| is fired with base::File::FILE_OK when every file/directory | 109 // |callback| is fired with base::File::FILE_OK when every file/directory |
108 // under |root| is processed, or fired earlier when any suboperation fails. | 110 // under |root| is processed, or fired earlier when any suboperation fails. |
109 void StartRecursiveOperation(const FileSystemURL& root, | 111 void StartRecursiveOperation(const FileSystemURL& root, |
| 112 ErrorBehavior error_behavior, |
110 const StatusCallback& callback); | 113 const StatusCallback& callback); |
111 | 114 |
112 // Starts to process files/directories recursively from the given |root|. | |
113 // Compared with StartRecursiveOperation, this continues operation with | |
114 // ignoring erros of ProcessFile. | |
115 // | |
116 // |error_callback| is fired when a ProcessFile has failed in the middle of | |
117 // operations. If some errors had happened, |status_callback| is fired with | |
118 // base::File::FILE_ERROR_FAILED at the end. | |
119 // | |
120 // TODO(yawano): Handle errors of ProcessDirectory as well. | |
121 void StartRecursiveOperationWithIgnoringError( | |
122 const FileSystemURL& root, | |
123 const ErrorCallback& error_callback, | |
124 const StatusCallback& status_callback); | |
125 | |
126 FileSystemContext* file_system_context() { return file_system_context_; } | 115 FileSystemContext* file_system_context() { return file_system_context_; } |
127 const FileSystemContext* file_system_context() const { | 116 const FileSystemContext* file_system_context() const { |
128 return file_system_context_; | 117 return file_system_context_; |
129 } | 118 } |
130 | 119 |
131 FileSystemOperationRunner* operation_runner(); | 120 FileSystemOperationRunner* operation_runner(); |
132 | 121 |
133 // Called when Cancel() is called. This is a hook to do something more | 122 // Called when Cancel() is called. This is a hook to do something more |
134 // in a derived class. By default, do nothing. | 123 // in a derived class. By default, do nothing. |
135 virtual void OnCancel(); | 124 virtual void OnCancel(); |
(...skipping 11 matching lines...) Expand all Loading... |
147 void ProcessPendingFiles(); | 136 void ProcessPendingFiles(); |
148 void DidProcessFile(const FileSystemURL& url, base::File::Error error); | 137 void DidProcessFile(const FileSystemURL& url, base::File::Error error); |
149 void ProcessSubDirectory(); | 138 void ProcessSubDirectory(); |
150 void DidPostProcessDirectory(base::File::Error error); | 139 void DidPostProcessDirectory(base::File::Error error); |
151 | 140 |
152 // Called when all recursive operation is done (or an error occurs). | 141 // Called when all recursive operation is done (or an error occurs). |
153 void Done(base::File::Error error); | 142 void Done(base::File::Error error); |
154 | 143 |
155 FileSystemContext* file_system_context_; | 144 FileSystemContext* file_system_context_; |
156 StatusCallback callback_; | 145 StatusCallback callback_; |
157 ErrorCallback error_callback_; | |
158 std::stack<FileSystemURL> pending_directories_; | 146 std::stack<FileSystemURL> pending_directories_; |
159 std::stack<std::queue<FileSystemURL> > pending_directory_stack_; | 147 std::stack<std::queue<FileSystemURL> > pending_directory_stack_; |
160 std::queue<FileSystemURL> pending_files_; | 148 std::queue<FileSystemURL> pending_files_; |
161 int inflight_operations_; | 149 int inflight_operations_; |
162 bool canceled_; | 150 bool canceled_; |
163 bool ignore_error_; | 151 ErrorBehavior error_behavior_; |
164 bool failed_some_operations_; | 152 bool failed_some_operations_; |
165 | 153 |
166 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); | 154 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); |
167 }; | 155 }; |
168 | 156 |
169 } // namespace storage | 157 } // namespace storage |
170 | 158 |
171 #endif // STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ | 159 #endif // STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
OLD | NEW |