OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/database/quota_table.h" |
| 6 |
| 7 #include "app/sql/connection.h" |
| 8 #include "app/sql/statement.h" |
| 9 #include "base/string_util.h" |
| 10 |
| 11 namespace webkit_database { |
| 12 |
| 13 bool QuotaTable::Init() { |
| 14 // 'Quota' schema: |
| 15 // origin The origin. |
| 16 // quota The quota for this origin. |
| 17 return db_->DoesTableExist("Quota") || |
| 18 db_->Execute( |
| 19 "CREATE TABLE Quota (" |
| 20 "origin TEXT NOT NULL PRIMARY KEY, " |
| 21 "quota INTEGER NOT NULL)"); |
| 22 } |
| 23 |
| 24 int64 QuotaTable::GetOriginQuota(const string16& origin_identifier) { |
| 25 sql::Statement statement(db_->GetCachedStatement( |
| 26 SQL_FROM_HERE, "SELECT quota FROM Quota WHERE origin = ?")); |
| 27 if (statement.is_valid() && |
| 28 statement.BindString(0, UTF16ToUTF8(origin_identifier)) && |
| 29 statement.Step()) { |
| 30 return statement.ColumnInt64(0); |
| 31 } |
| 32 |
| 33 return -1; |
| 34 } |
| 35 |
| 36 bool QuotaTable::SetOriginQuota(const string16& origin_identifier, |
| 37 int64 quota) { |
| 38 DCHECK(quota >= 0); |
| 39 |
| 40 // Insert or update the quota for this origin. |
| 41 sql::Statement replace_statement(db_->GetCachedStatement( |
| 42 SQL_FROM_HERE, "REPLACE INTO Quota VALUES (?, ?)")); |
| 43 if (replace_statement.is_valid() && |
| 44 replace_statement.BindString(0, UTF16ToUTF8(origin_identifier)) && |
| 45 replace_statement.BindInt64(1, quota)) { |
| 46 return replace_statement.Run(); |
| 47 } |
| 48 |
| 49 return false; |
| 50 } |
| 51 |
| 52 bool QuotaTable::ClearOriginQuota(const string16& origin_identifier) { |
| 53 sql::Statement statement(db_->GetCachedStatement( |
| 54 SQL_FROM_HERE, "DELETE FROM Quota WHERE origin = ?")); |
| 55 if (statement.is_valid() && |
| 56 statement.BindString(0, UTF16ToUTF8(origin_identifier))) { |
| 57 return (statement.Run() && db_->GetLastChangeCount()); |
| 58 } |
| 59 |
| 60 return false; |
| 61 } |
| 62 |
| 63 } // namespace webkit_database |
OLD | NEW |