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

Side by Side Diff: content/renderer/indexed_db_dispatcher.h

Issue 8747002: Dispatch IndexedDB IPC messages to worker threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: repurpose obsolete indexed-db switch to control idb on workers Created 9 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) 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_RENDERER_INDEXED_DB_DISPATCHER_H_ 5 #ifndef CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_
6 #define CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ 6 #define CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/id_map.h" 12 #include "base/id_map.h"
13 #include "base/nullable_string16.h" 13 #include "base/nullable_string16.h"
14 #include "content/common/indexed_db_message_filter.h"
14 #include "ipc/ipc_channel.h" 15 #include "ipc/ipc_channel.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbac ks.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCall backs.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCall backs.h"
20 22
21 class IndexedDBKey; 23 class IndexedDBKey;
22 class RendererWebIDBCursorImpl; 24 class RendererWebIDBCursorImpl;
23 25
24 namespace WebKit { 26 namespace WebKit {
25 class WebFrame; 27 class WebFrame;
26 class WebIDBKeyRange; 28 class WebIDBKeyRange;
27 class WebIDBTransaction; 29 class WebIDBTransaction;
28 } 30 }
29 31
30 namespace content { 32 namespace content {
31 class SerializedScriptValue; 33 class SerializedScriptValue;
32 } 34 }
33 35
34 // Handle the indexed db related communication for this entire renderer. 36 // Handle the indexed db related communication for this entire renderer.
35 class IndexedDBDispatcher : public IPC::Channel::Listener { 37 class IndexedDBDispatcher {
36 public: 38 public:
37 IndexedDBDispatcher(); 39 IndexedDBDispatcher(IndexedDBMessageFilter*);
38 virtual ~IndexedDBDispatcher(); 40 virtual ~IndexedDBDispatcher();
39 41
40 // IPC::Channel::Listener implementation. 42 void OnMessageReceived(const IPC::Message& msg);
41 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
42 void Send(IPC::Message* msg); 43 void Send(IPC::Message* msg);
43 44
44 void RequestIDBFactoryGetDatabaseNames( 45 void RequestIDBFactoryGetDatabaseNames(
45 WebKit::WebIDBCallbacks* callbacks, 46 WebKit::WebIDBCallbacks* callbacks,
46 const string16& origin, 47 const string16& origin,
47 WebKit::WebFrame* web_frame); 48 WebKit::WebFrame* web_frame);
48 49
49 void RequestIDBFactoryOpen( 50 void RequestIDBFactoryOpen(
50 const string16& name, 51 const string16& name,
51 WebKit::WebIDBCallbacks* callbacks, 52 WebKit::WebIDBCallbacks* callbacks,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const std::vector<string16>& value); 179 const std::vector<string16>& value);
179 void OnSuccessSerializedScriptValue( 180 void OnSuccessSerializedScriptValue(
180 int32 response_id, 181 int32 response_id,
181 const content::SerializedScriptValue& value); 182 const content::SerializedScriptValue& value);
182 void OnError(int32 response_id, int code, const string16& message); 183 void OnError(int32 response_id, int code, const string16& message);
183 void OnBlocked(int32 response_id); 184 void OnBlocked(int32 response_id);
184 void OnAbort(int32 transaction_id); 185 void OnAbort(int32 transaction_id);
185 void OnComplete(int32 transaction_id); 186 void OnComplete(int32 transaction_id);
186 void OnVersionChange(int32 database_id, const string16& newVersion); 187 void OnVersionChange(int32 database_id, const string16& newVersion);
187 188
189 // This class facilitates mapping callback ids specified in incoming IPC
190 // messages to threads. It:
191 // * Retrieves process-unique ids for each stored WebIDBCallbacks object. The
192 // browser process includes these ids in messages sent back to us.
193 // * Registers incoming transaction and database callback ids that are created
194 // in the browser process. We'll need to revisit this scheme if the browser
195 // stops generating unique ids.
196 // * Ensures, through IDMap, that it is only called on a single thread.
197 template<class CallbackType>
198 class CallbackIDMap {
199 public:
200 CallbackIDMap(IndexedDBMessageFilter* filter) : filter_(filter) {
201 }
202 virtual int32 Add(CallbackType* callbacks) {
203 int id = filter_->GetUniqueCallbackIDWithThreadID();
204 map_.AddWithID(callbacks, id);
205 return id;
206 }
207 virtual void Remove(int32 id) {
208 map_.Remove(id);
209 }
210 CallbackType* Lookup(int32 id) {
211 return map_.Lookup(id);
212 }
213 protected:
214 // The filter is alive for the life of the process, nothing deletes it.
215 IndexedDBMessageFilter* filter_;
216 IDMap<CallbackType, IDMapOwnPointer> map_;
217 };
218
219 class TransactionCallbackIDMap :
220 public CallbackIDMap<WebKit::WebIDBTransactionCallbacks> {
221 public:
222 TransactionCallbackIDMap(IndexedDBMessageFilter* filter) :
223 CallbackIDMap<WebKit::WebIDBTransactionCallbacks>(filter) {
224 }
225 void AddWithID(WebKit::WebIDBTransactionCallbacks* callbacks, int32 id) {
226 filter_->DidAddTransactionID(id);
227 map_.AddWithID(callbacks, id);
228 }
229 virtual void Remove(int32 id) OVERRIDE {
230 filter_->DidRemoveTransactionID(id);
231 CallbackIDMap<WebKit::WebIDBTransactionCallbacks>::Remove(id);
232 }
233 };
234
188 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be 235 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be
189 // destroyed and used on the same thread it was created on. 236 // destroyed and used on the same thread it was created on.
190 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; 237 CallbackIDMap<WebKit::WebIDBCallbacks> pending_callbacks_;
191 IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer> 238 TransactionCallbackIDMap pending_transaction_callbacks_;
192 pending_transaction_callbacks_; 239 CallbackIDMap<WebKit::WebIDBDatabaseCallbacks> pending_database_callbacks_;
193 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer>
194 pending_database_callbacks_;
195 240
196 // Map from cursor id to RendererWebIDBCursorImpl. 241 // Map from cursor id to RendererWebIDBCursorImpl.
197 std::map<int32, RendererWebIDBCursorImpl*> cursors_; 242 std::map<int32, RendererWebIDBCursorImpl*> cursors_;
198 243
244 std::map<int32, int32> database_id_to_callbacks_id_;
245
199 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); 246 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
200 }; 247 };
201 248
202 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ 249 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698