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 virtual ~DomStorageDatabase(); | |
25 | |
26 typedef std::map<string16, string16> ValuesMap; | |
27 typedef std::set<string16> ValuesSet; | |
28 | |
29 // Open the database at file_path_, creating it if it does not exist. | |
30 // Returns false on failure. | |
31 virtual bool Open(); | |
32 | |
33 // Initiate the Dom Storage database and create tables as necessary. | |
34 // Also performs database upgrades if necessary. Returns true if the | |
35 // tables were created or upgraded successfully. | |
36 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.
| |
37 | |
38 // Reads all the key, value pairs stored in the database and returns | |
39 // them. | |
40 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.
| |
41 | |
42 // Write all |values| into the database, overwriting previously set | |
43 // keys and values. | |
44 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
| |
45 | |
46 // Removes the |keys| and their mappings from the database. | |
47 virtual bool RemoveValues(const ValuesSet& keys); | |
48 | |
49 private: | |
50 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenInitAndClose); | |
51 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | |
52 TestInitUpgradesV1TableToV2); | |
53 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestIsOpen); | |
54 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleRead); | |
55 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleWrite); | |
56 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, UpgradeFromV1ToV2NoData); | |
57 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | |
58 UpgradeFromV1ToV2WithData); | |
59 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | |
60 TestOpenCloseDataPreserved); | |
61 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestSimpleRemoveOneValue); | |
62 | |
63 // Creates the ItemTable at the current version of the database. | |
64 bool CreateTable(); | |
65 bool CreateTableV2(); | |
66 | |
67 // Version 1 -> 2 migrated the value column in the ItemTable from a TEXT | |
68 // to a BLOB. Exisitng data is preserved. | |
69 bool UpgradeVersion1To2IfNeeded(); | |
70 | |
71 void Close(); | |
72 bool IsOpen() const { return db_.get() ? db_->is_open() : false; } | |
73 | |
74 // Path to the database on disk. | |
75 FilePath file_path_; | |
76 scoped_ptr<sql::Connection> db_; | |
77 }; | |
78 | |
79 } // namespace dom_storage | |
80 | |
81 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | |
OLD | NEW |