Chromium Code Reviews| Index: webkit/dom_storage/dom_storage_database.h |
| diff --git a/webkit/dom_storage/dom_storage_database.h b/webkit/dom_storage/dom_storage_database.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a3d7d29d4d313323b3744f0b2d5a2f68827f9111 |
| --- /dev/null |
| +++ b/webkit/dom_storage/dom_storage_database.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2012 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. |
| + |
| +#ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |
| +#define WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |
| + |
| +#include <map> |
| +#include <set> |
| + |
| +#include "base/file_path.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string16.h" |
| +#include "sql/connection.h" |
| + |
| +namespace dom_storage { |
| + |
| +// Represents a SQLite based backing for DOM storage data. This |
| +// class is designed to be used on a single thread. |
| +class DomStorageDatabase { |
| + public: |
| + explicit DomStorageDatabase(const FilePath& file_path); |
| + virtual ~DomStorageDatabase(); |
| + |
| + typedef std::map<string16, string16> ValuesMap; |
| + typedef std::set<string16> ValuesSet; |
| + |
| + // Open the database at file_path_, creating it if it does not exist. |
| + // Returns false on failure. |
| + virtual bool Open(); |
| + |
| + // Initiate the Dom Storage database and create tables as necessary. |
| + // Also performs database upgrades if necessary. Returns true if the |
| + // tables were created or upgraded successfully. |
| + virtual bool Init(); |
|
michaeln
2012/01/31 03:11:16
In other 'db' classes we create and open underlyin
benm (inactive)
2012/01/31 15:10:53
sgtm.
|
| + |
| + // Reads all the key, value pairs stored in the database and returns |
| + // them. |
| + virtual ValuesMap ReadAllValues() const; |
|
michaeln
2012/01/31 03:11:16
do you know if all of our compilers are smart enou
benm (inactive)
2012/01/31 15:10:53
I would've thought so, but don't know for certain.
|
| + |
| + // Write all |values| into the database, overwriting previously set |
| + // keys and values. |
| + virtual bool WriteValues(const ValuesMap& values); |
|
michaeln
2012/01/31 03:11:16
do the methods of this class need to be virtual?
benm (inactive)
2012/01/31 15:10:53
I think the virtuals are left over from an older i
|
| + |
| + // Removes the |keys| and their mappings from the database. |
| + virtual bool RemoveValues(const ValuesSet& keys); |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenInitAndClose); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, |
| + TestInitUpgradesV1TableToV2); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestIsOpen); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleRead); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleWrite); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, UpgradeFromV1ToV2NoData); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, |
| + UpgradeFromV1ToV2WithData); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, |
| + TestOpenCloseDataPreserved); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestSimpleRemoveOneValue); |
| + |
| + // Creates the ItemTable at the current version of the database. |
| + bool CreateTable(); |
| + bool CreateTableV2(); |
| + |
| + // Version 1 -> 2 migrated the value column in the ItemTable from a TEXT |
| + // to a BLOB. Exisitng data is preserved. |
| + bool UpgradeVersion1To2IfNeeded(); |
| + |
| + void Close(); |
| + bool IsOpen() const { return db_.get() ? db_->is_open() : false; } |
| + |
| + // Path to the database on disk. |
| + FilePath file_path_; |
| + scoped_ptr<sql::Connection> db_; |
| +}; |
| + |
| +} // namespace dom_storage |
| + |
| +#endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |