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 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void Cancel(); | 60 void Cancel(); |
61 | 61 |
62 protected: | 62 protected: |
63 explicit RecursiveOperationDelegate(FileSystemContext* file_system_context); | 63 explicit RecursiveOperationDelegate(FileSystemContext* file_system_context); |
64 | 64 |
65 // Starts to process files/directories recursively from the given |root|. | 65 // Starts to process files/directories recursively from the given |root|. |
66 // This will call ProcessFile and ProcessDirectory on each file or directory. | 66 // This will call ProcessFile and ProcessDirectory on each file or directory. |
67 // | 67 // |
68 // First, this tries to call ProcessFile with |root| regardless whether it is | 68 // First, this tries to call ProcessFile with |root| regardless whether it is |
69 // actually a file or a directory. If it is a directory, ProcessFile should | 69 // actually a file or a directory. If it is a directory, ProcessFile should |
70 // return PLATFORM_FILE_NOT_A_FILE. | 70 // return File::FILE_NOT_A_FILE. |
71 // | 71 // |
72 // For each directory, the recursive operation works as follows: | 72 // For each directory, the recursive operation works as follows: |
73 // ProcessDirectory is called first for the directory. | 73 // ProcessDirectory is called first for the directory. |
74 // Then the directory contents are read (to obtain its sub directories and | 74 // Then the directory contents are read (to obtain its sub directories and |
75 // files in it). | 75 // files in it). |
76 // ProcessFile is called for found files. This may run in parallel. | 76 // ProcessFile is called for found files. This may run in parallel. |
77 // The same step is recursively applied to each subdirectory. | 77 // The same step is recursively applied to each subdirectory. |
78 // After all files and subdirectories in a directory are processed, | 78 // After all files and subdirectories in a directory are processed, |
79 // PostProcessDirectory is called for the directory. | 79 // PostProcessDirectory is called for the directory. |
80 // Here is an example; | 80 // Here is an example; |
81 // a_dir/ -+- b1_dir/ -+- c1_dir/ -+- d1_file | 81 // a_dir/ -+- b1_dir/ -+- c1_dir/ -+- d1_file |
82 // | | | | 82 // | | | |
83 // | +- c2_file +- d2_file | 83 // | +- c2_file +- d2_file |
84 // | | 84 // | |
85 // +- b2_dir/ --- e_dir/ | 85 // +- b2_dir/ --- e_dir/ |
86 // | | 86 // | |
87 // +- b3_file | 87 // +- b3_file |
88 // | | 88 // | |
89 // +- b4_file | 89 // +- b4_file |
90 // Then traverse order is: | 90 // Then traverse order is: |
91 // ProcessFile(a_dir) (This should return PLATFORM_FILE_NOT_A_FILE). | 91 // ProcessFile(a_dir) (This should return File::FILE_NOT_A_FILE). |
92 // ProcessDirectory(a_dir). | 92 // ProcessDirectory(a_dir). |
93 // ProcessFile(b3_file), ProcessFile(b4_file). (in parallel). | 93 // ProcessFile(b3_file), ProcessFile(b4_file). (in parallel). |
94 // ProcessDirectory(b1_dir). | 94 // ProcessDirectory(b1_dir). |
95 // ProcessFile(c2_file) | 95 // ProcessFile(c2_file) |
96 // ProcessDirectory(c1_dir). | 96 // ProcessDirectory(c1_dir). |
97 // ProcessFile(d1_file), ProcessFile(d2_file). (in parallel). | 97 // ProcessFile(d1_file), ProcessFile(d2_file). (in parallel). |
98 // PostProcessDirectory(c1_dir) | 98 // PostProcessDirectory(c1_dir) |
99 // PostProcessDirectory(b1_dir). | 99 // PostProcessDirectory(b1_dir). |
100 // ProcessDirectory(b2_dir) | 100 // ProcessDirectory(b2_dir) |
101 // ProcessDirectory(e_dir) | 101 // ProcessDirectory(e_dir) |
102 // PostProcessDirectory(e_dir) | 102 // PostProcessDirectory(e_dir) |
103 // PostProcessDirectory(b2_dir) | 103 // PostProcessDirectory(b2_dir) |
104 // PostProcessDirectory(a_dir) | 104 // PostProcessDirectory(a_dir) |
105 // | 105 // |
106 // |callback| is fired with base::PLATFORM_FILE_OK when every file/directory | 106 // |callback| is fired with base::File::FILE_OK when every file/directory |
107 // under |root| is processed, or fired earlier when any suboperation fails. | 107 // under |root| is processed, or fired earlier when any suboperation fails. |
108 void StartRecursiveOperation(const FileSystemURL& root, | 108 void StartRecursiveOperation(const FileSystemURL& root, |
109 const StatusCallback& callback); | 109 const StatusCallback& callback); |
110 | 110 |
111 FileSystemContext* file_system_context() { return file_system_context_; } | 111 FileSystemContext* file_system_context() { return file_system_context_; } |
112 const FileSystemContext* file_system_context() const { | 112 const FileSystemContext* file_system_context() const { |
113 return file_system_context_; | 113 return file_system_context_; |
114 } | 114 } |
115 | 115 |
116 FileSystemOperationRunner* operation_runner(); | 116 FileSystemOperationRunner* operation_runner(); |
(...skipping 26 matching lines...) Expand all Loading... |
143 std::queue<FileSystemURL> pending_files_; | 143 std::queue<FileSystemURL> pending_files_; |
144 int inflight_operations_; | 144 int inflight_operations_; |
145 bool canceled_; | 145 bool canceled_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); | 147 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate); |
148 }; | 148 }; |
149 | 149 |
150 } // namespace fileapi | 150 } // namespace fileapi |
151 | 151 |
152 #endif // WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ | 152 #endif // WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_ |
OLD | NEW |