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_DOM_STORAGE_AREA_H_ | 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/nullable_string16.h" | 13 #include "base/nullable_string16.h" |
13 #include "base/string16.h" | 14 #include "base/string16.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "webkit/dom_storage/dom_storage_database.h" | 16 #include "webkit/dom_storage/dom_storage_database_adapter.h" |
16 #include "webkit/dom_storage/dom_storage_types.h" | 17 #include "webkit/dom_storage/dom_storage_types.h" |
17 | 18 |
18 namespace dom_storage { | 19 namespace dom_storage { |
19 | 20 |
| 21 class DomStorageDatabaseAdapter; |
20 class DomStorageMap; | 22 class DomStorageMap; |
21 class DomStorageTaskRunner; | 23 class DomStorageTaskRunner; |
| 24 class SessionStorageDatabase; |
22 | 25 |
23 // Container for a per-origin Map of key/value pairs potentially | 26 // Container for a per-origin Map of key/value pairs potentially |
24 // backed by storage on disk and lazily commits changes to disk. | 27 // backed by storage on disk and lazily commits changes to disk. |
25 // See class comments for DomStorageContext for a larger overview. | 28 // See class comments for DomStorageContext for a larger overview. |
26 class DomStorageArea | 29 class DomStorageArea |
27 : public base::RefCountedThreadSafe<DomStorageArea> { | 30 : public base::RefCountedThreadSafe<DomStorageArea> { |
28 | 31 |
29 public: | 32 public: |
30 static const FilePath::CharType kDatabaseFileExtension[]; | 33 static const FilePath::CharType kDatabaseFileExtension[]; |
31 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); | 34 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); |
32 static GURL OriginFromDatabaseFileName(const FilePath& file_name); | 35 static GURL OriginFromDatabaseFileName(const FilePath& file_name); |
33 | 36 |
| 37 // Local storage. Backed on disk if directory is nonempty. |
34 DomStorageArea(int64 namespace_id, | 38 DomStorageArea(int64 namespace_id, |
35 const GURL& origin, | 39 const GURL& origin, |
36 const FilePath& directory, | 40 const FilePath& directory, |
37 DomStorageTaskRunner* task_runner); | 41 DomStorageTaskRunner* task_runner); |
38 | 42 |
| 43 // Session storage. Backed on disk if |session_storage_backing| is not NULL. |
| 44 DomStorageArea(int64 namespace_id, |
| 45 const std::string& persistent_namespace_id, |
| 46 const GURL& origin, |
| 47 SessionStorageDatabase* session_storage_backing, |
| 48 DomStorageTaskRunner* task_runner); |
| 49 |
39 const GURL& origin() const { return origin_; } | 50 const GURL& origin() const { return origin_; } |
40 int64 namespace_id() const { return namespace_id_; } | 51 int64 namespace_id() const { return namespace_id_; } |
41 | 52 |
42 // Writes a copy of the current set of values in the area to the |map|. | 53 // Writes a copy of the current set of values in the area to the |map|. |
43 void ExtractValues(ValuesMap* map); | 54 void ExtractValues(ValuesMap* map); |
44 | 55 |
45 unsigned Length(); | 56 unsigned Length(); |
46 NullableString16 Key(unsigned index); | 57 NullableString16 Key(unsigned index); |
47 NullableString16 GetItem(const string16& key); | 58 NullableString16 GetItem(const string16& key); |
48 bool SetItem(const string16& key, const string16& value, | 59 bool SetItem(const string16& key, const string16& value, |
49 NullableString16* old_value); | 60 NullableString16* old_value); |
50 bool RemoveItem(const string16& key, string16* old_value); | 61 bool RemoveItem(const string16& key, string16* old_value); |
51 bool Clear(); | 62 bool Clear(); |
52 | 63 |
53 DomStorageArea* ShallowCopy(int64 destination_namespace_id); | 64 DomStorageArea* ShallowCopy( |
| 65 int64 destination_namespace_id, |
| 66 const std::string& destination_persistent_namespace_id); |
54 | 67 |
55 bool HasUncommittedChanges() const; | 68 bool HasUncommittedChanges() const; |
56 | 69 |
57 // Similar to Clear() but more optimized for just deleting | 70 // Similar to Clear() but more optimized for just deleting |
58 // without raising events. | 71 // without raising events. |
59 void DeleteOrigin(); | 72 void DeleteOrigin(); |
60 | 73 |
61 // Frees up memory when possible. Typically, this method returns | 74 // Frees up memory when possible. Typically, this method returns |
62 // the object to its just constructed state, however if uncommitted | 75 // the object to its just constructed state, however if uncommitted |
63 // changes are pending, it does nothing. | 76 // changes are pending, it does nothing. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // disk on the commit sequence, and to call back on the primary | 110 // disk on the commit sequence, and to call back on the primary |
98 // task sequence when complete. | 111 // task sequence when complete. |
99 CommitBatch* CreateCommitBatchIfNeeded(); | 112 CommitBatch* CreateCommitBatchIfNeeded(); |
100 void OnCommitTimer(); | 113 void OnCommitTimer(); |
101 void CommitChanges(const CommitBatch* commit_batch); | 114 void CommitChanges(const CommitBatch* commit_batch); |
102 void OnCommitComplete(); | 115 void OnCommitComplete(); |
103 | 116 |
104 void ShutdownInCommitSequence(); | 117 void ShutdownInCommitSequence(); |
105 | 118 |
106 int64 namespace_id_; | 119 int64 namespace_id_; |
| 120 std::string persistent_namespace_id_; |
107 GURL origin_; | 121 GURL origin_; |
108 FilePath directory_; | 122 FilePath directory_; |
109 scoped_refptr<DomStorageTaskRunner> task_runner_; | 123 scoped_refptr<DomStorageTaskRunner> task_runner_; |
110 scoped_refptr<DomStorageMap> map_; | 124 scoped_refptr<DomStorageMap> map_; |
111 scoped_ptr<DomStorageDatabase> backing_; | 125 scoped_ptr<DomStorageDatabaseAdapter> backing_; |
| 126 scoped_refptr<SessionStorageDatabase> session_storage_backing_; |
112 bool is_initial_import_done_; | 127 bool is_initial_import_done_; |
113 bool is_shutdown_; | 128 bool is_shutdown_; |
114 scoped_ptr<CommitBatch> commit_batch_; | 129 scoped_ptr<CommitBatch> commit_batch_; |
115 int commit_batches_in_flight_; | 130 int commit_batches_in_flight_; |
116 }; | 131 }; |
117 | 132 |
118 } // namespace dom_storage | 133 } // namespace dom_storage |
119 | 134 |
120 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 135 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
OLD | NEW |