| Index: storage/browser/quota/quota_database.cc
|
| diff --git a/webkit/browser/quota/quota_database.cc b/storage/browser/quota/quota_database.cc
|
| similarity index 72%
|
| rename from webkit/browser/quota/quota_database.cc
|
| rename to storage/browser/quota/quota_database.cc
|
| index 03bed771db0051710caaf553607ca3f510fe81a6..c6b3d5af55d7cdacd390b28ffe13f515be5451d9 100644
|
| --- a/webkit/browser/quota/quota_database.cc
|
| +++ b/storage/browser/quota/quota_database.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "webkit/browser/quota/quota_database.h"
|
| +#include "storage/browser/quota/quota_database.h"
|
|
|
| #include <string>
|
| #include <vector>
|
| @@ -16,7 +16,7 @@
|
| #include "sql/statement.h"
|
| #include "sql/transaction.h"
|
| #include "url/gurl.h"
|
| -#include "webkit/browser/quota/special_storage_policy.h"
|
| +#include "storage/browser/quota/special_storage_policy.h"
|
|
|
| namespace quota {
|
| namespace {
|
| @@ -46,38 +46,28 @@ const char QuotaDatabase::kTemporaryQuotaOverrideKey[] =
|
| "TemporaryQuotaOverride";
|
|
|
| const QuotaDatabase::TableSchema QuotaDatabase::kTables[] = {
|
| - { kHostQuotaTable,
|
| - "(host TEXT NOT NULL,"
|
| - " type INTEGER NOT NULL,"
|
| - " quota INTEGER DEFAULT 0,"
|
| - " UNIQUE(host, type))" },
|
| - { kOriginInfoTable,
|
| - "(origin TEXT NOT NULL,"
|
| - " type INTEGER NOT NULL,"
|
| - " used_count INTEGER DEFAULT 0,"
|
| - " last_access_time INTEGER DEFAULT 0,"
|
| - " last_modified_time INTEGER DEFAULT 0,"
|
| - " UNIQUE(origin, type))" },
|
| + {kHostQuotaTable,
|
| + "(host TEXT NOT NULL,"
|
| + " type INTEGER NOT NULL,"
|
| + " quota INTEGER DEFAULT 0,"
|
| + " UNIQUE(host, type))"},
|
| + {kOriginInfoTable,
|
| + "(origin TEXT NOT NULL,"
|
| + " type INTEGER NOT NULL,"
|
| + " used_count INTEGER DEFAULT 0,"
|
| + " last_access_time INTEGER DEFAULT 0,"
|
| + " last_modified_time INTEGER DEFAULT 0,"
|
| + " UNIQUE(origin, type))"},
|
| };
|
|
|
| // static
|
| const QuotaDatabase::IndexSchema QuotaDatabase::kIndexes[] = {
|
| - { "HostIndex",
|
| - kHostQuotaTable,
|
| - "(host)",
|
| - false },
|
| - { "OriginInfoIndex",
|
| - kOriginInfoTable,
|
| - "(origin)",
|
| - false },
|
| - { "OriginLastAccessTimeIndex",
|
| - kOriginInfoTable,
|
| - "(last_access_time)",
|
| - false },
|
| - { "OriginLastModifiedTimeIndex",
|
| - kOriginInfoTable,
|
| - "(last_modified_time)",
|
| - false },
|
| + {"HostIndex", kHostQuotaTable, "(host)", false},
|
| + {"OriginInfoIndex", kOriginInfoTable, "(origin)", false},
|
| + {"OriginLastAccessTimeIndex", kOriginInfoTable, "(last_access_time)",
|
| + false},
|
| + {"OriginLastModifiedTimeIndex", kOriginInfoTable, "(last_modified_time)",
|
| + false},
|
| };
|
|
|
| struct QuotaDatabase::QuotaTableImporter {
|
| @@ -90,22 +80,17 @@ struct QuotaDatabase::QuotaTableImporter {
|
|
|
| // Clang requires explicit out-of-line constructors for them.
|
| QuotaDatabase::QuotaTableEntry::QuotaTableEntry()
|
| - : type(kStorageTypeUnknown),
|
| - quota(0) {
|
| + : type(kStorageTypeUnknown), quota(0) {
|
| }
|
|
|
| -QuotaDatabase::QuotaTableEntry::QuotaTableEntry(
|
| - const std::string& host,
|
| - StorageType type,
|
| - int64 quota)
|
| - : host(host),
|
| - type(type),
|
| - quota(quota) {
|
| +QuotaDatabase::QuotaTableEntry::QuotaTableEntry(const std::string& host,
|
| + StorageType type,
|
| + int64 quota)
|
| + : host(host), type(type), quota(quota) {
|
| }
|
|
|
| QuotaDatabase::OriginInfoTableEntry::OriginInfoTableEntry()
|
| - : type(kStorageTypeUnknown),
|
| - used_count(0) {
|
| + : type(kStorageTypeUnknown), used_count(0) {
|
| }
|
|
|
| QuotaDatabase::OriginInfoTableEntry::OriginInfoTableEntry(
|
| @@ -123,9 +108,7 @@ QuotaDatabase::OriginInfoTableEntry::OriginInfoTableEntry(
|
|
|
| // QuotaDatabase ------------------------------------------------------------
|
| QuotaDatabase::QuotaDatabase(const base::FilePath& path)
|
| - : db_file_path_(path),
|
| - is_recreating_(false),
|
| - is_disabled_(false) {
|
| + : db_file_path_(path), is_recreating_(false), is_disabled_(false) {
|
| }
|
|
|
| QuotaDatabase::~QuotaDatabase() {
|
| @@ -139,8 +122,9 @@ void QuotaDatabase::CloseConnection() {
|
| db_.reset();
|
| }
|
|
|
| -bool QuotaDatabase::GetHostQuota(
|
| - const std::string& host, StorageType type, int64* quota) {
|
| +bool QuotaDatabase::GetHostQuota(const std::string& host,
|
| + StorageType type,
|
| + int64* quota) {
|
| DCHECK(quota);
|
| if (!LazyOpen(false))
|
| return false;
|
| @@ -161,8 +145,9 @@ bool QuotaDatabase::GetHostQuota(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::SetHostQuota(
|
| - const std::string& host, StorageType type, int64 quota) {
|
| +bool QuotaDatabase::SetHostQuota(const std::string& host,
|
| + StorageType type,
|
| + int64 quota) {
|
| DCHECK_GE(quota, 0);
|
| if (!LazyOpen(true))
|
| return false;
|
| @@ -183,8 +168,9 @@ bool QuotaDatabase::SetHostQuota(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::SetOriginLastAccessTime(
|
| - const GURL& origin, StorageType type, base::Time last_access_time) {
|
| +bool QuotaDatabase::SetOriginLastAccessTime(const GURL& origin,
|
| + StorageType type,
|
| + base::Time last_access_time) {
|
| if (!LazyOpen(true))
|
| return false;
|
|
|
| @@ -198,7 +184,7 @@ bool QuotaDatabase::SetOriginLastAccessTime(
|
| " SET used_count = ?, last_access_time = ?"
|
| " WHERE origin = ? AND type = ?";
|
| statement.Assign(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
|
| - } else {
|
| + } else {
|
| const char* kSql =
|
| "INSERT INTO OriginInfoTable"
|
| " (used_count, last_access_time, origin, type)"
|
| @@ -217,8 +203,9 @@ bool QuotaDatabase::SetOriginLastAccessTime(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::SetOriginLastModifiedTime(
|
| - const GURL& origin, StorageType type, base::Time last_modified_time) {
|
| +bool QuotaDatabase::SetOriginLastModifiedTime(const GURL& origin,
|
| + StorageType type,
|
| + base::Time last_modified_time) {
|
| if (!LazyOpen(true))
|
| return false;
|
|
|
| @@ -248,14 +235,13 @@ bool QuotaDatabase::SetOriginLastModifiedTime(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::RegisterInitialOriginInfo(
|
| - const std::set<GURL>& origins, StorageType type) {
|
| +bool QuotaDatabase::RegisterInitialOriginInfo(const std::set<GURL>& origins,
|
| + StorageType type) {
|
| if (!LazyOpen(true))
|
| return false;
|
|
|
| typedef std::set<GURL>::const_iterator itr_type;
|
| - for (itr_type itr = origins.begin(), end = origins.end();
|
| - itr != end; ++itr) {
|
| + for (itr_type itr = origins.begin(), end = origins.end(); itr != end; ++itr) {
|
| const char* kSql =
|
| "INSERT OR IGNORE INTO OriginInfoTable"
|
| " (origin, type) VALUES (?, ?)";
|
| @@ -271,8 +257,7 @@ bool QuotaDatabase::RegisterInitialOriginInfo(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::DeleteHostQuota(
|
| - const std::string& host, StorageType type) {
|
| +bool QuotaDatabase::DeleteHostQuota(const std::string& host, StorageType type) {
|
| if (!LazyOpen(false))
|
| return false;
|
|
|
| @@ -291,8 +276,7 @@ bool QuotaDatabase::DeleteHostQuota(
|
| return true;
|
| }
|
|
|
| -bool QuotaDatabase::DeleteOriginInfo(
|
| - const GURL& origin, StorageType type) {
|
| +bool QuotaDatabase::DeleteOriginInfo(const GURL& origin, StorageType type) {
|
| if (!LazyOpen(false))
|
| return false;
|
|
|
| @@ -325,18 +309,18 @@ bool QuotaDatabase::SetQuotaConfigValue(const char* key, int64 value) {
|
| return meta_table_->SetValue(key, value);
|
| }
|
|
|
| -bool QuotaDatabase::GetLRUOrigin(
|
| - StorageType type,
|
| - const std::set<GURL>& exceptions,
|
| - SpecialStoragePolicy* special_storage_policy,
|
| - GURL* origin) {
|
| +bool QuotaDatabase::GetLRUOrigin(StorageType type,
|
| + const std::set<GURL>& exceptions,
|
| + SpecialStoragePolicy* special_storage_policy,
|
| + GURL* origin) {
|
| DCHECK(origin);
|
| if (!LazyOpen(false))
|
| return false;
|
|
|
| - const char* kSql = "SELECT origin FROM OriginInfoTable"
|
| - " WHERE type = ?"
|
| - " ORDER BY last_access_time ASC";
|
| + const char* kSql =
|
| + "SELECT origin FROM OriginInfoTable"
|
| + " WHERE type = ?"
|
| + " ORDER BY last_access_time ASC";
|
|
|
| sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
|
| statement.BindInt(0, static_cast<int>(type));
|
| @@ -356,14 +340,16 @@ bool QuotaDatabase::GetLRUOrigin(
|
| return statement.Succeeded();
|
| }
|
|
|
| -bool QuotaDatabase::GetOriginsModifiedSince(
|
| - StorageType type, std::set<GURL>* origins, base::Time modified_since) {
|
| +bool QuotaDatabase::GetOriginsModifiedSince(StorageType type,
|
| + std::set<GURL>* origins,
|
| + base::Time modified_since) {
|
| DCHECK(origins);
|
| if (!LazyOpen(false))
|
| return false;
|
|
|
| - const char* kSql = "SELECT origin FROM OriginInfoTable"
|
| - " WHERE type = ? AND last_modified_time >= ?";
|
| + const char* kSql =
|
| + "SELECT origin FROM OriginInfoTable"
|
| + " WHERE type = ? AND last_modified_time >= ?";
|
|
|
| sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
|
| statement.BindInt(0, static_cast<int>(type));
|
| @@ -405,12 +391,15 @@ void QuotaDatabase::Commit() {
|
| void QuotaDatabase::ScheduleCommit() {
|
| if (timer_.IsRunning())
|
| return;
|
| - timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kCommitIntervalMs),
|
| - this, &QuotaDatabase::Commit);
|
| + timer_.Start(FROM_HERE,
|
| + base::TimeDelta::FromMilliseconds(kCommitIntervalMs),
|
| + this,
|
| + &QuotaDatabase::Commit);
|
| }
|
|
|
| -bool QuotaDatabase::FindOriginUsedCount(
|
| - const GURL& origin, StorageType type, int* used_count) {
|
| +bool QuotaDatabase::FindOriginUsedCount(const GURL& origin,
|
| + StorageType type,
|
| + int* used_count) {
|
| DCHECK(used_count);
|
| if (!LazyOpen(false))
|
| return false;
|
| @@ -454,7 +443,7 @@ bool QuotaDatabase::LazyOpen(bool create_if_needed) {
|
| if (in_memory_only) {
|
| opened = db_->OpenInMemory();
|
| } else if (!base::CreateDirectory(db_file_path_.DirName())) {
|
| - LOG(ERROR) << "Failed to create quota database directory.";
|
| + LOG(ERROR) << "Failed to create quota database directory.";
|
| } else {
|
| opened = db_->Open(db_file_path_);
|
| if (opened)
|
| @@ -479,10 +468,14 @@ bool QuotaDatabase::EnsureDatabaseVersion() {
|
| static const size_t kTableCount = ARRAYSIZE_UNSAFE(kTables);
|
| static const size_t kIndexCount = ARRAYSIZE_UNSAFE(kIndexes);
|
| if (!sql::MetaTable::DoesTableExist(db_.get()))
|
| - return CreateSchema(db_.get(), meta_table_.get(),
|
| - kCurrentVersion, kCompatibleVersion,
|
| - kTables, kTableCount,
|
| - kIndexes, kIndexCount);
|
| + return CreateSchema(db_.get(),
|
| + meta_table_.get(),
|
| + kCurrentVersion,
|
| + kCompatibleVersion,
|
| + kTables,
|
| + kTableCount,
|
| + kIndexes,
|
| + kIndexCount);
|
|
|
| if (!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion))
|
| return false;
|
| @@ -508,12 +501,14 @@ bool QuotaDatabase::EnsureDatabaseVersion() {
|
| }
|
|
|
| // static
|
| -bool QuotaDatabase::CreateSchema(
|
| - sql::Connection* database,
|
| - sql::MetaTable* meta_table,
|
| - int schema_version, int compatible_version,
|
| - const TableSchema* tables, size_t tables_size,
|
| - const IndexSchema* indexes, size_t indexes_size) {
|
| +bool QuotaDatabase::CreateSchema(sql::Connection* database,
|
| + sql::MetaTable* meta_table,
|
| + int schema_version,
|
| + int compatible_version,
|
| + const TableSchema* tables,
|
| + size_t tables_size,
|
| + const IndexSchema* indexes,
|
| + size_t indexes_size) {
|
| // TODO(kinuko): Factor out the common code to create databases.
|
| sql::Transaction transaction(database);
|
| if (!transaction.Begin())
|
| @@ -580,7 +575,8 @@ bool QuotaDatabase::UpgradeSchema(int current_version) {
|
| }
|
| ResetSchema();
|
| for (QuotaTableEntries::const_iterator iter = importer.entries.begin();
|
| - iter != importer.entries.end(); ++iter) {
|
| + iter != importer.entries.end();
|
| + ++iter) {
|
| if (!SetHostQuota(iter->host, iter->type, iter->quota))
|
| return false;
|
| }
|
| @@ -598,10 +594,10 @@ bool QuotaDatabase::DumpQuotaTable(const QuotaTableCallback& callback) {
|
| sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
|
|
|
| while (statement.Step()) {
|
| - QuotaTableEntry entry = QuotaTableEntry(
|
| - statement.ColumnString(0),
|
| - static_cast<StorageType>(statement.ColumnInt(1)),
|
| - statement.ColumnInt64(2));
|
| + QuotaTableEntry entry =
|
| + QuotaTableEntry(statement.ColumnString(0),
|
| + static_cast<StorageType>(statement.ColumnInt(1)),
|
| + statement.ColumnInt64(2));
|
|
|
| if (!callback.Run(entry))
|
| return true;
|
| @@ -612,7 +608,6 @@ bool QuotaDatabase::DumpQuotaTable(const QuotaTableCallback& callback) {
|
|
|
| bool QuotaDatabase::DumpOriginInfoTable(
|
| const OriginInfoTableCallback& callback) {
|
| -
|
| if (!LazyOpen(true))
|
| return false;
|
|
|
| @@ -621,11 +616,11 @@ bool QuotaDatabase::DumpOriginInfoTable(
|
|
|
| while (statement.Step()) {
|
| OriginInfoTableEntry entry(
|
| - GURL(statement.ColumnString(0)),
|
| - static_cast<StorageType>(statement.ColumnInt(1)),
|
| - statement.ColumnInt(2),
|
| - base::Time::FromInternalValue(statement.ColumnInt64(3)),
|
| - base::Time::FromInternalValue(statement.ColumnInt64(4)));
|
| + GURL(statement.ColumnString(0)),
|
| + static_cast<StorageType>(statement.ColumnInt(1)),
|
| + statement.ColumnInt(2),
|
| + base::Time::FromInternalValue(statement.ColumnInt64(3)),
|
| + base::Time::FromInternalValue(statement.ColumnInt64(4)));
|
|
|
| if (!callback.Run(entry))
|
| return true;
|
| @@ -636,21 +631,31 @@ bool QuotaDatabase::DumpOriginInfoTable(
|
|
|
| bool operator<(const QuotaDatabase::QuotaTableEntry& lhs,
|
| const QuotaDatabase::QuotaTableEntry& rhs) {
|
| - if (lhs.host < rhs.host) return true;
|
| - if (rhs.host < lhs.host) return false;
|
| - if (lhs.type < rhs.type) return true;
|
| - if (rhs.type < lhs.type) return false;
|
| + if (lhs.host < rhs.host)
|
| + return true;
|
| + if (rhs.host < lhs.host)
|
| + return false;
|
| + if (lhs.type < rhs.type)
|
| + return true;
|
| + if (rhs.type < lhs.type)
|
| + return false;
|
| return lhs.quota < rhs.quota;
|
| }
|
|
|
| bool operator<(const QuotaDatabase::OriginInfoTableEntry& lhs,
|
| const QuotaDatabase::OriginInfoTableEntry& rhs) {
|
| - if (lhs.origin < rhs.origin) return true;
|
| - if (rhs.origin < lhs.origin) return false;
|
| - if (lhs.type < rhs.type) return true;
|
| - if (rhs.type < lhs.type) return false;
|
| - if (lhs.used_count < rhs.used_count) return true;
|
| - if (rhs.used_count < lhs.used_count) return false;
|
| + if (lhs.origin < rhs.origin)
|
| + return true;
|
| + if (rhs.origin < lhs.origin)
|
| + return false;
|
| + if (lhs.type < rhs.type)
|
| + return true;
|
| + if (rhs.type < lhs.type)
|
| + return false;
|
| + if (lhs.used_count < rhs.used_count)
|
| + return true;
|
| + if (rhs.used_count < lhs.used_count)
|
| + return false;
|
| return lhs.last_access_time < rhs.last_access_time;
|
| }
|
|
|
|
|