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

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

Issue 5680007: Make IndexedDBDispatcherHost be a message filter and move its messages into a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_
6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/id_map.h" 10 #include "base/id_map.h"
11 #include "base/process.h" 11 #include "chrome/browser/browser_message_filter.h"
12 #include "base/ref_counted.h"
13 #include "chrome/browser/in_process_webkit/webkit_context.h" 12 #include "chrome/browser/in_process_webkit/webkit_context.h"
14 #include "ipc/ipc_message.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebExceptionCode.h"
15 14
16 class HostContentSettingsMap; 15 class HostContentSettingsMap;
17 class IndexedDBKey; 16 class IndexedDBKey;
17 class NullableString16;
18 class Profile; 18 class Profile;
19 class SerializedScriptValue; 19 class SerializedScriptValue;
20 struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params; 20 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params;
21 struct ViewHostMsg_IDBFactoryOpen_Params; 21 struct IndexedDBHostMsg_FactoryOpen_Params;
22 struct ViewHostMsg_IDBIndexOpenCursor_Params; 22 struct IndexedDBHostMsg_IndexOpenCursor_Params;
23 struct ViewHostMsg_IDBObjectStoreCreateIndex_Params; 23 struct IndexedDBHostMsg_ObjectStoreCreateIndex_Params;
24 struct ViewHostMsg_IDBObjectStoreOpenCursor_Params; 24 struct IndexedDBHostMsg_ObjectStoreOpenCursor_Params;
25 struct ViewHostMsg_IDBObjectStorePut_Params; 25 struct IndexedDBHostMsg_ObjectStorePut_Params;
26 26
27 namespace WebKit { 27 namespace WebKit {
28 class WebIDBCursor; 28 class WebIDBCursor;
29 class WebIDBDatabase; 29 class WebIDBDatabase;
30 class WebIDBIndex; 30 class WebIDBIndex;
31 class WebIDBObjectStore; 31 class WebIDBObjectStore;
32 class WebIDBTransaction; 32 class WebIDBTransaction;
33 } 33 }
34 34
35 // Handles all IndexedDB related messages from a particular renderer process. 35 // Handles all IndexedDB related messages from a particular renderer process.
36 class IndexedDBDispatcherHost 36 class IndexedDBDispatcherHost : public BrowserMessageFilter {
37 : public base::RefCountedThreadSafe<IndexedDBDispatcherHost> {
38 public: 37 public:
39 // Only call the constructor from the UI thread. 38 // Only call the constructor from the UI thread.
40 IndexedDBDispatcherHost(IPC::Message::Sender* sender, Profile* profile); 39 IndexedDBDispatcherHost(int process_id, Profile* profile);
41 40
42 // Only call from ResourceMessageFilter on the IO thread. 41 // BrowserMessageFilter implementation.
43 void Init(int process_id, base::ProcessHandle process_handle); 42 virtual void OnChannelClosing();
44 43 virtual void OverrideThreadForMessage(const IPC::Message& message,
45 // Only call from ResourceMessageFilter on the IO thread. Calls self on the 44 BrowserThread::ID* thread);
46 // WebKit thread in some cases. 45 virtual bool OnMessageReceived(const IPC::Message& message,
47 void Shutdown(); 46 bool* message_was_ok);
48
49 // Only call from ResourceMessageFilter on the IO thread.
50 bool OnMessageReceived(const IPC::Message& message);
51
52 // Send a message to the renderer process associated with our sender_ via the
53 // IO thread. May be called from any thread.
54 void Send(IPC::Message* message);
55 47
56 // A shortcut for accessing our context. 48 // A shortcut for accessing our context.
57 IndexedDBContext* Context() { 49 IndexedDBContext* Context() {
58 return webkit_context_->indexed_db_context(); 50 return webkit_context_->indexed_db_context();
59 } 51 }
60 52
61 // The various IndexedDBCallbacks children call these methods to add the 53 // The various IndexedDBCallbacks children call these methods to add the
62 // results into the applicable map. See below for more details. 54 // results into the applicable map. See below for more details.
63 int32 Add(WebKit::WebIDBCursor* idb_cursor); 55 int32 Add(WebKit::WebIDBCursor* idb_cursor);
64 int32 Add(WebKit::WebIDBDatabase* idb_database); 56 int32 Add(WebKit::WebIDBDatabase* idb_database);
65 int32 Add(WebKit::WebIDBIndex* idb_index); 57 int32 Add(WebKit::WebIDBIndex* idb_index);
66 int32 Add(WebKit::WebIDBObjectStore* idb_object_store); 58 int32 Add(WebKit::WebIDBObjectStore* idb_object_store);
67 int32 Add(WebKit::WebIDBTransaction* idb_transaction); 59 int32 Add(WebKit::WebIDBTransaction* idb_transaction);
68 60
69 private: 61 private:
70 friend class base::RefCountedThreadSafe<IndexedDBDispatcherHost>;
71 ~IndexedDBDispatcherHost(); 62 ~IndexedDBDispatcherHost();
72 63
73 // Message processing. Most of the work is delegated to the dispatcher hosts 64 // Message processing. Most of the work is delegated to the dispatcher hosts
74 // below. 65 // below.
75 void OnMessageReceivedWebKit(const IPC::Message& message); 66 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p);
76 void OnIDBFactoryOpen(const ViewHostMsg_IDBFactoryOpen_Params& p);
77 67
78 // Helper templates. 68 // Helper templates.
79 template <class ReturnType> 69 template <class ReturnType>
80 ReturnType* GetOrTerminateProcess( 70 ReturnType* GetOrTerminateProcess(
81 IDMap<ReturnType, IDMapOwnPointer>* map, int32 return_object_id, 71 IDMap<ReturnType, IDMapOwnPointer>* map, int32 return_object_id,
82 IPC::Message* reply_msg, uint32 message_type); 72 uint32 message_type);
83 73
84 template <typename ReplyType, typename MessageType, 74 template <typename ReplyType, typename MessageType,
85 typename WebObjectType, typename Method> 75 typename WebObjectType, typename Method>
86 void SyncGetter(IDMap<WebObjectType, IDMapOwnPointer>* map, int32 object_id, 76 void SyncGetter(IDMap<WebObjectType, IDMapOwnPointer>* map, int32 object_id,
87 IPC::Message* reply_msg, Method method); 77 ReplyType* reply, Method method);
88 78
89 template <typename ObjectType> 79 template <typename ObjectType>
90 void DestroyObject(IDMap<ObjectType, IDMapOwnPointer>* map, int32 object_id, 80 void DestroyObject(IDMap<ObjectType, IDMapOwnPointer>* map, int32 object_id,
91 uint32 message_type); 81 uint32 message_type);
92 82
93 class DatabaseDispatcherHost { 83 class DatabaseDispatcherHost {
94 public: 84 public:
95 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent); 85 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent);
96 ~DatabaseDispatcherHost(); 86 ~DatabaseDispatcherHost();
97 87
98 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); 88 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
99 void Send(IPC::Message* message); 89 void Send(IPC::Message* message);
100 90
101 void OnName(int32 idb_database_id, IPC::Message* reply_msg); 91 void OnName(int32 idb_database_id, string16* name);
102 void OnVersion(int32 idb_database_id, IPC::Message* reply_msg); 92 void OnVersion(int32 idb_database_id, string16* version);
103 void OnObjectStoreNames(int32 idb_database_id, IPC::Message* reply_msg); 93 void OnObjectStoreNames(int32 idb_database_id,
94 std::vector<string16>* object_stores);
104 void OnCreateObjectStore( 95 void OnCreateObjectStore(
105 const ViewHostMsg_IDBDatabaseCreateObjectStore_Params& params, 96 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params,
106 IPC::Message* reply_msg); 97 int32* object_store_id, WebKit::WebExceptionCode* ec);
107 void OnDeleteObjectStore(int32 idb_database_id, 98 void OnDeleteObjectStore(int32 idb_database_id,
108 const string16& name, 99 const string16& name,
109 int32 transaction_id, 100 int32 transaction_id,
110 IPC::Message* reply_msg); 101 WebKit::WebExceptionCode* ec);
111 void OnSetVersion(int32 idb_database_id, 102 void OnSetVersion(int32 idb_database_id,
112 int32 response_id, 103 int32 response_id,
113 const string16& version, 104 const string16& version,
114 IPC::Message* reply_msg); 105 WebKit::WebExceptionCode* ec);
115 void OnTransaction(int32 idb_database_id, 106 void OnTransaction(int32 idb_database_id,
116 const std::vector<string16>& names, 107 const std::vector<string16>& names,
117 int32 mode, int32 timeout, 108 int32 mode, int32 timeout,
118 IPC::Message* reply_msg); 109 int32* idb_transaction_id,
110 WebKit::WebExceptionCode* ec);
119 void OnDestroyed(int32 idb_database_id); 111 void OnDestroyed(int32 idb_database_id);
120 112
121 IndexedDBDispatcherHost* parent_; 113 IndexedDBDispatcherHost* parent_;
122 IDMap<WebKit::WebIDBDatabase, IDMapOwnPointer> map_; 114 IDMap<WebKit::WebIDBDatabase, IDMapOwnPointer> map_;
123 }; 115 };
124 116
125 class IndexDispatcherHost { 117 class IndexDispatcherHost {
126 public: 118 public:
127 explicit IndexDispatcherHost(IndexedDBDispatcherHost* parent); 119 explicit IndexDispatcherHost(IndexedDBDispatcherHost* parent);
128 ~IndexDispatcherHost(); 120 ~IndexDispatcherHost();
129 121
130 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); 122 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
131 void Send(IPC::Message* message); 123 void Send(IPC::Message* message);
132 124
133 void OnName(int32 idb_index_id, IPC::Message* reply_msg); 125 void OnName(int32 idb_index_id, string16* name);
134 void OnStoreName(int32 idb_index_id, IPC::Message* reply_msg); 126 void OnStoreName(int32 idb_index_id, string16* store_name);
135 void OnKeyPath(int32 idb_index_id, IPC::Message* reply_msg); 127 void OnKeyPath(int32 idb_index_id, NullableString16* key_path);
136 void OnUnique(int32 idb_index_id, IPC::Message* reply_msg); 128 void OnUnique(int32 idb_index_id, bool* unique);
137 void OnOpenObjectCursor( 129 void OnOpenObjectCursor(
138 const ViewHostMsg_IDBIndexOpenCursor_Params& params, 130 const IndexedDBHostMsg_IndexOpenCursor_Params& params,
139 IPC::Message* reply_msg); 131 WebKit::WebExceptionCode* ec);
140 void OnOpenKeyCursor(const ViewHostMsg_IDBIndexOpenCursor_Params& params, 132 void OnOpenKeyCursor(const IndexedDBHostMsg_IndexOpenCursor_Params& params,
141 IPC::Message* reply_msg); 133 WebKit::WebExceptionCode* ec);
142 void OnGetObject(int idb_index_id, 134 void OnGetObject(int idb_index_id,
143 int32 response_id, 135 int32 response_id,
144 const IndexedDBKey& key, 136 const IndexedDBKey& key,
145 int32 transaction_id, 137 int32 transaction_id,
146 IPC::Message* reply_msg); 138 WebKit::WebExceptionCode* ec);
147 void OnGetKey(int idb_index_id, 139 void OnGetKey(int idb_index_id,
148 int32 response_id, 140 int32 response_id,
149 const IndexedDBKey& key, 141 const IndexedDBKey& key,
150 int32 transaction_id, 142 int32 transaction_id,
151 IPC::Message* reply_msg); 143 WebKit::WebExceptionCode* ec);
152 void OnDestroyed(int32 idb_index_id); 144 void OnDestroyed(int32 idb_index_id);
153 145
154 IndexedDBDispatcherHost* parent_; 146 IndexedDBDispatcherHost* parent_;
155 IDMap<WebKit::WebIDBIndex, IDMapOwnPointer> map_; 147 IDMap<WebKit::WebIDBIndex, IDMapOwnPointer> map_;
156 }; 148 };
157 149
158 class ObjectStoreDispatcherHost { 150 class ObjectStoreDispatcherHost {
159 public: 151 public:
160 explicit ObjectStoreDispatcherHost(IndexedDBDispatcherHost* parent); 152 explicit ObjectStoreDispatcherHost(IndexedDBDispatcherHost* parent);
161 ~ObjectStoreDispatcherHost(); 153 ~ObjectStoreDispatcherHost();
162 154
163 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); 155 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
164 void Send(IPC::Message* message); 156 void Send(IPC::Message* message);
165 157
166 void OnName(int32 idb_object_store_id, IPC::Message* reply_msg); 158 void OnName(int32 idb_object_store_id, string16* name);
167 void OnKeyPath(int32 idb_object_store_id, IPC::Message* reply_msg); 159 void OnKeyPath(int32 idb_object_store_id, NullableString16* keyPath);
168 void OnIndexNames(int32 idb_object_store_id, IPC::Message* reply_msg); 160 void OnIndexNames(int32 idb_object_store_id,
161 std::vector<string16>* index_names);
169 void OnGet(int idb_object_store_id, 162 void OnGet(int idb_object_store_id,
170 int32 response_id, 163 int32 response_id,
171 const IndexedDBKey& key, 164 const IndexedDBKey& key,
172 int32 transaction_id, 165 int32 transaction_id,
173 IPC::Message* reply_msg); 166 WebKit::WebExceptionCode* ec);
174 void OnPut(const ViewHostMsg_IDBObjectStorePut_Params& params, 167 void OnPut(const IndexedDBHostMsg_ObjectStorePut_Params& params,
175 IPC::Message* reply_msg); 168 WebKit::WebExceptionCode* ec);
176 void OnDelete(int idb_object_store_id, 169 void OnDelete(int idb_object_store_id,
177 int32 response_id, 170 int32 response_id,
178 const IndexedDBKey& key, 171 const IndexedDBKey& key,
179 int32 transaction_id, 172 int32 transaction_id,
180 IPC::Message* reply_msg); 173 WebKit::WebExceptionCode* ec);
181 void OnCreateIndex( 174 void OnCreateIndex(
182 const ViewHostMsg_IDBObjectStoreCreateIndex_Params& params, 175 const IndexedDBHostMsg_ObjectStoreCreateIndex_Params& params,
183 IPC::Message* reply_msg); 176 int32* index_id,
177 WebKit::WebExceptionCode* ec);
184 void OnIndex(int32 idb_object_store_id, 178 void OnIndex(int32 idb_object_store_id,
185 const string16& name, 179 const string16& name,
186 IPC::Message* reply_msg); 180 int32* idb_index_id,
181 WebKit::WebExceptionCode* ec);
187 void OnDeleteIndex(int32 idb_object_store_id, 182 void OnDeleteIndex(int32 idb_object_store_id,
188 const string16& name, 183 const string16& name,
189 int32 transaction_id, 184 int32 transaction_id,
190 IPC::Message* reply_msg); 185 WebKit::WebExceptionCode* ec);
191 void OnOpenCursor( 186 void OnOpenCursor(
192 const ViewHostMsg_IDBObjectStoreOpenCursor_Params& params, 187 const IndexedDBHostMsg_ObjectStoreOpenCursor_Params& params,
193 IPC::Message* reply_msg); 188 WebKit::WebExceptionCode* ec);
194 void OnDestroyed(int32 idb_object_store_id); 189 void OnDestroyed(int32 idb_object_store_id);
195 190
196 IndexedDBDispatcherHost* parent_; 191 IndexedDBDispatcherHost* parent_;
197 IDMap<WebKit::WebIDBObjectStore, IDMapOwnPointer> map_; 192 IDMap<WebKit::WebIDBObjectStore, IDMapOwnPointer> map_;
198 }; 193 };
199 194
200 class CursorDispatcherHost { 195 class CursorDispatcherHost {
201 public: 196 public:
202 explicit CursorDispatcherHost(IndexedDBDispatcherHost* parent); 197 explicit CursorDispatcherHost(IndexedDBDispatcherHost* parent);
203 ~CursorDispatcherHost(); 198 ~CursorDispatcherHost();
204 199
205 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); 200 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
206 void Send(IPC::Message* message); 201 void Send(IPC::Message* message);
207 202
208 void OnDirection(int32 idb_object_store_id, IPC::Message* reply_msg); 203 void OnDirection(int32 idb_object_store_id, int32* direction);
209 void OnKey(int32 idb_object_store_id, IPC::Message* reply_msg); 204 void OnKey(int32 idb_object_store_id, IndexedDBKey* key);
210 void OnValue(int32 idb_object_store_id, IPC::Message* reply_msg); 205 void OnValue(int32 idb_object_store_id,
206 SerializedScriptValue* script_value,
207 IndexedDBKey* key);
211 void OnUpdate(int32 idb_object_store_id, 208 void OnUpdate(int32 idb_object_store_id,
212 int32 response_id, 209 int32 response_id,
213 const SerializedScriptValue& value, 210 const SerializedScriptValue& value,
214 IPC::Message* reply_msg); 211 WebKit::WebExceptionCode* ec);
215 void OnContinue(int32 idb_object_store_id, 212 void OnContinue(int32 idb_object_store_id,
216 int32 response_id, 213 int32 response_id,
217 const IndexedDBKey& key, 214 const IndexedDBKey& key,
218 IPC::Message* reply_msg); 215 WebKit::WebExceptionCode* ec);
219 void OnDelete(int32 idb_object_store_id, 216 void OnDelete(int32 idb_object_store_id,
220 int32 response_id, 217 int32 response_id,
221 IPC::Message* reply_msg); 218 WebKit::WebExceptionCode* ec);
222 void OnDestroyed(int32 idb_cursor_id); 219 void OnDestroyed(int32 idb_cursor_id);
223 220
224 IndexedDBDispatcherHost* parent_; 221 IndexedDBDispatcherHost* parent_;
225 IDMap<WebKit::WebIDBCursor, IDMapOwnPointer> map_; 222 IDMap<WebKit::WebIDBCursor, IDMapOwnPointer> map_;
226 }; 223 };
227 224
228 class TransactionDispatcherHost { 225 class TransactionDispatcherHost {
229 public: 226 public:
230 explicit TransactionDispatcherHost(IndexedDBDispatcherHost* parent); 227 explicit TransactionDispatcherHost(IndexedDBDispatcherHost* parent);
231 ~TransactionDispatcherHost(); 228 ~TransactionDispatcherHost();
232 229
233 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); 230 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
234 void Send(IPC::Message* message); 231 void Send(IPC::Message* message);
235 232
236 // TODO: add the rest of the transaction methods. 233 // TODO: add the rest of the transaction methods.
237 void OnAbort(int32 transaction_id); 234 void OnAbort(int32 transaction_id);
238 void OnMode(int32 transaction_id, IPC::Message* reply_msg); 235 void OnMode(int32 transaction_id, int* mode);
239 void OnObjectStore(int32 transaction_id, 236 void OnObjectStore(int32 transaction_id,
240 const string16& name, 237 const string16& name,
241 IPC::Message* reply_msg); 238 int32* object_store_id,
239 WebKit::WebExceptionCode* ec);
242 void OnDidCompleteTaskEvents(int transaction_id); 240 void OnDidCompleteTaskEvents(int transaction_id);
243 void OnDestroyed(int32 idb_transaction_id); 241 void OnDestroyed(int32 idb_transaction_id);
244 242
245 IndexedDBDispatcherHost* parent_; 243 IndexedDBDispatcherHost* parent_;
246 typedef IDMap<WebKit::WebIDBTransaction, IDMapOwnPointer> MapType; 244 typedef IDMap<WebKit::WebIDBTransaction, IDMapOwnPointer> MapType;
247 MapType map_; 245 MapType map_;
248 }; 246 };
249 247
250 // Only use on the IO thread.
251 IPC::Message::Sender* sender_;
252
253 // Data shared between renderer processes with the same profile. 248 // Data shared between renderer processes with the same profile.
254 scoped_refptr<WebKitContext> webkit_context_; 249 scoped_refptr<WebKitContext> webkit_context_;
255 250
256 // Tells us whether the user wants to allow databases to be opened. 251 // Tells us whether the user wants to allow databases to be opened.
257 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; 252 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
258 253
259 // Only access on WebKit thread. 254 // Only access on WebKit thread.
260 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; 255 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_;
261 scoped_ptr<IndexDispatcherHost> index_dispatcher_host_; 256 scoped_ptr<IndexDispatcherHost> index_dispatcher_host_;
262 scoped_ptr<ObjectStoreDispatcherHost> object_store_dispatcher_host_; 257 scoped_ptr<ObjectStoreDispatcherHost> object_store_dispatcher_host_;
263 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; 258 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_;
264 scoped_ptr<TransactionDispatcherHost> transaction_dispatcher_host_; 259 scoped_ptr<TransactionDispatcherHost> transaction_dispatcher_host_;
265 260
266 // If we get a corrupt message from a renderer, we need to kill it using this
267 // handle.
268 base::ProcessHandle process_handle_;
269
270 // Used to dispatch messages to the correct view host. 261 // Used to dispatch messages to the correct view host.
271 int process_id_; 262 int process_id_;
272 263
273 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); 264 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost);
274 }; 265 };
275 266
276 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ 267 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698