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 // TODO(palakj): Assign value to web_observation. | |
| 140 web_observations.push_back(std::move(web_observation)); | |
| 141 } | |
| 142 return web_observations; | |
| 143 } | |
| 144 | |
| 128 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { | 145 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 129 bool handled = true; | 146 bool handled = true; |
| 130 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) | 147 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) |
| 131 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, | 148 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, |
| 132 OnSuccessOpenCursor) | 149 OnSuccessOpenCursor) |
| 133 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance, | 150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance, |
| 134 OnSuccessCursorContinue) | 151 OnSuccessCursorContinue) |
| 135 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, | 152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, |
| 136 OnSuccessCursorContinue) | 153 OnSuccessCursorContinue) |
| 137 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, | 154 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 149 OnSuccessUndefined) | 166 OnSuccessUndefined) |
| 150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 167 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
| 151 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) | 168 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) |
| 152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) | 169 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) |
| 153 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, | 170 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, |
| 154 OnForcedClose) | 171 OnForcedClose) |
| 155 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, | 172 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, |
| 156 OnVersionChange) | 173 OnVersionChange) |
| 157 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksAbort, OnAbort) | 174 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksAbort, OnAbort) |
| 158 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksComplete, OnComplete) | 175 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksComplete, OnComplete) |
| 176 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges, | |
| 177 OnDatabaseChanges) | |
| 159 IPC_MESSAGE_UNHANDLED(handled = false) | 178 IPC_MESSAGE_UNHANDLED(handled = false) |
| 160 IPC_END_MESSAGE_MAP() | 179 IPC_END_MESSAGE_MAP() |
| 161 // If a message gets here, IndexedDBMessageFilter already determined that it | 180 // If a message gets here, IndexedDBMessageFilter already determined that it |
| 162 // is an IndexedDB message. | 181 // is an IndexedDB message. |
| 163 DCHECK(handled) << "Didn't handle a message defined at line " | 182 DCHECK(handled) << "Didn't handle a message defined at line " |
| 164 << IPC_MESSAGE_ID_LINE(msg.type()); | 183 << IPC_MESSAGE_ID_LINE(msg.type()); |
| 165 } | 184 } |
| 166 | 185 |
| 167 bool IndexedDBDispatcher::Send(IPC::Message* msg) { | 186 bool IndexedDBDispatcher::Send(IPC::Message* msg) { |
| 168 return thread_safe_sender_->Send(msg); | 187 return thread_safe_sender_->Send(msg); |
| 169 } | 188 } |
| 170 | 189 |
| 171 int32_t IndexedDBDispatcher::AddIDBObserver( | 190 int32_t IndexedDBDispatcher::AddIDBObserver( |
| 172 int32_t ipc_database_id, | 191 int32_t ipc_database_id, |
| 173 int64_t transaction_id, | 192 int64_t transaction_id, |
| 174 std::unique_ptr<WebIDBObserver> observer) { | 193 std::unique_ptr<WebIDBObserver> observer) { |
| 194 IndexedDBHostMsg_DatabaseObserve_Params params; | |
| 195 | |
| 196 static_assert( | |
| 197 blink::WebIDBOperationTypeCount <= std::numeric_limits<uint16_t>::max(), | |
|
Will Harris
2016/07/20 21:47:38
should this be < sizeof(uint16_t) not max()?
| |
| 198 "WebIDBOperationType Count exceeds 16 bit uint max limit"); | |
| 199 params.operation_types = | |
| 200 static_cast<uint16_t>(observer->operationTypes().to_ulong()); | |
| 201 params.include_transaction = observer->transaction(); | |
| 202 params.no_records = observer->noRecords(); | |
| 203 params.values = observer->values(); | |
| 175 int32_t observer_id = observers_.Add(observer.release()); | 204 int32_t observer_id = observers_.Add(observer.release()); |
| 176 IndexedDBHostMsg_DatabaseObserve_Params params; | |
| 177 // TODO(palakj): Other params are assigned values as a part of next cl. | |
| 178 params.ipc_database_id = ipc_database_id; | 205 params.ipc_database_id = ipc_database_id; |
| 179 params.transaction_id = transaction_id; | 206 params.transaction_id = transaction_id; |
| 180 params.observer_id = observer_id; | 207 params.observer_id = observer_id; |
| 181 Send(new IndexedDBHostMsg_DatabaseObserve(params)); | 208 Send(new IndexedDBHostMsg_DatabaseObserve(params)); |
| 182 return observer_id; | 209 return observer_id; |
| 183 } | 210 } |
| 184 | 211 |
| 185 void IndexedDBDispatcher::RemoveIDBObserversFromDatabase( | 212 void IndexedDBDispatcher::RemoveIDBObserversFromDatabase( |
| 186 int32_t ipc_database_id, | 213 int32_t ipc_database_id, |
| 187 const std::vector<int32_t>& observer_ids_to_remove) { | 214 const std::vector<int32_t>& observer_ids_to_remove) { |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 int32_t ipc_database_callbacks_id, | 821 int32_t ipc_database_callbacks_id, |
| 795 int64_t transaction_id) { | 822 int64_t transaction_id) { |
| 796 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 823 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 797 WebIDBDatabaseCallbacks* callbacks = | 824 WebIDBDatabaseCallbacks* callbacks = |
| 798 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | 825 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); |
| 799 if (!callbacks) | 826 if (!callbacks) |
| 800 return; | 827 return; |
| 801 callbacks->onComplete(transaction_id); | 828 callbacks->onComplete(transaction_id); |
| 802 } | 829 } |
| 803 | 830 |
| 831 void IndexedDBDispatcher::OnDatabaseChanges( | |
| 832 int32_t ipc_thread_id, | |
| 833 int32_t ipc_database_id, | |
| 834 const IndexedDBMsg_ObserverChanges& changes) { | |
| 835 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
| 836 std::vector<WebIDBObservation> observations( | |
| 837 ConvertObservations(changes.observations)); | |
| 838 for (auto& it : changes.observation_index) { | |
| 839 WebIDBObserver* observer = observers_.Lookup(it.first); | |
| 840 // An observer can be removed from the renderer, but still exist in the | |
| 841 // backend. Moreover, observer might have recorded some changes before being | |
| 842 // removed from the backend and thus, have its id be present in changes. | |
| 843 if (!observer) | |
| 844 continue; | |
| 845 observer->onChange(observations, std::move(it.second)); | |
| 846 } | |
| 847 } | |
| 848 | |
| 804 void IndexedDBDispatcher::OnForcedClose(int32_t ipc_thread_id, | 849 void IndexedDBDispatcher::OnForcedClose(int32_t ipc_thread_id, |
| 805 int32_t ipc_database_callbacks_id) { | 850 int32_t ipc_database_callbacks_id) { |
| 806 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 851 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 807 WebIDBDatabaseCallbacks* callbacks = | 852 WebIDBDatabaseCallbacks* callbacks = |
| 808 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | 853 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); |
| 809 if (!callbacks) | 854 if (!callbacks) |
| 810 return; | 855 return; |
| 811 callbacks->onForcedClose(); | 856 callbacks->onForcedClose(); |
| 812 } | 857 } |
| 813 | 858 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 831 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; | 876 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; |
| 832 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 877 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
| 833 if (i->first == ipc_exception_cursor_id || | 878 if (i->first == ipc_exception_cursor_id || |
| 834 i->second->transaction_id() != transaction_id) | 879 i->second->transaction_id() != transaction_id) |
| 835 continue; | 880 continue; |
| 836 i->second->ResetPrefetchCache(); | 881 i->second->ResetPrefetchCache(); |
| 837 } | 882 } |
| 838 } | 883 } |
| 839 | 884 |
| 840 } // namespace content | 885 } // namespace content |
| OLD | NEW |