IndexedDB API cleanup.

Fix Chromium impls and calls to WebIDB* interfaces to match
current WebKit implementation.  No change in behavior, just
fewer wrapped function calls.

R=dgrogan@chromium.org,darin@chromium.org

Review URL: http://codereview.chromium.org/7692006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97687 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/in_process_webkit/indexed_db_callbacks.cc b/content/browser/in_process_webkit/indexed_db_callbacks.cc
index 24b2b41..24a7799 100644
--- a/content/browser/in_process_webkit/indexed_db_callbacks.cc
+++ b/content/browser/in_process_webkit/indexed_db_callbacks.cc
@@ -25,21 +25,6 @@
   dispatcher_host_->Send(new IndexedDBMsg_CallbacksBlocked(response_id_));
 }
 
-void IndexedDBCallbacks<WebKit::WebIDBDatabase>::onSuccess(
-    WebKit::WebIDBDatabase* idb_object) {
-  int32 object_id = dispatcher_host()->Add(idb_object, origin_url());
-  dispatcher_host()->Send(
-      new IndexedDBMsg_CallbacksSuccessIDBDatabase(response_id(), object_id));
-}
-
-void IndexedDBCallbacks<WebKit::WebIDBTransaction>::onSuccess(
-    WebKit::WebIDBTransaction* idb_object) {
-  int32 object_id = dispatcher_host()->Add(idb_object, origin_url());
-  dispatcher_host()->Send(
-      new IndexedDBMsg_CallbacksSuccessIDBTransaction(response_id(),
-                                                      object_id));
-}
-
 void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess(
     WebKit::WebIDBCursor* idb_object) {
   int32 object_id = dispatcher_host()->Add(idb_object);
diff --git a/content/browser/in_process_webkit/indexed_db_callbacks.h b/content/browser/in_process_webkit/indexed_db_callbacks.h
index fc9ff81..df60ec0 100644
--- a/content/browser/in_process_webkit/indexed_db_callbacks.h
+++ b/content/browser/in_process_webkit/indexed_db_callbacks.h
@@ -16,14 +16,17 @@
 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h"
 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
 
-class IndexedDBMsg_CallbacksSuccessIDBIndex;
+class IndexedDBMsg_CallbacksSuccessIDBDatabase;
 class IndexedDBMsg_CallbacksSuccessIDBTransaction;
 
 // Template magic to figure out what message to send to the renderer based on
 // which (overloaded) onSuccess method we expect to be called.
 template <class Type> struct WebIDBToMsgHelper { };
-template <> struct WebIDBToMsgHelper<WebKit::WebIDBIndex> {
-  typedef IndexedDBMsg_CallbacksSuccessIDBIndex MsgType;
+template <> struct WebIDBToMsgHelper<WebKit::WebIDBDatabase> {
+  typedef IndexedDBMsg_CallbacksSuccessIDBDatabase MsgType;
+};
+template <> struct WebIDBToMsgHelper<WebKit::WebIDBTransaction> {
+  typedef IndexedDBMsg_CallbacksSuccessIDBTransaction MsgType;
 };
 
 // The code the following two classes share.
@@ -55,54 +58,20 @@
 class IndexedDBCallbacks : public IndexedDBCallbacksBase {
  public:
   IndexedDBCallbacks(
-      IndexedDBDispatcherHost* dispatcher_host, int32 response_id)
-      : IndexedDBCallbacksBase(dispatcher_host, response_id) { }
+      IndexedDBDispatcherHost* dispatcher_host, int32 response_id,
+      const GURL& origin_url)
+      : IndexedDBCallbacksBase(dispatcher_host, response_id),
+        origin_url_(origin_url) {
+  }
 
   virtual void onSuccess(WebObjectType* idb_object) {
-    int32 object_id = dispatcher_host()->Add(idb_object);
+    int32 object_id = dispatcher_host()->Add(idb_object, origin_url_);
     dispatcher_host()->Send(
         new typename WebIDBToMsgHelper<WebObjectType>::MsgType(response_id(),
                                                                object_id));
   }
 
  private:
-  DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
-};
-
-template <>
-class IndexedDBCallbacks<WebKit::WebIDBTransaction>
-    : public IndexedDBCallbacksBase {
- public:
-  IndexedDBCallbacks(
-      IndexedDBDispatcherHost* dispatcher_host, int32 response_id,
-      const GURL& origin_url)
-      : IndexedDBCallbacksBase(dispatcher_host, response_id),
-        origin_url_(origin_url) {
-  }
-
-  virtual void onSuccess(WebKit::WebIDBTransaction* idb_object);
-  const GURL& origin_url() const { return origin_url_; }
-
- private:
-  const GURL& origin_url_;
-  DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
-};
-
-template <>
-class IndexedDBCallbacks<WebKit::WebIDBDatabase>
-    : public IndexedDBCallbacksBase {
- public:
-  IndexedDBCallbacks(
-      IndexedDBDispatcherHost* dispatcher_host, int32 response_id,
-      const GURL& origin_url)
-      : IndexedDBCallbacksBase(dispatcher_host, response_id),
-        origin_url_(origin_url) {
-  }
-
-  virtual void onSuccess(WebKit::WebIDBDatabase* idb_object);
-  const GURL& origin_url() const { return origin_url_; }
-
- private:
   GURL origin_url_;
   DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
 };
diff --git a/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc b/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc
index 01b152f..bf14813 100644
--- a/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc
+++ b/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc
@@ -431,7 +431,6 @@
     int32 idb_database_id,
     const std::vector<string16>& names,
     int32 mode,
-    int32 timeout,
     int32* idb_transaction_id,
     WebKit::WebExceptionCode* ec) {
   WebIDBDatabase* database = parent_->GetOrTerminateProcess(
@@ -447,7 +446,7 @@
 
   *ec = 0;
   WebIDBTransaction* transaction = database->transaction(
-      object_stores, mode, timeout, *ec);
+      object_stores, mode, *ec);
   DCHECK(!transaction != !*ec);
   *idb_transaction_id =
       *ec ? 0 : parent_->Add(transaction, database_url_map_[idb_database_id]);
@@ -917,18 +916,12 @@
 
 void IndexedDBDispatcherHost::CursorDispatcherHost::OnValue(
     int32 object_id,
-    SerializedScriptValue* script_value,
-    IndexedDBKey* key) {
+    SerializedScriptValue* script_value) {
   WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_, object_id);
   if (!idb_cursor)
     return;
 
-  WebSerializedScriptValue temp_script_value;
-  WebIDBKey temp_key;
-  idb_cursor->value(temp_script_value, temp_key);
-
-  *script_value = SerializedScriptValue(temp_script_value);
-  *key = IndexedDBKey(temp_key);
+  *script_value = SerializedScriptValue(idb_cursor->value());
 }
 
 void IndexedDBDispatcherHost::CursorDispatcherHost::OnUpdate(
@@ -971,8 +964,7 @@
     return;
 
   *ec = 0;
-  // TODO(jorlow): This should be delete.
-  idb_cursor->remove(
+  idb_cursor->deleteFunction(
       new IndexedDBCallbacks<WebSerializedScriptValue>(parent_, response_id), *ec);
 }
 
diff --git a/content/browser/in_process_webkit/indexed_db_dispatcher_host.h b/content/browser/in_process_webkit/indexed_db_dispatcher_host.h
index dd0737d..ae77824 100644
--- a/content/browser/in_process_webkit/indexed_db_dispatcher_host.h
+++ b/content/browser/in_process_webkit/indexed_db_dispatcher_host.h
@@ -112,7 +112,7 @@
                       WebKit::WebExceptionCode* ec);
     void OnTransaction(int32 idb_database_id,
                        const std::vector<string16>& names,
-                       int32 mode, int32 timeout,
+                       int32 mode,
                        int32* idb_transaction_id,
                        WebKit::WebExceptionCode* ec);
     void OnOpen(int32 idb_database_id, int32 response_id);
