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_RECURSIVE_OPERATION_DELEGATE_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <stack> | 9 #include <stack> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "webkit/browser/fileapi/file_system_operation.h" | 14 #include "storage/browser/fileapi/file_system_operation.h" |
15 #include "webkit/browser/fileapi/file_system_url.h" | 15 #include "storage/browser/fileapi/file_system_url.h" |
16 | 16 |
17 namespace fileapi { | 17 namespace storage { |
18 | 18 |
19 class FileSystemContext; | 19 class FileSystemContext; |
20 class FileSystemOperationRunner; | 20 class FileSystemOperationRunner; |
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 WEBKIT_STORAGE_BROWSER_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::FileEntryList FileEntryList; | 31 typedef FileSystemOperation::FileEntryList FileEntryList; |
32 | 32 |
33 virtual ~RecursiveOperationDelegate(); | 33 virtual ~RecursiveOperationDelegate(); |
34 | 34 |
35 // This is called when the consumer of this instance starts a non-recursive | 35 // This is called when the consumer of this instance starts a non-recursive |
36 // operation. | 36 // operation. |
37 virtual void Run() = 0; | 37 virtual void Run() = 0; |
38 | 38 |
39 // This is called when the consumer of this instance starts a recursive | 39 // This is called when the consumer of this instance starts a recursive |
40 // operation. | 40 // operation. |
41 virtual void RunRecursively() = 0; | 41 virtual void RunRecursively() = 0; |
42 | 42 |
43 // This is called each time a file is found while recursively | 43 // This is called each time a file is found while recursively |
44 // performing an operation. | 44 // performing an operation. |
45 virtual void ProcessFile(const FileSystemURL& url, | 45 virtual void ProcessFile(const FileSystemURL& url, |
46 const StatusCallback& callback) = 0; | 46 const StatusCallback& callback) = 0; |
47 | 47 |
48 // This is called each time a directory is found while recursively | 48 // This is called each time a directory is found while recursively |
49 // performing an operation. | 49 // performing an operation. |
50 virtual void ProcessDirectory(const FileSystemURL& url, | 50 virtual void ProcessDirectory(const FileSystemURL& url, |
51 const StatusCallback& callback) = 0; | 51 const StatusCallback& callback) = 0; |
52 | 52 |
53 | |
54 // This is called each time after files and subdirectories for a | 53 // This is called each time after files and subdirectories for a |
55 // directory is processed while recursively performing an operation. | 54 // directory is processed while recursively performing an operation. |
56 virtual void PostProcessDirectory(const FileSystemURL& url, | 55 virtual void PostProcessDirectory(const FileSystemURL& url, |
57 const StatusCallback& callback) = 0; | 56 const StatusCallback& callback) = 0; |
58 | 57 |
59 // Cancels the currently running operation. | 58 // Cancels the currently running operation. |
60 void Cancel(); | 59 void Cancel(); |
61 | 60 |
62 protected: | 61 protected: |
63 explicit RecursiveOperationDelegate(FileSystemContext* file_system_context); | 62 explicit RecursiveOperationDelegate(FileSystemContext* file_system_context); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return file_system_context_; | 112 return file_system_context_; |
114 } | 113 } |
115 | 114 |
116 FileSystemOperationRunner* operation_runner(); | 115 FileSystemOperationRunner* operation_runner(); |
117 | 116 |
118 // Called when Cancel() is called. This is a hook to do something more | 117 // Called when Cancel() is called. This is a hook to do something more |
119 // in a derived class. By default, do nothing. | 118 // in a derived class. By default, do nothing. |
120 virtual void OnCancel(); | 119 virtual void OnCancel(); |
121 | 120 |
122 private: | 121 private: |
123 void DidTryProcessFile(const FileSystemURL& root, | 122 void DidTryProcessFile(const FileSystemURL& root, base::File::Error error); |
124 base::File::Error error); | |
125 void ProcessNextDirectory(); | 123 void ProcessNextDirectory(); |
126 void DidProcessDirectory(base::File::Error error); | 124 void DidProcessDirectory(base::File::Error error); |
127 void DidReadDirectory(const FileSystemURL& parent, | 125 void DidReadDirectory(const FileSystemURL& parent, |
128 base::File::Error error, | 126 base::File::Error error, |
129 const FileEntryList& entries, | 127 const FileEntryList& entries, |
130 bool has_more); | 128 bool has_more); |
131 void ProcessPendingFiles(); | 129 void ProcessPendingFiles(); |
132 void DidProcessFile(base::File::Error error); | 130 void DidProcessFile(base::File::Error error); |
133 void ProcessSubDirectory(); | 131 void ProcessSubDirectory(); |
134 void DidPostProcessDirectory(base::File::Error error); | 132 void DidPostProcessDirectory(base::File::Error error); |
135 | 133 |
136 // Called when all recursive operation is done (or an error occurs). | 134 // Called when all recursive operation is done (or an error occurs). |
137 void Done(base::File::Error error); | 135 void Done(base::File::Error error); |
138 | 136 |
139 FileSystemContext* file_system_context_; | 137 FileSystemContext* file_system_context_; |
140 StatusCallback callback_; | 138 StatusCallback callback_; |
141 std::stack<FileSystemURL> pending_directories_; | 139 std::stack<FileSystemURL> pending_directories_; |
142 std::stack<std::queue<FileSystemURL> > pending_directory_stack_; | 140 std::stack<std::queue<FileSystemURL> > pending_directory_stack_; |
143 std::queue<FileSystemURL> pending_files_; | 141 std::queue<FileSystemURL> pending_files_; |
144 int inflight_operations_; | 142 int inflight_operations_; |
145 bool canceled_; | 143 bool canceled_; |
146 | 144 |
147 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); | 145 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); |
148 }; | 146 }; |
149 | 147 |
150 } // namespace fileapi | 148 } // namespace storage |
151 | 149 |
152 #endif // WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ | 150 #endif // WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
OLD | NEW |