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 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/nullable_string16.h" | 12 #include "base/nullable_string16.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "webkit/dom_storage/dom_storage_types.h" | 15 #include "webkit/dom_storage/dom_storage_types.h" |
16 | 16 |
| 17 class DOMStorageContextImpl; |
| 18 |
17 namespace dom_storage { | 19 namespace dom_storage { |
18 | 20 |
19 class DomStorageDatabaseAdapter; | 21 class DomStorageDatabaseAdapter; |
20 class DomStorageMap; | 22 class DomStorageMap; |
21 class DomStorageTaskRunner; | 23 class DomStorageTaskRunner; |
22 class SessionStorageDatabase; | 24 class SessionStorageDatabase; |
23 | 25 |
24 // Container for a per-origin Map of key/value pairs potentially | 26 // Container for a per-origin Map of key/value pairs potentially |
25 // backed by storage on disk and lazily commits changes to disk. | 27 // backed by storage on disk and lazily commits changes to disk. |
26 // See class comments for DomStorageContext for a larger overview. | 28 // See class comments for DomStorageContext for a larger overview. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 friend class DomStorageAreaTest; | 84 friend class DomStorageAreaTest; |
83 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); | 85 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); |
84 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); | 86 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); |
85 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); | 87 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); |
86 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); | 88 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); |
87 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown); | 89 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown); |
88 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin); | 90 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin); |
89 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory); | 91 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory); |
90 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, PersistentIds); | 92 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, PersistentIds); |
91 friend class base::RefCountedThreadSafe<DomStorageArea>; | 93 friend class base::RefCountedThreadSafe<DomStorageArea>; |
| 94 // For calling DisableCommitDelayForTesting in tests. |
| 95 friend class ::DOMStorageContextImpl; |
92 | 96 |
93 struct CommitBatch { | 97 struct CommitBatch { |
94 bool clear_all_first; | 98 bool clear_all_first; |
95 ValuesMap changed_values; | 99 ValuesMap changed_values; |
96 CommitBatch(); | 100 CommitBatch(); |
97 ~CommitBatch(); | 101 ~CommitBatch(); |
98 }; | 102 }; |
99 | 103 |
100 ~DomStorageArea(); | 104 ~DomStorageArea(); |
101 | 105 |
102 // If we haven't done so already and this is a local storage area, | 106 // If we haven't done so already and this is a local storage area, |
103 // will attempt to read any values for this origin currently | 107 // will attempt to read any values for this origin currently |
104 // stored on disk. | 108 // stored on disk. |
105 void InitialImportIfNeeded(); | 109 void InitialImportIfNeeded(); |
106 | 110 |
107 // Post tasks to defer writing a batch of changed values to | 111 // Post tasks to defer writing a batch of changed values to |
108 // disk on the commit sequence, and to call back on the primary | 112 // disk on the commit sequence, and to call back on the primary |
109 // task sequence when complete. | 113 // task sequence when complete. |
110 CommitBatch* CreateCommitBatchIfNeeded(); | 114 CommitBatch* CreateCommitBatchIfNeeded(); |
111 void OnCommitTimer(); | 115 void OnCommitTimer(); |
112 void CommitChanges(const CommitBatch* commit_batch); | 116 void CommitChanges(const CommitBatch* commit_batch); |
113 void OnCommitComplete(); | 117 void OnCommitComplete(); |
114 | 118 |
115 void ShutdownInCommitSequence(); | 119 void ShutdownInCommitSequence(); |
116 | 120 |
| 121 static void DisableCommitDelayForTesting(); |
| 122 |
117 int64 namespace_id_; | 123 int64 namespace_id_; |
118 std::string persistent_namespace_id_; | 124 std::string persistent_namespace_id_; |
119 GURL origin_; | 125 GURL origin_; |
120 FilePath directory_; | 126 FilePath directory_; |
121 scoped_refptr<DomStorageTaskRunner> task_runner_; | 127 scoped_refptr<DomStorageTaskRunner> task_runner_; |
122 scoped_refptr<DomStorageMap> map_; | 128 scoped_refptr<DomStorageMap> map_; |
123 scoped_ptr<DomStorageDatabaseAdapter> backing_; | 129 scoped_ptr<DomStorageDatabaseAdapter> backing_; |
124 scoped_refptr<SessionStorageDatabase> session_storage_backing_; | 130 scoped_refptr<SessionStorageDatabase> session_storage_backing_; |
125 bool is_initial_import_done_; | 131 bool is_initial_import_done_; |
126 bool is_shutdown_; | 132 bool is_shutdown_; |
127 scoped_ptr<CommitBatch> commit_batch_; | 133 scoped_ptr<CommitBatch> commit_batch_; |
128 int commit_batches_in_flight_; | 134 int commit_batches_in_flight_; |
129 }; | 135 }; |
130 | 136 |
131 } // namespace dom_storage | 137 } // namespace dom_storage |
132 | 138 |
133 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 139 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
OLD | NEW |