Chromium Code Reviews| Index: webkit/fileapi/file_system_origin_database.cc |
| diff --git a/webkit/fileapi/file_system_origin_database.cc b/webkit/fileapi/file_system_origin_database.cc |
| index 125576ae38d1eda4f7dfeae35a63059f1b326c06..c30204b306b46f5df2f79bfa97a74eaceea3b8cf 100644 |
| --- a/webkit/fileapi/file_system_origin_database.cc |
| +++ b/webkit/fileapi/file_system_origin_database.cc |
| @@ -54,7 +54,7 @@ FileSystemOriginDatabase::FileSystemOriginDatabase(const FilePath& path) { |
| FileSystemOriginDatabase::~FileSystemOriginDatabase() { |
| } |
| -bool FileSystemOriginDatabase::Init() { |
| +bool FileSystemOriginDatabase::Init(RecoveringOption recovering_option) { |
| if (db_.get()) |
| return true; |
| @@ -62,11 +62,25 @@ bool FileSystemOriginDatabase::Init() { |
| options.create_if_missing = true; |
| leveldb::DB* db; |
| leveldb::Status status = leveldb::DB::Open(options, path_, &db); |
| + // TODO(tzik): Collect status metrics here. |
| if (status.ok()) { |
| db_.reset(db); |
| return true; |
| } |
| HandleError(FROM_HERE, status); |
| + |
| + if (recovering_option == LEAVE_ON_CORRUPTION) |
| + return false; |
| + |
| + DCHECK_EQ(REBUILD_ON_CORRUPTION, recovering_option); |
| + LOG(WARNING) << "FileSystem API origin database is corrupted." |
| + << " Attempting cleanup."; |
| + if (leveldb::DestroyDB(path_, leveldb::Options()).ok()) { |
|
michaeln
2012/03/11 17:40:10
once we've lost this database of all origins using
ericu
2012/03/12 19:46:01
Yes. If we lose the origins database, we have no
|
| + LOG(WARNING) << "FileSystem API origin database cleanup completed." |
| + << " Reopening."; |
| + return Init(LEAVE_ON_CORRUPTION); |
| + } |
| + LOG(WARNING) << "Failed to cleanup FileSystem API origin database."; |
| return false; |
| } |
| @@ -78,7 +92,7 @@ void FileSystemOriginDatabase::HandleError( |
| } |
| bool FileSystemOriginDatabase::HasOriginPath(const std::string& origin) { |
| - if (!Init()) |
| + if (!Init(REBUILD_ON_CORRUPTION)) |
| return false; |
| if (origin.empty()) |
| return false; |
| @@ -95,7 +109,7 @@ bool FileSystemOriginDatabase::HasOriginPath(const std::string& origin) { |
| bool FileSystemOriginDatabase::GetPathForOrigin( |
| const std::string& origin, FilePath* directory) { |
| - if (!Init()) |
| + if (!Init(REBUILD_ON_CORRUPTION)) |
| return false; |
| DCHECK(directory); |
| if (origin.empty()) |
| @@ -132,7 +146,7 @@ bool FileSystemOriginDatabase::GetPathForOrigin( |
| } |
| bool FileSystemOriginDatabase::RemovePathForOrigin(const std::string& origin) { |
| - if (!Init()) |
| + if (!Init(REBUILD_ON_CORRUPTION)) |
| return false; |
| leveldb::Status status = |
| db_->Delete(leveldb::WriteOptions(), OriginToOriginKey(origin)); |
| @@ -144,7 +158,7 @@ bool FileSystemOriginDatabase::RemovePathForOrigin(const std::string& origin) { |
| bool FileSystemOriginDatabase::ListAllOrigins( |
| std::vector<OriginRecord>* origins) { |
| - if (!Init()) |
| + if (!Init(REBUILD_ON_CORRUPTION)) |
| return false; |
| DCHECK(origins); |
| scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(leveldb::ReadOptions())); |
| @@ -171,7 +185,7 @@ void FileSystemOriginDatabase::DropDatabase() { |
| } |
| bool FileSystemOriginDatabase::GetLastPathNumber(int* number) { |
| - if (!Init()) |
| + if (!Init(REBUILD_ON_CORRUPTION)) |
| return false; |
| DCHECK(number); |
| std::string number_string; |