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

Unified 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: inject thread ids into ipcs Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/indexed_db_dispatcher.h
diff --git a/content/renderer/indexed_db_dispatcher.h b/content/renderer/indexed_db_dispatcher.h
index d2b3f1aa95953f5545e1b2755aceaeb6e66a840c..8e3392bf5fa468c4390706994b12691b29a34d72 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,12 @@ class SerializedScriptValue;
}
// Handle the indexed db related communication for this entire renderer.
-class IndexedDBDispatcher : public IPC::Channel::Listener {
+class 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(
@@ -185,13 +186,47 @@ class IndexedDBDispatcher : public IPC::Channel::Listener {
void OnComplete(int32 transaction_id);
void OnVersionChange(int32 database_id, const string16& newVersion);
+ // This class facilitates mapping callback ids specified in incoming IPC
+ // messages to threads. It:
+ // * Retrieves process-unique ids for each stored WebIDBCallbacks object. The
+ // browser process includes these ids in messages sent back to us.
+ // * Registers incoming transaction and database callback 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.
+ template<class CallbackType>
+ class CallbackIDMap {
+ public:
+ CallbackIDMap(IndexedDBMessageFilter* filter) : filter_(filter) {
+ }
+ void AddWithID(CallbackType* callbacks, int32 id) {
+ filter_->NotifyAddWithIDForType(id, callbacks);
+ map_.AddWithID(callbacks, id);
+ }
+ int32 Add(CallbackType* callbacks) {
+ int id = filter_->GetUniqueID();
+ map_.AddWithID(callbacks, id);
+ return id;
+ }
+ void Remove(int32 id) {
+ filter_->RemoveForType(id, (CallbackType*)NULL);
+ map_.Remove(id);
+ }
+ CallbackType* Lookup(int32 id) {
+ return map_.Lookup(id);
+ }
+ private:
+ // The filter is alive for the life of the process, nothing deletes it.
+ IndexedDBMessageFilter* filter_;
+ IDMap<CallbackType, 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>
+ CallbackIDMap<WebKit::WebIDBCallbacks> pending_callbacks_;
+ CallbackIDMap<WebKit::WebIDBTransactionCallbacks>
pending_transaction_callbacks_;
- IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer>
- pending_database_callbacks_;
+ CallbackIDMap<WebKit::WebIDBDatabaseCallbacks> pending_database_callbacks_;
// Map from cursor id to RendererWebIDBCursorImpl.
std::map<int32, RendererWebIDBCursorImpl*> cursors_;

Powered by Google App Engine
This is Rietveld 408576698