| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |
| 6 #define CONTENT_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 #include <memory> | 9 #include <memory> |
| 10 #include <string> |
| 10 | 11 |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/strings/nullable_string16.h" | 14 #include "base/strings/nullable_string16.h" |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 16 #include "content/common/dom_storage/dom_storage_types.h" | 17 #include "content/common/dom_storage/dom_storage_types.h" |
| 17 #include "sql/connection.h" | 18 #include "sql/connection.h" |
| 18 | 19 |
| 20 namespace base { |
| 21 namespace trace_event { |
| 22 class ProcessMemoryDump; |
| 23 } |
| 24 } |
| 25 |
| 19 namespace content { | 26 namespace content { |
| 20 | 27 |
| 21 // Represents a SQLite based backing for DOM storage data. This | 28 // Represents a SQLite based backing for DOM storage data. This |
| 22 // class is designed to be used on a single thread. | 29 // class is designed to be used on a single thread. |
| 23 class CONTENT_EXPORT DOMStorageDatabase { | 30 class CONTENT_EXPORT DOMStorageDatabase { |
| 24 public: | 31 public: |
| 25 static base::FilePath GetJournalFilePath(const base::FilePath& database_path); | 32 static base::FilePath GetJournalFilePath(const base::FilePath& database_path); |
| 26 | 33 |
| 27 explicit DOMStorageDatabase(const base::FilePath& file_path); | 34 explicit DOMStorageDatabase(const base::FilePath& file_path); |
| 28 virtual ~DOMStorageDatabase(); // virtual for unit testing | 35 virtual ~DOMStorageDatabase(); // virtual for unit testing |
| 29 | 36 |
| 30 // Reads all the key, value pairs stored in the database and returns | 37 // 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 | 38 // 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 | 39 // 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 | 40 // opened. If it does not exist then it will not be created and |
| 34 // |result| will be unmodified. | 41 // |result| will be unmodified. |
| 35 void ReadAllValues(DOMStorageValuesMap* result); | 42 void ReadAllValues(DOMStorageValuesMap* result); |
| 36 | 43 |
| 37 // Updates the backing database. Will remove all keys before updating | 44 // Updates the backing database. Will remove all keys before updating |
| 38 // the database if |clear_all_first| is set. Then all entries in | 45 // the database if |clear_all_first| is set. Then all entries in |
| 39 // |changes| will be examined - keys mapped to a null NullableString16 | 46 // |changes| will be examined - keys mapped to a null NullableString16 |
| 40 // will be removed and all others will be inserted/updated as appropriate. | 47 // will be removed and all others will be inserted/updated as appropriate. |
| 41 bool CommitChanges(bool clear_all_first, const DOMStorageValuesMap& changes); | 48 bool CommitChanges(bool clear_all_first, const DOMStorageValuesMap& changes); |
| 42 | 49 |
| 50 // Adds memory statistics of the database to |pmd| for tracing. |
| 51 void ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd, |
| 52 const std::string& name); |
| 53 |
| 43 // Simple getter for the path we were constructed with. | 54 // Simple getter for the path we were constructed with. |
| 44 const base::FilePath& file_path() const { return file_path_; } | 55 const base::FilePath& file_path() const { return file_path_; } |
| 45 | 56 |
| 46 protected: | 57 protected: |
| 47 // Constructor that uses an in-memory sqlite database, for testing. | 58 // Constructor that uses an in-memory sqlite database, for testing. |
| 48 DOMStorageDatabase(); | 59 DOMStorageDatabase(); |
| 49 | 60 |
| 50 private: | 61 private: |
| 51 friend class LocalStorageDatabaseAdapter; | 62 friend class LocalStorageDatabaseAdapter; |
| 52 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, SimpleOpenAndClose); | 63 FRIEND_TEST_ALL_PREFIXES(DOMStorageDatabaseTest, SimpleOpenAndClose); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const base::FilePath file_path_; | 121 const base::FilePath file_path_; |
| 111 std::unique_ptr<sql::Connection> db_; | 122 std::unique_ptr<sql::Connection> db_; |
| 112 bool failed_to_open_; | 123 bool failed_to_open_; |
| 113 bool tried_to_recreate_; | 124 bool tried_to_recreate_; |
| 114 bool known_to_be_empty_; | 125 bool known_to_be_empty_; |
| 115 }; | 126 }; |
| 116 | 127 |
| 117 } // namespace content | 128 } // namespace content |
| 118 | 129 |
| 119 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ | 130 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ |
| OLD | NEW |