@@ -218,8 +218,7 @@
     void OnKey(int32 idb_object_store_id, IndexedDBKey* key);
     void OnPrimaryKey(int32 idb_object_store_id, IndexedDBKey* primary_key);
     void OnValue(int32 idb_object_store_id,
-                 SerializedScriptValue* script_value,
-                 IndexedDBKey* key);
+                 SerializedScriptValue* script_value);
     void OnUpdate(int32 idb_object_store_id,
                   int32 response_id,
                   const SerializedScriptValue& value,
diff --git a/content/common/indexed_db_messages.h b/content/common/indexed_db_messages.h
index a8ca5810..b27fb53 100644
--- a/content/common/indexed_db_messages.h
+++ b/content/common/indexed_db_messages.h
@@ -142,9 +142,6 @@
 IPC_MESSAGE_CONTROL2(IndexedDBMsg_CallbacksSuccessIndexedDBKey,
                      int32 /* response_id */,
                      IndexedDBKey /* indexed_db_key */)
-IPC_MESSAGE_CONTROL2(IndexedDBMsg_CallbacksSuccessIDBIndex,
-                     int32 /* response_id */,
-                     int32 /* idb_index_id */)
 IPC_MESSAGE_CONTROL2(IndexedDBMsg_CallbacksSuccessIDBTransaction,
                      int32 /* response_id */,
                      int32 /* idb_transaction_id */)
@@ -186,10 +183,9 @@
                             IndexedDBKey /* primary_key */)
 
 // WebIDBCursor::value() message.
