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

Side by Side Diff: chrome/browser/in_process_webkit/dom_storage_context.h

Issue 545054: Introduce all the plumbing for Session Storage. This mostly consists of crea... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_
6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 10 matching lines...) Expand all
21 // the same profile. The specifics of responsibilities are fairly well 21 // the same profile. The specifics of responsibilities are fairly well
22 // documented here and in StorageNamespace and StorageArea. Everything is only 22 // documented here and in StorageNamespace and StorageArea. Everything is only
23 // to be accessed on the WebKit thread unless noted otherwise. 23 // to be accessed on the WebKit thread unless noted otherwise.
24 // 24 //
25 // NOTE: Virtual methods facilitate mocking functions for testing. 25 // NOTE: Virtual methods facilitate mocking functions for testing.
26 class DOMStorageContext { 26 class DOMStorageContext {
27 public: 27 public:
28 explicit DOMStorageContext(WebKitContext* webkit_context); 28 explicit DOMStorageContext(WebKitContext* webkit_context);
29 virtual ~DOMStorageContext(); 29 virtual ~DOMStorageContext();
30 30
31 // Get the local storage instance. The pointer is owned by this class. 31 // Allocate a new storage area id. Only call on the WebKit thread.
32 DOMStorageNamespace* LocalStorage(); 32 int64 AllocateStorageAreaId();
33 33
34 // Get a new session storage namespace (but it's still owned by this class). 34 // Allocate a new session storage id. Only call on the UI or IO thread.
35 DOMStorageNamespace* NewSessionStorage(); 35 int64 AllocateSessionStorageNamespaceId();
36 36
37 // Allocate a new storage ___ id. 37 // Clones a session storage namespace and returns the cloned namespaces' id.
38 int64 AllocateStorageAreaId() { return ++last_storage_area_id_; } 38 // Only call on the IO thread.
39 int64 AllocateStorageNamespaceId() { return ++last_storage_namespace_id_; } 39 int64 CloneSessionStorage(int64 original_id);
40 40
41 // Various storage area methods. The storage area is owned by one of the 41 // Various storage area methods. The storage area is owned by one of the
42 // namespaces that's owned by this class. 42 // namespaces that's owned by this class.
43 void RegisterStorageArea(DOMStorageArea* storage_area); 43 void RegisterStorageArea(DOMStorageArea* storage_area);
44 void UnregisterStorageArea(DOMStorageArea* storage_area); 44 void UnregisterStorageArea(DOMStorageArea* storage_area);
45 DOMStorageArea* GetStorageArea(int64 id); 45 DOMStorageArea* GetStorageArea(int64 id);
46 46
47 // Get a namespace from an id. What's returned is owned by this class. The 47 // Called on WebKit thread when a session storage namespace can be deleted.
48 // caller of GetStorageNamespace must immediately register itself with the 48 void DeleteSessionStorageNamespace(int64 namespace_id);
49 // returned StorageNamespace. 49
50 void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace); 50 // Get a namespace from an id. What's returned is owned by this class. If
51 void UnregisterStorageNamespace(DOMStorageNamespace* storage_namespace); 51 // allocation_allowed is true, then this function will create the storage
52 DOMStorageNamespace* GetStorageNamespace(int64 id); 52 // namespace if it hasn't been already.
53 DOMStorageNamespace* GetStorageNamespace(int64 id, bool allocation_allowed);
53 54
54 // Sometimes an event from one DOM storage dispatcher host requires 55 // Sometimes an event from one DOM storage dispatcher host requires
55 // communication to all of them. 56 // communication to all of them.
56 typedef std::set<DOMStorageDispatcherHost*> DispatcherHostSet; 57 typedef std::set<DOMStorageDispatcherHost*> DispatcherHostSet;
57 void RegisterDispatcherHost(DOMStorageDispatcherHost* dispatcher_host); 58 void RegisterDispatcherHost(DOMStorageDispatcherHost* dispatcher_host);
58 void UnregisterDispatcherHost(DOMStorageDispatcherHost* dispatcher_host); 59 void UnregisterDispatcherHost(DOMStorageDispatcherHost* dispatcher_host);
59 const DispatcherHostSet* GetDispatcherHostSet() const; 60 const DispatcherHostSet* GetDispatcherHostSet() const;
60 61
61 // Tells storage namespaces to purge any memory they do not need. 62 // Tells storage namespaces to purge any memory they do not need.
62 virtual void PurgeMemory(); 63 virtual void PurgeMemory();
63 64
64 // Delete any local storage files that have been touched since the cutoff 65 // Delete any local storage files that have been touched since the cutoff
65 // date that's supplied. 66 // date that's supplied.
66 void DeleteDataModifiedSince(const base::Time& cutoff); 67 void DeleteDataModifiedSince(const base::Time& cutoff);
67 68
68 // The special ID used for local storage. 69 private:
69 static const int64 kLocalStorageNamespaceId = 0; 70 // Get the local storage instance. The object is owned by this class.
71 DOMStorageNamespace* CreateLocalStorage();
70 72
71 private: 73 // Get a new session storage namespace. The object is owned by this class.
72 // The last used storage_area_id and storage_namespace_id's. 74 DOMStorageNamespace* CreateSessionStorage(int64 namespace_id);
73 static const int64 kFirstStorageAreaId = 1; 75
76 // Used internally to register storage namespaces we create.
77 void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace);
78
79 // The WebKit thread half of CloneSessionStorage above. Static because we
80 // DOMStorageContext isn't ref counted and so we can't use a runnable method.
81 // That said, we know this is safe because this class is destroyed on the
82 // WebKit thread, so there's no way it could be destroyed before this is run.
83 static void CompleteCloningSessionStorage(DOMStorageContext* context,
84 int64 existing_id, int64 clone_id);
85
86 // The last used storage_area_id and storage_namespace_id's. For the storage
87 // namespaces, IDs allocated on the UI thread are positive and count up while
88 // IDs allocated on the IO thread are negative and count down. This allows us
89 // to allocate unique IDs on both without any locking. All storage area ids
90 // are allocated on the WebKit thread.
74 int64 last_storage_area_id_; 91 int64 last_storage_area_id_;
75 static const int64 kFirstStorageNamespaceId = 1; 92 int64 last_session_storage_namespace_id_on_ui_thread_;
76 int64 last_storage_namespace_id_; 93 int64 last_session_storage_namespace_id_on_io_thread_;
77 94
78 // We're owned by this WebKit context. Used while instantiating LocalStorage. 95 // We're owned by this WebKit context. Used while instantiating LocalStorage.
79 WebKitContext* webkit_context_; 96 WebKitContext* webkit_context_;
80 97
81 // All the DOMStorageDispatcherHosts that are attached to us. ONLY USE ON THE 98 // All the DOMStorageDispatcherHosts that are attached to us. ONLY USE ON THE
82 // IO THREAD! 99 // IO THREAD!
83 DispatcherHostSet dispatcher_host_set_; 100 DispatcherHostSet dispatcher_host_set_;
84 101
85 // Maps ids to StorageAreas. We do NOT own these objects. StorageNamespace 102 // Maps ids to StorageAreas. We do NOT own these objects. StorageNamespace
86 // (which does own them) will notify us when we should remove the entries. 103 // (which does own them) will notify us when we should remove the entries.
87 typedef std::map<int64, DOMStorageArea*> StorageAreaMap; 104 typedef std::map<int64, DOMStorageArea*> StorageAreaMap;
88 StorageAreaMap storage_area_map_; 105 StorageAreaMap storage_area_map_;
89 106
90 // Maps ids to StorageNamespaces. We own these objects. 107 // Maps ids to StorageNamespaces. We own these objects.
91 typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap; 108 typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap;
92 StorageNamespaceMap storage_namespace_map_; 109 StorageNamespaceMap storage_namespace_map_;
93 110
94 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContext); 111 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContext);
95 }; 112 };
96 113
97 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ 114 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_
OLDNEW
« no previous file with comments | « chrome/browser/in_process_webkit/browser_webkitclient_impl.cc ('k') | chrome/browser/in_process_webkit/dom_storage_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698