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..bb3f2890fff19acea4d5ad98ec7efdf8294929d3 |
| --- /dev/null |
| +++ b/webkit/dom_storage/dom_storage_database.h |
| @@ -0,0 +1,77 @@ |
| +// 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); |
| + ~DomStorageDatabase(); |
| + |
| + typedef std::map<string16, string16> ValuesMap; |
| + typedef std::set<string16> ValuesSet; |
| + |
| + // Reads all the key, value pairs stored in the database and returns |
| + // them. |
| + void ReadAllValues(ValuesMap* result); |
| + |
| + // Write all |values| into the database, overwriting previously set |
| + // keys and values. |
| + bool WriteValues(const ValuesMap& values); |
|
michaeln
2012/01/31 22:45:32
With the current public interface, there is no way
benm (inactive)
2012/02/01 15:42:09
Like it!
|
| + |
| + // Removes the |keys| and their mappings from the database. |
| + bool RemoveValues(const ValuesSet& keys); |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenAndClose); |
| + FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, |
| + TestUpgradesV1TableToV2); |
| + 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); |
| + |
| + // Open the database at file_path_, creating it if it does not exist. |
| + // Ensures we are at the correct database version and creates or updates |
| + // tables as necessary. Returns false on failure. |
| + bool LazyOpen(); |
|
michaeln
2012/01/31 22:45:32
If we can avoid creating files on disk, all the be
benm (inactive)
2012/02/01 15:42:09
OK, I guess we need to check if the file exists to
|
| + |
| + // 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_ |