Chromium Code Reviews| Index: content/renderer/indexed_db_dispatcher.h |
| diff --git a/content/renderer/indexed_db_dispatcher.h b/content/renderer/indexed_db_dispatcher.h |
| index 28071580c195e2ce2c271bc67bf566306b97c46a..870d4536c6a7de5bc7a4aa78de97b052725ea9d2 100644 |
| --- a/content/renderer/indexed_db_dispatcher.h |
| +++ b/content/renderer/indexed_db_dispatcher.h |
| @@ -11,6 +11,8 @@ |
| #include "base/id_map.h" |
| #include "base/nullable_string16.h" |
| +#include "content/common/child_thread.h" |
| +#include "content/renderer/indexed_db_message_filter.h" |
| #include "ipc/ipc_channel.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" |
| @@ -32,13 +34,14 @@ class SerializedScriptValue; |
| } |
| // Handle the indexed db related communication for this entire renderer. |
| -class IndexedDBDispatcher : public IPC::Channel::Listener { |
| +class IndexedDBDispatcher : |
| + public base::RefCountedThreadSafe<IndexedDBDispatcher> { |
| public: |
| - IndexedDBDispatcher(); |
| + IndexedDBDispatcher(IndexedDBMessageFilter*); |
| virtual ~IndexedDBDispatcher(); |
| - // IPC::Channel::Listener implementation. |
| - virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| + void OnMessageReceived(const IPC::Message& msg); |
| + void Send(IPC::Message* msg); |
| void RequestIDBFactoryGetDatabaseNames( |
| WebKit::WebIDBCallbacks* callbacks, |
| @@ -184,13 +187,47 @@ class IndexedDBDispatcher : public IPC::Channel::Listener { |
| void OnComplete(int32 transaction_id); |
| void OnVersionChange(int32 database_id, const string16& newVersion); |
| + // This class facilitates mapping incoming ids to threads. It: |
| + // * Gets process-unique ids for each stored IDBCallbacks. |
| + // * Registers incoming transaction and database ids that are created in |
| + // the browser process. We'll need to revisit this scheme if the browser |
| + // stops generating unique ids. |
| + // * 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
|
| + template<class T> |
| + class ThreadSafeIDMap |
|
hans
2011/11/30 15:05:40
ultra nit: curly brace on same line
dgrogan
2011/11/30 21:34:35
Done.
|
| + { |
| + public: |
| + ThreadSafeIDMap(IndexedDBMessageFilter* filter) { |
| + filter_ = filter; |
|
hans
2011/11/30 15:05:40
nit: maybe use constructor initializer list?
dgrogan
2011/11/30 21:34:35
Done.
|
| + } |
| + void AddWithID(T* callbacks, int32 id) { |
| + filter_->NotifyAddWithIDForType(id, callbacks); |
| + map_.AddWithID(callbacks, id); |
| + } |
| + int32 Add(T* callbacks) { |
| + int id = filter_->GetUniqueID(); |
| + map_.AddWithID(callbacks, id); |
| + return id; |
| + } |
| + void Remove(int32 id) { |
| + filter_->RemoveForType(id, (T*)NULL); |
| + map_.Remove(id); |
| + } |
| + T* Lookup(int32 id) { |
| + return map_.Lookup(id); |
| + } |
| + private: |
| + // The filter is alive for the life of the process, nothing deletes it. |
| + IndexedDBMessageFilter* filter_; |
| + IDMap<T, IDMapOwnPointer> map_; |
| + }; |
| + |
| // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be |
| // destroyed and used on the same thread it was created on. |
| - IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; |
| - IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer> |
| + ThreadSafeIDMap<WebKit::WebIDBCallbacks> pending_callbacks_; |
| + ThreadSafeIDMap<WebKit::WebIDBTransactionCallbacks> |
| pending_transaction_callbacks_; |
| - IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> |
| - pending_database_callbacks_; |
| + ThreadSafeIDMap<WebKit::WebIDBDatabaseCallbacks> pending_database_callbacks_; |
| // Map from cursor id to RendererWebIDBCursorImpl. |
| std::map<int32, RendererWebIDBCursorImpl*> cursors_; |