| 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_origin_database.h" | 5 #include "webkit/fileapi/file_system_origin_database.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_enumerator.h" |
| 10 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 19 #include "webkit/fileapi/file_system_util.h" | 20 #include "webkit/fileapi/file_system_util.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 bool FileSystemOriginDatabase::RepairDatabase(const std::string& db_path) { | 127 bool FileSystemOriginDatabase::RepairDatabase(const std::string& db_path) { |
| 127 DCHECK(!db_.get()); | 128 DCHECK(!db_.get()); |
| 128 if (!leveldb::RepairDB(db_path, leveldb::Options()).ok() || | 129 if (!leveldb::RepairDB(db_path, leveldb::Options()).ok() || |
| 129 !Init(FAIL_ON_CORRUPTION)) { | 130 !Init(FAIL_ON_CORRUPTION)) { |
| 130 LOG(WARNING) << "Failed to repair FileSystemOriginDatabase."; | 131 LOG(WARNING) << "Failed to repair FileSystemOriginDatabase."; |
| 131 return false; | 132 return false; |
| 132 } | 133 } |
| 133 | 134 |
| 134 // See if the repaired entries match with what we have on disk. | 135 // See if the repaired entries match with what we have on disk. |
| 135 std::set<base::FilePath> directories; | 136 std::set<base::FilePath> directories; |
| 136 file_util::FileEnumerator file_enum(file_system_directory_, | 137 base::FileEnumerator file_enum(file_system_directory_, |
| 137 false /* recursive */, | 138 false /* recursive */, |
| 138 file_util::FileEnumerator::DIRECTORIES); | 139 base::FileEnumerator::DIRECTORIES); |
| 139 base::FilePath path_each; | 140 base::FilePath path_each; |
| 140 while (!(path_each = file_enum.Next()).empty()) | 141 while (!(path_each = file_enum.Next()).empty()) |
| 141 directories.insert(path_each.BaseName()); | 142 directories.insert(path_each.BaseName()); |
| 142 std::set<base::FilePath>::iterator db_dir_itr = | 143 std::set<base::FilePath>::iterator db_dir_itr = |
| 143 directories.find(base::FilePath(kOriginDatabaseName)); | 144 directories.find(base::FilePath(kOriginDatabaseName)); |
| 144 // Make sure we have the database file in its directory and therefore we are | 145 // Make sure we have the database file in its directory and therefore we are |
| 145 // working on the correct path. | 146 // working on the correct path. |
| 146 DCHECK(db_dir_itr != directories.end()); | 147 DCHECK(db_dir_itr != directories.end()); |
| 147 directories.erase(db_dir_itr); | 148 directories.erase(db_dir_itr); |
| 148 | 149 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); | 325 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); |
| 325 if (!status.ok()) { | 326 if (!status.ok()) { |
| 326 HandleError(FROM_HERE, status); | 327 HandleError(FROM_HERE, status); |
| 327 return false; | 328 return false; |
| 328 } | 329 } |
| 329 *number = -1; | 330 *number = -1; |
| 330 return true; | 331 return true; |
| 331 } | 332 } |
| 332 | 333 |
| 333 } // namespace fileapi | 334 } // namespace fileapi |
| OLD | NEW |