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

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: Draft: associate with session restore. Created 8 years, 6 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 <vector> 10 #include <vector>
(...skipping 17 matching lines...) Expand all
28 namespace quota { 28 namespace quota {
29 class SpecialStoragePolicy; 29 class SpecialStoragePolicy;
30 } 30 }
31 31
32 namespace dom_storage { 32 namespace dom_storage {
33 33
34 class DomStorageArea; 34 class DomStorageArea;
35 class DomStorageNamespace; 35 class DomStorageNamespace;
36 class DomStorageSession; 36 class DomStorageSession;
37 class DomStorageTaskRunner; 37 class DomStorageTaskRunner;
38 class SessionStorageDatabase;
38 39
39 // The Context is the root of an object containment hierachy for 40 // The Context is the root of an object containment hierachy for
40 // Namespaces and Areas related to the owning profile. 41 // Namespaces and Areas related to the owning profile.
41 // One instance is allocated in the main process for each profile, 42 // One instance is allocated in the main process for each profile,
42 // instance methods should be called serially in the background as 43 // instance methods should be called serially in the background as
43 // 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
44 // IO thread since these methods can result in blocking file io. 45 // IO thread since these methods can result in blocking file io.
45 // 46 //
46 // In general terms, the DomStorage object relationships are... 47 // In general terms, the DomStorage object relationships are...
47 // Contexts (per-profile) own Namespaces which own Areas which share Maps. 48 // Contexts (per-profile) own Namespaces which own Areas which share Maps.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const DomStorageArea* area, 82 const DomStorageArea* area,
82 const string16& key, 83 const string16& key,
83 const string16& old_value, 84 const string16& old_value,
84 const GURL& page_url) = 0; 85 const GURL& page_url) = 0;
85 virtual void OnDomStorageAreaCleared( 86 virtual void OnDomStorageAreaCleared(
86 const DomStorageArea* area, 87 const DomStorageArea* area,
87 const GURL& page_url) = 0; 88 const GURL& page_url) = 0;
88 virtual ~EventObserver() {} 89 virtual ~EventObserver() {}
89 }; 90 };
90 91
92 class SessionStorageObserver {
93 public:
94 virtual void OnSessionStorageNamespaceAssociated(
95 int64 real_namespace_id) = 0;
96 virtual ~SessionStorageObserver() {}
97 };
98
91 DomStorageContext( 99 DomStorageContext(
92 const FilePath& localstorage_directory, // empty for incognito profiles 100 const FilePath& localstorage_directory, // empty for incognito profiles
93 const FilePath& sessionstorage_directory, // empty for incognito profiles 101 const FilePath& sessionstorage_directory, // empty for incognito profiles
94 quota::SpecialStoragePolicy* special_storage_policy, 102 quota::SpecialStoragePolicy* special_storage_policy,
95 DomStorageTaskRunner* task_runner); 103 DomStorageTaskRunner* task_runner);
96 104
97 // Returns the directory path for localStorage, or an empty directory, if 105 // Returns the directory path for localStorage, or an empty directory, if
98 // there is no backing on disk. 106 // there is no backing on disk.
99 const FilePath& localstorage_directory() { return localstorage_directory_; } 107 const FilePath& localstorage_directory() { return localstorage_directory_; }
100 108
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const GURL& page_url); 149 const GURL& page_url);
142 void NotifyItemRemoved( 150 void NotifyItemRemoved(
143 const DomStorageArea* area, 151 const DomStorageArea* area,
144 const string16& key, 152 const string16& key,
145 const string16& old_value, 153 const string16& old_value,
146 const GURL& page_url); 154 const GURL& page_url);
147 void NotifyAreaCleared( 155 void NotifyAreaCleared(
148 const DomStorageArea* area, 156 const DomStorageArea* area,
149 const GURL& page_url); 157 const GURL& page_url);
150 158
159 // Adds |observer| to get notified about the association between
160 // |namespace_id| and its real id in the database.
161 void AddSessionStorageObserver(int64 namespace_id,
162 SessionStorageObserver* observer);
163 void RemoveSessionStorageObserver(int64 namespace_id);
164
165 void NotifySessionStorageNamespaceAssociated(int64 namespace_id,
166 int64 real_namespace_id);
167
151 // May be called on any thread. 168 // May be called on any thread.
152 int64 AllocateSessionId() { 169 int64 AllocateSessionId() {
153 return session_id_sequence_.GetNext(); 170 return session_id_sequence_.GetNext();
154 } 171 }
155 172
156 // Must be called on the background thread. 173 // Must be called on the background thread.
157 void CreateSessionNamespace(int64 namespace_id); 174 void CreateSessionNamespace(int64 namespace_id);
158 void DeleteSessionNamespace(int64 namespace_id); 175 void DeleteSessionNamespace(int64 namespace_id);
159 void CloneSessionNamespace(int64 existing_id, int64 new_id); 176 void CloneSessionNamespace(int64 existing_id, int64 new_id);
160 177
178 // May be called on any thread.
179 void AssociateSessionStorage(int64 namespace_id, int64 real_id);
180
161 private: 181 private:
162 friend class DomStorageContextTest; 182 friend class DomStorageContextTest;
163 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, Basics); 183 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, Basics);
164 friend class base::RefCountedThreadSafe<DomStorageContext>; 184 friend class base::RefCountedThreadSafe<DomStorageContext>;
165 typedef std::map<int64, scoped_refptr<DomStorageNamespace> > 185 typedef std::map<int64, scoped_refptr<DomStorageNamespace> >
166 StorageNamespaceMap; 186 StorageNamespaceMap;
167 187
168 ~DomStorageContext(); 188 ~DomStorageContext();
169 189
170 void ClearLocalStateInCommitSequence(); 190 void ClearLocalStateInCommitSequence();
171 191
192 void DeleteSessionNamespaceInCommitSequence(int64 namespace_id);
193 void DeleteLeftoverDataInCommitSequence();
194
195 void SessionStorageAssociated(int64 id, int64 real_id);
196
172 // Collection of namespaces keyed by id. 197 // Collection of namespaces keyed by id.
173 StorageNamespaceMap namespaces_; 198 StorageNamespaceMap namespaces_;
174 199
175 // Where localstorage data is stored, maybe empty for the incognito use case. 200 // Where localstorage data is stored, maybe empty for the incognito use case.
176 FilePath localstorage_directory_; 201 FilePath localstorage_directory_;
177 202
178 // Where sessionstorage data is stored, maybe empty for the incognito use 203 // Where sessionstorage data is stored, maybe empty for the incognito use
179 // case. Always empty until the file-backed session storage feature is 204 // case. Always empty until the file-backed session storage feature is
180 // implemented. 205 // implemented.
181 FilePath sessionstorage_directory_; 206 FilePath sessionstorage_directory_;
182 207
183 // Used to schedule sequenced background tasks. 208 // Used to schedule sequenced background tasks.
184 scoped_refptr<DomStorageTaskRunner> task_runner_; 209 scoped_refptr<DomStorageTaskRunner> task_runner_;
185 210
186 // List of objects observing local storage events. 211 // List of objects observing local storage events.
187 ObserverList<EventObserver> event_observers_; 212 ObserverList<EventObserver> event_observers_;
188 213
214 // Map of objects observing the association between session storage namespace
215 // ids and real ids in the database.
216 std::map<int64, SessionStorageObserver*> session_storage_observers_;
217
189 // We use a 32 bit identifier for per tab storage sessions. 218 // We use a 32 bit identifier for per tab storage sessions.
190 // At a tab per second, this range is large enough for 68 years. 219 // At a tab per second, this range is large enough for 68 years.
191 base::AtomicSequenceNumber session_id_sequence_; 220 base::AtomicSequenceNumber session_id_sequence_;
192 221
193 bool is_shutdown_; 222 bool is_shutdown_;
194 bool clear_local_state_; 223 bool clear_local_state_;
195 bool save_session_state_; 224 bool save_session_state_;
196 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; 225 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
226 scoped_refptr<SessionStorageDatabase> session_storage_database_;
197 }; 227 };
198 228
199 } // namespace dom_storage 229 } // namespace dom_storage
200 230
201 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ 231 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698