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