Index: webkit/quota/quota_database.cc |
diff --git a/webkit/quota/quota_database.cc b/webkit/quota/quota_database.cc |
index 50a9ed2b564af82c1bba52081d0460f5f53de01e..a039d9d6a726f27f61049925da6997d041057114 100644 |
--- a/webkit/quota/quota_database.cc |
+++ b/webkit/quota/quota_database.cc |
@@ -219,8 +219,6 @@ bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins, |
if (!transaction.Begin()) |
return false; |
- sql::Statement statement; |
- |
typedef std::set<GURL>::const_iterator itr_type; |
for (itr_type itr = origins.begin(), end = origins.end(); |
itr != end; ++itr) { |
@@ -228,6 +226,7 @@ bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins, |
"INSERT OR IGNORE INTO OriginLastAccessTable" |
" (used_count, last_access_time, origin, type)" |
" VALUES (?, ?, ?, ?)"; |
+ sql::Statement statement; |
if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
return false; |
@@ -485,4 +484,151 @@ bool QuotaDatabase::ResetSchema() { |
return LazyOpen(true); |
} |
+bool QuotaDatabase::DumpQuotaTable(QuotaTableCallback* callback) { |
+ if (!LazyOpen(true)) |
+ return false; |
+ |
+ const char* kSql = "SELECT * FROM HostQuotaTable"; |
+ sql::Statement statement; |
+ if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
+ return false; |
+ |
+ while (statement.Step()) { |
+ QuotaTableEntry entry = { |
+ statement.ColumnString(0), |
+ static_cast<StorageType>(statement.ColumnInt(1)), |
+ statement.ColumnInt64(2) |
+ }; |
+ |
+ if (!callback->Run(entry)) |
+ return true; |
+ } |
+ |
+ return statement.Succeeded(); |
+} |
+ |
+bool QuotaDatabase::DumpAccessTable(AccessTableCallback* callback) { |
kinuko
2011/05/20 13:19:54
Can we rename s/AccessTable/LastAccessTimeTable/
tzik
2011/05/23 05:24:15
Done.
|
+ if (!LazyOpen(true)) |
+ return false; |
+ |
+ const char* kSql = "SELECT * FROM OriginLastAccessTable"; |
+ sql::Statement statement; |
+ if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
+ return false; |
+ |
+ while (statement.Step()) { |
+ AccessTableEntry entry = { |
+ GURL(statement.ColumnString(0)), |
+ static_cast<StorageType>(statement.ColumnInt(1)), |
+ statement.ColumnInt(2), |
+ base::Time::FromInternalValue(statement.ColumnInt64(3)) |
+ }; |
+ |
+ if (!callback->Run(entry)) |
+ return true; |
+ } |
+ |
+ return statement.Succeeded(); |
+} |
+ |
+bool QuotaDatabase::AssignQuotaTable( |
+ const std::set<QuotaTableEntry>& entries) { |
kinuko
2011/05/20 13:19:54
As we chatted locally, as long as it is labeled 'f
|
+ if (!LazyOpen(true)) |
+ return false; |
+ |
+ sql::Transaction transaction(db_.get()); |
+ if (!transaction.Begin()) |
+ return false; |
+ |
+ { |
+ const char* kSql = "DELETE FROM HostQuotaTable"; |
+ sql::Statement statement; |
+ if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
+ return false; |
+ if (!statement.Run()) |
+ return false; |
+ } |
+ |
+ typedef std::set<QuotaTableEntry>::const_iterator itr_type; |
+ for (itr_type itr = entries.begin(), end = entries.end(); |
+ itr != end; ++itr) { |
+ const char* kSql = |
+ "INSERT INTO HostQuotaTable" |
+ " (host, type, quota)" |
+ " VALUES (?, ?, ?)"; |
+ sql::Statement statement; |
+ if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
+ return false; |
+ |
+ statement.BindString(0, itr->host); |
+ statement.BindInt(1, static_cast<int>(itr->type)); |
+ statement.BindInt64(2, itr->quota); |
+ if (!statement.Run()) |
+ return false; |
+ } |
+ |
+ return transaction.Commit(); |
+} |
+ |
+bool QuotaDatabase::AssignAccessTable( |
+ const std::set<AccessTableEntry>& entries) { |
+ if (!LazyOpen(true)) |
+ return false; |
+ |
+ sql::Transaction transaction(db_.get()); |
+ if (!transaction.Begin()) |
+ return false; |
+ |
+ { |
+ const char* kSql = "DELETE FROM OriginLastAccessTable"; |
+ sql::Statement statement; |
+ if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
+ return false; |
+ if (!statement.Run()) |
+ return false; |
+ } |
+ |
+ typedef std::set<AccessTableEntry>::const_iterator itr_type; |
+ for (itr_type itr = entries.begin(), end = entries.end(); |
+ itr != end; ++itr) { |
+ const char* kSql = |
+ "INSERT INTO OriginLastAccessTable" |
+ " (origin, type, used_count, last_access_time)" |
+ " VALUES (?, ?, ?, ?)"; |
+ sql::Statement statement; |
+ if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
+ return false; |
+ |
+ statement.BindString(0, itr->origin.spec()); |
+ statement.BindInt(1, static_cast<int>(itr->type)); |
+ statement.BindInt(2, itr->used_count); |
+ statement.BindInt64(3, itr->last_access_time.ToInternalValue()); |
+ if (!statement.Run()) |
+ return false; |
+ } |
+ |
+ return transaction.Commit(); |
+} |
+ |
+ |
+bool operator<(const QuotaDatabase::QuotaTableEntry& lhs, |
+ const QuotaDatabase::QuotaTableEntry& rhs) { |
+ if (lhs.host < rhs.host) return true; |
+ if (rhs.host < lhs.host) return false; |
+ if (lhs.type < rhs.type) return true; |
+ if (rhs.type < lhs.type) return false; |
+ return lhs.quota < rhs.quota; |
+} |
+ |
+bool operator<(const QuotaDatabase::AccessTableEntry& lhs, |
+ const QuotaDatabase::AccessTableEntry& rhs) { |
+ if (lhs.origin < rhs.origin) return true; |
+ if (rhs.origin < lhs.origin) return false; |
+ if (lhs.type < rhs.type) return true; |
+ if (rhs.type < lhs.type) return false; |
+ if (lhs.used_count < rhs.used_count) return true; |
+ if (rhs.used_count < lhs.used_count) return false; |
+ return lhs.last_access_time < rhs.last_access_time; |
+} |
+ |
} // quota namespace |