-IPC_SYNC_MESSAGE_CONTROL1_2(IndexedDBHostMsg_CursorValue,
+IPC_SYNC_MESSAGE_CONTROL1_1(IndexedDBHostMsg_CursorValue,
                             int32, /* idb_cursor_id */
-                            SerializedScriptValue, /* script_value */
-                            IndexedDBKey /* key */)
+                            SerializedScriptValue /* script_value */)
 
 // WebIDBCursor::update() message.
 IPC_SYNC_MESSAGE_CONTROL3_1(IndexedDBHostMsg_CursorUpdate,
@@ -259,11 +255,10 @@
 // temporary ID and keep a map in the browser process of real
 // IDs to temporary IDs. We can then update the transaction
 // to its real ID asynchronously.
-IPC_SYNC_MESSAGE_CONTROL4_2(IndexedDBHostMsg_DatabaseTransaction,
+IPC_SYNC_MESSAGE_CONTROL3_2(IndexedDBHostMsg_DatabaseTransaction,
                             int32, /* idb_database_id */
                             std::vector<string16>, /* object_stores */
                             int32, /* mode */
-                            int32, /* timeout */
                             int32, /* idb_transaction_id */
                             WebKit::WebExceptionCode /* ec */)
 
diff --git a/content/renderer/indexed_db_dispatcher.cc b/content/renderer/indexed_db_dispatcher.cc
index cf04a7e8..f137a83 100644
--- a/content/renderer/indexed_db_dispatcher.cc
+++ b/content/renderer/indexed_db_dispatcher.cc
@@ -43,8 +43,6 @@
                         OnSuccessOpenCursor)
     IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase,
                         OnSuccessIDBDatabase)
-    IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBIndex,
-                        OnSuccessIDBIndex)
     IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey,
                         OnSuccessIndexedDBKey)
     IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction,
@@ -388,13 +386,6 @@
   pending_callbacks_.Remove(response_id);
 }
 
-void IndexedDBDispatcher::OnSuccessIDBIndex(int32 response_id,
-                                            int32 object_id) {
-  WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
-  callbacks->onSuccess(new RendererWebIDBIndexImpl(object_id));
-  pending_callbacks_.Remove(response_id);
-}
-
 void IndexedDBDispatcher::OnSuccessSerializedScriptValue(
     int32 response_id, const SerializedScriptValue& value) {
   WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
diff --git a/content/renderer/indexed_db_dispatcher.h b/content/renderer/indexed_db_dispatcher.h
index 3839ff7..59d774b 100644
--- a/content/renderer/indexed_db_dispatcher.h
+++ b/content/renderer/indexed_db_dispatcher.h
@@ -151,7 +151,6 @@
   void OnSuccessIDBDatabase(int32 response_id, int32 object_id);
   void OnSuccessIndexedDBKey(int32 response_id, const IndexedDBKey& key);
   void OnSuccessIDBTransaction(int32 response_id, int32 object_id);
-  void OnSuccessIDBIndex(int32 response_id, int32 object_id);
   void OnSuccessOpenCursor(int32 response_id, int32 object_id);
   void OnSuccessSerializedScriptValue(int32 response_id,
                                       const SerializedScriptValue& value);
diff --git a/content/renderer/renderer_webidbcursor_impl.cc b/content/renderer/renderer_webidbcursor_impl.cc
index 21332e1..2e20cd5 100644
--- a/content/renderer/renderer_webidbcursor_impl.cc
+++ b/content/renderer/renderer_webidbcursor_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -47,18 +47,11 @@
   return primaryKey;
 }
 
