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 "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
11 #include "content/child/indexed_db/indexed_db_key_builders.h" | 11 #include "content/child/indexed_db/indexed_db_key_builders.h" |
12 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" | 12 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" |
13 #include "content/child/indexed_db/proxy_webidbdatabase_impl.h" | 13 #include "content/child/indexed_db/proxy_webidbdatabase_impl.h" |
14 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
15 #include "content/common/indexed_db/indexed_db_constants.h" | 15 #include "content/common/indexed_db/indexed_db_constants.h" |
16 #include "content/common/indexed_db/indexed_db_messages.h" | 16 #include "content/common/indexed_db/indexed_db_messages.h" |
17 #include "ipc/ipc_channel.h" | 17 #include "ipc/ipc_channel.h" |
18 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" | 18 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" |
19 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h" | 19 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h" |
20 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 20 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
21 | 21 |
| 22 using blink::WebBlobInfo; |
22 using blink::WebData; | 23 using blink::WebData; |
23 using blink::WebIDBCallbacks; | 24 using blink::WebIDBCallbacks; |
24 using blink::WebIDBDatabase; | 25 using blink::WebIDBDatabase; |
25 using blink::WebIDBDatabaseCallbacks; | 26 using blink::WebIDBDatabaseCallbacks; |
26 using blink::WebIDBDatabaseError; | 27 using blink::WebIDBDatabaseError; |
27 using blink::WebIDBKey; | 28 using blink::WebIDBKey; |
28 using blink::WebIDBMetadata; | 29 using blink::WebIDBMetadata; |
29 using blink::WebString; | 30 using blink::WebString; |
30 using blink::WebVector; | 31 using blink::WebVector; |
31 using base::ThreadLocalPointer; | 32 using base::ThreadLocalPointer; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 params.key_range = key_range; | 316 params.key_range = key_range; |
316 params.key_only = key_only; | 317 params.key_only = key_only; |
317 Send(new IndexedDBHostMsg_DatabaseGet(params)); | 318 Send(new IndexedDBHostMsg_DatabaseGet(params)); |
318 } | 319 } |
319 | 320 |
320 void IndexedDBDispatcher::RequestIDBDatabasePut( | 321 void IndexedDBDispatcher::RequestIDBDatabasePut( |
321 int32 ipc_database_id, | 322 int32 ipc_database_id, |
322 int64 transaction_id, | 323 int64 transaction_id, |
323 int64 object_store_id, | 324 int64 object_store_id, |
324 const WebData& value, | 325 const WebData& value, |
| 326 const blink::WebVector<WebBlobInfo>& webBlobInfo, |
325 const IndexedDBKey& key, | 327 const IndexedDBKey& key, |
326 WebIDBDatabase::PutMode put_mode, | 328 WebIDBDatabase::PutMode put_mode, |
327 WebIDBCallbacks* callbacks, | 329 WebIDBCallbacks* callbacks, |
328 const WebVector<long long>& index_ids, | 330 const WebVector<long long>& index_ids, |
329 const WebVector<WebVector<WebIDBKey> >& index_keys) { | 331 const WebVector<WebVector<WebIDBKey> >& index_keys) { |
330 | 332 |
331 if (value.size() > kMaxIDBValueSizeInBytes) { | 333 if (value.size() > kMaxIDBValueSizeInBytes) { |
332 callbacks->onError(WebIDBDatabaseError( | 334 callbacks->onError(WebIDBDatabaseError( |
333 blink::WebIDBDatabaseExceptionUnknownError, | 335 blink::WebIDBDatabaseExceptionUnknownError, |
334 WebString::fromUTF8(base::StringPrintf( | 336 WebString::fromUTF8(base::StringPrintf( |
(...skipping 21 matching lines...) Expand all Loading... |
356 .assign(index_ids.data(), index_ids.data() + index_ids.size()); | 358 .assign(index_ids.data(), index_ids.data() + index_ids.size()); |
357 | 359 |
358 params.index_keys.resize(index_keys.size()); | 360 params.index_keys.resize(index_keys.size()); |
359 for (size_t i = 0; i < index_keys.size(); ++i) { | 361 for (size_t i = 0; i < index_keys.size(); ++i) { |
360 params.index_keys[i].resize(index_keys[i].size()); | 362 params.index_keys[i].resize(index_keys[i].size()); |
361 for (size_t j = 0; j < index_keys[i].size(); ++j) { | 363 for (size_t j = 0; j < index_keys[i].size(); ++j) { |
362 params.index_keys[i][j] = | 364 params.index_keys[i][j] = |
363 IndexedDBKey(IndexedDBKeyBuilder::Build(index_keys[i][j])); | 365 IndexedDBKey(IndexedDBKeyBuilder::Build(index_keys[i][j])); |
364 } | 366 } |
365 } | 367 } |
| 368 |
| 369 params.blob_or_file_info.resize(webBlobInfo.size()); |
| 370 for (size_t i = 0; i < webBlobInfo.size(); ++i) { |
| 371 const WebBlobInfo& info = webBlobInfo[i]; |
| 372 params.blob_or_file_info[i].is_file = info.isFile(); |
| 373 if (info.isFile()) { |
| 374 params.blob_or_file_info[i].file_path = info.filePath(); |
| 375 params.blob_or_file_info[i].file_name = info.fileName(); |
| 376 } else { |
| 377 params.blob_or_file_info[i].size = info.size(); |
| 378 } |
| 379 params.blob_or_file_info[i].uuid = info.uuid().latin1(); |
| 380 DCHECK(params.blob_or_file_info[i].uuid.size()); |
| 381 params.blob_or_file_info[i].mime_type = info.type(); |
| 382 } |
| 383 |
366 Send(new IndexedDBHostMsg_DatabasePut(params)); | 384 Send(new IndexedDBHostMsg_DatabasePut(params)); |
367 } | 385 } |
368 | 386 |
369 void IndexedDBDispatcher::RequestIDBDatabaseOpenCursor( | 387 void IndexedDBDispatcher::RequestIDBDatabaseOpenCursor( |
370 int32 ipc_database_id, | 388 int32 ipc_database_id, |
371 int64 transaction_id, | 389 int64 transaction_id, |
372 int64 object_store_id, | 390 int64 object_store_id, |
373 int64 index_id, | 391 int64 index_id, |
374 const IndexedDBKeyRange& key_range, | 392 const IndexedDBKeyRange& key_range, |
375 unsigned short direction, | 393 unsigned short direction, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 int32 ipc_callbacks_id, | 507 int32 ipc_callbacks_id, |
490 const std::vector<string16>& value) { | 508 const std::vector<string16>& value) { |
491 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 509 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
492 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 510 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
493 if (!callbacks) | 511 if (!callbacks) |
494 return; | 512 return; |
495 callbacks->onSuccess(WebVector<WebString>(value)); | 513 callbacks->onSuccess(WebVector<WebString>(value)); |
496 pending_callbacks_.Remove(ipc_callbacks_id); | 514 pending_callbacks_.Remove(ipc_callbacks_id); |
497 } | 515 } |
498 | 516 |
499 void IndexedDBDispatcher::OnSuccessValue(int32 ipc_thread_id, | 517 static void LoadBlobInfo( |
500 int32 ipc_callbacks_id, | 518 WebData* web_value, |
501 const std::string& value) { | 519 const std::string& value, |
502 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 520 const std::vector<IndexedDBMsg_BlobOrFileInfo>& blob_info, |
503 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 521 blink::WebVector<WebBlobInfo>* web_blob_info) { |
| 522 |
| 523 if (value.size()) { |
| 524 web_value->assign(&*value.begin(), value.size()); |
| 525 blink::WebVector<WebBlobInfo> local_blob_info(blob_info.size()); |
| 526 for (size_t i = 0; i < blob_info.size(); ++i) { |
| 527 const IndexedDBMsg_BlobOrFileInfo& info = blob_info[i]; |
| 528 if (info.is_file) { |
| 529 local_blob_info[i] = |
| 530 WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), info.file_path, |
| 531 info.file_name, info.mime_type, info.last_modified, info.size); |
| 532 } else { |
| 533 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), |
| 534 info.mime_type, info.size); |
| 535 } |
| 536 } |
| 537 web_blob_info->swap(local_blob_info); |
| 538 } |
| 539 } |
| 540 |
| 541 void IndexedDBDispatcher::OnSuccessValue( |
| 542 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { |
| 543 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); |
| 544 WebIDBCallbacks* callbacks = |
| 545 pending_callbacks_.Lookup(params.ipc_callbacks_id); |
504 if (!callbacks) | 546 if (!callbacks) |
505 return; | 547 return; |
506 WebData web_value; | 548 WebData web_value; |
507 if (value.size()) | 549 WebVector<WebBlobInfo> web_blob_info; |
508 web_value.assign(&*value.begin(), value.size()); | 550 LoadBlobInfo(&web_value, params.value, params.blob_or_file_info, |
509 callbacks->onSuccess(web_value); | 551 &web_blob_info); |
510 pending_callbacks_.Remove(ipc_callbacks_id); | 552 callbacks->onSuccess(web_value, web_blob_info); |
| 553 pending_callbacks_.Remove(params.ipc_callbacks_id); |
511 } | 554 } |
512 | 555 |
513 void IndexedDBDispatcher::OnSuccessValueWithKey( | 556 void IndexedDBDispatcher::OnSuccessValueWithKey( |
514 int32 ipc_thread_id, | 557 const IndexedDBMsg_CallbacksSuccessValueWithKey_Params& params) { |
515 int32 ipc_callbacks_id, | 558 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); |
516 const std::string& value, | 559 WebIDBCallbacks* callbacks = |
517 const IndexedDBKey& primary_key, | 560 pending_callbacks_.Lookup(params.ipc_callbacks_id); |
518 const IndexedDBKeyPath& key_path) { | |
519 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
520 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | |
521 if (!callbacks) | 561 if (!callbacks) |
522 return; | 562 return; |
523 WebData web_value; | 563 WebData web_value; |
524 if (value.size()) | 564 WebVector<WebBlobInfo> web_blob_info; |
525 web_value.assign(&*value.begin(), value.size()); | 565 LoadBlobInfo(&web_value, params.value, params.blob_or_file_info, |
526 callbacks->onSuccess(web_value, | 566 &web_blob_info); |
527 WebIDBKeyBuilder::Build(primary_key), | 567 callbacks->onSuccess(web_value, web_blob_info, |
528 WebIDBKeyPathBuilder::Build(key_path)); | 568 WebIDBKeyBuilder::Build(params.primary_key), |
529 pending_callbacks_.Remove(ipc_callbacks_id); | 569 WebIDBKeyPathBuilder::Build(params.key_path)); |
| 570 pending_callbacks_.Remove(params.ipc_callbacks_id); |
530 } | 571 } |
531 | 572 |
532 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, | 573 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, |
533 int32 ipc_callbacks_id, | 574 int32 ipc_callbacks_id, |
534 int64 value) { | 575 int64 value) { |
535 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 576 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
536 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 577 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
537 if (!callbacks) | 578 if (!callbacks) |
538 return; | 579 return; |
539 callbacks->onSuccess(value); | 580 callbacks->onSuccess(value); |
(...skipping 11 matching lines...) Expand all Loading... |
551 } | 592 } |
552 | 593 |
553 void IndexedDBDispatcher::OnSuccessOpenCursor( | 594 void IndexedDBDispatcher::OnSuccessOpenCursor( |
554 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) { | 595 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) { |
555 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 596 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
556 int32 ipc_callbacks_id = p.ipc_callbacks_id; | 597 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
557 int32 ipc_object_id = p.ipc_cursor_id; | 598 int32 ipc_object_id = p.ipc_cursor_id; |
558 const IndexedDBKey& key = p.key; | 599 const IndexedDBKey& key = p.key; |
559 const IndexedDBKey& primary_key = p.primary_key; | 600 const IndexedDBKey& primary_key = p.primary_key; |
560 WebData web_value; | 601 WebData web_value; |
561 if (p.value.size()) | 602 WebVector<WebBlobInfo> web_blob_info; |
562 web_value.assign(&*p.value.begin(), p.value.size()); | 603 LoadBlobInfo(&web_value, p.value, p.blob_or_file_info, |
| 604 &web_blob_info); |
563 | 605 |
564 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 606 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
565 if (!callbacks) | 607 if (!callbacks) |
566 return; | 608 return; |
567 | 609 |
568 RendererWebIDBCursorImpl* cursor = | 610 RendererWebIDBCursorImpl* cursor = |
569 new RendererWebIDBCursorImpl(ipc_object_id, thread_safe_sender_.get()); | 611 new RendererWebIDBCursorImpl(ipc_object_id, thread_safe_sender_.get()); |
570 cursors_[ipc_object_id] = cursor; | 612 cursors_[ipc_object_id] = cursor; |
571 callbacks->onSuccess(cursor, WebIDBKeyBuilder::Build(key), | 613 callbacks->onSuccess(cursor, WebIDBKeyBuilder::Build(key), |
572 WebIDBKeyBuilder::Build(primary_key), web_value); | 614 WebIDBKeyBuilder::Build(primary_key), web_value, |
| 615 web_blob_info); |
573 | 616 |
574 pending_callbacks_.Remove(ipc_callbacks_id); | 617 pending_callbacks_.Remove(ipc_callbacks_id); |
575 } | 618 } |
576 | 619 |
577 void IndexedDBDispatcher::OnSuccessCursorContinue( | 620 void IndexedDBDispatcher::OnSuccessCursorContinue( |
578 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { | 621 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { |
579 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 622 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
580 int32 ipc_callbacks_id = p.ipc_callbacks_id; | 623 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
581 int32 ipc_cursor_id = p.ipc_cursor_id; | 624 int32 ipc_cursor_id = p.ipc_cursor_id; |
582 const IndexedDBKey& key = p.key; | 625 const IndexedDBKey& key = p.key; |
583 const IndexedDBKey& primary_key = p.primary_key; | 626 const IndexedDBKey& primary_key = p.primary_key; |
584 const std::string& value = p.value; | 627 const std::string& value = p.value; |
585 | 628 |
586 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; | 629 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; |
587 DCHECK(cursor); | 630 DCHECK(cursor); |
588 | 631 |
589 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 632 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
590 if (!callbacks) | 633 if (!callbacks) |
591 return; | 634 return; |
592 | 635 |
593 WebData web_value; | 636 WebData web_value; |
594 if (value.size()) | 637 WebVector<WebBlobInfo> web_blob_info; |
595 web_value.assign(&*value.begin(), value.size()); | 638 LoadBlobInfo(&web_value, value, p.blob_or_file_info, &web_blob_info); |
596 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), | 639 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), |
597 WebIDBKeyBuilder::Build(primary_key), web_value); | 640 WebIDBKeyBuilder::Build(primary_key), web_value, |
| 641 web_blob_info); |
598 | 642 |
599 pending_callbacks_.Remove(ipc_callbacks_id); | 643 pending_callbacks_.Remove(ipc_callbacks_id); |
600 } | 644 } |
601 | 645 |
602 void IndexedDBDispatcher::OnSuccessCursorPrefetch( | 646 void IndexedDBDispatcher::OnSuccessCursorPrefetch( |
603 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) { | 647 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) { |
604 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 648 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
605 int32 ipc_callbacks_id = p.ipc_callbacks_id; | 649 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
606 int32 ipc_cursor_id = p.ipc_cursor_id; | 650 int32 ipc_cursor_id = p.ipc_cursor_id; |
607 const std::vector<IndexedDBKey>& keys = p.keys; | 651 const std::vector<IndexedDBKey>& keys = p.keys; |
608 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys; | 652 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys; |
609 std::vector<WebData> values(p.values.size()); | 653 std::vector<WebData> values(p.values.size()); |
| 654 DCHECK_EQ(p.values.size(), p.blob_or_file_infos.size()); |
| 655 std::vector<WebVector<WebBlobInfo> > blob_infos(p.blob_or_file_infos.size()); |
610 for (size_t i = 0; i < p.values.size(); ++i) { | 656 for (size_t i = 0; i < p.values.size(); ++i) { |
611 if (p.values[i].size()) | 657 LoadBlobInfo(&values[i], p.values[i], p.blob_or_file_infos[i], |
612 values[i].assign(&*p.values[i].begin(), p.values[i].size()); | 658 &blob_infos[i]); |
613 } | 659 } |
614 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; | 660 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; |
615 DCHECK(cursor); | 661 DCHECK(cursor); |
616 cursor->SetPrefetchData(keys, primary_keys, values); | 662 cursor->SetPrefetchData(keys, primary_keys, values, blob_infos); |
617 | 663 |
618 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 664 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
619 DCHECK(callbacks); | 665 DCHECK(callbacks); |
620 cursor->CachedContinue(callbacks); | 666 cursor->CachedContinue(callbacks); |
621 pending_callbacks_.Remove(ipc_callbacks_id); | 667 pending_callbacks_.Remove(ipc_callbacks_id); |
622 } | 668 } |
623 | 669 |
624 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id, | 670 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id, |
625 int32 ipc_callbacks_id, | 671 int32 ipc_callbacks_id, |
626 int64 existing_version) { | 672 int64 existing_version) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 int32 ipc_exception_cursor_id) { | 765 int32 ipc_exception_cursor_id) { |
720 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; | 766 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; |
721 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 767 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
722 if (i->first == ipc_exception_cursor_id) | 768 if (i->first == ipc_exception_cursor_id) |
723 continue; | 769 continue; |
724 i->second->ResetPrefetchCache(); | 770 i->second->ResetPrefetchCache(); |
725 } | 771 } |
726 } | 772 } |
727 | 773 |
728 } // namespace content | 774 } // namespace content |
OLD | NEW |