 Chromium Code Reviews
 Chromium Code Reviews Issue 8747002:
  Dispatch IndexedDB IPC messages to worker threads  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 8747002:
  Dispatch IndexedDB IPC messages to worker threads  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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_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 "ipc/ipc_channel.h" | 14 #include "base/threading/thread_local.h" | 
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" | 
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" | 
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" | 
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbac ks.h" | |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" | 
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCall backs.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCall backs.h" | 
| 21 #include "webkit/glue/worker_task_runner.h" | |
| 20 | 22 | 
| 21 class IndexedDBKey; | 23 class IndexedDBKey; | 
| 24 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; | |
| 25 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; | |
| 26 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; | |
| 22 class RendererWebIDBCursorImpl; | 27 class RendererWebIDBCursorImpl; | 
| 23 | 28 | 
| 29 namespace IPC { | |
| 30 class Message; | |
| 31 } | |
| 32 | |
| 24 namespace WebKit { | 33 namespace WebKit { | 
| 25 class WebFrame; | 34 class WebFrame; | 
| 26 class WebIDBKeyRange; | 35 class WebIDBKeyRange; | 
| 27 class WebIDBTransaction; | 36 class WebIDBTransaction; | 
| 28 } | 37 } | 
| 29 | 38 | 
| 30 namespace content { | 39 namespace content { | 
| 31 class SerializedScriptValue; | 40 class SerializedScriptValue; | 
| 32 } | 41 } | 
| 33 | 42 | 
| 34 // Handle the indexed db related communication for this entire renderer. | 43 // Handle the indexed db related communication for this entire renderer. | 
| 
michaeln
2011/12/14 02:15:53
comment might be misleading now that there are thr
 
dgrogan
2011/12/15 02:47:44
Updated.
 | |
