Chromium Code Reviews| Index: storage/browser/quota/quota_database.cc |
| diff --git a/storage/browser/quota/quota_database.cc b/storage/browser/quota/quota_database.cc |
| index aff5602cb505e5c8e332524e6676732bf235d8d9..47fa23e7d8a1d6d1423082ad6b773cea1814c4d5 100644 |
| --- a/storage/browser/quota/quota_database.cc |
| +++ b/storage/browser/quota/quota_database.cc |
| @@ -21,11 +21,12 @@ namespace { |
| // Definitions for database schema. |
| -const int kCurrentVersion = 4; |
| +const int kCurrentVersion = 5; |
| const int kCompatibleVersion = 2; |
| const char kHostQuotaTable[] = "HostQuotaTable"; |
| const char kOriginInfoTable[] = "OriginInfoTable"; |
| +const char kEvictionInfoTable[] = "EvictionInfoTable"; |
| const char kIsOriginTableBootstrapped[] = "IsOriginTableBootstrapped"; |
| bool VerifyValidQuotaConfig(const char* key) { |
| @@ -62,19 +63,23 @@ const char QuotaDatabase::kTemporaryQuotaOverrideKey[] = |
| "TemporaryQuotaOverride"; |
| const QuotaDatabase::TableSchema QuotaDatabase::kTables[] = { |
| - { kHostQuotaTable, |
| - "(host TEXT NOT NULL," |
| - " type INTEGER NOT NULL," |
| - " quota INTEGER DEFAULT 0," |
| - " UNIQUE(host, type))" }, |
| - { kOriginInfoTable, |
| - "(origin TEXT NOT NULL," |
| - " type INTEGER NOT NULL," |
| - " used_count INTEGER DEFAULT 0," |
| - " last_access_time INTEGER DEFAULT 0," |
| - " last_modified_time INTEGER DEFAULT 0," |
| - " UNIQUE(origin, type))" }, |
| -}; |
| + {kHostQuotaTable, |
| + "(host TEXT NOT NULL," |
| + " type INTEGER NOT NULL," |
| + " quota INTEGER DEFAULT 0," |
| + " UNIQUE(host, type))"}, |
| + {kOriginInfoTable, |
| + "(origin TEXT NOT NULL," |
| + " type INTEGER NOT NULL," |
| + " used_count INTEGER DEFAULT 0," |
| + " last_access_time INTEGER DEFAULT 0," |
| + " last_modified_time INTEGER DEFAULT 0," |
| + " UNIQUE(origin, type))"}, |
| + {kEvictionInfoTable, |
| + "(origin TEXT NOT NULL," |
| + " type INTEGER NOT NULL," |
| + " last_eviction_time INTEGER DEFAULT 0," |
| + " UNIQUE(origin, type))"}}; |
| // static |
| const QuotaDatabase::IndexSchema QuotaDatabase::kIndexes[] = { |
| @@ -264,6 +269,71 @@ bool QuotaDatabase::SetOriginLastModifiedTime( |
| return true; |
| } |
| +bool QuotaDatabase::GetOriginLastEvictionTime(const GURL& origin, |
| + StorageType type, |
| + base::Time* last_modified_time) { |
| + DCHECK(last_modified_time); |
| + if (!LazyOpen(false)) |
| + return false; |
| + |
| + const char* kSql = |
| + "SELECT last_eviction_time" |
| + " FROM EvictionInfoTable" |
| + " WHERE origin = ? AND type = ?"; |
| + |
| + sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| + statement.BindString(0, origin.spec()); |
| + statement.BindInt(1, static_cast<int>(type)); |
| + |
| + if (!statement.Step()) |
| + return statement.Succeeded(); |
| + |
| + *last_modified_time = base::Time::FromInternalValue(statement.ColumnInt64(0)); |
| + return true; |
| +} |
| + |
| +bool QuotaDatabase::SetOriginLastEvictionTime(const GURL& origin, |
| + StorageType type, |
| + base::Time last_modified_time) { |
| + if (!LazyOpen(true)) |
| + return false; |
| + |
| + const char* kSql = |
| + "INSERT OR REPLACE INTO EvictionInfoTable" |
| + " (last_eviction_time, origin, type)" |
| + " VALUES (?, ?, ?)"; |
| + sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| + statement.BindInt64(0, last_modified_time.ToInternalValue()); |
| + statement.BindString(1, origin.spec()); |
| + statement.BindInt(2, static_cast<int>(type)); |
| + |
| + if (!statement.Run()) |
| + return false; |
| + |
| + ScheduleCommit(); |
| + return true; |
| +} |
| + |
| +bool QuotaDatabase::DeleteOriginLastEvictionTime(const GURL& origin, |
| + StorageType type) { |
| + if (!LazyOpen(false)) |
| + return false; |
| + |
| + const char* kSql = |
| + "DELETE FROM EvictionInfoTable" |
| + " WHERE origin = ? AND type = ?"; |
| + |
| + sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| + statement.BindString(0, origin.spec()); |
| + statement.BindInt(1, static_cast<int>(type)); |
| + |
| + if (!statement.Run()) |
| + return false; |
| + |
| + ScheduleCommit(); |
| + return true; |
| +} |
| + |
| bool QuotaDatabase::RegisterInitialOriginInfo( |
| const std::set<GURL>& origins, StorageType type) { |
| if (!LazyOpen(true)) |
| @@ -603,6 +673,7 @@ bool QuotaDatabase::ResetSchema() { |
| } |
| bool QuotaDatabase::UpgradeSchema(int current_version) { |
| + bool upgraded = false; |
| if (current_version == 2) { |
| QuotaTableImporter importer; |
| typedef std::vector<QuotaTableEntry> QuotaTableEntries; |
| @@ -617,9 +688,23 @@ bool QuotaDatabase::UpgradeSchema(int current_version) { |
| return false; |
| } |
| Commit(); |
| - return true; |
| + upgraded = true; |
| + } else if (current_version < 5) { |
| + const QuotaDatabase::TableSchema& eviction_table_schema = kTables[2]; |
| + DCHECK_EQ(strcmp(kEvictionInfoTable, eviction_table_schema.table_name), 0); |
| + |
| + std::string sql("CREATE TABLE "); |
| + sql += eviction_table_schema.table_name; |
| + sql += eviction_table_schema.columns; |
| + if (!db_->Execute(sql.c_str())) { |
| + VLOG(1) << "Failed to execute " << sql; |
| + return false; |
| + } |
|
michaeln
2015/10/13 21:35:36
do you want an index on the origin column?
calamity
2015/10/15 07:56:43
See above.
|
| + |
| + meta_table_->SetVersionNumber(5); |
|
michaeln
2015/10/13 21:35:36
i think you want to to Commit() here
calamity
2015/10/15 07:56:43
Done.
calamity
2015/10/15 11:11:06
Oops, missed this one. Will do it tomorrow.
|
| + upgraded = true; |
| } |
| - return false; |
| + return upgraded; |
| } |
| bool QuotaDatabase::DumpQuotaTable(const QuotaTableCallback& callback) { |