Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 5 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
| 13 #include "content/child/indexed_db/indexed_db_key_builders.h" | 13 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 14 #include "content/child/indexed_db/webidbcursor_impl.h" | 14 #include "content/child/indexed_db/webidbcursor_impl.h" |
| 15 #include "content/child/indexed_db/webidbdatabase_impl.h" | 15 #include "content/child/indexed_db/webidbdatabase_impl.h" |
| 16 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
| 17 #include "content/common/indexed_db/indexed_db_messages.h" | 17 #include "content/common/indexed_db/indexed_db_messages.h" |
| 18 #include "ipc/ipc_channel.h" | 18 #include "ipc/ipc_channel.h" |
| 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h" | 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h" |
| 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr or.h" | 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr or.h" |
| 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" | 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" |
| 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation .h" | |
| 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" | 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" |
| 23 | 24 |
| 24 using blink::WebBlobInfo; | 25 using blink::WebBlobInfo; |
| 25 using blink::WebData; | 26 using blink::WebData; |
| 26 using blink::WebIDBCallbacks; | 27 using blink::WebIDBCallbacks; |
| 27 using blink::WebIDBCursor; | 28 using blink::WebIDBCursor; |
| 28 using blink::WebIDBDatabase; | 29 using blink::WebIDBDatabase; |
| 29 using blink::WebIDBDatabaseCallbacks; | 30 using blink::WebIDBDatabaseCallbacks; |
| 30 using blink::WebIDBDatabaseError; | 31 using blink::WebIDBDatabaseError; |
| 31 using blink::WebIDBKey; | 32 using blink::WebIDBKey; |
| 32 using blink::WebIDBMetadata; | 33 using blink::WebIDBMetadata; |
| 34 using blink::WebIDBObservation; | |
| 33 using blink::WebIDBObserver; | 35 using blink::WebIDBObserver; |
| 34 using blink::WebIDBValue; | 36 using blink::WebIDBValue; |
| 35 using blink::WebString; | 37 using blink::WebString; |
| 36 using blink::WebVector; | 38 using blink::WebVector; |
| 37 using base::ThreadLocalPointer; | 39 using base::ThreadLocalPointer; |
| 38 | 40 |
| 39 namespace content { | 41 namespace content { |
| 40 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky | 42 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky |
| 41 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 43 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
| 42 | 44 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 web_index_metadata.keyPath = | 120 web_index_metadata.keyPath = |
| 119 WebIDBKeyPathBuilder::Build(idb_index_metadata.key_path); | 121 WebIDBKeyPathBuilder::Build(idb_index_metadata.key_path); |
| 120 web_index_metadata.unique = idb_index_metadata.unique; | 122 web_index_metadata.unique = idb_index_metadata.unique; |
| 121 web_index_metadata.multiEntry = idb_index_metadata.multi_entry; | 123 web_index_metadata.multiEntry = idb_index_metadata.multi_entry; |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 | 126 |
| 125 return web_metadata; | 127 return web_metadata; |
| 126 } | 128 } |
| 127 | 129 |
| 130 std::vector<WebIDBObservation> IndexedDBDispatcher::ConvertObservations( | |
| 131 const std::vector<IndexedDBMsg_Observation>& idb_observations) { | |
| 132 std::vector<WebIDBObservation> web_observations; | |
| 133 for (const auto& idb_observation : idb_observations) { | |
| 134 WebIDBObservation web_observation; | |
| 135 web_observation.objectStoreId = idb_observation.object_store_id; | |
| 136 web_observation.type = idb_observation.type; | |
| 137 web_observation.keyRange = | |
| 138 WebIDBKeyRangeBuilder::Build(idb_observation.key_range); | |
| 139 web_observations.push_back(std::move(web_observation)); | |
| 140 } | |
| 141 return web_observations; | |
| 142 } | |
| 143 | |
| 128 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { | 144 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 129 bool handled = true; | 145 bool handled = true; |
| 130 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) | 146 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) |
| 131 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, | 147 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, |
| 132 OnSuccessOpenCursor) | 148 OnSuccessOpenCursor) |
| 133 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance, | 149 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance, |
| 134 OnSuccessCursorContinue) | 150 OnSuccessCursorContinue) |
| 135 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, | 151 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, |
| 136 OnSuccessCursorContinue) | 152 OnSuccessCursorContinue) |
| 137 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, | 153 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 149 OnSuccessUndefined) | 165 OnSuccessUndefined) |
| 150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 166 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
| 151 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) | 167 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) |
| 152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) | 168 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) |
| 153 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, | 169 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, |
| 154 OnForcedClose) | 170 OnForcedClose) |
| 155 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, | 171 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, |
| 156 OnVersionChange) | 172 OnVersionChange) |
| 157 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksAbort, OnAbort) | 173 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksAbort, OnAbort) |
| 158 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksComplete, OnComplete) | 174 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksComplete, OnComplete) |
| 175 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges, OnDatabaseChange) | |
| 159 IPC_MESSAGE_UNHANDLED(handled = false) | 176 IPC_MESSAGE_UNHANDLED(handled = false) |
| 160 IPC_END_MESSAGE_MAP() | 177 IPC_END_MESSAGE_MAP() |
| 161 // If a message gets here, IndexedDBMessageFilter already determined that it | 178 // If a message gets here, IndexedDBMessageFilter already determined that it |
| 162 // is an IndexedDB message. | 179 // is an IndexedDB message. |
| 163 DCHECK(handled) << "Didn't handle a message defined at line " | 180 DCHECK(handled) << "Didn't handle a message defined at line " |
| 164 << IPC_MESSAGE_ID_LINE(msg.type()); | 181 << IPC_MESSAGE_ID_LINE(msg.type()); |
| 165 } | 182 } |
| 166 | 183 |
| 167 bool IndexedDBDispatcher::Send(IPC::Message* msg) { | 184 bool IndexedDBDispatcher::Send(IPC::Message* msg) { |
| 168 return thread_safe_sender_->Send(msg); | 185 return thread_safe_sender_->Send(msg); |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 int32_t ipc_database_callbacks_id, | 807 int32_t ipc_database_callbacks_id, |
| 791 int64_t transaction_id) { | 808 int64_t transaction_id) { |
| 792 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 809 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 793 WebIDBDatabaseCallbacks* callbacks = | 810 WebIDBDatabaseCallbacks* callbacks = |
| 794 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | 811 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); |
| 795 if (!callbacks) | 812 if (!callbacks) |
| 796 return; | 813 return; |
| 797 callbacks->onComplete(transaction_id); | 814 callbacks->onComplete(transaction_id); |
| 798 } | 815 } |
| 799 | 816 |
| 817 void IndexedDBDispatcher::OnDatabaseChange( | |
| 818 int32_t ipc_thread_id, | |
| 819 int32_t ipc_database_id, | |
| 820 const IndexedDBMsg_ObserverChanges& changes) { | |
| 821 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
| 822 std::vector<WebIDBObservation> observations( | |
| 823 ConvertObservations(changes.observations)); | |
| 824 for (auto& obs : changes.observation_index) { | |
| 825 WebIDBObserver* observer = observers_.Lookup(obs.first); | |
| 826 // TODO(palakj): Get IDBDatabase object from ipc_database_id. | |
|
jsbell
2016/07/11 18:25:33
Communication from the back end to an IDBDatabase
palakj1
2016/07/11 19:37:54
Thanks for the insight. This seems a good option.
jsbell
2016/07/11 21:23:04
It sounds like the weakptr in IDBObserver would be
| |
| 827 observer->onChange(observations, std::move(obs.second)); | |
| 828 } | |
| 829 } | |
| 830 | |
| 800 void IndexedDBDispatcher::OnForcedClose(int32_t ipc_thread_id, | 831 void IndexedDBDispatcher::OnForcedClose(int32_t ipc_thread_id, |
| 801 int32_t ipc_database_callbacks_id) { | 832 int32_t ipc_database_callbacks_id) { |
| 802 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 833 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 803 WebIDBDatabaseCallbacks* callbacks = | 834 WebIDBDatabaseCallbacks* callbacks = |
| 804 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | 835 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); |
| 805 if (!callbacks) | 836 if (!callbacks) |
| 806 return; | 837 return; |
| 807 callbacks->onForcedClose(); | 838 callbacks->onForcedClose(); |
| 808 } | 839 } |
| 809 | 840 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 827 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; | 858 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; |
| 828 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 859 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
| 829 if (i->first == ipc_exception_cursor_id || | 860 if (i->first == ipc_exception_cursor_id || |
| 830 i->second->transaction_id() != transaction_id) | 861 i->second->transaction_id() != transaction_id) |
| 831 continue; | 862 continue; |
| 832 i->second->ResetPrefetchCache(); | 863 i->second->ResetPrefetchCache(); |
| 833 } | 864 } |
| 834 } | 865 } |
| 835 | 866 |
| 836 } // namespace content | 867 } // namespace content |
| OLD | NEW |