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

Side by Side Diff: content/browser/dom_storage/dom_storage_context_impl_new.h

Issue 9695013: DOMStorageContextImpl that's implemented in terms of the new dom_storage classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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) 2011 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 CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_
6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_IMPL_H_ 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <vector>
jsbell 2012/03/19 20:24:29 Is this include needed?
michaeln 2012/03/19 20:49:58 Done, dont think it is
10 #include <set>
11 10
12 #include "base/compiler_specific.h"
13 #include "base/file_path.h" 11 #include "base/file_path.h"
14 #include "base/gtest_prod_util.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/string16.h"
15 #include "base/time.h" 14 #include "base/time.h"
16 #include "content/public/browser/dom_storage_context.h" 15 #include "content/public/browser/dom_storage_context.h"
16 #include "webkit/dom_storage/dom_storage_types.h"
17 17
18 class DOMStorageArea; 18 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND
19 class DOMStorageMessageFilter;
20 class DOMStorageNamespace;
21 19
22 namespace base { 20 namespace dom_storage {
23 class MessageLoopProxy; 21 class DomStorageContext;
24 class SequencedTaskRunner;
25 } 22 }
26 23
27 namespace quota { 24 namespace quota {
28 class SpecialStoragePolicy; 25 class SpecialStoragePolicy;
29 } 26 }
30 27
31 // This is owned by BrowserContext and is all the dom storage information that's 28 // This is owned by BrowserContext (aka Profile) and encapsulates all
32 // shared by all the DOMStorageMessageFilters that share the same browser 29 // per-profile dom storage state.
33 // context. The specifics of responsibilities are fairly well documented here
34 // and in StorageNamespace and StorageArea. Everything is only to be accessed
35 // on the WebKit thread unless noted otherwise.
36 class CONTENT_EXPORT DOMStorageContextImpl : 30 class CONTENT_EXPORT DOMStorageContextImpl :
37 NON_EXPORTED_BASE(public content::DOMStorageContext) { 31 NON_EXPORTED_BASE(public content::DOMStorageContext),
32 public base::RefCountedThreadSafe<DOMStorageContextImpl> {
38 public: 33 public:
39 // If |data_path| is empty, nothing will be saved to disk. 34 // If |data_path| is empty, nothing will be saved to disk.
40 DOMStorageContextImpl(const FilePath& data_path, 35 DOMStorageContextImpl(const FilePath& data_path,
41 quota::SpecialStoragePolicy* special_storage_policy); 36 quota::SpecialStoragePolicy* special_storage_policy);
42 virtual ~DOMStorageContextImpl();
43 37
44 // DOMStorageContext implementation: 38 // DOMStorageContext implementation.
45 virtual base::SequencedTaskRunner* task_runner() const OVERRIDE; 39 virtual void GetAllStorageFiles(
46 virtual std::vector<FilePath> GetAllStorageFiles() OVERRIDE; 40 const GetAllStorageFilesCallback& callback) OVERRIDE;
47 virtual FilePath GetFilePath(const string16& origin_id) const OVERRIDE; 41 virtual FilePath GetFilePath(const string16& origin_id) const OVERRIDE;
48 virtual void DeleteForOrigin(const string16& origin_id) OVERRIDE; 42 virtual void DeleteForOrigin(const string16& origin_id) OVERRIDE;
49 virtual void DeleteLocalStorageFile(const FilePath& file_path) OVERRIDE; 43 virtual void DeleteLocalStorageFile(const FilePath& file_path) OVERRIDE;
50 virtual void DeleteDataModifiedSince(const base::Time& cutoff) OVERRIDE; 44 virtual void DeleteDataModifiedSince(const base::Time& cutoff) OVERRIDE;
51 45
52 // Invalid storage id. No storage session will ever report this value. 46 // Called to free up memory that's not strictly needed.
53 // Used in DOMStorageMessageFilter::OnStorageAreaId when coping with
54 // interactions with non-existent storage sessions.
55 static const int64 kInvalidStorageId = -1;
56
57 // Allocate a new storage area id. Only call on the WebKit thread.
58 int64 AllocateStorageAreaId();
59
60 // Allocate a new session storage id. Only call on the UI or IO thread.
61 int64 AllocateSessionStorageNamespaceId();
62
63 // Clones a session storage namespace and returns the cloned namespaces' id.
64 // Only call on the IO thread.
65 int64 CloneSessionStorage(int64 original_id);
66
67 // Various storage area methods. The storage area is owned by one of the
68 // namespaces that's owned by this class.
69 void RegisterStorageArea(DOMStorageArea* storage_area);
70 void UnregisterStorageArea(DOMStorageArea* storage_area);
71 DOMStorageArea* GetStorageArea(int64 id);
72
73 // Called on WebKit thread when a session storage namespace can be deleted.
74 void DeleteSessionStorageNamespace(int64 namespace_id);
75
76 // Get a namespace from an id. What's returned is owned by this class. If
77 // allocation_allowed is true, then this function will create the storage
78 // namespace if it hasn't been already.
79 DOMStorageNamespace* GetStorageNamespace(int64 id, bool allocation_allowed);
80
81 // Sometimes an event from one DOM storage message filter requires
82 // communication to all of them.
83 typedef std::set<DOMStorageMessageFilter*> MessageFilterSet;
84 void RegisterMessageFilter(DOMStorageMessageFilter* message_filter);
85 void UnregisterMessageFilter(DOMStorageMessageFilter* MessageFilter);
86 const MessageFilterSet* GetMessageFilterSet() const;
87
88 // Tells storage namespaces to purge any memory they do not need.
89 void PurgeMemory(); 47 void PurgeMemory();
90 48
91 // Deletes all local storage files. 49 // Used by content settings to alter the behavior around
92 void DeleteAllLocalStorageFiles(); 50 // what data to keep and what data to discard at shutdown.
51 // The policy is not so straight forward to describe, see
52 // the implementation for details.
53 void SetClearLocalState(bool clear_local_state);
54 void SaveSessionState();
93 55
94 // The local storage directory. 56 // Called when the BrowserContext/Profile is going away.
95 static const FilePath::CharType kLocalStorageDirectory[]; 57 void Shutdown();
96 58
97 // The local storage file extension. 59 // See render_message_filter.cc for details.
98 static const FilePath::CharType kLocalStorageExtension[]; 60 // TODO(michaeln): Remove this method when that bug is fixed.
jsbell 2012/03/19 20:24:29 Is there a crbug for this, or will you fix before
michaeln 2012/03/19 20:49:58 there is no crbug for this afaik, i'll file a bug
99 61 int64 LeakyCloneSessionStorage(int64 existing_namespace_id);
100 void set_clear_local_state_on_exit(bool clear_local_state) {
101 clear_local_state_on_exit_ = clear_local_state;
102 }
103
104 // Disables the exit-time deletion for all data (also session-only data).
105 void SaveSessionState() {
106 save_session_state_ = true;
107 }
108
109 void set_data_path_for_testing(const FilePath& data_path) {
110 data_path_ = data_path;
111 }
112 62
113 private: 63 private:
114 FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SessionOnly); 64 friend class DOMStorageMessageFilter; // for access to context()
115 FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SaveSessionState); 65 friend class SessionStorageNamespaceImpl; // ditto
66 friend class base::RefCountedThreadSafe<DOMStorageContextImpl>;
116 67
117 // Get the local storage instance. The object is owned by this class. 68 virtual ~DOMStorageContextImpl();
118 DOMStorageNamespace* CreateLocalStorage(); 69 dom_storage::DomStorageContext* context() const { return context_.get(); }
119 70
120 // Get a new session storage namespace. The object is owned by this class. 71 scoped_refptr<dom_storage::DomStorageContext> context_;
121 DOMStorageNamespace* CreateSessionStorage(int64 namespace_id);
122
123 // Used internally to register storage namespaces we create.
124 void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace);
125
126 // The WebKit thread half of CloneSessionStorage above.
127 void CompleteCloningSessionStorage(int64 existing_id, int64 clone_id);
128
129 // The last used storage_area_id and storage_namespace_id's. For the storage
130 // namespaces, IDs allocated on the UI thread are positive and count up while
131 // IDs allocated on the IO thread are negative and count down. This allows us
132 // to allocate unique IDs on both without any locking. All storage area ids
133 // are allocated on the WebKit thread.
134 int64 last_storage_area_id_;
135 int64 last_session_storage_namespace_id_on_ui_thread_;
136 int64 last_session_storage_namespace_id_on_io_thread_;
137
138 // True if the destructor should delete its files.
139 bool clear_local_state_on_exit_;
140
141 // If true, nothing (not even session-only data) should be deleted on exit.
142 bool save_session_state_;
143
144 // Path where the browser context data is stored.
145 // TODO(pastarmovj): Keep in mind that unlike indexed db data_path_ variable
146 // this one still has to point to the upper level dir because of the
147 // MigrateLocalStorageDirectory function. Once this function disappears we can
148 // make it point directly to the dom storage path.
149 FilePath data_path_;
150
151 // All the DOMStorageMessageFilters that are attached to us. ONLY USE ON THE
152 // IO THREAD!
153 MessageFilterSet message_filter_set_;
154
155 // Maps ids to StorageAreas. We do NOT own these objects. StorageNamespace
156 // (which does own them) will notify us when we should remove the entries.
157 typedef std::map<int64, DOMStorageArea*> StorageAreaMap;
158 StorageAreaMap storage_area_map_;
159
160 // Maps ids to StorageNamespaces. We own these objects.
161 typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap;
162 StorageNamespaceMap storage_namespace_map_;
163
164 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
165 scoped_refptr<base::MessageLoopProxy> webkit_message_loop_;
166 72
167 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextImpl); 73 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextImpl);
168 }; 74 };
169 75
170 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_IMPL_H_ 76 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND
77 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698