OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sandbox_directory_database.h" | 5 #include "webkit/browser/fileapi/sandbox_directory_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <set> | 9 #include <set> |
10 #include <stack> | 10 #include <stack> |
11 | 11 |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file_enumerator.h" |
13 #include "base/location.h" | 14 #include "base/location.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/pickle.h" | 16 #include "base/pickle.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
19 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
20 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 21 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
21 #include "webkit/common/fileapi/file_system_util.h" | 22 #include "webkit/common/fileapi/file_system_util.h" |
22 | 23 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 }; | 276 }; |
276 | 277 |
277 // Any path in |pending_directories| is relative to |path_|. | 278 // Any path in |pending_directories| is relative to |path_|. |
278 std::stack<base::FilePath> pending_directories; | 279 std::stack<base::FilePath> pending_directories; |
279 pending_directories.push(base::FilePath()); | 280 pending_directories.push(base::FilePath()); |
280 | 281 |
281 while (!pending_directories.empty()) { | 282 while (!pending_directories.empty()) { |
282 base::FilePath dir_path = pending_directories.top(); | 283 base::FilePath dir_path = pending_directories.top(); |
283 pending_directories.pop(); | 284 pending_directories.pop(); |
284 | 285 |
285 file_util::FileEnumerator file_enum( | 286 base::FileEnumerator file_enum( |
286 dir_path.empty() ? path_ : path_.Append(dir_path), | 287 dir_path.empty() ? path_ : path_.Append(dir_path), |
287 false /* not recursive */, | 288 false /* not recursive */, |
288 file_util::FileEnumerator::DIRECTORIES | | 289 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); |
289 file_util::FileEnumerator::FILES); | |
290 | 290 |
291 base::FilePath absolute_file_path; | 291 base::FilePath absolute_file_path; |
292 while (!(absolute_file_path = file_enum.Next()).empty()) { | 292 while (!(absolute_file_path = file_enum.Next()).empty()) { |
293 file_util::FileEnumerator::FindInfo find_info; | 293 base::FileEnumerator::FileInfo find_info = file_enum.GetInfo(); |
294 file_enum.GetFindInfo(&find_info); | |
295 | 294 |
296 base::FilePath relative_file_path; | 295 base::FilePath relative_file_path; |
297 if (!path_.AppendRelativePath(absolute_file_path, &relative_file_path)) | 296 if (!path_.AppendRelativePath(absolute_file_path, &relative_file_path)) |
298 return false; | 297 return false; |
299 | 298 |
300 if (std::find(kExcludes, kExcludes + arraysize(kExcludes), | 299 if (std::find(kExcludes, kExcludes + arraysize(kExcludes), |
301 relative_file_path) != kExcludes + arraysize(kExcludes)) | 300 relative_file_path) != kExcludes + arraysize(kExcludes)) |
302 continue; | 301 continue; |
303 | 302 |
304 if (file_util::FileEnumerator::IsDirectory(find_info)) { | 303 if (find_info.IsDirectory()) { |
305 pending_directories.push(relative_file_path); | 304 pending_directories.push(relative_file_path); |
306 continue; | 305 continue; |
307 } | 306 } |
308 | 307 |
309 // Check if the file has a database entry. | 308 // Check if the file has a database entry. |
310 std::set<base::FilePath>::iterator itr = | 309 std::set<base::FilePath>::iterator itr = |
311 files_in_db_.find(relative_file_path); | 310 files_in_db_.find(relative_file_path); |
312 if (itr == files_in_db_.end()) { | 311 if (itr == files_in_db_.end()) { |
313 if (!file_util::Delete(absolute_file_path, false)) | 312 if (!file_util::Delete(absolute_file_path, false)) |
314 return false; | 313 return false; |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 | 916 |
918 void SandboxDirectoryDatabase::HandleError( | 917 void SandboxDirectoryDatabase::HandleError( |
919 const tracked_objects::Location& from_here, | 918 const tracked_objects::Location& from_here, |
920 const leveldb::Status& status) { | 919 const leveldb::Status& status) { |
921 LOG(ERROR) << "SandboxDirectoryDatabase failed at: " | 920 LOG(ERROR) << "SandboxDirectoryDatabase failed at: " |
922 << from_here.ToString() << " with error: " << status.ToString(); | 921 << from_here.ToString() << " with error: " << status.ToString(); |
923 db_.reset(); | 922 db_.reset(); |
924 } | 923 } |
925 | 924 |
926 } // namespace fileapi | 925 } // namespace fileapi |
OLD | NEW |