diff options
author | michaeln <michaeln@chromium.org> | 2015-10-28 15:43:03 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-28 22:44:06 +0000 |
commit | dea7ae9bd84c6e66f74351f3af1368226ce2de17 (patch) | |
tree | 241423a495fd1c28b72ae87cbb81b1ba4bacc9cb | |
parent | acfa922fcb47dce98ee648a589db0d9cc6171256 (diff) | |
download | chromium_src-dea7ae9bd84c6e66f74351f3af1368226ce2de17.zip chromium_src-dea7ae9bd84c6e66f74351f3af1368226ce2de17.tar.gz chromium_src-dea7ae9bd84c6e66f74351f3af1368226ce2de17.tar.bz2 |
[sql] QuotaDatabase schema upgrade doesn't use transactions right.
BUG=548371
Review URL: https://codereview.chromium.org/1419573008
Cr-Commit-Position: refs/heads/master@{#356675}
-rw-r--r-- | sql/connection.cc | 2 | ||||
-rw-r--r-- | storage/browser/quota/quota_database.cc | 51 | ||||
-rw-r--r-- | storage/browser/quota/quota_database.h | 2 |
3 files changed, 35 insertions, 20 deletions
diff --git a/sql/connection.cc b/sql/connection.cc index 669344a..28beafc 100644 --- a/sql/connection.cc +++ b/sql/connection.cc @@ -1139,7 +1139,7 @@ void Connection::RollbackTransaction() { bool Connection::CommitTransaction() { if (!transaction_nesting_) { - DLOG_IF(FATAL, !poisoned_) << "Rolling back a nonexistent transaction"; + DLOG_IF(FATAL, !poisoned_) << "Committing back a nonexistent transaction"; return false; } transaction_nesting_--; diff --git a/storage/browser/quota/quota_database.cc b/storage/browser/quota/quota_database.cc index f1fefb6..5fcacd5 100644 --- a/storage/browser/quota/quota_database.cc +++ b/storage/browser/quota/quota_database.cc @@ -187,19 +187,8 @@ bool QuotaDatabase::SetHostQuota( DCHECK_GE(quota, 0); if (!LazyOpen(true)) return false; - - const char* kSql = - "INSERT OR REPLACE INTO HostQuotaTable" - " (quota, host, type)" - " VALUES (?, ?, ?)"; - sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); - statement.BindInt64(0, quota); - statement.BindString(1, host); - statement.BindInt(2, static_cast<int>(type)); - - if (!statement.Run()) + if (!InsertOrReplaceHostQuota(host, type, quota)) return false; - ScheduleCommit(); return true; } @@ -497,8 +486,11 @@ void QuotaDatabase::Commit() { if (timer_.IsRunning()) timer_.Stop(); + DCHECK_EQ(1, db_->transaction_nesting()); db_->CommitTransaction(); + DCHECK_EQ(0, db_->transaction_nesting()); db_->BeginTransaction(); + DCHECK_EQ(1, db_->transaction_nesting()); } void QuotaDatabase::ScheduleCommit() { @@ -656,6 +648,7 @@ bool QuotaDatabase::CreateSchema( bool QuotaDatabase::ResetSchema() { DCHECK(!db_file_path_.empty()); DCHECK(base::PathExists(db_file_path_)); + DCHECK(!db_ || !db_->transaction_nesting()); VLOG(1) << "Deleting existing quota data and starting over."; db_.reset(); @@ -673,6 +666,8 @@ bool QuotaDatabase::ResetSchema() { } bool QuotaDatabase::UpgradeSchema(int current_version) { + DCHECK_EQ(0, db_->transaction_nesting()); + if (current_version == 2) { QuotaTableImporter importer; typedef std::vector<QuotaTableEntry> QuotaTableEntries; @@ -681,15 +676,21 @@ bool QuotaDatabase::UpgradeSchema(int current_version) { return false; } ResetSchema(); + + sql::Transaction transaction(db_.get()); + if (!transaction.Begin()) + return false; for (QuotaTableEntries::const_iterator iter = importer.entries.begin(); iter != importer.entries.end(); ++iter) { - if (!SetHostQuota(iter->host, iter->type, iter->quota)) + if (!InsertOrReplaceHostQuota(iter->host, iter->type, iter->quota)) return false; } - Commit(); - - return true; + return transaction.Commit(); } else if (current_version < 5) { + sql::Transaction transaction(db_.get()); + if (!transaction.Begin()) + return false; + const QuotaDatabase::TableSchema& eviction_table_schema = kTables[2]; DCHECK_EQ(strcmp(kEvictionInfoTable, eviction_table_schema.table_name), 0); @@ -702,13 +703,25 @@ bool QuotaDatabase::UpgradeSchema(int current_version) { } meta_table_->SetVersionNumber(5); - Commit(); - - return true; + return transaction.Commit(); } return false; } +bool QuotaDatabase::InsertOrReplaceHostQuota( + const std::string& host, StorageType type, int64 quota) { + DCHECK(db_.get()); + const char* kSql = + "INSERT OR REPLACE INTO HostQuotaTable" + " (quota, host, type)" + " VALUES (?, ?, ?)"; + sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); + statement.BindInt64(0, quota); + statement.BindString(1, host); + statement.BindInt(2, static_cast<int>(type)); + return statement.Run(); +} + bool QuotaDatabase::DumpQuotaTable(const QuotaTableCallback& callback) { if (!LazyOpen(true)) return false; diff --git a/storage/browser/quota/quota_database.h b/storage/browser/quota/quota_database.h index 09e90b3..e95fba8 100644 --- a/storage/browser/quota/quota_database.h +++ b/storage/browser/quota/quota_database.h @@ -162,6 +162,8 @@ class STORAGE_EXPORT_PRIVATE QuotaDatabase { bool EnsureDatabaseVersion(); bool ResetSchema(); bool UpgradeSchema(int current_version); + bool InsertOrReplaceHostQuota( + const std::string& host, StorageType type, int64 quota); static bool CreateSchema( sql::Connection* database, |