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