OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ |
6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ | 6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 DOMStorageArea* GetStorageArea(int64 id); | 60 DOMStorageArea* GetStorageArea(int64 id); |
61 | 61 |
62 // Called on WebKit thread when a session storage namespace can be deleted. | 62 // Called on WebKit thread when a session storage namespace can be deleted. |
63 void DeleteSessionStorageNamespace(int64 namespace_id); | 63 void DeleteSessionStorageNamespace(int64 namespace_id); |
64 | 64 |
65 // Get a namespace from an id. What's returned is owned by this class. If | 65 // Get a namespace from an id. What's returned is owned by this class. If |
66 // allocation_allowed is true, then this function will create the storage | 66 // allocation_allowed is true, then this function will create the storage |
67 // namespace if it hasn't been already. | 67 // namespace if it hasn't been already. |
68 DOMStorageNamespace* GetStorageNamespace(int64 id, bool allocation_allowed); | 68 DOMStorageNamespace* GetStorageNamespace(int64 id, bool allocation_allowed); |
69 | 69 |
| 70 // Creates a session storage namespace which is backed up by the existing |
| 71 // |session_storage_directory|. |
| 72 DOMStorageNamespace* RecreateSessionStorageNamespace( |
| 73 int64 id, |
| 74 const FilePath& session_storage_directory); |
| 75 |
70 // Sometimes an event from one DOM storage message filter requires | 76 // Sometimes an event from one DOM storage message filter requires |
71 // communication to all of them. | 77 // communication to all of them. |
72 typedef std::set<DOMStorageMessageFilter*> MessageFilterSet; | 78 typedef std::set<DOMStorageMessageFilter*> MessageFilterSet; |
73 void RegisterMessageFilter(DOMStorageMessageFilter* message_filter); | 79 void RegisterMessageFilter(DOMStorageMessageFilter* message_filter); |
74 void UnregisterMessageFilter(DOMStorageMessageFilter* MessageFilter); | 80 void UnregisterMessageFilter(DOMStorageMessageFilter* MessageFilter); |
75 const MessageFilterSet* GetMessageFilterSet() const; | 81 const MessageFilterSet* GetMessageFilterSet() const; |
76 | 82 |
77 // Tells storage namespaces to purge any memory they do not need. | 83 // Tells storage namespaces to purge any memory they do not need. |
78 virtual void PurgeMemory(); | 84 virtual void PurgeMemory(); |
79 | 85 |
80 // Delete any local storage files that have been touched since the cutoff | 86 // Delete any local storage files that have been touched since the cutoff |
81 // date that's supplied. Protected origins, per the SpecialStoragePolicy, | 87 // date that's supplied. Protected origins, per the SpecialStoragePolicy, |
82 // are not deleted by this method. | 88 // are not deleted by this method. |
83 void DeleteDataModifiedSince(const base::Time& cutoff); | 89 void DeleteDataModifiedSince(const base::Time& cutoff); |
84 | 90 |
85 // Deletes a single local storage file. | 91 // Deletes a single local storage file. |
86 void DeleteLocalStorageFile(const FilePath& file_path); | 92 void DeleteLocalStorageFile(const FilePath& file_path); |
87 | 93 |
88 // Deletes the local storage file for the given origin. | 94 // Deletes the local storage file for the given origin. |
89 void DeleteLocalStorageForOrigin(const string16& origin_id); | 95 void DeleteLocalStorageForOrigin(const string16& origin_id); |
90 | 96 |
91 // Deletes all local storage files. | 97 // Deletes all local storage files. |
92 void DeleteAllLocalStorageFiles(); | 98 void DeleteAllLocalStorageFiles(); |
93 | 99 |
94 // The local storage directory. | 100 // The local storage directory. |
95 static const FilePath::CharType kLocalStorageDirectory[]; | 101 static const FilePath::CharType kLocalStorageDirectory[]; |
96 | 102 |
| 103 // The session storage directory. |
| 104 static const FilePath::CharType kSessionStorageDirectory[]; |
| 105 |
97 // The local storage file extension. | 106 // The local storage file extension. |
98 static const FilePath::CharType kLocalStorageExtension[]; | 107 static const FilePath::CharType kLocalStorageExtension[]; |
99 | 108 |
100 // Get the file name of the local storage file for the given origin. | 109 // Get the file name of the local storage file for the given origin. |
101 FilePath GetLocalStorageFilePath(const string16& origin_id) const; | 110 FilePath GetLocalStorageFilePath(const string16& origin_id) const; |
102 | 111 |
103 void set_clear_local_state_on_exit_(bool clear_local_state) { | 112 void set_clear_local_state_on_exit_(bool clear_local_state) { |
104 clear_local_state_on_exit_ = clear_local_state; | 113 clear_local_state_on_exit_ = clear_local_state; |
105 } | 114 } |
106 | 115 |
107 // Disables the exit-time deletion for all data (also session-only data). | 116 // Disables the exit-time deletion for all data (also session-only data). |
108 void SaveSessionState() { | 117 void SaveSessionState() { |
109 save_session_state_ = true; | 118 save_session_state_ = true; |
110 } | 119 } |
111 | 120 |
112 void set_data_path_for_testing(const FilePath& data_path) { | 121 void set_data_path_for_testing(const FilePath& data_path) { |
113 data_path_ = data_path; | 122 data_path_ = data_path; |
114 } | 123 } |
115 | 124 |
| 125 // Deletes the session storages which are not in |needed_session_storages|. |
| 126 void DeleteUnneededSessionStorages( |
| 127 const std::set<std::string>& needed_session_storages); |
| 128 |
116 private: | 129 private: |
117 | 130 |
118 FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SessionOnly); | 131 FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SessionOnly); |
119 FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SaveSessionState); | 132 FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SaveSessionState); |
120 | 133 |
121 // Get the local storage instance. The object is owned by this class. | 134 // Get the local storage instance. The object is owned by this class. |
122 DOMStorageNamespace* CreateLocalStorage(); | 135 DOMStorageNamespace* CreateLocalStorage(); |
123 | 136 |
124 // Get a new session storage namespace. The object is owned by this class. | 137 // Get a new session storage namespace. The object is owned by this class. |
125 DOMStorageNamespace* CreateSessionStorage(int64 namespace_id); | 138 DOMStorageNamespace* CreateSessionStorage(int64 namespace_id); |
126 | 139 |
127 // Used internally to register storage namespaces we create. | 140 // Used internally to register storage namespaces we create. |
128 void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace); | 141 void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace); |
129 | 142 |
130 // The WebKit thread half of CloneSessionStorage above. Static because | 143 // The WebKit thread half of CloneSessionStorage above. Static because |
131 // DOMStorageContext isn't ref counted thus we can't use a runnable method. | 144 // DOMStorageContext isn't ref counted thus we can't use a runnable method. |
132 // That said, we know this is safe because this class is destroyed on the | 145 // That said, we know this is safe because this class is destroyed on the |
133 // WebKit thread, so there's no way it could be destroyed before this is run. | 146 // WebKit thread, so there's no way it could be destroyed before this is run. |
134 static void CompleteCloningSessionStorage(DOMStorageContext* context, | 147 static void CompleteCloningSessionStorage(DOMStorageContext* context, |
135 int64 existing_id, int64 clone_id); | 148 int64 existing_id, int64 clone_id, |
| 149 const FilePath& data_path); |
136 | 150 |
137 // The last used storage_area_id and storage_namespace_id's. For the storage | 151 // The last used storage_area_id and storage_namespace_id's. For the storage |
138 // namespaces, IDs allocated on the UI thread are positive and count up while | 152 // namespaces, IDs allocated on the UI thread are positive and count up while |
139 // IDs allocated on the IO thread are negative and count down. This allows us | 153 // IDs allocated on the IO thread are negative and count down. This allows us |
140 // to allocate unique IDs on both without any locking. All storage area ids | 154 // to allocate unique IDs on both without any locking. All storage area ids |
141 // are allocated on the WebKit thread. | 155 // are allocated on the WebKit thread. |
142 int64 last_storage_area_id_; | 156 int64 last_storage_area_id_; |
143 int64 last_session_storage_namespace_id_on_ui_thread_; | 157 int64 last_session_storage_namespace_id_on_ui_thread_; |
144 int64 last_session_storage_namespace_id_on_io_thread_; | 158 int64 last_session_storage_namespace_id_on_io_thread_; |
145 | 159 |
(...skipping 22 matching lines...) Expand all Loading... |
168 // Maps ids to StorageNamespaces. We own these objects. | 182 // Maps ids to StorageNamespaces. We own these objects. |
169 typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap; | 183 typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap; |
170 StorageNamespaceMap storage_namespace_map_; | 184 StorageNamespaceMap storage_namespace_map_; |
171 | 185 |
172 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 186 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
173 | 187 |
174 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContext); | 188 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContext); |
175 }; | 189 }; |
176 | 190 |
177 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ | 191 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ |
OLD | NEW |