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

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: 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/child_thread.h"
15 #include "content/renderer/indexed_db_message_filter.h"
14 #include "ipc/ipc_channel.h" 16 #include "ipc/ipc_channel.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.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 :
38 public base::RefCountedThreadSafe<IndexedDBDispatcher> {
36 public: 39 public:
37 IndexedDBDispatcher(); 40 IndexedDBDispatcher(IndexedDBMessageFilter*);
38 virtual ~IndexedDBDispatcher(); 41 virtual ~IndexedDBDispatcher();
39 42
40 // IPC::Channel::Listener implementation. 43 void OnMessageReceived(const IPC::Message& msg);
41 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 44 void Send(IPC::Message* msg);
42 45
43 void RequestIDBFactoryGetDatabaseNames( 46 void RequestIDBFactoryGetDatabaseNames(
44 WebKit::WebIDBCallbacks* callbacks, 47 WebKit::WebIDBCallbacks* callbacks,
45 const string16& origin, 48 const string16& origin,
46 WebKit::WebFrame* web_frame); 49 WebKit::WebFrame* web_frame);
47 50
48 void RequestIDBFactoryOpen( 51 void RequestIDBFactoryOpen(
49 const string16& name, 52 const string16& name,
50 WebKit::WebIDBCallbacks* callbacks, 53 WebKit::WebIDBCallbacks* callbacks,
51 const string16& origin, 54 const string16& origin,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 const std::vector<string16>& value); 180 const std::vector<string16>& value);
178 void OnSuccessSerializedScriptValue( 181 void OnSuccessSerializedScriptValue(
179 int32 response_id, 182 int32 response_id,
180 const content::SerializedScriptValue& value); 183 const content::SerializedScriptValue& value);
181 void OnError(int32 response_id, int code, const string16& message); 184 void OnError(int32 response_id, int code, const string16& message);
182 void OnBlocked(int32 response_id); 185 void OnBlocked(int32 response_id);
183 void OnAbort(int32 transaction_id); 186 void OnAbort(int32 transaction_id);
184 void OnComplete(int32 transaction_id); 187 void OnComplete(int32 transaction_id);
185 void OnVersionChange(int32 database_id, const string16& newVersion); 188 void OnVersionChange(int32 database_id, const string16& newVersion);
186 189
190 // This class facilitates mapping incoming ids to threads. It:
191 // * Gets process-unique ids for each stored IDBCallbacks.
192 // * Registers incoming transaction and database ids that are created in
193 // the browser process. We'll need to revisit this scheme if the browser
194 // stops generating unique ids.
195 // * Ensures, through IDMap, that it is only called on a single thread.
hans 2011/11/30 15:05:40 mabye point out in the comments that this map is i
dgrogan 2011/11/30 21:34:35 You're right. Updated the comments and name to re
michaeln 2011/11/30 21:48:14 "ThreadSafe" usually means safe to call from multi
dgrogan 2011/11/30 23:25:18 You're right. I renamed it CallbacksIDMap in a la
196 template<class T>
197 class ThreadSafeIDMap
hans 2011/11/30 15:05:40 ultra nit: curly brace on same line
dgrogan 2011/11/30 21:34:35 Done.
198 {
199 public:
200 ThreadSafeIDMap(IndexedDBMessageFilter* filter) {
201 filter_ = filter;
hans 2011/11/30 15:05:40 nit: maybe use constructor initializer list?
dgrogan 2011/11/30 21:34:35 Done.
202 }
203 void AddWithID(T* callbacks, int32 id) {
204 filter_->NotifyAddWithIDForType(id, callbacks);
205 map_.AddWithID(callbacks, id);
206 }
207 int32 Add(T* callbacks) {
208 int id = filter_->GetUniqueID();
209 map_.AddWithID(callbacks, id);
210 return id;
211 }
212 void Remove(int32 id) {
213 filter_->RemoveForType(id, (T*)NULL);
214 map_.Remove(id);
215 }
216 T* Lookup(int32 id) {
217 return map_.Lookup(id);
218 }
219 private:
220 // The filter is alive for the life of the process, nothing deletes it.
221 IndexedDBMessageFilter* filter_;
222 IDMap<T, IDMapOwnPointer> map_;
223 };
224
187 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be 225 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be
188 // destroyed and used on the same thread it was created on. 226 // destroyed and used on the same thread it was created on.
189 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; 227 ThreadSafeIDMap<WebKit::WebIDBCallbacks> pending_callbacks_;
190 IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer> 228 ThreadSafeIDMap<WebKit::WebIDBTransactionCallbacks>
191 pending_transaction_callbacks_; 229 pending_transaction_callbacks_;
192 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> 230 ThreadSafeIDMap<WebKit::WebIDBDatabaseCallbacks> pending_database_callbacks_;
193 pending_database_callbacks_;
194 231
195 // Map from cursor id to RendererWebIDBCursorImpl. 232 // Map from cursor id to RendererWebIDBCursorImpl.
196 std::map<int32, RendererWebIDBCursorImpl*> cursors_; 233 std::map<int32, RendererWebIDBCursorImpl*> cursors_;
197 234
198 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); 235 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
199 }; 236 };
200 237
201 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ 238 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698