diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-20 13:02:53 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-20 13:02:53 +0000 |
commit | 6eea807ff6ac38e61ff3e6721c1c0acaa6f213d2 (patch) | |
tree | 6efc69bc9671dcbbc54d2d72ce493aa2a35d6a60 /webkit/quota/quota_database.cc | |
parent | 7f9a8e49ef9340c838562c0d4fa0750e8c172d43 (diff) | |
download | chromium_src-6eea807ff6ac38e61ff3e6721c1c0acaa6f213d2.zip chromium_src-6eea807ff6ac38e61ff3e6721c1c0acaa6f213d2.tar.gz chromium_src-6eea807ff6ac38e61ff3e6721c1c0acaa6f213d2.tar.bz2 |
Implement NotifyStorageAccessed
BUG=61676
TEST=to be added
Review URL: http://codereview.chromium.org/7011033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota/quota_database.cc')
-rw-r--r-- | webkit/quota/quota_database.cc | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/webkit/quota/quota_database.cc b/webkit/quota/quota_database.cc index 50a9ed2..52caf2e 100644 --- a/webkit/quota/quota_database.cc +++ b/webkit/quota/quota_database.cc @@ -13,6 +13,7 @@ #include "app/sql/transaction.h" #include "base/auto_reset.h" #include "base/file_util.h" +#include "base/time.h" #include "googleurl/src/gurl.h" namespace { @@ -90,6 +91,8 @@ std::string GetGlobalQuotaKey(quota::StorageType type) { return std::string(); } +const int kCommitIntervalMs = 30000; + } // anonymous namespace namespace quota { @@ -101,6 +104,9 @@ QuotaDatabase::QuotaDatabase(const FilePath& path) } QuotaDatabase::~QuotaDatabase() { + if (db_.get()) { + db_->CommitTransaction(); + } } void QuotaDatabase::CloseConnection() { @@ -138,10 +144,6 @@ bool QuotaDatabase::SetHostQuota( if (!LazyOpen(true)) return false; - sql::Transaction transaction(db_.get()); - if (!transaction.Begin()) - return false; - sql::Statement statement; int64 dummy; @@ -167,7 +169,8 @@ bool QuotaDatabase::SetHostQuota( if (!statement.Run()) return false; - return transaction.Commit(); + ScheduleCommit(); + return true; } bool QuotaDatabase::SetOriginLastAccessTime( @@ -175,10 +178,6 @@ bool QuotaDatabase::SetOriginLastAccessTime( if (!LazyOpen(true)) return false; - sql::Transaction transaction(db_.get()); - if (!transaction.Begin()) - return false; - sql::Statement statement; int used_count = 0; @@ -206,7 +205,8 @@ bool QuotaDatabase::SetOriginLastAccessTime( if (!statement.Run()) return false; - return transaction.Commit(); + ScheduleCommit(); + return true; } bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins, @@ -257,7 +257,11 @@ bool QuotaDatabase::DeleteHostQuota( statement.BindString(0, host); statement.BindInt(1, static_cast<int>(type)); - return statement.Run(); + if (!statement.Run()) + return false; + + ScheduleCommit(); + return true; } bool QuotaDatabase::DeleteOriginLastAccessTime( @@ -275,7 +279,11 @@ bool QuotaDatabase::DeleteOriginLastAccessTime( statement.BindString(0, origin.spec()); statement.BindInt(1, static_cast<int>(type)); - return statement.Run(); + if (!statement.Run()) + return false; + + ScheduleCommit(); + return true; } bool QuotaDatabase::GetGlobalQuota(StorageType type, int64* quota) { @@ -334,6 +342,25 @@ bool QuotaDatabase::SetOriginDatabaseBootstrapped(bool bootstrap_flag) { return meta_table_->SetValue(kIsOriginTableBootstrapped, bootstrap_flag); } +void QuotaDatabase::Commit() { + if (!db_.get()) + return; + + // Note: for now this will be called only by ScheduleCommit, but when it + // becomes untrue we should call timer_.Stop() here. + DCHECK(!timer_.IsRunning()); + + db_->CommitTransaction(); + db_->BeginTransaction(); +} + +void QuotaDatabase::ScheduleCommit() { + if (timer_.IsRunning()) + return; + timer_.Start(base::TimeDelta::FromMilliseconds(kCommitIntervalMs), this, + &QuotaDatabase::Commit); +} + bool QuotaDatabase::FindOriginUsedCount( const GURL& origin, StorageType type, int* used_count) { DCHECK(used_count); @@ -394,6 +421,9 @@ bool QuotaDatabase::LazyOpen(bool create_if_needed) { return false; } + // Start a long-running transaction. + db_->BeginTransaction(); + return true; } |