| 35 class IndexedDBDispatcher : public IPC::Channel::Listener { | 44 class IndexedDBDispatcher : public webkit_glue::WorkerTaskRunner::Observer { | 
| 36 public: | 45 public: | 
| 37 IndexedDBDispatcher(); | |
| 38 virtual ~IndexedDBDispatcher(); | 46 virtual ~IndexedDBDispatcher(); | 
| 47 static void Init(); | |
| 48 // This returns the dispatcher associated with the current WebWorkerRunLoop, | |
| 
michaeln
2011/12/14 02:15:53
The comment is a little misleading since it will a
 
dgrogan
2011/12/15 02:47:44
Renaming Instance to ThreadSpecificInstance should
 | |
| 49 // if being run from a worker. | |
| 50 static IndexedDBDispatcher* Instance(); | |
| 
michaeln
2011/12/14 02:15:53
maybe name this as ThreadSpecificInstance() for cl
 
dgrogan
2011/12/15 02:47:44
Done.
 | |
| 39 | 51 | 
| 40 // IPC::Channel::Listener implementation. | 52 // webkit_glue::WorkerTaskRunner::Observer implementation. | 
| 41 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 53 virtual void OnWorkerRunLoopStopped(); | 
| 54 | |
| 55 void OnMessageReceived(const IPC::Message& msg); | |
| 42 void Send(IPC::Message* msg); | 56 void Send(IPC::Message* msg); | 
| 43 | 57 | 
| 44 void RequestIDBFactoryGetDatabaseNames( | 58 void RequestIDBFactoryGetDatabaseNames( | 
| 45 WebKit::WebIDBCallbacks* callbacks, | 59 WebKit::WebIDBCallbacks* callbacks, | 
| 46 const string16& origin, | 60 const string16& origin, | 
| 47 WebKit::WebFrame* web_frame); | 61 WebKit::WebFrame* web_frame); | 
| 48 | 62 | 
| 49 void RequestIDBFactoryOpen( | 63 void RequestIDBFactoryOpen( | 
| 50 const string16& name, | 64 const string16& name, | 
| 51 WebKit::WebIDBCallbacks* callbacks, | 65 WebKit::WebIDBCallbacks* callbacks, | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 176 | 
| 163 void RegisterWebIDBTransactionCallbacks( | 177 void RegisterWebIDBTransactionCallbacks( | 
| 164 WebKit::WebIDBTransactionCallbacks* callbacks, | 178 WebKit::WebIDBTransactionCallbacks* callbacks, | 
| 165 int32 id); | 179 int32 id); | 
| 166 | 180 | 
| 167 void CursorDestroyed(int32 cursor_id); | 181 void CursorDestroyed(int32 cursor_id); | 
| 168 | 182 | 
| 169 static int32 TransactionId(const WebKit::WebIDBTransaction& transaction); | 183 static int32 TransactionId(const WebKit::WebIDBTransaction& transaction); | 
| 170 | 184 | 
| 171 private: | 185 private: | 
| 186 IndexedDBDispatcher(); | |
| 172 // IDBCallback message handlers. | 187 // IDBCallback message handlers. | 
| 173 void OnSuccessNull(int32 response_id); | 188 void OnSuccessNull(int32 response_id); | 
| 174 void OnSuccessIDBDatabase(int32 response_id, int32 object_id); | 189 void OnSuccessIDBDatabase(int32 thread_id, | 
| 175 void OnSuccessIndexedDBKey(int32 response_id, const IndexedDBKey& key); | 190 int32 response_id, | 
| 176 void OnSuccessIDBTransaction(int32 response_id, int32 object_id); | 191 int32 object_id); | 
| 177 void OnSuccessOpenCursor(int32 response_id, int32 object_id, | 192 void OnSuccessIndexedDBKey(int32 thread_id, | 
| 178 const IndexedDBKey& key, | 193 int32 response_id, | 
| 179 const IndexedDBKey& primary_key, | 194 const IndexedDBKey& key); | 
| 180 const content::SerializedScriptValue& value); | 195 void OnSuccessIDBTransaction(int32 thread_id, | 
| 181 void OnSuccessCursorContinue(int32 response_id, | 196 int32 response_id, | 
| 182 int32 cursor_id, | 197 int32 object_id); | 
| 183 const IndexedDBKey& key, | 198 void OnSuccessOpenCursor( | 
| 184 const IndexedDBKey& primary_key, | 199 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p); | 
| 185 const content::SerializedScriptValue& value); | 200 void OnSuccessCursorContinue( | 
| 201 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); | |
| 186 void OnSuccessCursorPrefetch( | 202 void OnSuccessCursorPrefetch( | 
| 187 int32 response_id, | 203 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); | 
| 188 int32 cursor_id, | 204 void OnSuccessStringList(int32 thread_id, | 
| 189 const std::vector<IndexedDBKey>& keys, | 205 int32 response_id, | 
| 190 const std::vector<IndexedDBKey>& primary_keys, | |
| 191 const std::vector<content::SerializedScriptValue>& values); | |
| 192 void OnSuccessStringList(int32 response_id, | |
| 193 const std::vector<string16>& value); | 206 const std::vector<string16>& value); | 
| 194 void OnSuccessSerializedScriptValue( | 207 void OnSuccessSerializedScriptValue( | 
| 208 int32 thread_id, | |
| 195 int32 response_id, | 209 int32 response_id, | 
| 196 const content::SerializedScriptValue& value); | 210 const content::SerializedScriptValue& value); | 
| 197 void OnError(int32 response_id, int code, const string16& message); | 211 void OnError(int32 thread_id, | 
| 198 void OnBlocked(int32 response_id); | 212 int32 response_id, | 
| 199 void OnAbort(int32 transaction_id); | 213 int code, | 
| 200 void OnComplete(int32 transaction_id); | 214 const string16& message); | 
| 201 void OnVersionChange(int32 database_id, const string16& newVersion); | 215 void OnBlocked(int32 thread_id, int32 response_id); | 
| 216 void OnAbort(int32 thread_id, int32 transaction_id); | |
| 217 void OnComplete(int32 thread_id, int32 transaction_id); | |
| 218 void OnVersionChange(int32 thread_id, | |
| 219 int32 database_id, | |
| 220 const string16& newVersion); | |
| 202 | 221 | 
| 203 // Reset cursor prefetch caches for all cursors except exception_cursor_id. | 222 // Reset cursor prefetch caches for all cursors except exception_cursor_id. | 
| 204 void ResetCursorPrefetchCaches(int32 exception_cursor_id = -1); | 223 void ResetCursorPrefetchCaches(int32 exception_cursor_id = -1); | 
| 205 | 224 | 
| 206 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | 225 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | 
| 207 // destroyed and used on the same thread it was created on. | 226 // destroyed and used on the same thread it was created on. | 
| 208 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | 227 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | 
| 209 IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer> | 228 IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer> | 
| 210 pending_transaction_callbacks_; | 229 pending_transaction_callbacks_; | 
| 211 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> | 230 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> | 
| 212 pending_database_callbacks_; | 231 pending_database_callbacks_; | 
| 213 | 232 | 
| 214 // Map from cursor id to RendererWebIDBCursorImpl. | 233 // Map from cursor id to RendererWebIDBCursorImpl. | 
| 215 std::map<int32, RendererWebIDBCursorImpl*> cursors_; | 234 std::map<int32, RendererWebIDBCursorImpl*> cursors_; | 
| 216 | 235 | 
| 236 static base::ThreadLocalPointer<IndexedDBDispatcher>* idb_dispatcher_tls_; | |
| 237 | |
| 217 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 238 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 
| 218 }; | 239 }; | 
| 219 | 240 | 
| 220 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ | 241 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ | 
| OLD | NEW |