| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/quota/quota_database.h" | 5 #include "webkit/quota/quota_database.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
| 10 #include "app/sql/diagnostic_error_delegate.h" | 10 #include "app/sql/diagnostic_error_delegate.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 ScheduleCommit(); | 208 ScheduleCommit(); |
| 209 return true; | 209 return true; |
| 210 } | 210 } |
| 211 | 211 |
| 212 bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins, | 212 bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins, |
| 213 StorageType type, | 213 StorageType type, |
| 214 base::Time last_access_time) { | 214 base::Time last_access_time) { |
| 215 if (!LazyOpen(true)) | 215 if (!LazyOpen(true)) |
| 216 return false; | 216 return false; |
| 217 | 217 |
| 218 sql::Transaction transaction(db_.get()); | |
| 219 if (!transaction.Begin()) | |
| 220 return false; | |
| 221 | |
| 222 sql::Statement statement; | |
| 223 | |
| 224 typedef std::set<GURL>::const_iterator itr_type; | 218 typedef std::set<GURL>::const_iterator itr_type; |
| 225 for (itr_type itr = origins.begin(), end = origins.end(); | 219 for (itr_type itr = origins.begin(), end = origins.end(); |
| 226 itr != end; ++itr) { | 220 itr != end; ++itr) { |
| 227 const char* kSql = | 221 const char* kSql = |
| 228 "INSERT OR IGNORE INTO OriginLastAccessTable" | 222 "INSERT OR IGNORE INTO OriginLastAccessTable" |
| 229 " (used_count, last_access_time, origin, type)" | 223 " (used_count, last_access_time, origin, type)" |
| 230 " VALUES (?, ?, ?, ?)"; | 224 " VALUES (?, ?, ?, ?)"; |
| 225 sql::Statement statement; |
| 231 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 226 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 232 return false; | 227 return false; |
| 233 | 228 |
| 234 statement.BindInt(0, 0); // used_count | 229 statement.BindInt(0, 0); // used_count |
| 235 statement.BindInt64(1, last_access_time.ToInternalValue()); | 230 statement.BindInt64(1, last_access_time.ToInternalValue()); |
| 236 statement.BindString(2, itr->spec()); | 231 statement.BindString(2, itr->spec()); |
| 237 statement.BindInt(3, static_cast<int>(type)); | 232 statement.BindInt(3, static_cast<int>(type)); |
| 238 if (!statement.Run()) | 233 if (!statement.Run()) |
| 239 return false; | 234 return false; |
| 240 } | 235 } |
| 241 | 236 |
| 242 return transaction.Commit(); | 237 ScheduleCommit(); |
| 238 return true; |
| 243 } | 239 } |
| 244 | 240 |
| 245 bool QuotaDatabase::DeleteHostQuota( | 241 bool QuotaDatabase::DeleteHostQuota( |
| 246 const std::string& host, StorageType type) { | 242 const std::string& host, StorageType type) { |
| 247 if (!LazyOpen(false)) | 243 if (!LazyOpen(false)) |
| 248 return false; | 244 return false; |
| 249 | 245 |
| 250 const char* kSql = | 246 const char* kSql = |
| 251 "DELETE FROM HostQuotaTable" | 247 "DELETE FROM HostQuotaTable" |
| 252 " WHERE host = ? AND type = ?"; | 248 " WHERE host = ? AND type = ?"; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 return false; | 504 return false; |
| 509 | 505 |
| 510 // So we can't go recursive. | 506 // So we can't go recursive. |
| 511 if (is_recreating_) | 507 if (is_recreating_) |
| 512 return false; | 508 return false; |
| 513 | 509 |
| 514 AutoReset<bool> auto_reset(&is_recreating_, true); | 510 AutoReset<bool> auto_reset(&is_recreating_, true); |
| 515 return LazyOpen(true); | 511 return LazyOpen(true); |
| 516 } | 512 } |
| 517 | 513 |
| 514 bool QuotaDatabase::DumpQuotaTable(QuotaTableCallback* callback) { |
| 515 scoped_ptr<QuotaTableCallback> callback_deleter(callback); |
| 516 if (!LazyOpen(true)) |
| 517 return false; |
| 518 |
| 519 const char* kSql = "SELECT * FROM HostQuotaTable"; |
| 520 sql::Statement statement; |
| 521 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 522 return false; |
| 523 |
| 524 while (statement.Step()) { |
| 525 QuotaTableEntry entry = { |
| 526 statement.ColumnString(0), |
| 527 static_cast<StorageType>(statement.ColumnInt(1)), |
| 528 statement.ColumnInt64(2) |
| 529 }; |
| 530 |
| 531 if (!callback->Run(entry)) |
| 532 return true; |
| 533 } |
| 534 |
| 535 return statement.Succeeded(); |
| 536 } |
| 537 |
| 538 bool QuotaDatabase::DumpLastAccessTimeTable( |
| 539 LastAccessTimeTableCallback* callback) { |
| 540 scoped_ptr<LastAccessTimeTableCallback> callback_deleter(callback); |
| 541 |
| 542 if (!LazyOpen(true)) |
| 543 return false; |
| 544 |
| 545 const char* kSql = "SELECT * FROM OriginLastAccessTable"; |
| 546 sql::Statement statement; |
| 547 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 548 return false; |
| 549 |
| 550 while (statement.Step()) { |
| 551 LastAccessTimeTableEntry entry = { |
| 552 GURL(statement.ColumnString(0)), |
| 553 static_cast<StorageType>(statement.ColumnInt(1)), |
| 554 statement.ColumnInt(2), |
| 555 base::Time::FromInternalValue(statement.ColumnInt64(3)) |
| 556 }; |
| 557 |
| 558 if (!callback->Run(entry)) |
| 559 return true; |
| 560 } |
| 561 |
| 562 return statement.Succeeded(); |
| 563 } |
| 564 |
| 565 bool operator<(const QuotaDatabase::QuotaTableEntry& lhs, |
| 566 const QuotaDatabase::QuotaTableEntry& rhs) { |
| 567 if (lhs.host < rhs.host) return true; |
| 568 if (rhs.host < lhs.host) return false; |
| 569 if (lhs.type < rhs.type) return true; |
| 570 if (rhs.type < lhs.type) return false; |
| 571 return lhs.quota < rhs.quota; |
| 572 } |
| 573 |
| 574 bool operator<(const QuotaDatabase::LastAccessTimeTableEntry& lhs, |
| 575 const QuotaDatabase::LastAccessTimeTableEntry& rhs) { |
| 576 if (lhs.origin < rhs.origin) return true; |
| 577 if (rhs.origin < lhs.origin) return false; |
| 578 if (lhs.type < rhs.type) return true; |
| 579 if (rhs.type < lhs.type) return false; |
| 580 if (lhs.used_count < rhs.used_count) return true; |
| 581 if (rhs.used_count < lhs.used_count) return false; |
| 582 return lhs.last_access_time < rhs.last_access_time; |
| 583 } |
| 518 } // quota namespace | 584 } // quota namespace |
| OLD | NEW |