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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 IndexedDBDispatcher::IndexedDBDispatcher(ThreadSafeSender* thread_safe_sender) | 52 IndexedDBDispatcher::IndexedDBDispatcher(ThreadSafeSender* thread_safe_sender) |
53 : thread_safe_sender_(thread_safe_sender) { | 53 : thread_safe_sender_(thread_safe_sender) { |
54 g_idb_dispatcher_tls.Pointer()->Set(this); | 54 g_idb_dispatcher_tls.Pointer()->Set(this); |
55 } | 55 } |
56 | 56 |
57 IndexedDBDispatcher::~IndexedDBDispatcher() { | 57 IndexedDBDispatcher::~IndexedDBDispatcher() { |
58 // Clear any pending callbacks - which may result in dispatch requests - | 58 // Clear any pending callbacks - which may result in dispatch requests - |
59 // before marking the dispatcher as deleted. | 59 // before marking the dispatcher as deleted. |
60 pending_callbacks_.Clear(); | 60 pending_callbacks_.Clear(); |
61 pending_database_callbacks_.Clear(); | |
62 | 61 |
63 DCHECK(pending_callbacks_.IsEmpty()); | 62 DCHECK(pending_callbacks_.IsEmpty()); |
64 DCHECK(pending_database_callbacks_.IsEmpty()); | |
65 | 63 |
66 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 64 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
67 } | 65 } |
68 | 66 |
69 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance( | 67 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance( |
70 ThreadSafeSender* thread_safe_sender) { | 68 ThreadSafeSender* thread_safe_sender) { |
71 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { | 69 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { |
72 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; | 70 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; |
73 g_idb_dispatcher_tls.Pointer()->Set(NULL); | 71 g_idb_dispatcher_tls.Pointer()->Set(NULL); |
74 } | 72 } |
75 if (g_idb_dispatcher_tls.Pointer()->Get()) | 73 if (g_idb_dispatcher_tls.Pointer()->Get()) |
76 return g_idb_dispatcher_tls.Pointer()->Get(); | 74 return g_idb_dispatcher_tls.Pointer()->Get(); |
77 | 75 |
78 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher(thread_safe_sender); | 76 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher(thread_safe_sender); |
79 if (WorkerThread::GetCurrentId()) | 77 if (WorkerThread::GetCurrentId()) |
80 WorkerThread::AddObserver(dispatcher); | 78 WorkerThread::AddObserver(dispatcher); |
81 return dispatcher; | 79 return dispatcher; |
82 } | 80 } |
83 | 81 |
84 void IndexedDBDispatcher::WillStopCurrentWorkerThread() { | 82 void IndexedDBDispatcher::WillStopCurrentWorkerThread() { |
85 delete this; | 83 delete this; |
86 } | 84 } |
87 | 85 |
88 WebIDBMetadata IndexedDBDispatcher::ConvertMetadata( | |
89 const IndexedDBDatabaseMetadata& idb_metadata) { | |
90 WebIDBMetadata web_metadata; | |
91 web_metadata.id = idb_metadata.id; | |
92 web_metadata.name = idb_metadata.name; | |
93 web_metadata.version = idb_metadata.version; | |
94 web_metadata.maxObjectStoreId = idb_metadata.max_object_store_id; | |
95 web_metadata.objectStores = | |
96 WebVector<WebIDBMetadata::ObjectStore>(idb_metadata.object_stores.size()); | |
97 | |
98 for (size_t i = 0; i < idb_metadata.object_stores.size(); ++i) { | |
99 const IndexedDBObjectStoreMetadata& idb_store_metadata = | |
100 idb_metadata.object_stores[i]; | |
101 WebIDBMetadata::ObjectStore& web_store_metadata = | |
102 web_metadata.objectStores[i]; | |
103 | |
104 web_store_metadata.id = idb_store_metadata.id; | |
105 web_store_metadata.name = idb_store_metadata.name; | |
106 web_store_metadata.keyPath = | |
107 WebIDBKeyPathBuilder::Build(idb_store_metadata.key_path); | |
108 web_store_metadata.autoIncrement = idb_store_metadata.auto_increment; | |
109 web_store_metadata.maxIndexId = idb_store_metadata.max_index_id; | |
110 web_store_metadata.indexes = | |
111 WebVector<WebIDBMetadata::Index>(idb_store_metadata.indexes.size()); | |
112 | |
113 for (size_t j = 0; j < idb_store_metadata.indexes.size(); ++j) { | |
114 const IndexedDBIndexMetadata& idb_index_metadata = | |
115 idb_store_metadata.indexes[j]; | |
116 WebIDBMetadata::Index& web_index_metadata = web_store_metadata.indexes[j]; | |
117 | |
118 web_index_metadata.id = idb_index_metadata.id; | |
119 web_index_metadata.name = idb_index_metadata.name; | |
120 web_index_metadata.keyPath = | |
121 WebIDBKeyPathBuilder::Build(idb_index_metadata.key_path); | |
122 web_index_metadata.unique = idb_index_metadata.unique; | |
123 web_index_metadata.multiEntry = idb_index_metadata.multi_entry; | |
124 } | |
125 } | |
126 | |
127 return web_metadata; | |
128 } | |
129 | |
130 std::vector<WebIDBObservation> IndexedDBDispatcher::ConvertObservations( | 86 std::vector<WebIDBObservation> IndexedDBDispatcher::ConvertObservations( |
131 const std::vector<IndexedDBMsg_Observation>& idb_observations) { | 87 const std::vector<IndexedDBMsg_Observation>& idb_observations) { |
132 std::vector<WebIDBObservation> web_observations; | 88 std::vector<WebIDBObservation> web_observations; |
133 for (const auto& idb_observation : idb_observations) { | 89 for (const auto& idb_observation : idb_observations) { |
134 WebIDBObservation web_observation; | 90 WebIDBObservation web_observation; |
135 web_observation.objectStoreId = idb_observation.object_store_id; | 91 web_observation.objectStoreId = idb_observation.object_store_id; |
136 web_observation.type = idb_observation.type; | 92 web_observation.type = idb_observation.type; |
137 web_observation.keyRange = | 93 web_observation.keyRange = |
138 WebIDBKeyRangeBuilder::Build(idb_observation.key_range); | 94 WebIDBKeyRangeBuilder::Build(idb_observation.key_range); |
139 // TODO(palakj): Assign value to web_observation. | 95 // TODO(palakj): Assign value to web_observation. |
140 web_observations.push_back(std::move(web_observation)); | 96 web_observations.push_back(std::move(web_observation)); |
141 } | 97 } |
142 return web_observations; | 98 return web_observations; |
143 } | 99 } |
144 | 100 |
145 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { | 101 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { |
146 bool handled = true; | 102 bool handled = true; |
147 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) | 103 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) |
148 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, | 104 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, |
149 OnSuccessOpenCursor) | 105 OnSuccessOpenCursor) |
150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance, | 106 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance, |
151 OnSuccessCursorContinue) | 107 OnSuccessCursorContinue) |
152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, | 108 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, |
153 OnSuccessCursorContinue) | 109 OnSuccessCursorContinue) |
154 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, | 110 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, |
155 OnSuccessCursorPrefetch) | 111 OnSuccessCursorPrefetch) |
156 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, | |
157 OnSuccessIDBDatabase) | |
158 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, | 112 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, |
159 OnSuccessIndexedDBKey) | 113 OnSuccessIndexedDBKey) |
160 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, | |
161 OnSuccessStringList) | |
162 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessArray, OnSuccessArray) | 114 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessArray, OnSuccessArray) |
163 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) | 115 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) |
164 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) | 116 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) |
165 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, | 117 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, |
166 OnSuccessUndefined) | 118 OnSuccessUndefined) |
167 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 119 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
168 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) | |
169 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) | |
170 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, | |
171 OnForcedClose) | |
172 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, | |
173 OnVersionChange) | |
174 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksAbort, OnAbort) | |
175 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksComplete, OnComplete) | |
176 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges, | 120 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges, |
177 OnDatabaseChanges) | 121 OnDatabaseChanges) |
178 IPC_MESSAGE_UNHANDLED(handled = false) | 122 IPC_MESSAGE_UNHANDLED(handled = false) |
179 IPC_END_MESSAGE_MAP() | 123 IPC_END_MESSAGE_MAP() |
180 // If a message gets here, IndexedDBMessageFilter already determined that it | 124 // If a message gets here, IndexedDBMessageFilter already determined that it |
181 // is an IndexedDB message. | 125 // is an IndexedDB message. |
182 DCHECK(handled) << "Didn't handle a message defined at line " | 126 DCHECK(handled) << "Didn't handle a message defined at line " |
183 << IPC_MESSAGE_ID_LINE(msg.type()); | 127 << IPC_MESSAGE_ID_LINE(msg.type()); |
184 } | 128 } |
185 | 129 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, n)); | 209 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, n)); |
266 } | 210 } |
267 | 211 |
268 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches, | 212 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches, |
269 int unused_prefetches, | 213 int unused_prefetches, |
270 int32_t ipc_cursor_id) { | 214 int32_t ipc_cursor_id) { |
271 Send(new IndexedDBHostMsg_CursorPrefetchReset( | 215 Send(new IndexedDBHostMsg_CursorPrefetchReset( |
272 ipc_cursor_id, used_prefetches, unused_prefetches)); | 216 ipc_cursor_id, used_prefetches, unused_prefetches)); |
273 } | 217 } |
274 | 218 |
275 void IndexedDBDispatcher::RequestIDBFactoryOpen( | 219 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32_t ipc_database_id) { |
276 const base::string16& name, | |
277 int64_t version, | |
278 int64_t transaction_id, | |
279 WebIDBCallbacks* callbacks_ptr, | |
280 WebIDBDatabaseCallbacks* database_callbacks_ptr, | |
281 const url::Origin& origin) { | |
282 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | |
283 std::unique_ptr<WebIDBDatabaseCallbacks> database_callbacks( | |
284 database_callbacks_ptr); | |
285 | |
286 IndexedDBHostMsg_FactoryOpen_Params params; | |
287 params.ipc_thread_id = CurrentWorkerId(); | |
288 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | |
289 params.ipc_database_callbacks_id = | |
290 pending_database_callbacks_.Add(database_callbacks.release()); | |
291 params.origin = origin; | |
292 params.name = name; | |
293 params.transaction_id = transaction_id; | |
294 params.version = version; | |
295 Send(new IndexedDBHostMsg_FactoryOpen(params)); | |
296 } | |
297 | |
298 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames( | |
299 WebIDBCallbacks* callbacks_ptr, | |
300 const url::Origin& origin) { | |
301 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | |
302 | |
303 IndexedDBHostMsg_FactoryGetDatabaseNames_Params params; | |
304 params.ipc_thread_id = CurrentWorkerId(); | |
305 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | |
306 params.origin = origin; | |
307 Send(new IndexedDBHostMsg_FactoryGetDatabaseNames(params)); | |
308 } | |
309 | |
310 void IndexedDBDispatcher::RequestIDBFactoryDeleteDatabase( | |
311 const base::string16& name, | |
312 WebIDBCallbacks* callbacks_ptr, | |
313 const url::Origin& origin) { | |
314 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | |
315 | |
316 IndexedDBHostMsg_FactoryDeleteDatabase_Params params; | |
317 params.ipc_thread_id = CurrentWorkerId(); | |
318 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | |
319 params.origin = origin; | |
320 params.name = name; | |
321 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); | |
322 } | |
323 | |
324 void IndexedDBDispatcher::RequestIDBDatabaseClose( | |
325 int32_t ipc_database_id, | |
326 int32_t ipc_database_callbacks_id) { | |
327 Send(new IndexedDBHostMsg_DatabaseClose(ipc_database_id)); | 220 Send(new IndexedDBHostMsg_DatabaseClose(ipc_database_id)); |
328 // There won't be pending database callbacks if the transaction was aborted in | |
329 // the initial upgradeneeded event handler. | |
330 if (pending_database_callbacks_.Lookup(ipc_database_callbacks_id)) | |
331 pending_database_callbacks_.Remove(ipc_database_callbacks_id); | |
332 } | 221 } |
333 | 222 |
334 void IndexedDBDispatcher::NotifyIDBDatabaseVersionChangeIgnored( | 223 void IndexedDBDispatcher::NotifyIDBDatabaseVersionChangeIgnored( |
335 int32_t ipc_database_id) { | 224 int32_t ipc_database_id) { |
336 Send(new IndexedDBHostMsg_DatabaseVersionChangeIgnored(ipc_database_id)); | 225 Send(new IndexedDBHostMsg_DatabaseVersionChangeIgnored(ipc_database_id)); |
337 } | 226 } |
338 | 227 |
339 void IndexedDBDispatcher::RequestIDBDatabaseCreateTransaction( | 228 void IndexedDBDispatcher::RequestIDBDatabaseCreateTransaction( |
340 int32_t ipc_database_id, | 229 int32_t ipc_database_id, |
341 int64_t transaction_id, | 230 int64_t transaction_id, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 | 427 |
539 void IndexedDBDispatcher::CursorDestroyed(int32_t ipc_cursor_id) { | 428 void IndexedDBDispatcher::CursorDestroyed(int32_t ipc_cursor_id) { |
540 cursors_.erase(ipc_cursor_id); | 429 cursors_.erase(ipc_cursor_id); |
541 } | 430 } |
542 | 431 |
543 void IndexedDBDispatcher::DatabaseDestroyed(int32_t ipc_database_id) { | 432 void IndexedDBDispatcher::DatabaseDestroyed(int32_t ipc_database_id) { |
544 DCHECK_EQ(databases_.count(ipc_database_id), 1u); | 433 DCHECK_EQ(databases_.count(ipc_database_id), 1u); |
545 databases_.erase(ipc_database_id); | 434 databases_.erase(ipc_database_id); |
546 } | 435 } |
547 | 436 |
548 void IndexedDBDispatcher::OnSuccessIDBDatabase( | 437 WebIDBDatabase* IndexedDBDispatcher::RegisterDatabase(int32_t ipc_database_id) { |
549 int32_t ipc_thread_id, | 438 DCHECK(!databases_.count(ipc_database_id)); |
550 int32_t ipc_callbacks_id, | 439 return databases_[ipc_database_id] = |
551 int32_t ipc_database_callbacks_id, | 440 new WebIDBDatabaseImpl(ipc_database_id, thread_safe_sender_.get()); |
552 int32_t ipc_object_id, | 441 } |
553 const IndexedDBDatabaseMetadata& idb_metadata) { | |
554 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
555 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | |
556 if (!callbacks) | |
557 return; | |
558 WebIDBMetadata metadata(ConvertMetadata(idb_metadata)); | |
559 // If an upgrade was performed, count will be non-zero. | |
560 WebIDBDatabase* database = NULL; | |
561 | 442 |
562 // Back-end will send kNoDatabase if it was already sent in OnUpgradeNeeded. | 443 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks( |
563 // May already be deleted and removed from the table, but do not recreate.. | 444 IndexedDBCallbacksImpl::InternalState* callbacks) { |
564 if (ipc_object_id != kNoDatabase) { | 445 mojo_owned_callback_state_.insert(callbacks); |
565 DCHECK(!databases_.count(ipc_object_id)); | 446 } |
566 database = databases_[ipc_object_id] = new WebIDBDatabaseImpl( | |
567 ipc_object_id, ipc_database_callbacks_id, thread_safe_sender_.get()); | |
568 } | |
569 | 447 |
570 callbacks->onSuccess(database, metadata); | 448 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks( |
571 pending_callbacks_.Remove(ipc_callbacks_id); | 449 IndexedDBCallbacksImpl::InternalState* callbacks) { |
| 450 DCHECK(base::ContainsValue(mojo_owned_callback_state_, callbacks)); |
| 451 mojo_owned_callback_state_.erase(callbacks); |
| 452 } |
| 453 |
| 454 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks( |
| 455 blink::WebIDBDatabaseCallbacks* callbacks) { |
| 456 mojo_owned_database_callback_state_.insert(callbacks); |
| 457 } |
| 458 |
| 459 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks( |
| 460 blink::WebIDBDatabaseCallbacks* callbacks) { |
| 461 DCHECK(base::ContainsValue(mojo_owned_database_callback_state_, callbacks)); |
| 462 mojo_owned_database_callback_state_.erase(callbacks); |
572 } | 463 } |
573 | 464 |
574 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32_t ipc_thread_id, | 465 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32_t ipc_thread_id, |
575 int32_t ipc_callbacks_id, | 466 int32_t ipc_callbacks_id, |
576 const IndexedDBKey& key) { | 467 const IndexedDBKey& key) { |
577 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 468 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
578 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 469 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
579 if (!callbacks) | 470 if (!callbacks) |
580 return; | 471 return; |
581 callbacks->onSuccess(WebIDBKeyBuilder::Build(key)); | 472 callbacks->onSuccess(WebIDBKeyBuilder::Build(key)); |
582 pending_callbacks_.Remove(ipc_callbacks_id); | 473 pending_callbacks_.Remove(ipc_callbacks_id); |
583 } | 474 } |
584 | 475 |
585 void IndexedDBDispatcher::OnSuccessStringList( | |
586 int32_t ipc_thread_id, | |
587 int32_t ipc_callbacks_id, | |
588 const std::vector<base::string16>& value) { | |
589 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
590 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | |
591 if (!callbacks) | |
592 return; | |
593 callbacks->onSuccess(WebVector<WebString>(value)); | |
594 pending_callbacks_.Remove(ipc_callbacks_id); | |
595 } | |
596 | |
597 // Populate some WebIDBValue members (data & blob info) from the supplied | 476 // Populate some WebIDBValue members (data & blob info) from the supplied |
598 // value message (IndexedDBMsg_Value or one that includes it). | 477 // value message (IndexedDBMsg_Value or one that includes it). |
599 template <class IndexedDBMsgValueType> | 478 template <class IndexedDBMsgValueType> |
600 static void PrepareWebValue(const IndexedDBMsgValueType& value, | 479 static void PrepareWebValue(const IndexedDBMsgValueType& value, |
601 WebIDBValue* web_value) { | 480 WebIDBValue* web_value) { |
602 if (value.bits.empty()) | 481 if (value.bits.empty()) |
603 return; | 482 return; |
604 | 483 |
605 web_value->data.assign(&*value.bits.begin(), value.bits.size()); | 484 web_value->data.assign(&*value.bits.begin(), value.bits.size()); |
606 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); | 485 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 return; | 622 return; |
744 | 623 |
745 cur_iter->second->SetPrefetchData(p.keys, p.primary_keys, values); | 624 cur_iter->second->SetPrefetchData(p.keys, p.primary_keys, values); |
746 | 625 |
747 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 626 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
748 DCHECK(callbacks); | 627 DCHECK(callbacks); |
749 cur_iter->second->CachedContinue(callbacks); | 628 cur_iter->second->CachedContinue(callbacks); |
750 pending_callbacks_.Remove(ipc_callbacks_id); | 629 pending_callbacks_.Remove(ipc_callbacks_id); |
751 } | 630 } |
752 | 631 |
753 void IndexedDBDispatcher::OnIntBlocked(int32_t ipc_thread_id, | |
754 int32_t ipc_callbacks_id, | |
755 int64_t existing_version) { | |
756 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
757 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | |
758 DCHECK(callbacks); | |
759 callbacks->onBlocked(existing_version); | |
760 } | |
761 | |
762 void IndexedDBDispatcher::OnUpgradeNeeded( | |
763 const IndexedDBMsg_CallbacksUpgradeNeeded_Params& p) { | |
764 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | |
765 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(p.ipc_callbacks_id); | |
766 DCHECK(callbacks); | |
767 WebIDBMetadata metadata(ConvertMetadata(p.idb_metadata)); | |
768 DCHECK(!databases_.count(p.ipc_database_id)); | |
769 databases_[p.ipc_database_id] = | |
770 new WebIDBDatabaseImpl(p.ipc_database_id, | |
771 p.ipc_database_callbacks_id, | |
772 thread_safe_sender_.get()); | |
773 callbacks->onUpgradeNeeded( | |
774 p.old_version, | |
775 databases_[p.ipc_database_id], | |
776 metadata, | |
777 static_cast<blink::WebIDBDataLoss>(p.data_loss), | |
778 WebString::fromUTF8(p.data_loss_message)); | |
779 } | |
780 | |
781 void IndexedDBDispatcher::OnError(int32_t ipc_thread_id, | 632 void IndexedDBDispatcher::OnError(int32_t ipc_thread_id, |
782 int32_t ipc_callbacks_id, | 633 int32_t ipc_callbacks_id, |
783 int code, | 634 int code, |
784 const base::string16& message) { | 635 const base::string16& message) { |
785 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 636 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
786 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 637 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
787 if (!callbacks) | 638 if (!callbacks) |
788 return; | 639 return; |
789 if (message.empty()) | 640 if (message.empty()) |
790 callbacks->onError(WebIDBDatabaseError(code)); | 641 callbacks->onError(WebIDBDatabaseError(code)); |
791 else | 642 else |
792 callbacks->onError(WebIDBDatabaseError(code, message)); | 643 callbacks->onError(WebIDBDatabaseError(code, message)); |
793 pending_callbacks_.Remove(ipc_callbacks_id); | 644 pending_callbacks_.Remove(ipc_callbacks_id); |
794 cursor_transaction_ids_.erase(ipc_callbacks_id); | 645 cursor_transaction_ids_.erase(ipc_callbacks_id); |
795 } | 646 } |
796 | 647 |
797 void IndexedDBDispatcher::OnAbort(int32_t ipc_thread_id, | |
798 int32_t ipc_database_callbacks_id, | |
799 int64_t transaction_id, | |
800 int code, | |
801 const base::string16& message) { | |
802 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
803 WebIDBDatabaseCallbacks* callbacks = | |
804 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
805 if (!callbacks) | |
806 return; | |
807 if (message.empty()) | |
808 callbacks->onAbort(transaction_id, WebIDBDatabaseError(code)); | |
809 else | |
810 callbacks->onAbort(transaction_id, WebIDBDatabaseError(code, message)); | |
811 } | |
812 | |
813 void IndexedDBDispatcher::OnComplete(int32_t ipc_thread_id, | |
814 int32_t ipc_database_callbacks_id, | |
815 int64_t transaction_id) { | |
816 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
817 WebIDBDatabaseCallbacks* callbacks = | |
818 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
819 if (!callbacks) | |
820 return; | |
821 callbacks->onComplete(transaction_id); | |
822 } | |
823 | |
824 void IndexedDBDispatcher::OnDatabaseChanges( | 648 void IndexedDBDispatcher::OnDatabaseChanges( |
825 int32_t ipc_thread_id, | 649 int32_t ipc_thread_id, |
826 int32_t ipc_database_id, | 650 int32_t ipc_database_id, |
827 const IndexedDBMsg_ObserverChanges& changes) { | 651 const IndexedDBMsg_ObserverChanges& changes) { |
828 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 652 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
829 std::vector<WebIDBObservation> observations( | 653 std::vector<WebIDBObservation> observations( |
830 ConvertObservations(changes.observations)); | 654 ConvertObservations(changes.observations)); |
831 for (auto& it : changes.observation_index) { | 655 for (auto& it : changes.observation_index) { |
832 WebIDBObserver* observer = observers_.Lookup(it.first); | 656 WebIDBObserver* observer = observers_.Lookup(it.first); |
833 // An observer can be removed from the renderer, but still exist in the | 657 // An observer can be removed from the renderer, but still exist in the |
834 // backend. Moreover, observer might have recorded some changes before being | 658 // backend. Moreover, observer might have recorded some changes before being |
835 // removed from the backend and thus, have its id be present in changes. | 659 // removed from the backend and thus, have its id be present in changes. |
836 if (!observer) | 660 if (!observer) |
837 continue; | 661 continue; |
838 observer->onChange(observations, std::move(it.second)); | 662 observer->onChange(observations, std::move(it.second)); |
839 } | 663 } |
840 } | 664 } |
841 | 665 |
842 void IndexedDBDispatcher::OnForcedClose(int32_t ipc_thread_id, | |
843 int32_t ipc_database_callbacks_id) { | |
844 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
845 WebIDBDatabaseCallbacks* callbacks = | |
846 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
847 if (!callbacks) | |
848 return; | |
849 callbacks->onForcedClose(); | |
850 } | |
851 | |
852 void IndexedDBDispatcher::OnVersionChange(int32_t ipc_thread_id, | |
853 int32_t ipc_database_callbacks_id, | |
854 int64_t old_version, | |
855 int64_t new_version) { | |
856 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
857 WebIDBDatabaseCallbacks* callbacks = | |
858 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
859 // callbacks would be NULL if a versionchange event is received after close | |
860 // has been called. | |
861 if (!callbacks) | |
862 return; | |
863 callbacks->onVersionChange(old_version, new_version); | |
864 } | |
865 | |
866 void IndexedDBDispatcher::ResetCursorPrefetchCaches( | 666 void IndexedDBDispatcher::ResetCursorPrefetchCaches( |
867 int64_t transaction_id, | 667 int64_t transaction_id, |
868 int32_t ipc_exception_cursor_id) { | 668 int32_t ipc_exception_cursor_id) { |
869 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; | 669 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; |
870 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 670 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
871 if (i->first == ipc_exception_cursor_id || | 671 if (i->first == ipc_exception_cursor_id || |
872 i->second->transaction_id() != transaction_id) | 672 i->second->transaction_id() != transaction_id) |
873 continue; | 673 continue; |
874 i->second->ResetPrefetchCache(); | 674 i->second->ResetPrefetchCache(); |
875 } | 675 } |
876 } | 676 } |
877 | 677 |
878 } // namespace content | 678 } // namespace content |
OLD | NEW |