Commit 61a875bc authored by jsbell@chromium.org's avatar jsbell@chromium.org

IndexedDB: Send cursor data along with success messages

Chromium already behaves like this in the IPC plumbing for IDB,
but the code can be simplified by pushing this into the WebKit
implementation itself.

Full landing sequence is:

(1) WebKit prep: Add new API stubs http://webkit.org/b/92414 
(2) Chromium changes: dispatch to old and new API https://chromiumcodereview.appspot.com/10830028 (this patch)
(3) WebKit changes: use the new API http://webkit.org/b/92278
(4) Chromium cleanup: delete old API usage
(5) WebKit changes: delete old API


Review URL: https://chromiumcodereview.appspot.com/10830028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150883 0039d316-1c4b-4281-b951-d872f2087c98
parent e3f1f0c0
......@@ -53,6 +53,7 @@ void IndexedDBCallbacks<WebKit::WebIDBDatabase>::onUpgradeNeeded(
old_version));
}
// TODO(jsbell): Remove this after WK92278 rolls.
void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess(
WebKit::WebIDBCursor* idb_object) {
int32 object_id = dispatcher_host()->Add(idb_object);
......@@ -66,6 +67,22 @@ void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess(
dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(params));
}
void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess(
WebKit::WebIDBCursor* idb_object,
const WebKit::WebIDBKey& key,
const WebKit::WebIDBKey& primaryKey,
const WebKit::WebSerializedScriptValue& value) {
int32 object_id = dispatcher_host()->Add(idb_object);
IndexedDBMsg_CallbacksSuccessIDBCursor_Params params;
params.thread_id = thread_id();
params.response_id = response_id();
params.cursor_id = object_id;
params.key = IndexedDBKey(key);
params.primary_key = IndexedDBKey(primaryKey);
params.serialized_value = SerializedScriptValue(value);
dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(params));
}
void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess(
const WebKit::WebSerializedScriptValue& value) {
dispatcher_host()->Send(
......@@ -73,6 +90,7 @@ void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess(
thread_id(), response_id(), SerializedScriptValue(value)));
}
// TODO(jsbell): Remove this after WK92278 rolls.
void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccessWithContinuation() {
DCHECK(cursor_id_ != -1);
WebKit::WebIDBCursor* idb_cursor = dispatcher_host()->GetCursorFromId(
......@@ -88,7 +106,28 @@ void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccessWithContinuation() {
params.key = IndexedDBKey(idb_cursor->key());
params.primary_key = IndexedDBKey(idb_cursor->primaryKey());
params.serialized_value = SerializedScriptValue(idb_cursor->value());
dispatcher_host()->Send(
new IndexedDBMsg_CallbacksSuccessCursorContinue(params));
}
void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess(
const WebKit::WebIDBKey& key,
const WebKit::WebIDBKey& primaryKey,
const WebKit::WebSerializedScriptValue& value) {
DCHECK(cursor_id_ != -1);
WebKit::WebIDBCursor* idb_cursor = dispatcher_host()->GetCursorFromId(
cursor_id_);
DCHECK(idb_cursor);
if (!idb_cursor)
return;
IndexedDBMsg_CallbacksSuccessCursorContinue_Params params;
params.thread_id = thread_id();
params.response_id = response_id();
params.cursor_id = cursor_id_;
params.key = IndexedDBKey(key);
params.primary_key = IndexedDBKey(primaryKey);
params.serialized_value = SerializedScriptValue(value);
dispatcher_host()->Send(
new IndexedDBMsg_CallbacksSuccessCursorContinue(params));
}
......
......@@ -105,11 +105,22 @@ class IndexedDBCallbacks : public IndexedDBCallbacksBase {
DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
};
// TODO(jsbell): Remove this preamble comment after WK92278 rolls.
// Pre WK92278:
// WebIDBCursor uses onSuccess(WebIDBCursor*) when a cursor has been opened,
// onSuccessWithContinuation() when a continue() call has succeeded, or
// onSuccess(SerializedScriptValue::nullValue()) to indicate it does
// not contain any data, i.e., there is no key within the key range,
// or it has reached the end.
// Post WK92278:
// WebIDBCursor uses:
// * onSuccess(WebIDBCursor*, WebIDBKey, WebIDBKey, SerializedScriptValue)
// when an openCursor()/openKeyCursor() call has succeeded,
// * onSuccess(WebIDBKey, WebIDBKey, SerializedScriptValue)
// when an advance()/continue() call has succeeded, or
// * onSuccess(SerializedScriptValue::nullValue())
// to indicate it does not contain any data, i.e., there is no key within
// the key range, or it has reached the end.
template <>
class IndexedDBCallbacks<WebKit::WebIDBCursor>
: public IndexedDBCallbacksBase {
......@@ -122,8 +133,17 @@ class IndexedDBCallbacks<WebKit::WebIDBCursor>
: IndexedDBCallbacksBase(dispatcher_host, thread_id, response_id),
cursor_id_(cursor_id) { }
// TODO(jsbell): Remove this after WK92278 rolls.
virtual void onSuccess(WebKit::WebIDBCursor* idb_object);
virtual void onSuccess(WebKit::WebIDBCursor* idb_object,
const WebKit::WebIDBKey& key,
const WebKit::WebIDBKey& primaryKey,
const WebKit::WebSerializedScriptValue& value);
virtual void onSuccess(const WebKit::WebIDBKey& key,
const WebKit::WebIDBKey& primaryKey,
const WebKit::WebSerializedScriptValue& value);
virtual void onSuccess(const WebKit::WebSerializedScriptValue& value);
// TODO(jsbell): Remove this after WK92278 rolls.
virtual void onSuccessWithContinuation();
virtual void onSuccessWithPrefetch(
const WebKit::WebVector<WebKit::WebIDBKey>& keys,
......
......@@ -892,6 +892,7 @@ void IndexedDBDispatcherHost::CursorDispatcherHost::Send(
parent_->Send(message);
}
// TODO(jsbell): Remove this after WK92278 rolls.
void IndexedDBDispatcherHost::CursorDispatcherHost::OnKey(
int32 object_id, IndexedDBKey* key) {
WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_, object_id);
......@@ -901,6 +902,7 @@ void IndexedDBDispatcherHost::CursorDispatcherHost::OnKey(
*key = IndexedDBKey(idb_cursor->key());
}
// TODO(jsbell): Remove this after WK92278 rolls.
void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrimaryKey(
int32 object_id, IndexedDBKey* primary_key) {
WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_, object_id);
......@@ -910,6 +912,7 @@ void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrimaryKey(
*primary_key = IndexedDBKey(idb_cursor->primaryKey());
}
// TODO(jsbell): Remove this after WK92278 rolls.
void IndexedDBDispatcherHost::CursorDispatcherHost::OnValue(
int32 object_id,
SerializedScriptValue* script_value) {
......
......@@ -233,6 +233,7 @@ class IndexedDBDispatcherHost : public content::BrowserMessageFilter {
bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
void Send(IPC::Message* message);
// TODO(jsbell): Remove the next three methods after WK92278 rolls.
void OnKey(int32 idb_object_store_id, content::IndexedDBKey* key);
void OnPrimaryKey(int32 idb_object_store_id,
content::IndexedDBKey* primary_key);
......
......@@ -635,8 +635,10 @@ void IndexedDBDispatcher::OnSuccessOpenCursor(
RendererWebIDBCursorImpl* cursor = new RendererWebIDBCursorImpl(object_id);
cursors_[object_id] = cursor;
// TODO(jsbell): Remove the next two calls after WK92278 rolls.
cursor->SetKeyAndValue(key, primary_key, value);
callbacks->onSuccess(cursor);
callbacks->onSuccess(cursor, key, primary_key, value);
pending_callbacks_.Remove(response_id);
}
......@@ -652,12 +654,16 @@ void IndexedDBDispatcher::OnSuccessCursorContinue(
RendererWebIDBCursorImpl* cursor = cursors_[cursor_id];
DCHECK(cursor);
// TODO(jsbell): Remove the next call after WK92278·rolls.
cursor->SetKeyAndValue(key, primary_key, value);
WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
if (!callbacks)
return;
// TODO(jsbell): Remove the ...WithContinuation call after WK92278 rolls.
callbacks->onSuccessWithContinuation();
callbacks->onSuccess(key, primary_key, value);
pending_callbacks_.Remove(response_id);
}
......
......@@ -37,14 +37,17 @@ RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() {
dispatcher->CursorDestroyed(idb_cursor_id_);
}
// TODO(jsbell): Remove the following method after WK92278 rolls.
WebIDBKey RendererWebIDBCursorImpl::key() const {
return key_;
}
// TODO(jsbell): Remove the following method after WK92278 rolls.
WebIDBKey RendererWebIDBCursorImpl::primaryKey() const {
return primary_key_;
}
// TODO(jsbell): Remove the following method after WK92278 rolls.
WebSerializedScriptValue RendererWebIDBCursorImpl::value() const {
return value_;
}
......@@ -120,6 +123,7 @@ void RendererWebIDBCursorImpl::postSuccessHandlerCallback() {
ResetPrefetchCache();
}
// TODO(jsbell): Remove the following method after WK92278 rolls.
void RendererWebIDBCursorImpl::SetKeyAndValue(
const IndexedDBKey& key,
const IndexedDBKey& primary_key,
......@@ -147,6 +151,7 @@ void RendererWebIDBCursorImpl::CachedContinue(
DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size());
DCHECK(prefetch_values_.size() == prefetch_keys_.size());
// TODO(jsbell): Turn these three variables into locals after WK92278 rolls.
key_ = prefetch_keys_.front();
primary_key_ = prefetch_primary_keys_.front();
value_ = prefetch_values_.front();
......@@ -157,7 +162,10 @@ void RendererWebIDBCursorImpl::CachedContinue(
used_prefetches_++;
pending_onsuccess_callbacks_++;
// TODO(jsbell): Remove the ...WithContinuation call after WK92278 rolls.
callbacks->onSuccessWithContinuation();
callbacks->onSuccess(key_, primary_key_, value_);
}
void RendererWebIDBCursorImpl::ResetPrefetchCache() {
......
......@@ -21,6 +21,7 @@ class RendererWebIDBCursorImpl : public WebKit::WebIDBCursor {
explicit RendererWebIDBCursorImpl(int32 idb_cursor_id);
virtual ~RendererWebIDBCursorImpl();
// TODO(jsbell): Remove the following three methods after WK92278 rolls.
virtual WebKit::WebIDBKey key() const;
virtual WebKit::WebIDBKey primaryKey() const;
virtual WebKit::WebSerializedScriptValue value() const;
......@@ -34,6 +35,7 @@ class RendererWebIDBCursorImpl : public WebKit::WebIDBCursor {
WebKit::WebExceptionCode& ec);
virtual void postSuccessHandlerCallback();
// TODO(jsbell): Remove the following method after WK92278 rolls.
void SetKeyAndValue(const content::IndexedDBKey& key,
const content::IndexedDBKey& primary_key,
const content::SerializedScriptValue& value);
......@@ -47,6 +49,8 @@ class RendererWebIDBCursorImpl : public WebKit::WebIDBCursor {
private:
int32 idb_cursor_id_;
// TODO(jsbell): Remove the following three members after WK92278 rolls.
content::IndexedDBKey key_;
content::IndexedDBKey primary_key_;
content::SerializedScriptValue value_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment