diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-14 14:29:40 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-14 14:29:40 +0000 |
commit | 5c71640cdf15c2782b8331e9e2623da50ec5d102 (patch) | |
tree | da7cf7505bb23c3e206bdcaab66f064d3edc5936 /chrome/browser/in_process_webkit | |
parent | 699f2246bf56e1aadf31e1edd6c5aef9b4b39638 (diff) | |
download | chromium_src-5c71640cdf15c2782b8331e9e2623da50ec5d102.zip chromium_src-5c71640cdf15c2782b8331e9e2623da50ec5d102.tar.gz chromium_src-5c71640cdf15c2782b8331e9e2623da50ec5d102.tar.bz2 |
The Chrome half of implementing get/put/remove for object stores (https://bugs.webkit.org/show_bug.cgi?id=41250).
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/2830030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/in_process_webkit')
3 files changed, 119 insertions, 10 deletions
diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.h b/chrome/browser/in_process_webkit/indexed_db_callbacks.h index 56c5fd5..126a8f6 100644 --- a/chrome/browser/in_process_webkit/indexed_db_callbacks.h +++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.h @@ -9,7 +9,9 @@ #include "base/logging.h" #include "base/ref_counted.h" #include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h" +#include "chrome/common/indexed_db_key.h" #include "chrome/common/render_messages.h" +#include "chrome/common/serialized_script_value.h" #include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h" @@ -17,13 +19,13 @@ // which (overloaded) onSuccess method we expect to be called. template <class Type> struct WebIDBToMsgHelper { }; template <> struct WebIDBToMsgHelper<WebKit::WebIDBDatabase> { - typedef ViewMsg_IDBCallbackSuccessCreateIDBDatabase MsgType; + typedef ViewMsg_IDBCallbacksSuccessIDBDatabase MsgType; }; template <> struct WebIDBToMsgHelper<WebKit::WebIDBIndex> { - typedef ViewMsg_IDBCallbackSuccessCreateIDBIndex MsgType; + typedef ViewMsg_IDBCallbacksSuccessIDBIndex MsgType; }; template <> struct WebIDBToMsgHelper<WebKit::WebIDBObjectStore> { - typedef ViewMsg_IDBCallbackSuccessCreateIDBObjectStore MsgType; + typedef ViewMsg_IDBCallbacksSuccessIDBObjectStore MsgType; }; // The code the following two classes share. @@ -34,7 +36,7 @@ class IndexedDBCallbacksBase : public WebKit::WebIDBCallbacks { : dispatcher_host_(dispatcher_host), response_id_(response_id) { } virtual void onError(const WebKit::WebIDBDatabaseError& error) { - dispatcher_host_->Send(new ViewMsg_IDBCallbackError( + dispatcher_host_->Send(new ViewMsg_IDBCallbacksError( response_id_, error.code(), error.message())); } @@ -70,6 +72,48 @@ class IndexedDBCallbacks : public IndexedDBCallbacksBase { DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); }; +// WebIDBKey is implemented in WebKit as opposed to being an interface Chromium +// implements. Thus we pass a const ___& version and thus we need this +// specialization. +template <> +class IndexedDBCallbacks<WebKit::WebIDBKey> + : public IndexedDBCallbacksBase { + public: + IndexedDBCallbacks( + IndexedDBDispatcherHost* dispatcher_host, int32 response_id) + : IndexedDBCallbacksBase(dispatcher_host, response_id) { } + + virtual void onSuccess(const WebKit::WebIDBKey& value) { + dispatcher_host()->Send( + new ViewMsg_IDBCallbacksSuccessIndexedDBKey( + response_id(), IndexedDBKey(value))); + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); +}; + +// WebSerializedScriptValue is implemented in WebKit as opposed to being an +// interface Chromium implements. Thus we pass a const ___& version and thus +// we need this specialization. +template <> +class IndexedDBCallbacks<WebKit::WebSerializedScriptValue> + : public IndexedDBCallbacksBase { + public: + IndexedDBCallbacks( + IndexedDBDispatcherHost* dispatcher_host, int32 response_id) + : IndexedDBCallbacksBase(dispatcher_host, response_id) { } + + virtual void onSuccess(const WebKit::WebSerializedScriptValue& value) { + dispatcher_host()->Send( + new ViewMsg_IDBCallbacksSuccessSerializedScriptValue( + response_id(), SerializedScriptValue(value))); + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); +}; + // A WebIDBCallbacks implementation that doesn't return a result. template <> class IndexedDBCallbacks<void> : public IndexedDBCallbacksBase { @@ -80,7 +124,7 @@ class IndexedDBCallbacks<void> : public IndexedDBCallbacksBase { virtual void onSuccess() { dispatcher_host()->Send( - new ViewMsg_IDBCallbackSuccessReturnNull(response_id())); + new ViewMsg_IDBCallbacksSuccessNull(response_id())); } private: 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 8c1b69e..f6523a1 100644 --- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc +++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc @@ -11,6 +11,7 @@ #include "chrome/browser/renderer_host/resource_message_filter.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" +#include "chrome/common/serialized_script_value.h" #include "third_party/WebKit/WebKit/chromium/public/WebDOMStringList.h" #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h" @@ -23,8 +24,10 @@ using WebKit::WebDOMStringList; using WebKit::WebIDBDatabase; using WebKit::WebIDBDatabaseError; using WebKit::WebIDBIndex; +using WebKit::WebIDBKey; using WebKit::WebIDBObjectStore; using WebKit::WebSecurityOrigin; +using WebKit::WebSerializedScriptValue; IndexedDBDispatcherHost::IndexedDBDispatcherHost( IPC::Message::Sender* sender, WebKitContext* webkit_context) @@ -82,8 +85,10 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { case ViewHostMsg_IDBDatabaseName::ID: case ViewHostMsg_IDBDatabaseDescription::ID: case ViewHostMsg_IDBDatabaseVersion::ID: - case ViewHostMsg_IDBDatabaseCreateObjectStore::ID: case ViewHostMsg_IDBDatabaseObjectStores::ID: + case ViewHostMsg_IDBDatabaseCreateObjectStore::ID: + case ViewHostMsg_IDBDatabaseObjectStore::ID: + case ViewHostMsg_IDBDatabaseRemoveObjectStore::ID: case ViewHostMsg_IDBDatabaseDestroyed::ID: case ViewHostMsg_IDBIndexName::ID: case ViewHostMsg_IDBIndexKeyPath::ID: @@ -91,6 +96,13 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { case ViewHostMsg_IDBIndexDestroyed::ID: case ViewHostMsg_IDBObjectStoreName::ID: case ViewHostMsg_IDBObjectStoreKeyPath::ID: + case ViewHostMsg_IDBObjectStoreIndexNames::ID: + case ViewHostMsg_IDBObjectStoreGet::ID: + case ViewHostMsg_IDBObjectStorePut::ID: + case ViewHostMsg_IDBObjectStoreRemove::ID: + case ViewHostMsg_IDBObjectStoreCreateIndex::ID: + case ViewHostMsg_IDBObjectStoreIndex::ID: + case ViewHostMsg_IDBObjectStoreRemoveIndex::ID: case ViewHostMsg_IDBObjectStoreDestroyed::ID: break; default: @@ -309,7 +321,7 @@ void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( if (!idb_database) return; idb_database->createObjectStore( - params.name_, params.keypath_, params.auto_increment_, + params.name_, params.key_path_, params.auto_increment_, new IndexedDBCallbacks<WebIDBObjectStore>(parent_, params.response_id_)); } @@ -390,7 +402,7 @@ void IndexedDBDispatcherHost::IndexDispatcherHost::OnName( void IndexedDBDispatcherHost::IndexDispatcherHost::OnKeyPath( int32 object_id, IPC::Message* reply_msg) { - parent_->SyncGetter<string16, ViewHostMsg_IDBIndexKeyPath>( + parent_->SyncGetter<NullableString16, ViewHostMsg_IDBIndexKeyPath>( &map_, object_id, reply_msg, &WebIDBIndex::keyPath); } @@ -426,6 +438,14 @@ bool IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnMessageReceived( IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreName, OnName) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreKeyPath, OnKeyPath) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreIndexNames, + OnIndexNames) + IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreGet, OnGet); + IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStorePut, OnPut); + IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreRemove, OnRemove); + IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreCreateIndex, OnCreateIndex); + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreIndex, OnIndex); + IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreRemoveIndex, OnRemoveIndex); IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreDestroyed, OnDestroyed) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -448,7 +468,7 @@ void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnName( void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnKeyPath( int32 object_id, IPC::Message* reply_msg) { - parent_->SyncGetter<string16, ViewHostMsg_IDBObjectStoreKeyPath>( + parent_->SyncGetter<NullableString16, ViewHostMsg_IDBObjectStoreKeyPath>( &map_, object_id, reply_msg, &WebIDBObjectStore::keyPath); } @@ -470,6 +490,42 @@ void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndexNames( parent_->Send(reply_msg); } +void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnGet( + int idb_object_store_id, int32 response_id, const IndexedDBKey& key) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess( + &map_, idb_object_store_id, NULL, ViewHostMsg_IDBObjectStoreGet::ID); + if (!idb_object_store) + return; + idb_object_store->get(key, new IndexedDBCallbacks<WebSerializedScriptValue>( + parent_, response_id)); +} + +void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnPut( + int idb_object_store_id, int32 response_id, + const SerializedScriptValue& value, const IndexedDBKey& key, + bool add_only) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess( + &map_, idb_object_store_id, NULL, ViewHostMsg_IDBObjectStorePut::ID); + if (!idb_object_store) + return; + idb_object_store->put( + value, key, add_only, new IndexedDBCallbacks<WebIDBKey>( + parent_, response_id)); +} + +void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnRemove( + int idb_object_store_id, int32 response_id, const IndexedDBKey& key) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess( + &map_, idb_object_store_id, NULL, ViewHostMsg_IDBObjectStoreRemove::ID); + if (!idb_object_store) + return; + idb_object_store->remove(key, new IndexedDBCallbacks<void>(parent_, + response_id)); +} + void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnCreateIndex( const ViewHostMsg_IDBObjectStoreCreateIndex_Params& params) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); @@ -479,7 +535,7 @@ void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnCreateIndex( if (!idb_object_store) return; idb_object_store->createIndex( - params.name_, params.keypath_, params.unique_, + params.name_, params.key_path_, params.unique_, new IndexedDBCallbacks<WebIDBIndex>(parent_, params.response_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 368e489..cc132ae 100644 --- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h +++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h @@ -12,6 +12,8 @@ #include "chrome/browser/in_process_webkit/webkit_context.h" #include "ipc/ipc_message.h" +class IndexedDBKey; +class SerializedScriptValue; struct ViewHostMsg_IndexedDatabaseOpen_Params; struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params; struct ViewHostMsg_IDBObjectStoreCreateIndex_Params; @@ -131,6 +133,13 @@ class IndexedDBDispatcherHost void OnName(int32 idb_object_store_id, IPC::Message* reply_msg); void OnKeyPath(int32 idb_object_store_id, IPC::Message* reply_msg); void OnIndexNames(int32 idb_object_store_id, IPC::Message* reply_msg); + void OnGet(int idb_object_store_id, int32 response_id, + const IndexedDBKey& key); + void OnPut(int idb_object_store_id, int32 response_id, + const SerializedScriptValue& value, const IndexedDBKey& key, + bool add_only); + void OnRemove(int idb_object_store_id, int32 response_id, + const IndexedDBKey& key); void OnCreateIndex( const ViewHostMsg_IDBObjectStoreCreateIndex_Params& params); void OnIndex(int32 idb_object_store_id, const string16& name, |