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; |
31 typedef FileSystemOperation::FileEntryList FileEntryList; | 32 typedef FileSystemOperation::FileEntryList FileEntryList; |
32 | 33 |
33 virtual ~RecursiveOperationDelegate(); | 34 virtual ~RecursiveOperationDelegate(); |
34 | 35 |
35 // 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 |
36 // operation. | 37 // operation. |
37 virtual void Run() = 0; | 38 virtual void Run() = 0; |
38 | 39 |
39 // 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 |
40 // operation. | 41 // operation. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // ProcessDirectory(e_dir) | 102 // ProcessDirectory(e_dir) |
102 // PostProcessDirectory(e_dir) | 103 // PostProcessDirectory(e_dir) |
103 // PostProcessDirectory(b2_dir) | 104 // PostProcessDirectory(b2_dir) |
104 // PostProcessDirectory(a_dir) | 105 // PostProcessDirectory(a_dir) |
105 // | 106 // |
106 // |callback| is fired with base::File::FILE_OK when every file/directory | 107 // |callback| is fired with base::File::FILE_OK when every file/directory |
107 // under |root| is processed, or fired earlier when any suboperation fails. | 108 // under |root| is processed, or fired earlier when any suboperation fails. |
108 void StartRecursiveOperation(const FileSystemURL& root, | 109 void StartRecursiveOperation(const FileSystemURL& root, |
109 const StatusCallback& callback); | 110 const StatusCallback& callback); |
110 | 111 |
| 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 |
111 FileSystemContext* file_system_context() { return file_system_context_; } | 126 FileSystemContext* file_system_context() { return file_system_context_; } |
112 const FileSystemContext* file_system_context() const { | 127 const FileSystemContext* file_system_context() const { |
113 return file_system_context_; | 128 return file_system_context_; |
114 } | 129 } |
115 | 130 |
116 FileSystemOperationRunner* operation_runner(); | 131 FileSystemOperationRunner* operation_runner(); |
117 | 132 |
118 // Called when Cancel() is called. This is a hook to do something more | 133 // Called when Cancel() is called. This is a hook to do something more |
119 // in a derived class. By default, do nothing. | 134 // in a derived class. By default, do nothing. |
120 virtual void OnCancel(); | 135 virtual void OnCancel(); |
121 | 136 |
122 private: | 137 private: |
| 138 void TryProcessFile(const FileSystemURL& root); |
123 void DidTryProcessFile(const FileSystemURL& root, | 139 void DidTryProcessFile(const FileSystemURL& root, |
124 base::File::Error error); | 140 base::File::Error error); |
125 void ProcessNextDirectory(); | 141 void ProcessNextDirectory(); |
126 void DidProcessDirectory(base::File::Error error); | 142 void DidProcessDirectory(base::File::Error error); |
127 void DidReadDirectory(const FileSystemURL& parent, | 143 void DidReadDirectory(const FileSystemURL& parent, |
128 base::File::Error error, | 144 base::File::Error error, |
129 const FileEntryList& entries, | 145 const FileEntryList& entries, |
130 bool has_more); | 146 bool has_more); |
131 void ProcessPendingFiles(); | 147 void ProcessPendingFiles(); |
132 void DidProcessFile(base::File::Error error); | 148 void DidProcessFile(const FileSystemURL& url, base::File::Error error); |
133 void ProcessSubDirectory(); | 149 void ProcessSubDirectory(); |
134 void DidPostProcessDirectory(base::File::Error error); | 150 void DidPostProcessDirectory(base::File::Error error); |
135 | 151 |
136 // Called when all recursive operation is done (or an error occurs). | 152 // Called when all recursive operation is done (or an error occurs). |
137 void Done(base::File::Error error); | 153 void Done(base::File::Error error); |
138 | 154 |
139 FileSystemContext* file_system_context_; | 155 FileSystemContext* file_system_context_; |
140 StatusCallback callback_; | 156 StatusCallback callback_; |
| 157 ErrorCallback error_callback_; |
141 std::stack<FileSystemURL> pending_directories_; | 158 std::stack<FileSystemURL> pending_directories_; |
142 std::stack<std::queue<FileSystemURL> > pending_directory_stack_; | 159 std::stack<std::queue<FileSystemURL> > pending_directory_stack_; |
143 std::queue<FileSystemURL> pending_files_; | 160 std::queue<FileSystemURL> pending_files_; |
144 int inflight_operations_; | 161 int inflight_operations_; |
145 bool canceled_; | 162 bool canceled_; |
| 163 bool ignore_error_; |
| 164 bool failed_some_operations_; |
146 | 165 |
147 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); | 166 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); |
148 }; | 167 }; |
149 | 168 |
150 } // namespace storage | 169 } // namespace storage |
151 | 170 |
152 #endif // STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ | 171 #endif // STORAGE_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
OLD | NEW |