Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | |
| 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/file_path.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/string16.h" | |
| 15 #include "sql/connection.h" | |
| 16 | |
| 17 namespace dom_storage { | |
| 18 | |
| 19 // Represents a SQLite based backing for DOM storage data. This | |
| 20 // class is designed to be used on a single thread. | |
| 21 class DomStorageDatabase { | |
| 22 public: | |
| 23 explicit DomStorageDatabase(const FilePath& file_path); | |
| 24 ~DomStorageDatabase(); | |
| 25 | |
| 26 typedef std::map<string16, string16> ValuesMap; | |
| 27 typedef std::set<string16> ValuesSet; | |
| 28 | |
| 29 // Reads all the key, value pairs stored in the database and returns | |
| 30 // them. | |
| 31 void ReadAllValues(ValuesMap* result); | |
| 32 | |
| 33 // Write all |values| into the database, overwriting previously set | |
| 34 // keys and values. | |
| 35 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!
| |
| 36 | |
| 37 // Removes the |keys| and their mappings from the database. | |
| 38 bool RemoveValues(const ValuesSet& keys); | |
| 39 | |
| 40 private: | |
| 41 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenAndClose); | |
| 42 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | |
| 43 TestUpgradesV1TableToV2); | |
| 44 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestIsOpen); | |
| 45 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleRead); | |
| 46 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleWrite); | |
| 47 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, UpgradeFromV1ToV2NoData); | |
| 48 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | |
| 49 UpgradeFromV1ToV2WithData); | |
| 50 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | |
| 51 TestOpenCloseDataPreserved); | |
| 52 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestSimpleRemoveOneValue); | |
| 53 | |
| 54 // Open the database at file_path_, creating it if it does not exist. | |
| 55 // Ensures we are at the correct database version and creates or updates | |
| 56 // tables as necessary. Returns false on failure. | |
| 57 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
| |
| 58 | |
| 59 // Creates the ItemTable at the current version of the database. | |
| 60 bool CreateTable(); | |
| 61 bool CreateTableV2(); | |
| 62 | |
| 63 // Version 1 -> 2 migrated the value column in the ItemTable from a TEXT | |
| 64 // to a BLOB. Exisitng data is preserved. | |
| 65 bool UpgradeVersion1To2IfNeeded(); | |
| 66 | |
| 67 void Close(); | |
| 68 bool IsOpen() const { return db_.get() ? db_->is_open() : false; } | |
| 69 | |
| 70 // Path to the database on disk. | |
| 71 FilePath file_path_; | |
| 72 scoped_ptr<sql::Connection> db_; | |
| 73 }; | |
| 74 | |
| 75 } // namespace dom_storage | |
| 76 | |
| 77 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | |
| OLD | NEW |