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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()); | 218 sql::Transaction transaction(db_.get()); |
219 if (!transaction.Begin()) | 219 if (!transaction.Begin()) |
220 return false; | 220 return false; |
221 | 221 |
222 sql::Statement statement; | |
223 | |
224 typedef std::set<GURL>::const_iterator itr_type; | 222 typedef std::set<GURL>::const_iterator itr_type; |
225 for (itr_type itr = origins.begin(), end = origins.end(); | 223 for (itr_type itr = origins.begin(), end = origins.end(); |
226 itr != end; ++itr) { | 224 itr != end; ++itr) { |
227 const char* kSql = | 225 const char* kSql = |
228 "INSERT OR IGNORE INTO OriginLastAccessTable" | 226 "INSERT OR IGNORE INTO OriginLastAccessTable" |
229 " (used_count, last_access_time, origin, type)" | 227 " (used_count, last_access_time, origin, type)" |
230 " VALUES (?, ?, ?, ?)"; | 228 " VALUES (?, ?, ?, ?)"; |
229 sql::Statement statement; | |
231 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 230 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
232 return false; | 231 return false; |
233 | 232 |
234 statement.BindInt(0, 0); // used_count | 233 statement.BindInt(0, 0); // used_count |
235 statement.BindInt64(1, last_access_time.ToInternalValue()); | 234 statement.BindInt64(1, last_access_time.ToInternalValue()); |
236 statement.BindString(2, itr->spec()); | 235 statement.BindString(2, itr->spec()); |
237 statement.BindInt(3, static_cast<int>(type)); | 236 statement.BindInt(3, static_cast<int>(type)); |
238 if (!statement.Run()) | 237 if (!statement.Run()) |
239 return false; | 238 return false; |
240 } | 239 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 return false; | 507 return false; |
509 | 508 |
510 // So we can't go recursive. | 509 // So we can't go recursive. |
511 if (is_recreating_) | 510 if (is_recreating_) |
512 return false; | 511 return false; |
513 | 512 |
514 AutoReset<bool> auto_reset(&is_recreating_, true); | 513 AutoReset<bool> auto_reset(&is_recreating_, true); |
515 return LazyOpen(true); | 514 return LazyOpen(true); |
516 } | 515 } |
517 | 516 |
517 bool QuotaDatabase::DumpQuotaTable(QuotaTableCallback* callback) { | |
518 scoped_ptr<QuotaTableCallback> callback_deleter(callback); | |
519 if (!LazyOpen(true)) | |
520 return false; | |
521 | |
522 const char* kSql = "SELECT * FROM HostQuotaTable"; | |
523 sql::Statement statement; | |
524 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | |
525 return false; | |
526 | |
527 while (statement.Step()) { | |
528 QuotaTableEntry entry = { | |
529 statement.ColumnString(0), | |
530 static_cast<StorageType>(statement.ColumnInt(1)), | |
531 statement.ColumnInt64(2) | |
532 }; | |
533 | |
534 if (!callback->Run(entry)) | |
kinuko
2011/05/23 08:16:52
does this mean 'the callback may return false when
tzik
2011/05/24 04:32:41
Done.
| |
535 return true; | |
536 } | |
537 | |
538 return statement.Succeeded(); | |
539 } | |
540 | |
541 bool QuotaDatabase::DumpLastAccessTimeTable( | |
542 LastAccessTimeTableCallback* callback) { | |
543 scoped_ptr<LastAccessTimeTableCallback> callback_deleter(callback); | |
544 | |
545 if (!LazyOpen(true)) | |
546 return false; | |
547 | |
548 const char* kSql = "SELECT * FROM OriginLastAccessTable"; | |
549 sql::Statement statement; | |
550 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | |
551 return false; | |
552 | |
553 while (statement.Step()) { | |
554 LastAccessTimeTableEntry entry = { | |
555 GURL(statement.ColumnString(0)), | |
556 static_cast<StorageType>(statement.ColumnInt(1)), | |
557 statement.ColumnInt(2), | |
558 base::Time::FromInternalValue(statement.ColumnInt64(3)) | |
559 }; | |
560 | |
561 if (!callback->Run(entry)) | |
562 return true; | |
563 } | |
564 | |
565 return statement.Succeeded(); | |
566 } | |
567 | |
568 bool operator<(const QuotaDatabase::QuotaTableEntry& lhs, | |
569 const QuotaDatabase::QuotaTableEntry& rhs) { | |
570 if (lhs.host < rhs.host) return true; | |
571 if (rhs.host < lhs.host) return false; | |
572 if (lhs.type < rhs.type) return true; | |
573 if (rhs.type < lhs.type) return false; | |
574 return lhs.quota < rhs.quota; | |
575 } | |
576 | |
577 bool operator<(const QuotaDatabase::LastAccessTimeTableEntry& lhs, | |
578 const QuotaDatabase::LastAccessTimeTableEntry& rhs) { | |
579 if (lhs.origin < rhs.origin) return true; | |
580 if (rhs.origin < lhs.origin) return false; | |
581 if (lhs.type < rhs.type) return true; | |
582 if (rhs.type < lhs.type) return false; | |
583 if (lhs.used_count < rhs.used_count) return true; | |
584 if (rhs.used_count < lhs.used_count) return false; | |
585 return lhs.last_access_time < rhs.last_access_time; | |
586 } | |
518 } // quota namespace | 587 } // quota namespace |
OLD | NEW |