| 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_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ | 5 #ifndef WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ |
| 6 #define WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ | 6 #define WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // SessionStorageDatabase holds the data from multiple namespaces and multiple | 29 // SessionStorageDatabase holds the data from multiple namespaces and multiple |
| 30 // origins. All DomStorageAreas for session storage share the same | 30 // origins. All DomStorageAreas for session storage share the same |
| 31 // SessionStorageDatabase. | 31 // SessionStorageDatabase. |
| 32 | 32 |
| 33 // Only one thread is allowed to call the public functions other than | 33 // Only one thread is allowed to call the public functions other than |
| 34 // ReadAreaValues and ReadNamespacesAndOrigins. Other threads are allowed to | 34 // ReadAreaValues and ReadNamespacesAndOrigins. Other threads are allowed to |
| 35 // call ReadAreaValues and ReadNamespacesAndOrigins. | 35 // call ReadAreaValues and ReadNamespacesAndOrigins. |
| 36 class WEBKIT_STORAGE_EXPORT SessionStorageDatabase : | 36 class WEBKIT_STORAGE_EXPORT SessionStorageDatabase : |
| 37 public base::RefCountedThreadSafe<SessionStorageDatabase> { | 37 public base::RefCountedThreadSafe<SessionStorageDatabase> { |
| 38 public: | 38 public: |
| 39 explicit SessionStorageDatabase(const FilePath& file_path); | 39 explicit SessionStorageDatabase(const base::FilePath& file_path); |
| 40 | 40 |
| 41 // Reads the (key, value) pairs for |namespace_id| and |origin|. |result| is | 41 // Reads the (key, value) pairs for |namespace_id| and |origin|. |result| is |
| 42 // assumed to be empty and any duplicate keys will be overwritten. If the | 42 // assumed to be empty and any duplicate keys will be overwritten. If the |
| 43 // database exists on disk then it will be opened. If it does not exist then | 43 // database exists on disk then it will be opened. If it does not exist then |
| 44 // it will not be created and |result| will be unmodified. | 44 // it will not be created and |result| will be unmodified. |
| 45 void ReadAreaValues(const std::string& namespace_id, | 45 void ReadAreaValues(const std::string& namespace_id, |
| 46 const GURL& origin, | 46 const GURL& origin, |
| 47 ValuesMap* result); | 47 ValuesMap* result); |
| 48 | 48 |
| 49 // Updates the data for |namespace_id| and |origin|. Will remove all keys | 49 // Updates the data for |namespace_id| and |origin|. Will remove all keys |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // Helper functions for creating the keys needed for the schema. | 180 // Helper functions for creating the keys needed for the schema. |
| 181 static std::string NamespaceStartKey(const std::string& namespace_id); | 181 static std::string NamespaceStartKey(const std::string& namespace_id); |
| 182 static std::string NamespaceKey(const std::string& namespace_id, | 182 static std::string NamespaceKey(const std::string& namespace_id, |
| 183 const std::string& origin); | 183 const std::string& origin); |
| 184 static const char* NamespacePrefix(); | 184 static const char* NamespacePrefix(); |
| 185 static std::string MapRefCountKey(const std::string& map_id); | 185 static std::string MapRefCountKey(const std::string& map_id); |
| 186 static std::string MapKey(const std::string& map_id, const std::string& key); | 186 static std::string MapKey(const std::string& map_id, const std::string& key); |
| 187 static const char* NextMapIdKey(); | 187 static const char* NextMapIdKey(); |
| 188 | 188 |
| 189 scoped_ptr<leveldb::DB> db_; | 189 scoped_ptr<leveldb::DB> db_; |
| 190 FilePath file_path_; | 190 base::FilePath file_path_; |
| 191 | 191 |
| 192 // For protecting the database opening code. | 192 // For protecting the database opening code. |
| 193 base::Lock db_lock_; | 193 base::Lock db_lock_; |
| 194 | 194 |
| 195 // True if a database error has occurred (e.g., cannot read data). | 195 // True if a database error has occurred (e.g., cannot read data). |
| 196 bool db_error_; | 196 bool db_error_; |
| 197 // True if the database is in an inconsistent state. | 197 // True if the database is in an inconsistent state. |
| 198 bool is_inconsistent_; | 198 bool is_inconsistent_; |
| 199 | 199 |
| 200 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabase); | 200 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabase); |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 } // namespace dom_storage | 203 } // namespace dom_storage |
| 204 | 204 |
| 205 #endif // WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ | 205 #endif // WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ |
| OLD | NEW |