| Index: webkit/quota/quota_database.cc
|
| diff --git a/webkit/quota/quota_database.cc b/webkit/quota/quota_database.cc
|
| index 592a039bd447e7612fc681e3475ac25a193933e0..03f144d9f5fd39ec25ec1b23f14986521ad9e802 100644
|
| --- a/webkit/quota/quota_database.cc
|
| +++ b/webkit/quota/quota_database.cc
|
| @@ -21,12 +21,12 @@ namespace {
|
|
|
| // Definitions for database schema.
|
|
|
| -const int kCurrentVersion = 2;
|
| -const int kCompatibleVersion = 2;
|
| +const int kCurrentVersion = 3;
|
| +const int kCompatibleVersion = 3;
|
|
|
| const char kOriginsTable[] = "Origins";
|
| const char kHostQuotaTable[] = "HostQuotaTable";
|
| -const char kOriginLastAccessTable[] = "OriginLastAccessTable";
|
| +const char kOriginInfoTable[] = "OriginInfoTable";
|
| const char kGlobalQuotaKeyPrefix[] = "GlobalQuota-";
|
| const char kIsOriginTableBootstrapped[] = "IsOriginTableBootstrapped";
|
|
|
| @@ -37,13 +37,14 @@ const struct {
|
| { kHostQuotaTable,
|
| "(host TEXT NOT NULL,"
|
| " type INTEGER NOT NULL,"
|
| - " quota INTEGER,"
|
| + " quota INTEGER DEFAULT 0,"
|
| " UNIQUE(host, type))" },
|
| - { kOriginLastAccessTable,
|
| + { kOriginInfoTable,
|
| "(origin TEXT NOT NULL,"
|
| " type INTEGER NOT NULL,"
|
| - " used_count INTEGER,"
|
| - " last_access_time INTEGER,"
|
| + " used_count INTEGER DEFAULT 0,"
|
| + " last_access_time INTEGER DEFAULT 0,"
|
| + " last_modified_time INTEGER DEFAULT 0,"
|
| " UNIQUE(origin, type))" },
|
| };
|
|
|
| @@ -57,9 +58,17 @@ const struct {
|
| kHostQuotaTable,
|
| "(host)",
|
| false },
|
| - { "OriginLastAccessIndex",
|
| - kOriginLastAccessTable,
|
| - "(origin, last_access_time)",
|
| + { "OriginInfoIndex",
|
| + kOriginInfoTable,
|
| + "(origin)",
|
| + false },
|
| + { "OriginLastAccessTimeIndex",
|
| + kOriginInfoTable,
|
| + "(last_access_time)",
|
| + false },
|
| + { "OriginLastModifiedTimeIndex",
|
| + kOriginInfoTable,
|
| + "(last_modified_time)",
|
| false },
|
| };
|
|
|
| @@ -146,23 +155,12 @@ bool QuotaDatabase::SetHostQuota(
|
| return false;
|
|
|
| sql::Statement statement;
|
| -
|
| - int64 dummy;
|
| - if (GetHostQuota(host, type, &dummy)) {
|
| - const char* kSql =
|
| - "UPDATE HostQuotaTable"
|
| - " SET quota = ?"
|
| - " WHERE host = ? AND type = ?";
|
| - if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| - return false;
|
| - } else {
|
| - const char* kSql =
|
| - "INSERT INTO HostQuotaTable"
|
| - " (quota, host, type)"
|
| - " VALUES (?, ?, ?)";
|
| - if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| - return false;
|
| - }
|
| + const char* kSql =
|
| + "INSERT OR REPLACE INTO HostQuotaTable"
|
| + " (quota, host, type)"
|
| + " VALUES (?, ?, ?)";
|
| + if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| + return false;
|
|
|
| statement.BindInt64(0, quota);
|
| statement.BindString(1, host);
|
| @@ -185,14 +183,14 @@ bool QuotaDatabase::SetOriginLastAccessTime(
|
| if (FindOriginUsedCount(origin, type, &used_count)) {
|
| ++used_count;
|
| const char* kSql =
|
| - "UPDATE OriginLastAccessTable"
|
| + "UPDATE OriginInfoTable"
|
| " SET used_count = ?, last_access_time = ?"
|
| " WHERE origin = ? AND type = ?";
|
| if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| return false;
|
| } else {
|
| const char* kSql =
|
| - "INSERT INTO OriginLastAccessTable"
|
| + "INSERT INTO OriginInfoTable"
|
| " (used_count, last_access_time, origin, type)"
|
| " VALUES (?, ?, ?, ?)";
|
| if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| @@ -210,9 +208,41 @@ bool QuotaDatabase::SetOriginLastAccessTime(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins,
|
| - StorageType type,
|
| - base::Time last_access_time) {
|
| +bool QuotaDatabase::SetOriginLastModifiedTime(
|
| + const GURL& origin, StorageType type, base::Time last_modified_time) {
|
| + if (!LazyOpen(true))
|
| + return false;
|
| +
|
| + sql::Statement statement;
|
| +
|
| + int dummy;
|
| + if (FindOriginUsedCount(origin, type, &dummy)) {
|
| + const char* kSql =
|
| + "UPDATE OriginInfoTable"
|
| + " SET last_modified_time = ?"
|
| + " WHERE origin = ? AND type = ?";
|
| + if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| + return false;
|
| + } else {
|
| + const char* kSql =
|
| + "INSERT INTO OriginInfoTable"
|
| + " (last_modified_time, origin, type) VALUES (?, ?, ?)";
|
| + if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| + return false;
|
| + }
|
| +
|
| + 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::RegisterInitialOriginInfo(
|
| + const std::set<GURL>& origins, StorageType type) {
|
| if (!LazyOpen(true))
|
| return false;
|
|
|
| @@ -220,17 +250,14 @@ bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins,
|
| for (itr_type itr = origins.begin(), end = origins.end();
|
| itr != end; ++itr) {
|
| const char* kSql =
|
| - "INSERT OR IGNORE INTO OriginLastAccessTable"
|
| - " (used_count, last_access_time, origin, type)"
|
| - " VALUES (?, ?, ?, ?)";
|
| + "INSERT OR IGNORE INTO OriginInfoTable"
|
| + " (origin, type) VALUES (?, ?)";
|
| sql::Statement statement;
|
| if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| return false;
|
|
|
| - statement.BindInt(0, 0); // used_count
|
| - statement.BindInt64(1, last_access_time.ToInternalValue());
|
| - statement.BindString(2, itr->spec());
|
| - statement.BindInt(3, static_cast<int>(type));
|
| + statement.BindString(0, itr->spec());
|
| + statement.BindInt(1, static_cast<int>(type));
|
| if (!statement.Run())
|
| return false;
|
| }
|
| @@ -261,13 +288,13 @@ bool QuotaDatabase::DeleteHostQuota(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::DeleteOriginLastAccessTime(
|
| +bool QuotaDatabase::DeleteOriginInfo(
|
| const GURL& origin, StorageType type) {
|
| if (!LazyOpen(false))
|
| return false;
|
|
|
| const char* kSql =
|
| - "DELETE FROM OriginLastAccessTable"
|
| + "DELETE FROM OriginInfoTable"
|
| " WHERE origin = ? AND type = ?";
|
|
|
| sql::Statement statement;
|
| @@ -304,7 +331,7 @@ bool QuotaDatabase::GetLRUOrigin(
|
| if (!LazyOpen(false))
|
| return false;
|
|
|
| - const char* kSql = "SELECT origin FROM OriginLastAccessTable"
|
| + const char* kSql = "SELECT origin FROM OriginInfoTable"
|
| " WHERE type = ?"
|
| " ORDER BY last_access_time ASC";
|
|
|
| @@ -328,6 +355,28 @@ bool QuotaDatabase::GetLRUOrigin(
|
| return statement.Succeeded();
|
| }
|
|
|
| +bool QuotaDatabase::GetOriginsModifiedSince(
|
| + StorageType type, std::set<GURL>* origins, base::Time modified_since) {
|
| + DCHECK(origins);
|
| + if (!LazyOpen(false))
|
| + return false;
|
| +
|
| + const char* kSql = "SELECT origin FROM OriginInfoTable"
|
| + " WHERE type = ? AND last_modified_time > ?";
|
| +
|
| + sql::Statement statement;
|
| + if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| + return false;
|
| + statement.BindInt(0, static_cast<int>(type));
|
| + statement.BindInt64(1, modified_since.ToInternalValue());
|
| +
|
| + origins->clear();
|
| + while (statement.Step())
|
| + origins->insert(GURL(statement.ColumnString(0)));
|
| +
|
| + return statement.Succeeded();
|
| +}
|
| +
|
| bool QuotaDatabase::IsOriginDatabaseBootstrapped() {
|
| if (!LazyOpen(true))
|
| return false;
|
| @@ -369,7 +418,7 @@ bool QuotaDatabase::FindOriginUsedCount(
|
| return false;
|
|
|
| const char* kSql =
|
| - "SELECT used_count FROM OriginLastAccessTable"
|
| + "SELECT used_count FROM OriginInfoTable"
|
| " WHERE origin = ? AND type = ?";
|
|
|
| sql::Statement statement;
|
| @@ -540,24 +589,25 @@ bool QuotaDatabase::DumpQuotaTable(QuotaTableCallback* callback) {
|
| return statement.Succeeded();
|
| }
|
|
|
| -bool QuotaDatabase::DumpLastAccessTimeTable(
|
| - LastAccessTimeTableCallback* callback) {
|
| - scoped_ptr<LastAccessTimeTableCallback> callback_deleter(callback);
|
| +bool QuotaDatabase::DumpOriginInfoTable(
|
| + OriginInfoTableCallback* callback) {
|
| + scoped_ptr<OriginInfoTableCallback> callback_deleter(callback);
|
|
|
| if (!LazyOpen(true))
|
| return false;
|
|
|
| - const char* kSql = "SELECT * FROM OriginLastAccessTable";
|
| + const char* kSql = "SELECT * FROM OriginInfoTable";
|
| sql::Statement statement;
|
| if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
|
| return false;
|
|
|
| while (statement.Step()) {
|
| - LastAccessTimeTableEntry entry = {
|
| + OriginInfoTableEntry entry = {
|
| GURL(statement.ColumnString(0)),
|
| static_cast<StorageType>(statement.ColumnInt(1)),
|
| statement.ColumnInt(2),
|
| - base::Time::FromInternalValue(statement.ColumnInt64(3))
|
| + base::Time::FromInternalValue(statement.ColumnInt64(3)),
|
| + base::Time::FromInternalValue(statement.ColumnInt64(4))
|
| };
|
|
|
| if (!callback->Run(entry))
|
| @@ -576,8 +626,8 @@ bool operator<(const QuotaDatabase::QuotaTableEntry& lhs,
|
| return lhs.quota < rhs.quota;
|
| }
|
|
|
| -bool operator<(const QuotaDatabase::LastAccessTimeTableEntry& lhs,
|
| - const QuotaDatabase::LastAccessTimeTableEntry& rhs) {
|
| +bool operator<(const QuotaDatabase::OriginInfoTableEntry& lhs,
|
| + const QuotaDatabase::OriginInfoTableEntry& rhs) {
|
| if (lhs.origin < rhs.origin) return true;
|
| if (rhs.origin < lhs.origin) return false;
|
| if (lhs.type < rhs.type) return true;
|
|
|