-void RendererWebIDBCursorImpl::value(
-    WebSerializedScriptValue& webScriptValue,
-    WebIDBKey& webKey) const {
+WebSerializedScriptValue RendererWebIDBCursorImpl::value() const {
   SerializedScriptValue scriptValue;
-  IndexedDBKey key;
   RenderThread::current()->Send(
-      new IndexedDBHostMsg_CursorValue(idb_cursor_id_, &scriptValue,
-                                       &key));
-  // Only one or the other type should have been "returned" to us.
-  DCHECK(scriptValue.is_null() != (key.type() == WebIDBKey::InvalidType));
-  webScriptValue = scriptValue;
-  webKey = key;
+      new IndexedDBHostMsg_CursorValue(idb_cursor_id_, &scriptValue));
+  return scriptValue;
 }
 
 void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value,
@@ -79,8 +72,8 @@
                                        idb_cursor_id_, &ec);
 }
 
-void RendererWebIDBCursorImpl::remove(WebIDBCallbacks* callbacks,
-                                      WebExceptionCode& ec) {
+void RendererWebIDBCursorImpl::deleteFunction(WebIDBCallbacks* callbacks,
+                                              WebExceptionCode& ec) {
   IndexedDBDispatcher* dispatcher =
       RenderThread::current()->indexed_db_dispatcher();
   dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec);
diff --git a/content/renderer/renderer_webidbcursor_impl.h b/content/renderer/renderer_webidbcursor_impl.h
index 147345f..d7f4541 100644
--- a/content/renderer/renderer_webidbcursor_impl.h
+++ b/content/renderer/renderer_webidbcursor_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -21,16 +21,15 @@
   virtual unsigned short direction() const;
   virtual WebKit::WebIDBKey key() const;
   virtual WebKit::WebIDBKey primaryKey() const;
-  virtual void value(WebKit::WebSerializedScriptValue&,
-                     WebKit::WebIDBKey&) const;
+  virtual WebKit::WebSerializedScriptValue value() const;
   virtual void update(const WebKit::WebSerializedScriptValue& value,
                       WebKit::WebIDBCallbacks* callback,
                       WebKit::WebExceptionCode& ec);
   virtual void continueFunction(const WebKit::WebIDBKey& key,
                                 WebKit::WebIDBCallbacks* callback,
                                 WebKit::WebExceptionCode& ec);
-  virtual void remove(WebKit::WebIDBCallbacks* callback,
-                      WebKit::WebExceptionCode& ec);
+  virtual void deleteFunction(WebKit::WebIDBCallbacks* callback,
+                              WebKit::WebExceptionCode& ec);
 
  private:
   int32 idb_cursor_id_;
diff --git a/content/renderer/renderer_webidbdatabase_impl.cc b/content/renderer/renderer_webidbdatabase_impl.cc
index 1b0aed5..4709165 100644
--- a/content/renderer/renderer_webidbdatabase_impl.cc
+++ b/content/renderer/renderer_webidbdatabase_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -105,7 +105,6 @@
 WebKit::WebIDBTransaction* RendererWebIDBDatabaseImpl::transaction(
     const WebDOMStringList& names,
     unsigned short mode,
-    unsigned long timeout,
     WebExceptionCode& ec) {
   std::vector<string16> object_stores;
   object_stores.reserve(names.length());
@@ -116,7 +115,7 @@
   RenderThread::current()->Send(
       new IndexedDBHostMsg_DatabaseTransaction(
           idb_database_id_, object_stores, mode,
-          timeout, &transaction_id, &ec));
+          &transaction_id, &ec));
   if (!transaction_id)
     return NULL;
   return new RendererWebIDBTransactionImpl(transaction_id);
diff --git a/content/renderer/renderer_webidbdatabase_impl.h b/content/renderer/renderer_webidbdatabase_impl.h
index d87c4b0..524f05d41 100644
--- a/content/renderer/renderer_webidbdatabase_impl.h
+++ b/content/renderer/renderer_webidbdatabase_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -41,7 +41,7 @@
       WebKit::WebExceptionCode& ec);
   virtual WebKit::WebIDBTransaction* transaction(
       const WebKit::WebDOMStringList& names,
-      unsigned short mode, unsigned long timeout,
+      unsigned short mode,
       WebKit::WebExceptionCode& ec);
   virtual void close();
   virtual void open(WebKit::WebIDBDatabaseCallbacks*);