Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Side by Side Diff: content/child/indexed_db/indexed_db_dispatcher.cc

Issue 2449953008: Port messages sent by WebIDBDatabaseImpl to Mojo. (Closed)
Patch Set: Address more comments from dcheng@. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 WebIDBKeyRangeBuilder::Build(idb_observation.key_range); 94 WebIDBKeyRangeBuilder::Build(idb_observation.key_range);
95 // TODO(palakj): Assign value to web_observation. 95 // TODO(palakj): Assign value to web_observation.
96 web_observations.push_back(std::move(web_observation)); 96 web_observations.push_back(std::move(web_observation));
97 } 97 }
98 return web_observations; 98 return web_observations;
99 } 99 }
100 100
101 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { 101 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
102 bool handled = true; 102 bool handled = true;
103 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) 103 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg)
104 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor,
105 OnSuccessOpenCursor)
106 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance, 104 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorAdvance,
107 OnSuccessCursorContinue) 105 OnSuccessCursorContinue)
108 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, 106 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue,
109 OnSuccessCursorContinue) 107 OnSuccessCursorContinue)
110 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, 108 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch,
111 OnSuccessCursorPrefetch) 109 OnSuccessCursorPrefetch)
112 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey,
113 OnSuccessIndexedDBKey)
114 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessArray, OnSuccessArray)
115 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) 110 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue)
116 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) 111 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger)
117 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined,
118 OnSuccessUndefined)
119 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) 112 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError)
120 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges, 113 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges,
121 OnDatabaseChanges) 114 OnDatabaseChanges)
122 IPC_MESSAGE_UNHANDLED(handled = false) 115 IPC_MESSAGE_UNHANDLED(handled = false)
123 IPC_END_MESSAGE_MAP() 116 IPC_END_MESSAGE_MAP()
124 // If a message gets here, IndexedDBMessageFilter already determined that it 117 // If a message gets here, IndexedDBMessageFilter already determined that it
125 // is an IndexedDB message. 118 // is an IndexedDB message.
126 DCHECK(handled) << "Didn't handle a message defined at line " 119 DCHECK(handled) << "Didn't handle a message defined at line "
127 << IPC_MESSAGE_ID_LINE(msg.type()); 120 << IPC_MESSAGE_ID_LINE(msg.type());
128 } 121 }
129 122
130 bool IndexedDBDispatcher::Send(IPC::Message* msg) { 123 bool IndexedDBDispatcher::Send(IPC::Message* msg) {
131 return thread_safe_sender_->Send(msg); 124 return thread_safe_sender_->Send(msg);
132 } 125 }
133 126
134 int32_t IndexedDBDispatcher::AddIDBObserver( 127 int32_t IndexedDBDispatcher::RegisterObserver(
135 int32_t ipc_database_id,
136 int64_t transaction_id,
137 std::unique_ptr<WebIDBObserver> observer) { 128 std::unique_ptr<WebIDBObserver> observer) {
138 IndexedDBHostMsg_DatabaseObserve_Params params; 129 return observers_.Add(observer.release());
139 static_assert(blink::WebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT,
140 "WebIDBOperationType Count exceeds size of uint16_t");
141 params.operation_types =
142 static_cast<uint16_t>(observer->operationTypes().to_ulong());
143 params.include_transaction = observer->transaction();
144 params.no_records = observer->noRecords();
145 params.values = observer->values();
146 int32_t observer_id = observers_.Add(observer.release());
147 params.ipc_database_id = ipc_database_id;
148 params.transaction_id = transaction_id;
149 params.observer_id = observer_id;
150 Send(new IndexedDBHostMsg_DatabaseObserve(params));
151 return observer_id;
152 } 130 }
153 131
154 void IndexedDBDispatcher::RemoveIDBObserversFromDatabase( 132 void IndexedDBDispatcher::RemoveObservers(
155 int32_t ipc_database_id,
156 const std::vector<int32_t>& observer_ids_to_remove) { 133 const std::vector<int32_t>& observer_ids_to_remove) {
157 for (int32_t id_to_remove : observer_ids_to_remove) {
158 observers_.Remove(id_to_remove);
159 }
160 Send(new IndexedDBHostMsg_DatabaseUnobserve(ipc_database_id,
161 observer_ids_to_remove));
162 }
163
164 void IndexedDBDispatcher::RemoveIDBObservers(
165 const std::set<int32_t>& observer_ids_to_remove) {
166 for (int32_t id : observer_ids_to_remove) 134 for (int32_t id : observer_ids_to_remove)
167 observers_.Remove(id); 135 observers_.Remove(id);
168 } 136 }
169 137
170 void IndexedDBDispatcher::RequestIDBCursorAdvance( 138 void IndexedDBDispatcher::RequestIDBCursorAdvance(
171 unsigned long count, 139 unsigned long count,
172 WebIDBCallbacks* callbacks_ptr, 140 WebIDBCallbacks* callbacks_ptr,
173 int32_t ipc_cursor_id, 141 int32_t ipc_cursor_id,
174 int64_t transaction_id) { 142 int64_t transaction_id) {
175 // Reset all cursor prefetch caches except for this cursor. 143 // Reset all cursor prefetch caches except for this cursor.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, n)); 177 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, n));
210 } 178 }
211 179
212 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches, 180 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches,
213 int unused_prefetches, 181 int unused_prefetches,
214 int32_t ipc_cursor_id) { 182 int32_t ipc_cursor_id) {
215 Send(new IndexedDBHostMsg_CursorPrefetchReset( 183 Send(new IndexedDBHostMsg_CursorPrefetchReset(
216 ipc_cursor_id, used_prefetches, unused_prefetches)); 184 ipc_cursor_id, used_prefetches, unused_prefetches));
217 } 185 }
218 186
219 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32_t ipc_database_id) { 187 void IndexedDBDispatcher::RegisterCursor(int32_t ipc_cursor_id,
220 Send(new IndexedDBHostMsg_DatabaseClose(ipc_database_id)); 188 WebIDBCursorImpl* cursor) {
221 } 189 DCHECK(!base::ContainsKey(cursors_, ipc_cursor_id));
222 190 cursors_[ipc_cursor_id] = cursor;
223 void IndexedDBDispatcher::NotifyIDBDatabaseVersionChangeIgnored(
224 int32_t ipc_database_id) {
225 Send(new IndexedDBHostMsg_DatabaseVersionChangeIgnored(ipc_database_id));
226 }
227
228 void IndexedDBDispatcher::RequestIDBDatabaseCreateTransaction(
229 int32_t ipc_database_id,
230 int64_t transaction_id,
231 WebVector<long long> object_store_ids,
232 blink::WebIDBTransactionMode mode) {
233 IndexedDBHostMsg_DatabaseCreateTransaction_Params params;
234 params.ipc_thread_id = CurrentWorkerId();
235 params.ipc_database_id = ipc_database_id;
236 params.transaction_id = transaction_id;
237 params.object_store_ids
238 .assign(object_store_ids.data(),
239 object_store_ids.data() + object_store_ids.size());
240 params.mode = mode;
241
242 Send(new IndexedDBHostMsg_DatabaseCreateTransaction(params));
243 }
244
245 void IndexedDBDispatcher::RequestIDBDatabaseGet(
246 int32_t ipc_database_id,
247 int64_t transaction_id,
248 int64_t object_store_id,
249 int64_t index_id,
250 const IndexedDBKeyRange& key_range,
251 bool key_only,
252 WebIDBCallbacks* callbacks) {
253 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
254 IndexedDBHostMsg_DatabaseGet_Params params;
255 init_params(&params, callbacks);
256 params.ipc_database_id = ipc_database_id;
257 params.transaction_id = transaction_id;
258 params.object_store_id = object_store_id;
259 params.index_id = index_id;
260 params.key_range = key_range;
261 params.key_only = key_only;
262 Send(new IndexedDBHostMsg_DatabaseGet(params));
263 }
264
265 void IndexedDBDispatcher::RequestIDBDatabaseGetAll(
266 int32_t ipc_database_id,
267 int64_t transaction_id,
268 int64_t object_store_id,
269 int64_t index_id,
270 const IndexedDBKeyRange& key_range,
271 bool key_only,
272 int64_t max_count,
273 WebIDBCallbacks* callbacks) {
274 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
275 IndexedDBHostMsg_DatabaseGetAll_Params params;
276 init_params(&params, callbacks);
277 params.ipc_database_id = ipc_database_id;
278 params.transaction_id = transaction_id;
279 params.object_store_id = object_store_id;
280 params.index_id = index_id;
281 params.key_range = key_range;
282 params.key_only = key_only;
283 params.max_count = max_count;
284 Send(new IndexedDBHostMsg_DatabaseGetAll(params));
285 }
286
287 void IndexedDBDispatcher::RequestIDBDatabasePut(
288 int32_t ipc_database_id,
289 int64_t transaction_id,
290 int64_t object_store_id,
291 const WebData& value,
292 const blink::WebVector<WebBlobInfo>& web_blob_info,
293 const IndexedDBKey& key,
294 blink::WebIDBPutMode put_mode,
295 WebIDBCallbacks* callbacks,
296 const WebVector<long long>& index_ids,
297 const WebVector<WebVector<WebIDBKey>>& index_keys) {
298 if (value.size() + key.size_estimate() > max_put_value_size_) {
299 callbacks->onError(WebIDBDatabaseError(
300 blink::WebIDBDatabaseExceptionUnknownError,
301 WebString::fromUTF8(base::StringPrintf(
302 "The serialized value is too large"
303 " (size=%" PRIuS " bytes, max=%" PRIuS " bytes).",
304 value.size(),
305 max_put_value_size_).c_str())));
306 return;
307 }
308
309 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
310 IndexedDBHostMsg_DatabasePut_Params params;
311 init_params(&params, callbacks);
312 params.ipc_database_id = ipc_database_id;
313 params.transaction_id = transaction_id;
314 params.object_store_id = object_store_id;
315
316 params.value.bits.assign(value.data(), value.data() + value.size());
317 params.key = key;
318 params.put_mode = put_mode;
319
320 DCHECK_EQ(index_ids.size(), index_keys.size());
321 params.index_keys.resize(index_ids.size());
322 for (size_t i = 0, len = index_ids.size(); i < len; ++i) {
323 params.index_keys[i].first = index_ids[i];
324 params.index_keys[i].second.resize(index_keys[i].size());
325 for (size_t j = 0; j < index_keys[i].size(); ++j) {
326 params.index_keys[i].second[j] =
327 IndexedDBKey(IndexedDBKeyBuilder::Build(index_keys[i][j]));
328 }
329 }
330
331 params.value.blob_or_file_info.resize(web_blob_info.size());
332 for (size_t i = 0; i < web_blob_info.size(); ++i) {
333 const WebBlobInfo& info = web_blob_info[i];
334 IndexedDBMsg_BlobOrFileInfo& blob_or_file_info =
335 params.value.blob_or_file_info[i];
336 blob_or_file_info.is_file = info.isFile();
337 if (info.isFile()) {
338 blob_or_file_info.file_path = info.filePath();
339 blob_or_file_info.file_name = info.fileName();
340 blob_or_file_info.last_modified = info.lastModified();
341 }
342 blob_or_file_info.size = info.size();
343 blob_or_file_info.uuid = info.uuid().latin1();
344 DCHECK(blob_or_file_info.uuid.size());
345 blob_or_file_info.mime_type = info.type();
346 }
347
348 Send(new IndexedDBHostMsg_DatabasePut(params));
349 }
350
351 void IndexedDBDispatcher::RequestIDBDatabaseOpenCursor(
352 int32_t ipc_database_id,
353 int64_t transaction_id,
354 int64_t object_store_id,
355 int64_t index_id,
356 const IndexedDBKeyRange& key_range,
357 blink::WebIDBCursorDirection direction,
358 bool key_only,
359 blink::WebIDBTaskType task_type,
360 WebIDBCallbacks* callbacks) {
361 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
362 IndexedDBHostMsg_DatabaseOpenCursor_Params params;
363 init_params(&params, callbacks);
364 params.ipc_database_id = ipc_database_id;
365 params.transaction_id = transaction_id;
366 params.object_store_id = object_store_id;
367 params.index_id = index_id;
368 params.key_range = key_range;
369 params.direction = direction;
370 params.key_only = key_only;
371 params.task_type = task_type;
372 Send(new IndexedDBHostMsg_DatabaseOpenCursor(params));
373
374 DCHECK(cursor_transaction_ids_.find(params.ipc_callbacks_id) ==
375 cursor_transaction_ids_.end());
376 cursor_transaction_ids_[params.ipc_callbacks_id] = transaction_id;
377 }
378
379 void IndexedDBDispatcher::RequestIDBDatabaseCount(
380 int32_t ipc_database_id,
381 int64_t transaction_id,
382 int64_t object_store_id,
383 int64_t index_id,
384 const IndexedDBKeyRange& key_range,
385 WebIDBCallbacks* callbacks) {
386 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
387 IndexedDBHostMsg_DatabaseCount_Params params;
388 init_params(&params, callbacks);
389 params.ipc_database_id = ipc_database_id;
390 params.transaction_id = transaction_id;
391 params.object_store_id = object_store_id;
392 params.index_id = index_id;
393 params.key_range = key_range;
394 Send(new IndexedDBHostMsg_DatabaseCount(params));
395 }
396
397 void IndexedDBDispatcher::RequestIDBDatabaseDeleteRange(
398 int32_t ipc_database_id,
399 int64_t transaction_id,
400 int64_t object_store_id,
401 const IndexedDBKeyRange& key_range,
402 WebIDBCallbacks* callbacks) {
403 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
404 IndexedDBHostMsg_DatabaseDeleteRange_Params params;
405 init_params(&params, callbacks);
406 params.ipc_database_id = ipc_database_id;
407 params.transaction_id = transaction_id;
408 params.object_store_id = object_store_id;
409 params.key_range = key_range;
410 Send(new IndexedDBHostMsg_DatabaseDeleteRange(params));
411 }
412
413 void IndexedDBDispatcher::RequestIDBDatabaseClear(
414 int32_t ipc_database_id,
415 int64_t transaction_id,
416 int64_t object_store_id,
417 WebIDBCallbacks* callbacks_ptr) {
418 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
419 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
420 int32_t ipc_callbacks_id = pending_callbacks_.Add(callbacks.release());
421 Send(new IndexedDBHostMsg_DatabaseClear(CurrentWorkerId(),
422 ipc_callbacks_id,
423 ipc_database_id,
424 transaction_id,
425 object_store_id));
426 } 191 }
427 192
428 void IndexedDBDispatcher::CursorDestroyed(int32_t ipc_cursor_id) { 193 void IndexedDBDispatcher::CursorDestroyed(int32_t ipc_cursor_id) {
429 cursors_.erase(ipc_cursor_id); 194 cursors_.erase(ipc_cursor_id);
430 } 195 }
431 196
432 void IndexedDBDispatcher::DatabaseDestroyed(int32_t ipc_database_id) {
433 DCHECK_EQ(databases_.count(ipc_database_id), 1u);
434 databases_.erase(ipc_database_id);
435 }
436
437 WebIDBDatabase* IndexedDBDispatcher::RegisterDatabase(int32_t ipc_database_id) {
438 DCHECK(!databases_.count(ipc_database_id));
439 return databases_[ipc_database_id] =
440 new WebIDBDatabaseImpl(ipc_database_id, thread_safe_sender_.get());
441 }
442
443 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks( 197 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks(
444 IndexedDBCallbacksImpl::InternalState* callbacks) { 198 IndexedDBCallbacksImpl::InternalState* callbacks) {
445 mojo_owned_callback_state_.insert(callbacks); 199 mojo_owned_callback_state_.insert(callbacks);
446 } 200 }
447 201
448 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks( 202 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks(
449 IndexedDBCallbacksImpl::InternalState* callbacks) { 203 IndexedDBCallbacksImpl::InternalState* callbacks) {
450 DCHECK(base::ContainsValue(mojo_owned_callback_state_, callbacks)); 204 DCHECK(base::ContainsValue(mojo_owned_callback_state_, callbacks));
451 mojo_owned_callback_state_.erase(callbacks); 205 mojo_owned_callback_state_.erase(callbacks);
452 } 206 }
453 207
454 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks( 208 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks(
455 blink::WebIDBDatabaseCallbacks* callbacks) { 209 blink::WebIDBDatabaseCallbacks* callbacks) {
456 mojo_owned_database_callback_state_.insert(callbacks); 210 mojo_owned_database_callback_state_.insert(callbacks);
457 } 211 }
458 212
459 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks( 213 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks(
460 blink::WebIDBDatabaseCallbacks* callbacks) { 214 blink::WebIDBDatabaseCallbacks* callbacks) {
461 DCHECK(base::ContainsValue(mojo_owned_database_callback_state_, callbacks)); 215 DCHECK(base::ContainsValue(mojo_owned_database_callback_state_, callbacks));
462 mojo_owned_database_callback_state_.erase(callbacks); 216 mojo_owned_database_callback_state_.erase(callbacks);
463 } 217 }
464 218
465 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32_t ipc_thread_id,
466 int32_t ipc_callbacks_id,
467 const IndexedDBKey& key) {
468 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
469 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
470 if (!callbacks)
471 return;
472 callbacks->onSuccess(WebIDBKeyBuilder::Build(key));
473 pending_callbacks_.Remove(ipc_callbacks_id);
474 }
475
476 // Populate some WebIDBValue members (data & blob info) from the supplied 219 // Populate some WebIDBValue members (data & blob info) from the supplied
477 // value message (IndexedDBMsg_Value or one that includes it). 220 // value message (IndexedDBMsg_Value or one that includes it).
478 template <class IndexedDBMsgValueType> 221 template <class IndexedDBMsgValueType>
479 static void PrepareWebValue(const IndexedDBMsgValueType& value, 222 static void PrepareWebValue(const IndexedDBMsgValueType& value,
480 WebIDBValue* web_value) { 223 WebIDBValue* web_value) {
481 if (value.bits.empty()) 224 if (value.bits.empty())
482 return; 225 return;
483 226
484 web_value->data.assign(&*value.bits.begin(), value.bits.size()); 227 web_value->data.assign(&*value.bits.begin(), value.bits.size());
485 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); 228 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size());
(...skipping 12 matching lines...) Expand all
498 web_value->webBlobInfo.swap(local_blob_info); 241 web_value->webBlobInfo.swap(local_blob_info);
499 } 242 }
500 243
501 static void PrepareReturnWebValue(const IndexedDBMsg_ReturnValue& value, 244 static void PrepareReturnWebValue(const IndexedDBMsg_ReturnValue& value,
502 WebIDBValue* web_value) { 245 WebIDBValue* web_value) {
503 PrepareWebValue(value, web_value); 246 PrepareWebValue(value, web_value);
504 web_value->primaryKey = WebIDBKeyBuilder::Build(value.primary_key); 247 web_value->primaryKey = WebIDBKeyBuilder::Build(value.primary_key);
505 web_value->keyPath = WebIDBKeyPathBuilder::Build(value.key_path); 248 web_value->keyPath = WebIDBKeyPathBuilder::Build(value.key_path);
506 } 249 }
507 250
508 void IndexedDBDispatcher::OnSuccessArray(
509 const IndexedDBMsg_CallbacksSuccessArray_Params& p) {
510 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
511 int32_t ipc_callbacks_id = p.ipc_callbacks_id;
512 blink::WebVector<WebIDBValue> web_values(p.values.size());
513 for (size_t i = 0; i < p.values.size(); ++i)
514 PrepareReturnWebValue(p.values[i], &web_values[i]);
515 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
516 DCHECK(callbacks);
517 callbacks->onSuccess(web_values);
518 pending_callbacks_.Remove(ipc_callbacks_id);
519 }
520
521 void IndexedDBDispatcher::OnSuccessValue( 251 void IndexedDBDispatcher::OnSuccessValue(
522 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { 252 const IndexedDBMsg_CallbacksSuccessValue_Params& params) {
523 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); 253 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId());
524 WebIDBCallbacks* callbacks = 254 WebIDBCallbacks* callbacks =
525 pending_callbacks_.Lookup(params.ipc_callbacks_id); 255 pending_callbacks_.Lookup(params.ipc_callbacks_id);
526 if (!callbacks) 256 if (!callbacks)
527 return; 257 return;
528 WebIDBValue web_value; 258 WebIDBValue web_value;
529 PrepareReturnWebValue(params.value, &web_value); 259 PrepareReturnWebValue(params.value, &web_value);
530 if (params.value.primary_key.IsValid()) { 260 if (params.value.primary_key.IsValid()) {
531 web_value.primaryKey = WebIDBKeyBuilder::Build(params.value.primary_key); 261 web_value.primaryKey = WebIDBKeyBuilder::Build(params.value.primary_key);
532 web_value.keyPath = WebIDBKeyPathBuilder::Build(params.value.key_path); 262 web_value.keyPath = WebIDBKeyPathBuilder::Build(params.value.key_path);
533 } 263 }
534 callbacks->onSuccess(web_value); 264 callbacks->onSuccess(web_value);
535 cursor_transaction_ids_.erase(params.ipc_callbacks_id);
536 pending_callbacks_.Remove(params.ipc_callbacks_id); 265 pending_callbacks_.Remove(params.ipc_callbacks_id);
537 } 266 }
538 267
539 void IndexedDBDispatcher::OnSuccessInteger(int32_t ipc_thread_id, 268 void IndexedDBDispatcher::OnSuccessInteger(int32_t ipc_thread_id,
540 int32_t ipc_callbacks_id, 269 int32_t ipc_callbacks_id,
541 int64_t value) { 270 int64_t value) {
542 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 271 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
543 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 272 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
544 if (!callbacks) 273 if (!callbacks)
545 return; 274 return;
546 callbacks->onSuccess(value); 275 callbacks->onSuccess(value);
547 pending_callbacks_.Remove(ipc_callbacks_id); 276 pending_callbacks_.Remove(ipc_callbacks_id);
548 } 277 }
549 278
550 void IndexedDBDispatcher::OnSuccessUndefined(int32_t ipc_thread_id,
551 int32_t ipc_callbacks_id) {
552 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
553 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
554 if (!callbacks)
555 return;
556 callbacks->onSuccess();
557 pending_callbacks_.Remove(ipc_callbacks_id);
558 }
559
560 void IndexedDBDispatcher::OnSuccessOpenCursor(
561 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) {
562 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
563 int32_t ipc_callbacks_id = p.ipc_callbacks_id;
564 int32_t ipc_object_id = p.ipc_cursor_id;
565 const IndexedDBKey& key = p.key;
566 const IndexedDBKey& primary_key = p.primary_key;
567 WebIDBValue web_value;
568 PrepareWebValue(p.value, &web_value);
569
570 DCHECK(cursor_transaction_ids_.find(ipc_callbacks_id) !=
571 cursor_transaction_ids_.end());
572 int64_t transaction_id = cursor_transaction_ids_[ipc_callbacks_id];
573 cursor_transaction_ids_.erase(ipc_callbacks_id);
574
575 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
576 if (!callbacks)
577 return;
578
579 WebIDBCursorImpl* cursor = new WebIDBCursorImpl(
580 ipc_object_id, transaction_id, thread_safe_sender_.get());
581 cursors_[ipc_object_id] = cursor;
582 callbacks->onSuccess(cursor, WebIDBKeyBuilder::Build(key),
583 WebIDBKeyBuilder::Build(primary_key), web_value);
584
585 pending_callbacks_.Remove(ipc_callbacks_id);
586 }
587
588 void IndexedDBDispatcher::OnSuccessCursorContinue( 279 void IndexedDBDispatcher::OnSuccessCursorContinue(
589 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { 280 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) {
590 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 281 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
591 int32_t ipc_callbacks_id = p.ipc_callbacks_id; 282 int32_t ipc_callbacks_id = p.ipc_callbacks_id;
592 int32_t ipc_cursor_id = p.ipc_cursor_id; 283 int32_t ipc_cursor_id = p.ipc_cursor_id;
593 const IndexedDBKey& key = p.key; 284 const IndexedDBKey& key = p.key;
594 const IndexedDBKey& primary_key = p.primary_key; 285 const IndexedDBKey& primary_key = p.primary_key;
595 286
596 if (cursors_.find(ipc_cursor_id) == cursors_.end()) 287 if (cursors_.find(ipc_cursor_id) == cursors_.end())
597 return; 288 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 const base::string16& message) { 326 const base::string16& message) {
636 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 327 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
637 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 328 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
638 if (!callbacks) 329 if (!callbacks)
639 return; 330 return;
640 if (message.empty()) 331 if (message.empty())
641 callbacks->onError(WebIDBDatabaseError(code)); 332 callbacks->onError(WebIDBDatabaseError(code));
642 else 333 else
643 callbacks->onError(WebIDBDatabaseError(code, message)); 334 callbacks->onError(WebIDBDatabaseError(code, message));
644 pending_callbacks_.Remove(ipc_callbacks_id); 335 pending_callbacks_.Remove(ipc_callbacks_id);
645 cursor_transaction_ids_.erase(ipc_callbacks_id);
646 } 336 }
647 337
648 void IndexedDBDispatcher::OnDatabaseChanges( 338 void IndexedDBDispatcher::OnDatabaseChanges(
649 int32_t ipc_thread_id, 339 int32_t ipc_thread_id,
650 const IndexedDBMsg_ObserverChanges& changes) { 340 const IndexedDBMsg_ObserverChanges& changes) {
651 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 341 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
652 std::vector<WebIDBObservation> observations( 342 std::vector<WebIDBObservation> observations(
653 ConvertObservations(changes.observations)); 343 ConvertObservations(changes.observations));
654 for (auto& it : changes.observation_index) { 344 for (auto& it : changes.observation_index) {
655 WebIDBObserver* observer = observers_.Lookup(it.first); 345 WebIDBObserver* observer = observers_.Lookup(it.first);
(...skipping 12 matching lines...) Expand all
668 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; 358 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator;
669 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 359 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
670 if (i->first == ipc_exception_cursor_id || 360 if (i->first == ipc_exception_cursor_id ||
671 i->second->transaction_id() != transaction_id) 361 i->second->transaction_id() != transaction_id)
672 continue; 362 continue;
673 i->second->ResetPrefetchCache(); 363 i->second->ResetPrefetchCache();
674 } 364 }
675 } 365 }
676 366
677 } // namespace content 367 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/indexed_db_dispatcher.h ('k') | content/child/indexed_db/indexed_db_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698