summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorandreip@chromium.org <andreip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 16:05:02 +0000
committerandreip@chromium.org <andreip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 16:05:02 +0000
commit1f79401611f73ac332233ce35ef1c29b7c7af0c2 (patch)
tree93247f538a34e9d2ba7d6472599321869a051309 /chrome/browser
parent7de5b825b9c3baacaa038f3f1e6c7c45bdabad8e (diff)
downloadchromium_src-1f79401611f73ac332233ce35ef1c29b7c7af0c2.zip
chromium_src-1f79401611f73ac332233ce35ef1c29b7c7af0c2.tar.gz
chromium_src-1f79401611f73ac332233ce35ef1c29b7c7af0c2.tar.bz2
Add transaction coordinator. Allow idle transactions to be aborted when their parent JS context finishes executing.
This change depends on the following WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=44101 Review URL: http://codereview.chromium.org/3165026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_callbacks.h23
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc93
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h24
3 files changed, 139 insertions, 1 deletions
diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.h b/chrome/browser/in_process_webkit/indexed_db_callbacks.h
index 5421fc6..e726e3a 100644
--- a/chrome/browser/in_process_webkit/indexed_db_callbacks.h
+++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.h
@@ -15,6 +15,7 @@
#include "chrome/common/serialized_script_value.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBCursor.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBTransactionCallbacks.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h"
// Template magic to figure out what message to send to the renderer based on
@@ -158,5 +159,27 @@ class IndexedDBCallbacks<void> : public IndexedDBCallbacksBase {
DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
};
+class IndexedDBTransactionCallbacks
+ : public WebKit::WebIDBTransactionCallbacks {
+public:
+ IndexedDBTransactionCallbacks(
+ IndexedDBDispatcherHost* dispatcher_host, int transaction_id)
+ : dispatcher_host_(dispatcher_host), transaction_id_(transaction_id) {
+ }
+
+ virtual void onAbort() {
+ dispatcher_host_->Send(new ViewMsg_IDBTransactionCallbacksAbort(
+ transaction_id_));
+ }
+
+ virtual int id() const {
+ return transaction_id_;
+ }
+
+private:
+ int transaction_id_;
+ scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
+};
+
#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_
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 9603530..d0af866 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
@@ -20,7 +20,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::WebIDBCursor;
@@ -30,8 +32,10 @@ using WebKit::WebIDBIndex;
using WebKit::WebIDBKey;
using WebKit::WebIDBKeyRange;
using WebKit::WebIDBObjectStore;
+using WebKit::WebIDBTransaction;
using WebKit::WebSecurityOrigin;
using WebKit::WebSerializedScriptValue;
+using WebKit::WebVector;
IndexedDBDispatcherHost::IndexedDBDispatcherHost(
IPC::Message::Sender* sender, WebKitContext* webkit_context)
@@ -45,6 +49,8 @@ IndexedDBDispatcherHost::IndexedDBDispatcherHost(
new ObjectStoreDispatcherHost(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(cursor_dispatcher_host_(
new CursorDispatcherHost(this))),
+ ALLOW_THIS_IN_INITIALIZER_LIST(transaction_dispatcher_host_(
+ new TransactionDispatcherHost(this))),
process_handle_(0) {
DCHECK(sender_);
DCHECK(webkit_context_.get());
@@ -92,6 +98,7 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) {
case ViewHostMsg_IDBCursorKey::ID:
case ViewHostMsg_IDBCursorValue::ID:
case ViewHostMsg_IDBFactoryOpen::ID:
+ case ViewHostMsg_IDBFactoryAbortPendingTransactions::ID:
case ViewHostMsg_IDBDatabaseName::ID:
case ViewHostMsg_IDBDatabaseDescription::ID:
case ViewHostMsg_IDBDatabaseVersion::ID:
@@ -99,6 +106,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:
@@ -115,6 +123,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;
@@ -159,7 +168,8 @@ void IndexedDBDispatcherHost::OnMessageReceivedWebKit(
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) ||
- cursor_dispatcher_host_->OnMessageReceived(message, &msg_is_ok);
+ cursor_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
+ transaction_dispatcher_host_->OnMessageReceived(message, &msg_is_ok);
if (!handled) {
handled = true;
@@ -167,6 +177,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()
}
@@ -194,6 +206,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_
@@ -206,6 +223,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.
//
@@ -277,6 +302,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()
@@ -368,6 +395,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,
@@ -615,6 +667,7 @@ bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived(
return handled;
}
+
void IndexedDBDispatcherHost::CursorDispatcherHost::Send(
IPC::Message* message) {
// The macro magic in OnMessageReceived requires this to link, but it should
@@ -682,3 +735,41 @@ void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
parent_->DestroyObject(
&map_, object_id, ViewHostMsg_IDBCursorDestroyed::ID);
}
+
+//////////////////////////////////////////////////////////////////////
+// IndexedDBDispatcherHost::TransactionDispatcherHost
+//
+
+IndexedDBDispatcherHost::TransactionDispatcherHost::TransactionDispatcherHost(
+ IndexedDBDispatcherHost* parent)
+ : parent_(parent) {
+}
+
+IndexedDBDispatcherHost::
+ TransactionDispatcherHost::~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);
+}
diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
index ff0fad2..ed3357e 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
@@ -25,6 +25,7 @@ class WebIDBCursor;
class WebIDBDatabase;
class WebIDBIndex;
class WebIDBObjectStore;
+class WebIDBTransaction;
}
// Handles all IndexedDB related messages from a particular renderer process.
@@ -60,6 +61,7 @@ class IndexedDBDispatcherHost
int32 Add(WebKit::WebIDBDatabase* idb_database);
int32 Add(WebKit::WebIDBIndex* idb_index);
int32 Add(WebKit::WebIDBObjectStore* idb_object_store);
+ void Add(WebKit::WebIDBTransaction* idb_transaction);
private:
friend class base::RefCountedThreadSafe<IndexedDBDispatcherHost>;
@@ -69,6 +71,7 @@ class IndexedDBDispatcherHost
// below.
void OnMessageReceivedWebKit(const IPC::Message& message);
void OnIDBFactoryOpen(const ViewHostMsg_IDBFactoryOpen_Params& p);
+ void OnIDBFactoryAbortPendingTransactions(const std::vector<int32>& ids);
// Helper templates.
template <class ReturnType>
@@ -103,6 +106,9 @@ class IndexedDBDispatcherHost
IPC::Message* reply_msg);
void OnRemoveObjectStore(int32 idb_database_id, int32 response_id,
const string16& name);
+ void OnTransaction(int32 idb_database_id,
+ const std::vector<string16>& names,
+ int32 mode, int32 timeout, IPC::Message* reply_msg);
void OnDestroyed(int32 idb_database_id);
IndexedDBDispatcherHost* parent_;
@@ -174,6 +180,22 @@ class IndexedDBDispatcherHost
IndexedDBDispatcherHost* parent_;
IDMap<WebKit::WebIDBCursor, IDMapOwnPointer> map_;
};
+
+ class TransactionDispatcherHost {
+ public:
+ explicit TransactionDispatcherHost(IndexedDBDispatcherHost* parent);
+ ~TransactionDispatcherHost();
+
+ bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
+ void Send(IPC::Message* message);
+
+ // TODO: add the rest of the transaction methods.
+ void OnDestroyed(int32 idb_transaction_id);
+
+ IndexedDBDispatcherHost* parent_;
+ IDMap<WebKit::WebIDBTransaction, IDMapOwnPointer> map_;
+ };
+
// Only use on the IO thread.
IPC::Message::Sender* sender_;
@@ -185,6 +207,8 @@ class IndexedDBDispatcherHost
scoped_ptr<IndexDispatcherHost> index_dispatcher_host_;
scoped_ptr<ObjectStoreDispatcherHost> object_store_dispatcher_host_;
scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_;
+ scoped_ptr<TransactionDispatcherHost> transaction_dispatcher_host_;
+
// If we get a corrupt message from a renderer, we need to kill it using this
// handle.