diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 21:15:55 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 21:15:55 +0000 |
commit | 3ccfe535658c8852c1cc1df01372ecc602f376cd (patch) | |
tree | 47582af5ba2a4f0658126d564d618c18a93173cf /webkit/database/quota_table.cc | |
parent | 6d8e2a64b6961331816689850192a8ee864f9a97 (diff) | |
download | chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.zip chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.gz chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.bz2 |
Adding methods that will be used by the quota management UI.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/507014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/quota_table.cc')
-rw-r--r-- | webkit/database/quota_table.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/webkit/database/quota_table.cc b/webkit/database/quota_table.cc new file mode 100644 index 0000000..2b6507e --- /dev/null +++ b/webkit/database/quota_table.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/database/quota_table.h" + +#include "app/sql/connection.h" +#include "app/sql/statement.h" +#include "base/string_util.h" + +namespace webkit_database { + +bool QuotaTable::Init() { + // 'Quota' schema: + // origin The origin. + // quota The quota for this origin. + return db_->DoesTableExist("Quota") || + db_->Execute( + "CREATE TABLE Quota (" + "origin TEXT NOT NULL PRIMARY KEY, " + "quota INTEGER NOT NULL)"); +} + +int64 QuotaTable::GetOriginQuota(const string16& origin_identifier) { + sql::Statement statement(db_->GetCachedStatement( + SQL_FROM_HERE, "SELECT quota FROM Quota WHERE origin = ?")); + if (statement.is_valid() && + statement.BindString(0, UTF16ToUTF8(origin_identifier)) && + statement.Step()) { + return statement.ColumnInt64(0); + } + + return -1; +} + +bool QuotaTable::SetOriginQuota(const string16& origin_identifier, + int64 quota) { + DCHECK(quota >= 0); + + // Insert or update the quota for this origin. + sql::Statement replace_statement(db_->GetCachedStatement( + SQL_FROM_HERE, "REPLACE INTO Quota VALUES (?, ?)")); + if (replace_statement.is_valid() && + replace_statement.BindString(0, UTF16ToUTF8(origin_identifier)) && + replace_statement.BindInt64(1, quota)) { + return replace_statement.Run(); + } + + return false; +} + +bool QuotaTable::ClearOriginQuota(const string16& origin_identifier) { + sql::Statement statement(db_->GetCachedStatement( + SQL_FROM_HERE, "DELETE FROM Quota WHERE origin = ?")); + if (statement.is_valid() && + statement.BindString(0, UTF16ToUTF8(origin_identifier))) { + return (statement.Run() && db_->GetLastChangeCount()); + } + + return false; +} + +} // namespace webkit_database |