Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: webkit/quota/quota_database.cc

Issue 7057006: Add Dump{Quota,LastAccessTime}Table (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 'Move Assign*** and Rename AccessTable' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/quota/quota_database.h ('k') | webkit/quota/quota_database_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 if (!LazyOpen(true))
519 return false;
520
521 const char* kSql = "SELECT * FROM HostQuotaTable";
522 sql::Statement statement;
523 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement))
524 return false;
525
526 while (statement.Step()) {
527 QuotaTableEntry entry = {
528 statement.ColumnString(0),
529 static_cast<StorageType>(statement.ColumnInt(1)),
530 statement.ColumnInt64(2)
531 };
532
533 if (!callback->Run(entry))
Dai Mikurube (NOT FULLTIME) 2011/05/23 06:16:42 Is the caller responsible for deleting the callbac
tzik 2011/05/23 06:57:12 Done. Now, ownership of the callback shall be pass
534 return true;
535 }
536
537 return statement.Succeeded();
538 }
539
540 bool QuotaDatabase::DumpLastAccessTimeTable(
541 LastAccessTimeTableCallback* callback) {
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))
Dai Mikurube (NOT FULLTIME) 2011/05/23 06:16:42 ditto.
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
OLDNEW
« no previous file with comments | « webkit/quota/quota_database.h ('k') | webkit/quota/quota_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698