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

Unified Diff: chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc

Issue 3165026: [IndexedDB] Add transaction coordinator. (Closed)
Patch Set: Fix Jeremy's comments Created 10 years, 4 months 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: chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
index 3fd0714048aa1b1bed4ffe2eb9394e73810f692a..b9cdc9fddace69858646135781a79821929c9794 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
@@ -18,7 +18,9 @@
#include "third_party/WebKit/WebKit/chromium/public/WebIDBIndex.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBObjectStore.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBTransaction.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
using WebKit::WebDOMStringList;
using WebKit::WebIDBDatabase;
@@ -26,8 +28,10 @@ using WebKit::WebIDBDatabaseError;
using WebKit::WebIDBIndex;
using WebKit::WebIDBKey;
using WebKit::WebIDBObjectStore;
+using WebKit::WebIDBTransaction;
using WebKit::WebSecurityOrigin;
using WebKit::WebSerializedScriptValue;
+using WebKit::WebVector;
IndexedDBDispatcherHost::IndexedDBDispatcherHost(
IPC::Message::Sender* sender, WebKitContext* webkit_context)
@@ -39,6 +43,8 @@ IndexedDBDispatcherHost::IndexedDBDispatcherHost(
new IndexDispatcherHost(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(object_store_dispatcher_host_(
new ObjectStoreDispatcherHost(this))),
+ ALLOW_THIS_IN_INITIALIZER_LIST(transaction_dispatcher_host_(
+ new TransactionDispatcherHost(this))),
process_handle_(0) {
DCHECK(sender_);
DCHECK(webkit_context_.get());
@@ -82,6 +88,7 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) {
switch (message.type()) {
case ViewHostMsg_IDBFactoryOpen::ID:
+ case ViewHostMsg_IDBFactoryAbortPendingTransactions::ID:
case ViewHostMsg_IDBDatabaseName::ID:
case ViewHostMsg_IDBDatabaseDescription::ID:
case ViewHostMsg_IDBDatabaseVersion::ID:
@@ -89,6 +96,7 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) {
case ViewHostMsg_IDBDatabaseCreateObjectStore::ID:
case ViewHostMsg_IDBDatabaseObjectStore::ID:
case ViewHostMsg_IDBDatabaseRemoveObjectStore::ID:
+ case ViewHostMsg_IDBDatabaseTransaction::ID:
case ViewHostMsg_IDBDatabaseDestroyed::ID:
case ViewHostMsg_IDBIndexName::ID:
case ViewHostMsg_IDBIndexKeyPath::ID:
@@ -104,6 +112,7 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) {
case ViewHostMsg_IDBObjectStoreIndex::ID:
case ViewHostMsg_IDBObjectStoreRemoveIndex::ID:
case ViewHostMsg_IDBObjectStoreDestroyed::ID:
+ case ViewHostMsg_IDBTransactionDestroyed::ID:
break;
default:
return false;
@@ -147,7 +156,8 @@ void IndexedDBDispatcherHost::OnMessageReceivedWebKit(
bool handled =
database_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
index_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
- object_store_dispatcher_host_->OnMessageReceived(message, &msg_is_ok);
+ object_store_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
+ transaction_dispatcher_host_->OnMessageReceived(message, &msg_is_ok);
if (!handled) {
handled = true;
@@ -155,6 +165,8 @@ void IndexedDBDispatcherHost::OnMessageReceivedWebKit(
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, msg_is_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBFactoryOpen,
OnIDBFactoryOpen)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_IDBFactoryAbortPendingTransactions,
+ OnIDBFactoryAbortPendingTransactions)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
}
@@ -178,6 +190,11 @@ int32 IndexedDBDispatcherHost::Add(WebIDBObjectStore* idb_object_store) {
return object_store_dispatcher_host_->map_.Add(idb_object_store);
}
+void IndexedDBDispatcherHost::Add(WebIDBTransaction* idb_transaction) {
+ transaction_dispatcher_host_->map_.AddWithID(
+ idb_transaction, idb_transaction->id());
+}
+
void IndexedDBDispatcherHost::OnIDBFactoryOpen(
const ViewHostMsg_IDBFactoryOpen_Params& params) {
// TODO(jorlow): Check the content settings map and use params.routing_id_
@@ -190,6 +207,14 @@ void IndexedDBDispatcherHost::OnIDBFactoryOpen(
WebSecurityOrigin::createFromDatabaseIdentifier(params.origin_), NULL);
}
+void IndexedDBDispatcherHost::OnIDBFactoryAbortPendingTransactions(
+ const std::vector<int32>& ids) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+
+ WebVector<int32> pendingIDs = ids;
+ Context()->GetIDBFactory()->abortPendingTransactions(pendingIDs);
+}
+
//////////////////////////////////////////////////////////////////////
// Helper templates.
//
@@ -261,6 +286,8 @@ bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
OnObjectStore)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseRemoveObjectStore,
OnRemoveObjectStore)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseTransaction,
+ OnTransaction)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseDestroyed, OnDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -352,6 +379,31 @@ void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRemoveObjectStore(
name, new IndexedDBCallbacks<WebIDBObjectStore>(parent_, response_id));
}
+void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnTransaction(
+ int32 idb_database_id, const std::vector<string16>& names,
+ int32 mode, int32 timeout, IPC::Message* reply_msg) {
+ WebIDBDatabase* database = parent_->GetOrTerminateProcess(
+ &map_, idb_database_id, reply_msg,
+ ViewHostMsg_IDBDatabaseTransaction::ID);
+ if (!database)
+ return;
+
+ WebDOMStringList object_stores;
+ for (std::vector<string16>::const_iterator it = names.begin();
+ it != names.end(); ++it) {
+ object_stores.append(*it);
+ }
+
+ WebIDBTransaction* transaction = database->transaction(
+ object_stores, mode, timeout);
+ transaction->setCallbacks(
+ new IndexedDBTransactionCallbacks(parent_, transaction->id()));
+ parent_->Add(transaction);
+ ViewHostMsg_IDBDatabaseTransaction::WriteReplyParams(
+ reply_msg, transaction->id());
+ parent_->Send(reply_msg);
+}
+
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(&map_, object_id,
@@ -570,3 +622,41 @@ void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDestroyed(
parent_->DestroyObject(
&map_, object_id, ViewHostMsg_IDBObjectStoreDestroyed::ID);
}
+
+//////////////////////////////////////////////////////////////////////
+// IndexedDBDispatcherHost::TransactionDispatcherHost
+//
+
+IndexedDBDispatcherHost::TransactionDispatcherHost::TransactionDispatcherHost(
+ IndexedDBDispatcherHost* parent)
+ : parent_(parent) {
+}
+
+IndexedDBDispatcherHost::TransactionDispatcherHost::
jorlow 2010/08/19 13:05:34 I've been told to do the following in such cases:
+ ~TransactionDispatcherHost() {
+}
+
+bool IndexedDBDispatcherHost::TransactionDispatcherHost::OnMessageReceived(
+ const IPC::Message& message, bool* msg_is_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::TransactionDispatcherHost,
+ message, *msg_is_ok)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_IDBTransactionDestroyed, OnDestroyed)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void IndexedDBDispatcherHost::TransactionDispatcherHost::Send(
+ IPC::Message* message) {
+ // The macro magic in OnMessageReceived requires this to link, but it should
+ // never actually be called.
+ NOTREACHED();
+ parent_->Send(message);
+}
+
+void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed(
+ int32 object_id) {
+ parent_->DestroyObject(
+ &map_, object_id, ViewHostMsg_IDBTransactionDestroyed::ID);
+}

Powered by Google App Engine
This is Rietveld 408576698