| Index: content/child/indexed_db/indexed_db_dispatcher.cc
|
| diff --git a/content/child/indexed_db/indexed_db_dispatcher.cc b/content/child/indexed_db/indexed_db_dispatcher.cc
|
| index aafd24419d65f749c47d08f81e01134920406d48..4189fdfed76e851e98dd279bc78241449d02b03e 100644
|
| --- a/content/child/indexed_db/indexed_db_dispatcher.cc
|
| +++ b/content/child/indexed_db/indexed_db_dispatcher.cc
|
| @@ -6,36 +6,18 @@
|
|
|
| #include <utility>
|
|
|
| -#include "base/format_macros.h"
|
| #include "base/lazy_instance.h"
|
| -#include "base/strings/stringprintf.h"
|
| #include "base/threading/thread_local.h"
|
| #include "content/child/indexed_db/indexed_db_key_builders.h"
|
| #include "content/child/indexed_db/webidbcursor_impl.h"
|
| -#include "content/child/indexed_db/webidbdatabase_impl.h"
|
| -#include "content/child/thread_safe_sender.h"
|
| #include "content/common/indexed_db/indexed_db_messages.h"
|
| #include "ipc/ipc_channel.h"
|
| #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCallbacks.h"
|
| -#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseError.h"
|
| -#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseException.h"
|
| #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation.h"
|
| -#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h"
|
|
|
| -using blink::WebBlobInfo;
|
| -using blink::WebData;
|
| -using blink::WebIDBCallbacks;
|
| -using blink::WebIDBCursor;
|
| -using blink::WebIDBDatabase;
|
| -using blink::WebIDBDatabaseCallbacks;
|
| -using blink::WebIDBDatabaseError;
|
| using blink::WebIDBKey;
|
| -using blink::WebIDBMetadata;
|
| using blink::WebIDBObservation;
|
| using blink::WebIDBObserver;
|
| -using blink::WebIDBValue;
|
| -using blink::WebString;
|
| -using blink::WebVector;
|
| using base::ThreadLocalPointer;
|
|
|
| namespace content {
|
| @@ -49,23 +31,15 @@ IndexedDBDispatcher* const kHasBeenDeleted =
|
|
|
| } // unnamed namespace
|
|
|
| -IndexedDBDispatcher::IndexedDBDispatcher(ThreadSafeSender* thread_safe_sender)
|
| - : thread_safe_sender_(thread_safe_sender) {
|
| +IndexedDBDispatcher::IndexedDBDispatcher() {
|
| g_idb_dispatcher_tls.Pointer()->Set(this);
|
| }
|
|
|
| IndexedDBDispatcher::~IndexedDBDispatcher() {
|
| - // Clear any pending callbacks - which may result in dispatch requests -
|
| - // before marking the dispatcher as deleted.
|
| - pending_callbacks_.Clear();
|
| -
|
| - DCHECK(pending_callbacks_.IsEmpty());
|
| -
|
| g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
|
| }
|
|
|
| -IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance(
|
| - ThreadSafeSender* thread_safe_sender) {
|
| +IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() {
|
| if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) {
|
| NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher.";
|
| g_idb_dispatcher_tls.Pointer()->Set(NULL);
|
| @@ -73,7 +47,7 @@ IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance(
|
| if (g_idb_dispatcher_tls.Pointer()->Get())
|
| return g_idb_dispatcher_tls.Pointer()->Get();
|
|
|
| - IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher(thread_safe_sender);
|
| + IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher();
|
| if (WorkerThread::GetCurrentId())
|
| WorkerThread::AddObserver(dispatcher);
|
| return dispatcher;
|
| @@ -101,15 +75,6 @@ std::vector<WebIDBObservation> IndexedDBDispatcher::ConvertObservations(
|
| void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg)
|
| - IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance,
|
| - OnSuccessCursorContinue)
|
| - IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue,
|
| - OnSuccessCursorContinue)
|
| - IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch,
|
| - OnSuccessCursorPrefetch)
|
| - IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue)
|
| - IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger)
|
| - IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError)
|
| IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges,
|
| OnDatabaseChanges)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| @@ -120,10 +85,6 @@ void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
|
| << IPC_MESSAGE_ID_LINE(msg.type());
|
| }
|
|
|
| -bool IndexedDBDispatcher::Send(IPC::Message* msg) {
|
| - return thread_safe_sender_->Send(msg);
|
| -}
|
| -
|
| int32_t IndexedDBDispatcher::RegisterObserver(
|
| std::unique_ptr<WebIDBObserver> observer) {
|
| return observers_.Add(observer.release());
|
| @@ -135,65 +96,6 @@ void IndexedDBDispatcher::RemoveObservers(
|
| observers_.Remove(id);
|
| }
|
|
|
| -void IndexedDBDispatcher::RequestIDBCursorAdvance(
|
| - unsigned long count,
|
| - WebIDBCallbacks* callbacks_ptr,
|
| - int32_t ipc_cursor_id,
|
| - int64_t transaction_id) {
|
| - // Reset all cursor prefetch caches except for this cursor.
|
| - ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id);
|
| -
|
| - std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
|
| -
|
| - int32_t ipc_callbacks_id = pending_callbacks_.Add(callbacks.release());
|
| - Send(new IndexedDBHostMsg_CursorAdvance(
|
| - ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, count));
|
| -}
|
| -
|
| -void IndexedDBDispatcher::RequestIDBCursorContinue(
|
| - const IndexedDBKey& key,
|
| - const IndexedDBKey& primary_key,
|
| - WebIDBCallbacks* callbacks_ptr,
|
| - int32_t ipc_cursor_id,
|
| - int64_t transaction_id) {
|
| - // Reset all cursor prefetch caches except for this cursor.
|
| - ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id);
|
| -
|
| - std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
|
| -
|
| - int32_t ipc_callbacks_id = pending_callbacks_.Add(callbacks.release());
|
| - Send(new IndexedDBHostMsg_CursorContinue(
|
| - ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, key, primary_key));
|
| -}
|
| -
|
| -void IndexedDBDispatcher::RequestIDBCursorPrefetch(
|
| - int n,
|
| - WebIDBCallbacks* callbacks_ptr,
|
| - int32_t ipc_cursor_id) {
|
| - std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
|
| -
|
| - int32_t ipc_callbacks_id = pending_callbacks_.Add(callbacks.release());
|
| - Send(new IndexedDBHostMsg_CursorPrefetch(
|
| - ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, n));
|
| -}
|
| -
|
| -void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches,
|
| - int unused_prefetches,
|
| - int32_t ipc_cursor_id) {
|
| - Send(new IndexedDBHostMsg_CursorPrefetchReset(
|
| - ipc_cursor_id, used_prefetches, unused_prefetches));
|
| -}
|
| -
|
| -void IndexedDBDispatcher::RegisterCursor(int32_t ipc_cursor_id,
|
| - WebIDBCursorImpl* cursor) {
|
| - DCHECK(!base::ContainsKey(cursors_, ipc_cursor_id));
|
| - cursors_[ipc_cursor_id] = cursor;
|
| -}
|
| -
|
| -void IndexedDBDispatcher::CursorDestroyed(int32_t ipc_cursor_id) {
|
| - cursors_.erase(ipc_cursor_id);
|
| -}
|
| -
|
| void IndexedDBDispatcher::RegisterMojoOwnedCallbacks(
|
| IndexedDBCallbacksImpl::InternalState* callbacks) {
|
| mojo_owned_callback_state_.insert(callbacks);
|
| @@ -216,125 +118,6 @@ void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks(
|
| mojo_owned_database_callback_state_.erase(callbacks);
|
| }
|
|
|
| -// Populate some WebIDBValue members (data & blob info) from the supplied
|
| -// value message (IndexedDBMsg_Value or one that includes it).
|
| -template <class IndexedDBMsgValueType>
|
| -static void PrepareWebValue(const IndexedDBMsgValueType& value,
|
| - WebIDBValue* web_value) {
|
| - if (value.bits.empty())
|
| - return;
|
| -
|
| - web_value->data.assign(&*value.bits.begin(), value.bits.size());
|
| - blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size());
|
| - for (size_t i = 0; i < value.blob_or_file_info.size(); ++i) {
|
| - const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i];
|
| - if (info.is_file) {
|
| - local_blob_info[i] = WebBlobInfo(
|
| - WebString::fromUTF8(info.uuid.c_str()), info.file_path,
|
| - info.file_name, info.mime_type, info.last_modified, info.size);
|
| - } else {
|
| - local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()),
|
| - info.mime_type, info.size);
|
| - }
|
| - }
|
| -
|
| - web_value->webBlobInfo.swap(local_blob_info);
|
| -}
|
| -
|
| -static void PrepareReturnWebValue(const IndexedDBMsg_ReturnValue& value,
|
| - WebIDBValue* web_value) {
|
| - PrepareWebValue(value, web_value);
|
| - web_value->primaryKey = WebIDBKeyBuilder::Build(value.primary_key);
|
| - web_value->keyPath = WebIDBKeyPathBuilder::Build(value.key_path);
|
| -}
|
| -
|
| -void IndexedDBDispatcher::OnSuccessValue(
|
| - const IndexedDBMsg_CallbacksSuccessValue_Params& params) {
|
| - DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId());
|
| - WebIDBCallbacks* callbacks =
|
| - pending_callbacks_.Lookup(params.ipc_callbacks_id);
|
| - if (!callbacks)
|
| - return;
|
| - WebIDBValue web_value;
|
| - PrepareReturnWebValue(params.value, &web_value);
|
| - if (params.value.primary_key.IsValid()) {
|
| - web_value.primaryKey = WebIDBKeyBuilder::Build(params.value.primary_key);
|
| - web_value.keyPath = WebIDBKeyPathBuilder::Build(params.value.key_path);
|
| - }
|
| - callbacks->onSuccess(web_value);
|
| - pending_callbacks_.Remove(params.ipc_callbacks_id);
|
| -}
|
| -
|
| -void IndexedDBDispatcher::OnSuccessInteger(int32_t ipc_thread_id,
|
| - int32_t ipc_callbacks_id,
|
| - int64_t value) {
|
| - DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
|
| - WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
|
| - if (!callbacks)
|
| - return;
|
| - callbacks->onSuccess(value);
|
| - pending_callbacks_.Remove(ipc_callbacks_id);
|
| -}
|
| -
|
| -void IndexedDBDispatcher::OnSuccessCursorContinue(
|
| - const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) {
|
| - DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
|
| - int32_t ipc_callbacks_id = p.ipc_callbacks_id;
|
| - int32_t ipc_cursor_id = p.ipc_cursor_id;
|
| - const IndexedDBKey& key = p.key;
|
| - const IndexedDBKey& primary_key = p.primary_key;
|
| -
|
| - if (cursors_.find(ipc_cursor_id) == cursors_.end())
|
| - return;
|
| -
|
| - WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
|
| - if (!callbacks)
|
| - return;
|
| -
|
| - WebIDBValue web_value;
|
| - PrepareWebValue(p.value, &web_value);
|
| - callbacks->onSuccess(WebIDBKeyBuilder::Build(key),
|
| - WebIDBKeyBuilder::Build(primary_key), web_value);
|
| -
|
| - pending_callbacks_.Remove(ipc_callbacks_id);
|
| -}
|
| -
|
| -void IndexedDBDispatcher::OnSuccessCursorPrefetch(
|
| - const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) {
|
| - DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
|
| - int32_t ipc_callbacks_id = p.ipc_callbacks_id;
|
| - int32_t ipc_cursor_id = p.ipc_cursor_id;
|
| - std::vector<WebIDBValue> values(p.values.size());
|
| - for (size_t i = 0; i < p.values.size(); ++i)
|
| - PrepareWebValue(p.values[i], &values[i]);
|
| - std::map<int32_t, WebIDBCursorImpl*>::const_iterator cur_iter =
|
| - cursors_.find(ipc_cursor_id);
|
| - if (cur_iter == cursors_.end())
|
| - return;
|
| -
|
| - cur_iter->second->SetPrefetchData(p.keys, p.primary_keys, values);
|
| -
|
| - WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
|
| - DCHECK(callbacks);
|
| - cur_iter->second->CachedContinue(callbacks);
|
| - pending_callbacks_.Remove(ipc_callbacks_id);
|
| -}
|
| -
|
| -void IndexedDBDispatcher::OnError(int32_t ipc_thread_id,
|
| - int32_t ipc_callbacks_id,
|
| - int code,
|
| - const base::string16& message) {
|
| - DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
|
| - WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
|
| - if (!callbacks)
|
| - return;
|
| - if (message.empty())
|
| - callbacks->onError(WebIDBDatabaseError(code));
|
| - else
|
| - callbacks->onError(WebIDBDatabaseError(code, message));
|
| - pending_callbacks_.Remove(ipc_callbacks_id);
|
| -}
|
| -
|
| void IndexedDBDispatcher::OnDatabaseChanges(
|
| int32_t ipc_thread_id,
|
| const IndexedDBMsg_ObserverChanges& changes) {
|
| @@ -352,15 +135,23 @@ void IndexedDBDispatcher::OnDatabaseChanges(
|
| }
|
| }
|
|
|
| +void IndexedDBDispatcher::RegisterCursor(WebIDBCursorImpl* cursor) {
|
| + DCHECK(!base::ContainsValue(cursors_, cursor));
|
| + cursors_.insert(cursor);
|
| +}
|
| +
|
| +void IndexedDBDispatcher::UnregisterCursor(WebIDBCursorImpl* cursor) {
|
| + DCHECK(base::ContainsValue(cursors_, cursor));
|
| + cursors_.erase(cursor);
|
| +}
|
| +
|
| void IndexedDBDispatcher::ResetCursorPrefetchCaches(
|
| int64_t transaction_id,
|
| - int32_t ipc_exception_cursor_id) {
|
| - typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator;
|
| - for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
|
| - if (i->first == ipc_exception_cursor_id ||
|
| - i->second->transaction_id() != transaction_id)
|
| - continue;
|
| - i->second->ResetPrefetchCache();
|
| + WebIDBCursorImpl* exception_cursor) {
|
| + for (WebIDBCursorImpl* cursor : cursors_) {
|
| + if (cursor != exception_cursor &&
|
| + cursor->transaction_id() == transaction_id)
|
| + cursor->ResetPrefetchCache();
|
| }
|
| }
|
|
|
|
|