Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: webkit/dom_storage/dom_storage_context.h

Issue 9963107: Persist sessionStorage on disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review (pkasting) Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_CONTEXT_H_ 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/atomic_sequence_num.h" 12 #include "base/atomic_sequence_num.h"
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/file_path.h" 14 #include "base/file_path.h"
14 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/time.h" 18 #include "base/time.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 20
20 class FilePath; 21 class FilePath;
21 class NullableString16; 22 class NullableString16;
22 23
23 namespace base { 24 namespace base {
24 class Time; 25 class Time;
25 } 26 }
26 27
27 namespace quota { 28 namespace quota {
28 class SpecialStoragePolicy; 29 class SpecialStoragePolicy;
29 } 30 }
30 31
31 namespace dom_storage { 32 namespace dom_storage {
32 33
33 class DomStorageArea; 34 class DomStorageArea;
34 class DomStorageNamespace; 35 class DomStorageNamespace;
35 class DomStorageSession; 36 class DomStorageSession;
36 class DomStorageTaskRunner; 37 class DomStorageTaskRunner;
38 class SessionStorageDatabase;
37 39
38 // The Context is the root of an object containment hierachy for 40 // The Context is the root of an object containment hierachy for
39 // Namespaces and Areas related to the owning profile. 41 // Namespaces and Areas related to the owning profile.
40 // One instance is allocated in the main process for each profile, 42 // One instance is allocated in the main process for each profile,
41 // instance methods should be called serially in the background as 43 // instance methods should be called serially in the background as
42 // determined by the task_runner. Specifcally not on chrome's non-blocking 44 // determined by the task_runner. Specifcally not on chrome's non-blocking
43 // IO thread since these methods can result in blocking file io. 45 // IO thread since these methods can result in blocking file io.
44 // 46 //
45 // In general terms, the DomStorage object relationships are... 47 // In general terms, the DomStorage object relationships are...
46 // Contexts (per-profile) own Namespaces which own Areas which share Maps. 48 // Contexts (per-profile) own Namespaces which own Areas which share Maps.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 154
153 std::string AllocatePersistentSessionId(); 155 std::string AllocatePersistentSessionId();
154 156
155 // Must be called on the background thread. 157 // Must be called on the background thread.
156 void CreateSessionNamespace(int64 namespace_id, 158 void CreateSessionNamespace(int64 namespace_id,
157 const std::string& persistent_namespace_id); 159 const std::string& persistent_namespace_id);
158 void DeleteSessionNamespace(int64 namespace_id, bool should_persist_data); 160 void DeleteSessionNamespace(int64 namespace_id, bool should_persist_data);
159 void CloneSessionNamespace(int64 existing_id, int64 new_id, 161 void CloneSessionNamespace(int64 existing_id, int64 new_id,
160 const std::string& new_persistent_id); 162 const std::string& new_persistent_id);
161 163
164 // Starts backing sessionStorage on disk. This function must be called right
165 // after DomStorageContext is created, before it's used.
166 void SetSaveSessionStorageOnDisk();
167
168 // Deletes all namespaces which don't have an associated DomStorageNamespace
169 // alive. This function is used for deleting possible leftover data after an
170 // unclean exit.
171 void StartScavengingUnusedSessionStorage();
172
162 private: 173 private:
163 friend class DomStorageContextTest; 174 friend class DomStorageContextTest;
164 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, Basics); 175 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, Basics);
165 friend class base::RefCountedThreadSafe<DomStorageContext>; 176 friend class base::RefCountedThreadSafe<DomStorageContext>;
166 typedef std::map<int64, scoped_refptr<DomStorageNamespace> > 177 typedef std::map<int64, scoped_refptr<DomStorageNamespace> >
167 StorageNamespaceMap; 178 StorageNamespaceMap;
168 179
169 ~DomStorageContext(); 180 ~DomStorageContext();
170 181
171 void ClearSessionOnlyOrigins(); 182 void ClearSessionOnlyOrigins();
172 183
184 // For scavenging unused sessionStorages.
185 void FindUnusedNamespaces();
186 void FindUnusedNamespacesInCommitSequence(
187 const std::set<std::string>& namespace_ids_in_use,
188 const std::set<std::string>& protected_persistent_session_ids);
189 void DeleteNextUnusedNamespace();
190 void DeleteNextUnusedNamespaceInCommitSequence();
191
173 // Collection of namespaces keyed by id. 192 // Collection of namespaces keyed by id.
174 StorageNamespaceMap namespaces_; 193 StorageNamespaceMap namespaces_;
175 194
176 // Where localstorage data is stored, maybe empty for the incognito use case. 195 // Where localstorage data is stored, maybe empty for the incognito use case.
177 FilePath localstorage_directory_; 196 FilePath localstorage_directory_;
178 197
179 // Where sessionstorage data is stored, maybe empty for the incognito use 198 // Where sessionstorage data is stored, maybe empty for the incognito use
180 // case. Always empty until the file-backed session storage feature is 199 // case. Always empty until the file-backed session storage feature is
181 // implemented. 200 // implemented.
182 FilePath sessionstorage_directory_; 201 FilePath sessionstorage_directory_;
183 202
184 // Used to schedule sequenced background tasks. 203 // Used to schedule sequenced background tasks.
185 scoped_refptr<DomStorageTaskRunner> task_runner_; 204 scoped_refptr<DomStorageTaskRunner> task_runner_;
186 205
187 // List of objects observing local storage events. 206 // List of objects observing local storage events.
188 ObserverList<EventObserver> event_observers_; 207 ObserverList<EventObserver> event_observers_;
189 208
190 // We use a 32 bit identifier for per tab storage sessions. 209 // We use a 32 bit identifier for per tab storage sessions.
191 // At a tab per second, this range is large enough for 68 years. 210 // At a tab per second, this range is large enough for 68 years.
192 base::AtomicSequenceNumber session_id_sequence_; 211 base::AtomicSequenceNumber session_id_sequence_;
193 212
194 bool is_shutdown_; 213 bool is_shutdown_;
195 bool force_keep_session_state_; 214 bool force_keep_session_state_;
196 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; 215 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
216 scoped_refptr<SessionStorageDatabase> session_storage_database_;
217
218 // For cleaning up unused namespaces gradually.
219 bool scavenging_started_;
220 std::vector<std::string> deletable_persistent_namespace_ids_;
221
222 // Persistent namespace IDs to protect from gradual deletion (they will
223 // be needed for session restore).
224 std::set<std::string> protected_persistent_session_ids_;
197 }; 225 };
198 226
199 } // namespace dom_storage 227 } // namespace dom_storage
200 228
201 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ 229 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_area_unittest.cc ('k') | webkit/dom_storage/dom_storage_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698