Skip to content

Commit

Permalink
Try to reset quota database which is suspected to be corrupted
Browse files Browse the repository at this point in the history
If we are able to open quota database file but cannot create a table
then we suspect it to be corrupted and trying to reset.

patch from issue 1236583002 at patchset 20001 (http://crrev.com/1236583002#ps20001)

BUG=508916

Review URL: https://codereview.chromium.org/1322593002

Cr-Commit-Position: refs/heads/master@{#346178}
  • Loading branch information
michaeln authored and Commit bot committed Aug 28, 2015
1 parent 6684a66 commit 6959ac7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
22 changes: 22 additions & 0 deletions content/browser/quota/quota_database_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "sql/connection.h"
#include "sql/meta_table.h"
#include "sql/statement.h"
#include "sql/test/scoped_error_ignorer.h"
#include "sql/test/test_helpers.h"
#include "storage/browser/quota/quota_database.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -47,6 +49,13 @@ class QuotaDatabaseTest : public testing::Test {
EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile));
}

void Reopen(const base::FilePath& kDbFile) {
QuotaDatabase db(kDbFile);
ASSERT_TRUE(db.LazyOpen(false));
EXPECT_TRUE(db.db_.get());
EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile));
}

void UpgradeSchemaV2toV3(const base::FilePath& kDbFile) {
const QuotaTableEntry entries[] = {
QuotaTableEntry("a", kStorageTypeTemporary, 1),
Expand Down Expand Up @@ -569,4 +578,17 @@ TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) {
DumpOriginInfoTable(kDbFile);
DumpOriginInfoTable(base::FilePath());
}

TEST_F(QuotaDatabaseTest, OpenCorruptedDatabase) {
base::ScopedTempDir data_dir;
ASSERT_TRUE(data_dir.CreateUniqueTempDir());
const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
LazyOpen(kDbFile);
ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile));
sql::ScopedErrorIgnorer ignore_errors;
ignore_errors.IgnoreError(SQLITE_CORRUPT);
Reopen(kDbFile);
EXPECT_TRUE(ignore_errors.CheckIgnoredErrors());
}

} // namespace content
13 changes: 8 additions & 5 deletions storage/browser/quota/quota_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,14 @@ bool QuotaDatabase::LazyOpen(bool create_if_needed) {
}

if (!opened || !EnsureDatabaseVersion()) {
LOG(ERROR) << "Failed to open the quota database.";
is_disabled_ = true;
db_.reset();
meta_table_.reset();
return false;
LOG(ERROR) << "Could not open the quota database, resetting.";
if (!ResetSchema()) {
LOG(ERROR) << "Failed to reset the quota database.";
is_disabled_ = true;
db_.reset();
meta_table_.reset();
return false;
}
}

// Start a long-running transaction.
Expand Down

0 comments on commit 6959ac7

Please sign in to comment.