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

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: Rebased. Created 8 years, 5 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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/atomic_sequence_num.h" 13 #include "base/atomic_sequence_num.h"
13 #include "base/basictypes.h" 14 #include "base/basictypes.h"
14 #include "base/file_path.h" 15 #include "base/file_path.h"
15 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/observer_list.h" 18 #include "base/observer_list.h"
18 #include "base/time.h" 19 #include "base/time.h"
19 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
20 21
21 class FilePath; 22 class FilePath;
22 class NullableString16; 23 class NullableString16;
23 24
24 namespace base { 25 namespace base {
25 class Time; 26 class Time;
26 } 27 }
27 28
28 namespace quota { 29 namespace quota {
29 class SpecialStoragePolicy; 30 class SpecialStoragePolicy;
30 } 31 }
31 32
32 namespace dom_storage { 33 namespace dom_storage {
33 34
34 class DomStorageArea; 35 class DomStorageArea;
35 class DomStorageNamespace; 36 class DomStorageNamespace;
36 class DomStorageSession; 37 class DomStorageSession;
37 class DomStorageTaskRunner; 38 class DomStorageTaskRunner;
39 class SessionStorageDatabase;
38 40
39 // The Context is the root of an object containment hierachy for 41 // The Context is the root of an object containment hierachy for
40 // Namespaces and Areas related to the owning profile. 42 // Namespaces and Areas related to the owning profile.
41 // One instance is allocated in the main process for each profile, 43 // One instance is allocated in the main process for each profile,
42 // instance methods should be called serially in the background as 44 // instance methods should be called serially in the background as
43 // determined by the task_runner. Specifcally not on chrome's non-blocking 45 // determined by the task_runner. Specifcally not on chrome's non-blocking
44 // IO thread since these methods can result in blocking file io. 46 // IO thread since these methods can result in blocking file io.
45 // 47 //
46 // In general terms, the DomStorage object relationships are... 48 // In general terms, the DomStorage object relationships are...
47 // Contexts (per-profile) own Namespaces which own Areas which share Maps. 49 // Contexts (per-profile) own Namespaces which own Areas which share Maps.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 155
154 std::string AllocatePersistentSessionId(); 156 std::string AllocatePersistentSessionId();
155 157
156 // Must be called on the background thread. 158 // Must be called on the background thread.
157 void CreateSessionNamespace(int64 namespace_id, 159 void CreateSessionNamespace(int64 namespace_id,
158 const std::string& persistent_namespace_id); 160 const std::string& persistent_namespace_id);
159 void DeleteSessionNamespace(int64 namespace_id, bool should_persist_data); 161 void DeleteSessionNamespace(int64 namespace_id, bool should_persist_data);
160 void CloneSessionNamespace(int64 existing_id, int64 new_id, 162 void CloneSessionNamespace(int64 existing_id, int64 new_id,
161 const std::string& new_persistent_id); 163 const std::string& new_persistent_id);
162 164
165 // Deletes all namespaces which don't have an associated DomStorageNamespace
166 // alive. This function is used for deleting possible leftover data after an
167 // unclean exit.
168 void StartScavengingUnusedSessionStorage();
169
163 private: 170 private:
164 friend class DomStorageContextTest; 171 friend class DomStorageContextTest;
165 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, Basics); 172 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, Basics);
166 friend class base::RefCountedThreadSafe<DomStorageContext>; 173 friend class base::RefCountedThreadSafe<DomStorageContext>;
167 typedef std::map<int64, scoped_refptr<DomStorageNamespace> > 174 typedef std::map<int64, scoped_refptr<DomStorageNamespace> >
168 StorageNamespaceMap; 175 StorageNamespaceMap;
169 176
170 ~DomStorageContext(); 177 ~DomStorageContext();
171 178
172 void ClearSessionOnlyOrigins(); 179 void ClearSessionOnlyOrigins();
173 180
181 void FindUnusedSessionStorage(
michaeln 2012/07/10 01:16:58 naming nit: maybe name all of the Find and Delete
marja 2012/07/10 13:40:52 Done.
182 const std::set<std::string>& namespace_ids_in_use,
183 const std::set<std::string>& protected_persistent_session_ids);
184 void FindUnusedSessionStorageInCommitSequence(
185 const std::set<std::string>& namespace_ids_in_use,
186 const std::set<std::string>& protected_persistent_session_ids);
187 void DeleteNextUnunsedNamespace();
michaeln 2012/07/10 01:16:58 typo Ununsed -> Unused
marja 2012/07/10 13:40:52 Done.
188 void DeleteNextUnunsedNamespaceInCommitSequence();
189
174 // Collection of namespaces keyed by id. 190 // Collection of namespaces keyed by id.
175 StorageNamespaceMap namespaces_; 191 StorageNamespaceMap namespaces_;
176 192
177 // Where localstorage data is stored, maybe empty for the incognito use case. 193 // Where localstorage data is stored, maybe empty for the incognito use case.
178 FilePath localstorage_directory_; 194 FilePath localstorage_directory_;
179 195
180 // Where sessionstorage data is stored, maybe empty for the incognito use 196 // Where sessionstorage data is stored, maybe empty for the incognito use
181 // case. Always empty until the file-backed session storage feature is 197 // case. Always empty until the file-backed session storage feature is
182 // implemented. 198 // implemented.
183 FilePath sessionstorage_directory_; 199 FilePath sessionstorage_directory_;
184 200
185 // Used to schedule sequenced background tasks. 201 // Used to schedule sequenced background tasks.
186 scoped_refptr<DomStorageTaskRunner> task_runner_; 202 scoped_refptr<DomStorageTaskRunner> task_runner_;
187 203
188 // List of objects observing local storage events. 204 // List of objects observing local storage events.
189 ObserverList<EventObserver> event_observers_; 205 ObserverList<EventObserver> event_observers_;
190 206
191 // We use a 32 bit identifier for per tab storage sessions. 207 // We use a 32 bit identifier for per tab storage sessions.
192 // At a tab per second, this range is large enough for 68 years. 208 // At a tab per second, this range is large enough for 68 years.
193 base::AtomicSequenceNumber session_id_sequence_; 209 base::AtomicSequenceNumber session_id_sequence_;
194 210
195 bool is_shutdown_; 211 bool is_shutdown_;
196 bool force_keep_session_state_; 212 bool force_keep_session_state_;
197 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; 213 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
214 scoped_refptr<SessionStorageDatabase> session_storage_database_;
215
216 // For cleaning up unused namespaces gradually.
217 bool scavenging_started_;
218 std::vector<std::string> deletable_persistent_namespace_ids_;
219
220 // Persistent namespace IDs to protect from gradual deletion (they will
221 // be needed for session restore).
222 std::set<std::string> protected_persistent_session_ids_;
198 }; 223 };
199 224
200 } // namespace dom_storage 225 } // namespace dom_storage
201 226
202 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ 227 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698