diff options
Diffstat (limited to 'webkit/quota')
-rw-r--r-- | webkit/quota/quota_database.cc | 18 | ||||
-rw-r--r-- | webkit/quota/quota_database.h | 7 | ||||
-rw-r--r-- | webkit/quota/quota_database_unittest.cc | 16 |
3 files changed, 40 insertions, 1 deletions
diff --git a/webkit/quota/quota_database.cc b/webkit/quota/quota_database.cc index cbe6cad..c4e7f53 100644 --- a/webkit/quota/quota_database.cc +++ b/webkit/quota/quota_database.cc @@ -24,6 +24,7 @@ const char kOriginsTable[] = "Origins"; const char kHostQuotaTable[] = "HostQuotaTable"; const char kOriginLastAccessTable[] = "OriginLastAccessTable"; const char kGlobalQuotaKeyPrefix[] = "GlobalQuota-"; +const char kIsOriginTableBootstrapped[] = "IsOriginTableBootstrapped"; const struct { const char* table_name; @@ -129,7 +130,7 @@ bool QuotaDatabase::GetHostQuota( bool QuotaDatabase::SetHostQuota( const std::string& host, StorageType type, int64 quota) { - DCHECK(quota >= 0); + DCHECK_GE(quota, 0); if (!LazyOpen(true)) return false; @@ -281,6 +282,21 @@ bool QuotaDatabase::GetLRUOrigin( return statement.Succeeded(); } +bool QuotaDatabase::IsOriginDatabaseBootstrapped() { + if (!LazyOpen(true)) + return false; + + int flag = 0; + return meta_table_->GetValue(kIsOriginTableBootstrapped, &flag) && flag; +} + +bool QuotaDatabase::SetOriginDatabaseBootstrapped(bool bootstrap_flag) { + if (!LazyOpen(true)) + return false; + + return meta_table_->SetValue(kIsOriginTableBootstrapped, bootstrap_flag); +} + bool QuotaDatabase::FindOriginUsedCount( const GURL& origin, StorageType type, int* used_count) { DCHECK(used_count); diff --git a/webkit/quota/quota_database.h b/webkit/quota/quota_database.h index 2e27c1f..4cc55cb 100644 --- a/webkit/quota/quota_database.h +++ b/webkit/quota/quota_database.h @@ -6,6 +6,7 @@ #define WEBKIT_QUOTA_QUOTA_DATABASE_H_ #include <set> +#include <string> #include "base/basictypes.h" #include "base/file_path.h" @@ -52,6 +53,12 @@ class QuotaDatabase { const std::set<GURL>& exceptions, GURL* origin); + // Returns false if SetOriginDatabaseBootstrapped has never + // been called before, which means existing origins may not have been + // registered. + bool IsOriginDatabaseBootstrapped(); + bool SetOriginDatabaseBootstrapped(bool bootstrap_flag); + private: bool FindOriginUsedCount(const GURL& origin, StorageType type, diff --git a/webkit/quota/quota_database_unittest.cc b/webkit/quota/quota_database_unittest.cc index 5f6c1cc..f65bea2 100644 --- a/webkit/quota/quota_database_unittest.cc +++ b/webkit/quota/quota_database_unittest.cc @@ -184,4 +184,20 @@ TEST_F(QuotaDatabaseTest, OriginLastAccessTimeLRU) { OriginLastAccessTimeLRU(FilePath()); } +TEST(QuotaDatabaseTest, BootstrapFlag) { + ScopedTempDir data_dir; + ASSERT_TRUE(data_dir.CreateUniqueTempDir()); + + const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db"); + QuotaDatabase db(kDbFile); + + + EXPECT_FALSE(db.IsOriginDatabaseBootstrapped()); + EXPECT_TRUE(db.SetOriginDatabaseBootstrapped(true)); + EXPECT_TRUE(db.IsOriginDatabaseBootstrapped()); + EXPECT_TRUE(db.SetOriginDatabaseBootstrapped(false)); + EXPECT_FALSE(db.IsOriginDatabaseBootstrapped()); +} + + } // namespace quota |