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_SESSION_STORAGE_DATABASE_H_ | |
6 #define WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ | |
7 #pragma once | |
8 | |
9 #include "webkit/dom_storage/dom_storage_database.h" | |
10 | |
11 namespace leveldb { | |
12 | |
13 struct DB; | |
14 struct WriteBatch; | |
15 | |
16 } // namespace leveldb | |
17 | |
18 namespace dom_storage { | |
19 | |
20 // All DomStorageAreas for session storage share the same | |
21 // SessionStorageDatabase. | |
michaeln
2012/04/12 01:48:46
It'd be great if you carved this class out of the
marja
2012/04/19 10:20:50
I'll do that next...
| |
22 class SessionStorageDatabase : | |
23 public DomStorageDatabase, | |
24 public base::RefCountedThreadSafe<SessionStorageDatabase> { | |
25 public: | |
26 explicit SessionStorageDatabase(const FilePath& file_path); | |
27 virtual ~SessionStorageDatabase(); | |
28 | |
29 // Reads all the key, value pairs stored in the database and returns | |
30 // them. |result| is assumed to be empty and any duplicate keys will | |
31 // be overwritten. If the database exists on disk then it will be | |
32 // opened. If it does not exist then it will not be created and | |
33 // |result| will be unmodified. | |
34 virtual void ReadAllValues(int64 namespace_id, | |
35 const GURL& origin, | |
36 ValuesMap* result) OVERRIDE; | |
37 | |
38 // Updates the backing database. Will remove all keys before updating | |
39 // the database if |clear_all_first| is set. Then all entries in | |
40 // |changes| will be examined - keys mapped to a null NullableString16 | |
41 // will be removed and all others will be inserted/updated as appropriate. | |
42 virtual bool CommitChanges(int64 namespace_id, | |
43 const GURL& origin, | |
44 bool clear_all_first, | |
45 const ValuesMap& changes) OVERRIDE; | |
46 | |
47 // Creates a shallow copy of the map for the data associated with |origin| in | |
48 // |namespace_id| and associates it with |new_namespace_id|. | |
49 bool ShallowCopy(int64 namespace_id, | |
michaeln
2012/04/12 01:48:46
See comment elsewhere about having CloneNamespace
marja
2012/04/19 10:20:50
Done.
| |
50 const GURL& origin, | |
51 int64 new_namespace_id); | |
52 | |
53 // Creates a deep copy of the map for the data associated with |origin| in | |
54 // |namespace_id|. | |
55 bool DeepCopy(int64 namespace_id, const GURL& origin); | |
56 | |
57 // Deletes the data for |namespace_id| and |origin|. | |
58 void DeleteOrigin(int64 namespace_id, const GURL& origin); | |
59 | |
60 // Deletes the data for |namespace_id|. | |
61 void DeleteNamespace(int64 namespace_id); | |
62 | |
63 // Deletes possible leftover data from the previous run. | |
64 void DeleteLeftoverData(); | |
65 | |
66 private: | |
67 virtual bool LazyOpen(bool create_if_needed); | |
68 virtual bool IsOpen() const; | |
69 | |
70 // Helper for reading all values belonging to the map |map_id| into |result|. | |
71 void ReadValuesInMap(const std::string& map_id, ValuesMap* result); | |
72 | |
73 // Helper for creating a new map for |area_key|. |map_id| will hold the id of | |
74 // the created map. Retuns true if the creation succeeded, false otherwise. | |
75 bool CreateNewMap(const std::string& area_key, | |
76 leveldb::WriteBatch* batch, | |
77 std::string* map_id); | |
78 | |
79 // Helper for writing values into a map. | |
80 void WriteValuesToMap(const std::string& map_id, | |
81 const ValuesMap& values, | |
82 leveldb::WriteBatch* batch); | |
83 | |
84 // Helper for decreasing the ref count of a map. | |
85 void DecreaseRefCount(const std::string& map_id, | |
86 leveldb::WriteBatch* batch); | |
87 | |
88 // Helper for deleting all values in a map. | |
89 void DeleteValuesInMap(const std::string& map_id, | |
90 leveldb::WriteBatch* batch); | |
91 | |
92 // Helper for deleting data for |namespace_id| and |origin|. | |
93 void DeleteOrigin(const std::string& namespace_id, | |
94 const std::string& origin, | |
95 leveldb::WriteBatch* batch); | |
96 | |
97 // Helper for deleting data for |namespace_id|. | |
98 void DeleteNamespace(const std::string& namespace_id, | |
99 leveldb::WriteBatch* batch); | |
100 | |
101 // Helper for debugging | |
102 void DumpData() const; | |
103 | |
104 scoped_ptr<leveldb::DB> db_; | |
105 }; | |
106 | |
107 } // namespace dom_storage | |
108 | |
109 #endif // WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ | |
OLD | NEW |