| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |
| 6 #define WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/nullable_string16.h" | 13 #include "base/strings/nullable_string16.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "content/common/content_export.h" |
| 16 #include "content/common/dom_storage/dom_storage_types.h" |
| 15 #include "sql/connection.h" | 17 #include "sql/connection.h" |
| 16 #include "webkit/browser/webkit_storage_browser_export.h" | |
| 17 #include "webkit/common/dom_storage/dom_storage_types.h" | |
| 18 | 18 |
| 19 namespace dom_storage { | 19 namespace content { |
| 20 | 20 |
| 21 // Represents a SQLite based backing for DOM storage data. This | 21 // Represents a SQLite based backing for DOM storage data. This |
| 22 // class is designed to be used on a single thread. | 22 // class is designed to be used on a single thread. |
| 23 class WEBKIT_STORAGE_BROWSER_EXPORT DomStorageDatabase { | 23 class CONTENT_EXPORT DOMStorageDatabase { |
| 24 public: | 24 public: |
| 25 static base::FilePath GetJournalFilePath(const base::FilePath& database_path); | 25 static base::FilePath GetJournalFilePath(const base::FilePath& database_path); |
| 26 | 26 |
| 27 explicit DomStorageDatabase(const base::FilePath& file_path); | 27 explicit DOMStorageDatabase(const base::FilePath& file_path); |
| 28 virtual ~DomStorageDatabase(); // virtual for unit testing | 28 virtual ~DOMStorageDatabase(); // virtual for unit testing |
| 29 | 29 |
| 30 // Reads all the key, value pairs stored in the database and returns | 30 // Reads all the key, value pairs stored in the database and returns |
| 31 // them. |result| is assumed to be empty and any duplicate keys will | 31 // them. |result| is assumed to be empty and any duplicate keys will |
| 32 // be overwritten. If the database exists on disk then it will be | 32 // be overwritten. If the database exists on disk then it will be |
| 33 // opened. If it does not exist then it will not be created and | 33 // opened. If it does not exist then it will not be created and |
| 34 // |result| will be unmodified. | 34 // |result| will be unmodified. |
| 35 void ReadAllValues(ValuesMap* result); | 35 void ReadAllValues(DOMStorageValuesMap* result); |
| 36 | 36 |
| 37 // Updates the backing database. Will remove all keys before updating | 37 // Updates the backing database. Will remove all keys before updating |
| 38 // the database if |clear_all_first| is set. Then all entries in | 38 // the database if |clear_all_first| is set. Then all entries in |
| 39 // |changes| will be examined - keys mapped to a null NullableString16 | 39 // |changes| will be examined - keys mapped to a null NullableString16 |
| 40 // will be removed and all others will be inserted/updated as appropriate. | 40 // will be removed and all others will be inserted/updated as appropriate. |
| 41 bool CommitChanges(bool clear_all_first, const ValuesMap& changes); | 41 bool CommitChanges(bool clear_all_first, const DOMStorageValuesMap& changes); |
| 42 | 42 |
| 43 // Simple getter for the path we were constructed with. | 43 // Simple getter for the path we were constructed with. |
| 44 const base::FilePath& file_path() const { return file_path_; } | 44 const base::FilePath& file_path() const { return file_path_; } |
| 45 | 45 |
| 46 protected: | 46 protected: |
| 47 // Constructor that uses an in-memory sqlite database, for testing. | 47 // Constructor that uses an in-memory sqlite database, for testing. |
| 48 DomStorageDatabase(); | 48 DOMStorageDatabase(); |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 friend class LocalStorageDatabaseAdapter; | 51 friend class LocalStorageDatabaseAdapter; |
| 52 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenAndClose); | 52 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, SimpleOpenAndClose); |
| 53 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestLazyOpenIsLazy); | 53 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, TestLazyOpenIsLazy); |
| 54 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestDetectSchemaVersion); | 54 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, TestDetectSchemaVersion); |
| 55 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | 55 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, |
| 56 TestLazyOpenUpgradesDatabase); | 56 TestLazyOpenUpgradesDatabase); |
| 57 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleWriteAndReadBack); | 57 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, SimpleWriteAndReadBack); |
| 58 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, WriteWithClear); | 58 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, WriteWithClear); |
| 59 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | 59 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, |
| 60 UpgradeFromV1ToV2WithData); | 60 UpgradeFromV1ToV2WithData); |
| 61 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestSimpleRemoveOneValue); | 61 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, TestSimpleRemoveOneValue); |
| 62 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | 62 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, |
| 63 TestCanOpenAndReadWebCoreDatabase); | 63 TestCanOpenAndReadWebCoreDatabase); |
| 64 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, | 64 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, |
| 65 TestCanOpenFileThatIsNotADatabase); | 65 TestCanOpenFileThatIsNotADatabase); |
| 66 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); | 66 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, BackingDatabaseOpened); |
| 67 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); | 67 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitTasks); |
| 68 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory); | 68 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory); |
| 69 | 69 |
| 70 enum SchemaVersion { | 70 enum SchemaVersion { |
| 71 INVALID, | 71 INVALID, |
| 72 V1, | 72 V1, |
| 73 V2 | 73 V2 |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // Open the database at file_path_ if it exists already and creates it if | 76 // Open the database at file_path_ if it exists already and creates it if |
| 77 // |create_if_needed| is true. | 77 // |create_if_needed| is true. |
| 78 // Ensures we are at the correct database version and creates or updates | 78 // Ensures we are at the correct database version and creates or updates |
| (...skipping 28 matching lines...) Expand all Loading... |
| 107 void Init(); | 107 void Init(); |
| 108 | 108 |
| 109 // Path to the database on disk. | 109 // Path to the database on disk. |
| 110 const base::FilePath file_path_; | 110 const base::FilePath file_path_; |
| 111 scoped_ptr<sql::Connection> db_; | 111 scoped_ptr<sql::Connection> db_; |
| 112 bool failed_to_open_; | 112 bool failed_to_open_; |
| 113 bool tried_to_recreate_; | 113 bool tried_to_recreate_; |
| 114 bool known_to_be_empty_; | 114 bool known_to_be_empty_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 } // namespace dom_storage | 117 } // namespace content |
| 118 | 118 |
| 119 #endif // WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | 119 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |
| OLD | NEW |