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