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 #include "webkit/browser/fileapi/recursive_operation_delegate.h" | 5 #include "webkit/browser/fileapi/recursive_operation_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "webkit/browser/fileapi/file_system_context.h" | 8 #include "webkit/browser/fileapi/file_system_context.h" |
9 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 9 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 FileSystemOperationRunner* RecursiveOperationDelegate::operation_runner() { | 48 FileSystemOperationRunner* RecursiveOperationDelegate::operation_runner() { |
49 return file_system_context_->operation_runner(); | 49 return file_system_context_->operation_runner(); |
50 } | 50 } |
51 | 51 |
52 void RecursiveOperationDelegate::OnCancel() { | 52 void RecursiveOperationDelegate::OnCancel() { |
53 } | 53 } |
54 | 54 |
55 void RecursiveOperationDelegate::DidTryProcessFile( | 55 void RecursiveOperationDelegate::DidTryProcessFile( |
56 const FileSystemURL& root, | 56 const FileSystemURL& root, |
57 base::PlatformFileError error) { | 57 base::File::Error error) { |
58 DCHECK(pending_directory_stack_.empty()); | 58 DCHECK(pending_directory_stack_.empty()); |
59 DCHECK(pending_files_.empty()); | 59 DCHECK(pending_files_.empty()); |
60 DCHECK_EQ(1, inflight_operations_); | 60 DCHECK_EQ(1, inflight_operations_); |
61 | 61 |
62 --inflight_operations_; | 62 --inflight_operations_; |
63 if (canceled_ || error != base::PLATFORM_FILE_ERROR_NOT_A_FILE) { | 63 if (canceled_ || error != base::File::FILE_ERROR_NOT_A_FILE) { |
64 Done(error); | 64 Done(error); |
65 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 pending_directory_stack_.push(std::queue<FileSystemURL>()); | 68 pending_directory_stack_.push(std::queue<FileSystemURL>()); |
69 pending_directory_stack_.top().push(root); | 69 pending_directory_stack_.top().push(root); |
70 ProcessNextDirectory(); | 70 ProcessNextDirectory(); |
71 } | 71 } |
72 | 72 |
73 void RecursiveOperationDelegate::ProcessNextDirectory() { | 73 void RecursiveOperationDelegate::ProcessNextDirectory() { |
74 DCHECK(pending_files_.empty()); | 74 DCHECK(pending_files_.empty()); |
75 DCHECK(!pending_directory_stack_.empty()); | 75 DCHECK(!pending_directory_stack_.empty()); |
76 DCHECK(!pending_directory_stack_.top().empty()); | 76 DCHECK(!pending_directory_stack_.top().empty()); |
77 DCHECK_EQ(0, inflight_operations_); | 77 DCHECK_EQ(0, inflight_operations_); |
78 | 78 |
79 const FileSystemURL& url = pending_directory_stack_.top().front(); | 79 const FileSystemURL& url = pending_directory_stack_.top().front(); |
80 | 80 |
81 ++inflight_operations_; | 81 ++inflight_operations_; |
82 ProcessDirectory( | 82 ProcessDirectory( |
83 url, | 83 url, |
84 base::Bind( | 84 base::Bind( |
85 &RecursiveOperationDelegate::DidProcessDirectory, AsWeakPtr())); | 85 &RecursiveOperationDelegate::DidProcessDirectory, AsWeakPtr())); |
86 } | 86 } |
87 | 87 |
88 void RecursiveOperationDelegate::DidProcessDirectory( | 88 void RecursiveOperationDelegate::DidProcessDirectory( |
89 base::PlatformFileError error) { | 89 base::File::Error error) { |
90 DCHECK(pending_files_.empty()); | 90 DCHECK(pending_files_.empty()); |
91 DCHECK(!pending_directory_stack_.empty()); | 91 DCHECK(!pending_directory_stack_.empty()); |
92 DCHECK(!pending_directory_stack_.top().empty()); | 92 DCHECK(!pending_directory_stack_.top().empty()); |
93 DCHECK_EQ(1, inflight_operations_); | 93 DCHECK_EQ(1, inflight_operations_); |
94 | 94 |
95 --inflight_operations_; | 95 --inflight_operations_; |
96 if (canceled_ || error != base::PLATFORM_FILE_OK) { | 96 if (canceled_ || error != base::File::FILE_OK) { |
97 Done(error); | 97 Done(error); |
98 return; | 98 return; |
99 } | 99 } |
100 | 100 |
101 const FileSystemURL& parent = pending_directory_stack_.top().front(); | 101 const FileSystemURL& parent = pending_directory_stack_.top().front(); |
102 pending_directory_stack_.push(std::queue<FileSystemURL>()); | 102 pending_directory_stack_.push(std::queue<FileSystemURL>()); |
103 operation_runner()->ReadDirectory( | 103 operation_runner()->ReadDirectory( |
104 parent, | 104 parent, |
105 base::Bind(&RecursiveOperationDelegate::DidReadDirectory, | 105 base::Bind(&RecursiveOperationDelegate::DidReadDirectory, |
106 AsWeakPtr(), parent)); | 106 AsWeakPtr(), parent)); |
107 } | 107 } |
108 | 108 |
109 void RecursiveOperationDelegate::DidReadDirectory( | 109 void RecursiveOperationDelegate::DidReadDirectory( |
110 const FileSystemURL& parent, | 110 const FileSystemURL& parent, |
111 base::PlatformFileError error, | 111 base::File::Error error, |
112 const FileEntryList& entries, | 112 const FileEntryList& entries, |
113 bool has_more) { | 113 bool has_more) { |
114 DCHECK(pending_files_.empty()); | 114 DCHECK(pending_files_.empty()); |
115 DCHECK(!pending_directory_stack_.empty()); | 115 DCHECK(!pending_directory_stack_.empty()); |
116 DCHECK_EQ(0, inflight_operations_); | 116 DCHECK_EQ(0, inflight_operations_); |
117 | 117 |
118 if (canceled_ || error != base::PLATFORM_FILE_OK) { | 118 if (canceled_ || error != base::File::FILE_OK) { |
119 Done(error); | 119 Done(error); |
120 return; | 120 return; |
121 } | 121 } |
122 | 122 |
123 for (size_t i = 0; i < entries.size(); i++) { | 123 for (size_t i = 0; i < entries.size(); i++) { |
124 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 124 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
125 parent.origin(), | 125 parent.origin(), |
126 parent.mount_type(), | 126 parent.mount_type(), |
127 parent.virtual_path().Append(entries[i].name)); | 127 parent.virtual_path().Append(entries[i].name)); |
128 if (entries[i].is_directory) | 128 if (entries[i].is_directory) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 FROM_HERE, | 160 FROM_HERE, |
161 base::Bind(&RecursiveOperationDelegate::ProcessFile, | 161 base::Bind(&RecursiveOperationDelegate::ProcessFile, |
162 AsWeakPtr(), pending_files_.front(), | 162 AsWeakPtr(), pending_files_.front(), |
163 base::Bind(&RecursiveOperationDelegate::DidProcessFile, | 163 base::Bind(&RecursiveOperationDelegate::DidProcessFile, |
164 AsWeakPtr()))); | 164 AsWeakPtr()))); |
165 pending_files_.pop(); | 165 pending_files_.pop(); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 void RecursiveOperationDelegate::DidProcessFile( | 169 void RecursiveOperationDelegate::DidProcessFile( |
170 base::PlatformFileError error) { | 170 base::File::Error error) { |
171 --inflight_operations_; | 171 --inflight_operations_; |
172 if (error != base::PLATFORM_FILE_OK) { | 172 if (error != base::File::FILE_OK) { |
173 // If an error occurs, invoke Done immediately (even if there remain | 173 // If an error occurs, invoke Done immediately (even if there remain |
174 // running operations). It is because in the callback, this instance is | 174 // running operations). It is because in the callback, this instance is |
175 // deleted. | 175 // deleted. |
176 Done(error); | 176 Done(error); |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 ProcessPendingFiles(); | 180 ProcessPendingFiles(); |
181 } | 181 } |
182 | 182 |
183 void RecursiveOperationDelegate::ProcessSubDirectory() { | 183 void RecursiveOperationDelegate::ProcessSubDirectory() { |
184 DCHECK(pending_files_.empty()); | 184 DCHECK(pending_files_.empty()); |
185 DCHECK(!pending_directory_stack_.empty()); | 185 DCHECK(!pending_directory_stack_.empty()); |
186 DCHECK_EQ(0, inflight_operations_); | 186 DCHECK_EQ(0, inflight_operations_); |
187 | 187 |
188 if (canceled_) { | 188 if (canceled_) { |
189 Done(base::PLATFORM_FILE_ERROR_ABORT); | 189 Done(base::File::FILE_ERROR_ABORT); |
190 return; | 190 return; |
191 } | 191 } |
192 | 192 |
193 if (!pending_directory_stack_.top().empty()) { | 193 if (!pending_directory_stack_.top().empty()) { |
194 // There remain some sub directories. Process them first. | 194 // There remain some sub directories. Process them first. |
195 ProcessNextDirectory(); | 195 ProcessNextDirectory(); |
196 return; | 196 return; |
197 } | 197 } |
198 | 198 |
199 // All subdirectories are processed. | 199 // All subdirectories are processed. |
200 pending_directory_stack_.pop(); | 200 pending_directory_stack_.pop(); |
201 if (pending_directory_stack_.empty()) { | 201 if (pending_directory_stack_.empty()) { |
202 // All files/directories are processed. | 202 // All files/directories are processed. |
203 Done(base::PLATFORM_FILE_OK); | 203 Done(base::File::FILE_OK); |
204 return; | 204 return; |
205 } | 205 } |
206 | 206 |
207 DCHECK(!pending_directory_stack_.top().empty()); | 207 DCHECK(!pending_directory_stack_.top().empty()); |
208 ++inflight_operations_; | 208 ++inflight_operations_; |
209 PostProcessDirectory( | 209 PostProcessDirectory( |
210 pending_directory_stack_.top().front(), | 210 pending_directory_stack_.top().front(), |
211 base::Bind(&RecursiveOperationDelegate::DidPostProcessDirectory, | 211 base::Bind(&RecursiveOperationDelegate::DidPostProcessDirectory, |
212 AsWeakPtr())); | 212 AsWeakPtr())); |
213 } | 213 } |
214 | 214 |
215 void RecursiveOperationDelegate::DidPostProcessDirectory( | 215 void RecursiveOperationDelegate::DidPostProcessDirectory( |
216 base::PlatformFileError error) { | 216 base::File::Error error) { |
217 DCHECK(pending_files_.empty()); | 217 DCHECK(pending_files_.empty()); |
218 DCHECK(!pending_directory_stack_.empty()); | 218 DCHECK(!pending_directory_stack_.empty()); |
219 DCHECK(!pending_directory_stack_.top().empty()); | 219 DCHECK(!pending_directory_stack_.top().empty()); |
220 DCHECK_EQ(1, inflight_operations_); | 220 DCHECK_EQ(1, inflight_operations_); |
221 | 221 |
222 --inflight_operations_; | 222 --inflight_operations_; |
223 pending_directory_stack_.top().pop(); | 223 pending_directory_stack_.top().pop(); |
224 if (canceled_ || error != base::PLATFORM_FILE_OK) { | 224 if (canceled_ || error != base::File::FILE_OK) { |
225 Done(error); | 225 Done(error); |
226 return; | 226 return; |
227 } | 227 } |
228 | 228 |
229 ProcessSubDirectory(); | 229 ProcessSubDirectory(); |
230 } | 230 } |
231 | 231 |
232 void RecursiveOperationDelegate::Done(base::PlatformFileError error) { | 232 void RecursiveOperationDelegate::Done(base::File::Error error) { |
233 if (canceled_ && error == base::PLATFORM_FILE_OK) { | 233 if (canceled_ && error == base::File::FILE_OK) { |
234 callback_.Run(base::PLATFORM_FILE_ERROR_ABORT); | 234 callback_.Run(base::File::FILE_ERROR_ABORT); |
235 } else { | 235 } else { |
236 callback_.Run(error); | 236 callback_.Run(error); |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 } // namespace fileapi | 240 } // namespace fileapi |
OLD | NEW |