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

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

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle the rest of Josh's feedback. Created 7 years 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 | Annotate | Revision Log
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 "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
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
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
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] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()),
530 info.file_path,
531 info.file_name,
532 info.mime_type,
533 info.last_modified,
534 info.size);
535 } else {
536 local_blob_info[i] = WebBlobInfo(
537 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size);
538 }
539 }
540 web_blob_info->swap(local_blob_info);
541 }
542 }
543
544 void IndexedDBDispatcher::OnSuccessValue(
545 const IndexedDBMsg_CallbacksSuccessValue_Params& params) {
546 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId());
547 WebIDBCallbacks* callbacks =
548 pending_callbacks_.Lookup(params.ipc_callbacks_id);
504 if (!callbacks) 549 if (!callbacks)
505 return; 550 return;
506 WebData web_value; 551 WebData web_value;
507 if (value.size()) 552 WebVector<WebBlobInfo> web_blob_info;
508 web_value.assign(&*value.begin(), value.size()); 553 LoadBlobInfo(
jsbell 2013/12/20 00:44:20 Is there a good reason to have LoadBlobInfo do the
ericu 2014/02/20 00:50:29 Yeah, it started out just doing the blob info, and
509 callbacks->onSuccess(web_value); 554 &web_value, params.value, params.blob_or_file_info, &web_blob_info);
510 pending_callbacks_.Remove(ipc_callbacks_id); 555 callbacks->onSuccess(web_value, web_blob_info);
556 pending_callbacks_.Remove(params.ipc_callbacks_id);
511 } 557 }
512 558
513 void IndexedDBDispatcher::OnSuccessValueWithKey( 559 void IndexedDBDispatcher::OnSuccessValueWithKey(
514 int32 ipc_thread_id, 560 const IndexedDBMsg_CallbacksSuccessValueWithKey_Params& params) {
515 int32 ipc_callbacks_id, 561 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId());
516 const std::string& value, 562 WebIDBCallbacks* callbacks =
517 const IndexedDBKey& primary_key, 563 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) 564 if (!callbacks)
522 return; 565 return;
523 WebData web_value; 566 WebData web_value;
524 if (value.size()) 567 WebVector<WebBlobInfo> web_blob_info;
525 web_value.assign(&*value.begin(), value.size()); 568 LoadBlobInfo(
569 &web_value, params.value, params.blob_or_file_info, &web_blob_info);
526 callbacks->onSuccess(web_value, 570 callbacks->onSuccess(web_value,
527 WebIDBKeyBuilder::Build(primary_key), 571 web_blob_info,
528 WebIDBKeyPathBuilder::Build(key_path)); 572 WebIDBKeyBuilder::Build(params.primary_key),
529 pending_callbacks_.Remove(ipc_callbacks_id); 573 WebIDBKeyPathBuilder::Build(params.key_path));
574 pending_callbacks_.Remove(params.ipc_callbacks_id);
530 } 575 }
531 576
532 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, 577 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id,
533 int32 ipc_callbacks_id, 578 int32 ipc_callbacks_id,
534 int64 value) { 579 int64 value) {
535 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 580 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
536 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 581 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
537 if (!callbacks) 582 if (!callbacks)
538 return; 583 return;
539 callbacks->onSuccess(value); 584 callbacks->onSuccess(value);
(...skipping 11 matching lines...) Expand all
551 } 596 }
552 597
553 void IndexedDBDispatcher::OnSuccessOpenCursor( 598 void IndexedDBDispatcher::OnSuccessOpenCursor(
554 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) { 599 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) {
555 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 600 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
556 int32 ipc_callbacks_id = p.ipc_callbacks_id; 601 int32 ipc_callbacks_id = p.ipc_callbacks_id;
557 int32 ipc_object_id = p.ipc_cursor_id; 602 int32 ipc_object_id = p.ipc_cursor_id;
558 const IndexedDBKey& key = p.key; 603 const IndexedDBKey& key = p.key;
559 const IndexedDBKey& primary_key = p.primary_key; 604 const IndexedDBKey& primary_key = p.primary_key;
560 WebData web_value; 605 WebData web_value;
561 if (p.value.size()) 606 WebVector<WebBlobInfo> web_blob_info;
562 web_value.assign(&*p.value.begin(), p.value.size()); 607 LoadBlobInfo(&web_value, p.value, p.blob_or_file_info, &web_blob_info);
563 608
564 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 609 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
565 if (!callbacks) 610 if (!callbacks)
566 return; 611 return;
567 612
568 RendererWebIDBCursorImpl* cursor = 613 RendererWebIDBCursorImpl* cursor =
569 new RendererWebIDBCursorImpl(ipc_object_id, thread_safe_sender_.get()); 614 new RendererWebIDBCursorImpl(ipc_object_id, thread_safe_sender_.get());
570 cursors_[ipc_object_id] = cursor; 615 cursors_[ipc_object_id] = cursor;
571 callbacks->onSuccess(cursor, WebIDBKeyBuilder::Build(key), 616 callbacks->onSuccess(cursor,
572 WebIDBKeyBuilder::Build(primary_key), web_value); 617 WebIDBKeyBuilder::Build(key),
618 WebIDBKeyBuilder::Build(primary_key),
619 web_value,
620 web_blob_info);
573 621
574 pending_callbacks_.Remove(ipc_callbacks_id); 622 pending_callbacks_.Remove(ipc_callbacks_id);
575 } 623 }
576 624
577 void IndexedDBDispatcher::OnSuccessCursorContinue( 625 void IndexedDBDispatcher::OnSuccessCursorContinue(
578 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { 626 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) {
579 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 627 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
580 int32 ipc_callbacks_id = p.ipc_callbacks_id; 628 int32 ipc_callbacks_id = p.ipc_callbacks_id;
581 int32 ipc_cursor_id = p.ipc_cursor_id; 629 int32 ipc_cursor_id = p.ipc_cursor_id;
582 const IndexedDBKey& key = p.key; 630 const IndexedDBKey& key = p.key;
583 const IndexedDBKey& primary_key = p.primary_key; 631 const IndexedDBKey& primary_key = p.primary_key;
584 const std::string& value = p.value; 632 const std::string& value = p.value;
585 633
586 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; 634 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id];
587 DCHECK(cursor); 635 DCHECK(cursor);
588 636
589 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 637 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
590 if (!callbacks) 638 if (!callbacks)
591 return; 639 return;
592 640
593 WebData web_value; 641 WebData web_value;
594 if (value.size()) 642 WebVector<WebBlobInfo> web_blob_info;
595 web_value.assign(&*value.begin(), value.size()); 643 LoadBlobInfo(&web_value, value, p.blob_or_file_info, &web_blob_info);
596 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), 644 callbacks->onSuccess(WebIDBKeyBuilder::Build(key),
597 WebIDBKeyBuilder::Build(primary_key), web_value); 645 WebIDBKeyBuilder::Build(primary_key),
646 web_value,
647 web_blob_info);
598 648
599 pending_callbacks_.Remove(ipc_callbacks_id); 649 pending_callbacks_.Remove(ipc_callbacks_id);
600 } 650 }
601 651
602 void IndexedDBDispatcher::OnSuccessCursorPrefetch( 652 void IndexedDBDispatcher::OnSuccessCursorPrefetch(
603 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) { 653 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) {
604 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 654 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
605 int32 ipc_callbacks_id = p.ipc_callbacks_id; 655 int32 ipc_callbacks_id = p.ipc_callbacks_id;
606 int32 ipc_cursor_id = p.ipc_cursor_id; 656 int32 ipc_cursor_id = p.ipc_cursor_id;
607 const std::vector<IndexedDBKey>& keys = p.keys; 657 const std::vector<IndexedDBKey>& keys = p.keys;
608 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys; 658 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys;
609 std::vector<WebData> values(p.values.size()); 659 std::vector<WebData> values(p.values.size());
660 DCHECK_EQ(p.values.size(), p.blob_or_file_infos.size());
661 std::vector<WebVector<WebBlobInfo> > blob_infos(p.blob_or_file_infos.size());
610 for (size_t i = 0; i < p.values.size(); ++i) { 662 for (size_t i = 0; i < p.values.size(); ++i) {
611 if (p.values[i].size()) 663 LoadBlobInfo(
612 values[i].assign(&*p.values[i].begin(), p.values[i].size()); 664 &values[i], p.values[i], p.blob_or_file_infos[i], &blob_infos[i]);
613 } 665 }
614 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; 666 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id];
615 DCHECK(cursor); 667 DCHECK(cursor);
616 cursor->SetPrefetchData(keys, primary_keys, values); 668 cursor->SetPrefetchData(keys, primary_keys, values, blob_infos);
617 669
618 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 670 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
619 DCHECK(callbacks); 671 DCHECK(callbacks);
620 cursor->CachedContinue(callbacks); 672 cursor->CachedContinue(callbacks);
621 pending_callbacks_.Remove(ipc_callbacks_id); 673 pending_callbacks_.Remove(ipc_callbacks_id);
622 } 674 }
623 675
624 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id, 676 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id,
625 int32 ipc_callbacks_id, 677 int32 ipc_callbacks_id,
626 int64 existing_version) { 678 int64 existing_version) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 int32 ipc_exception_cursor_id) { 771 int32 ipc_exception_cursor_id) {
720 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; 772 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator;
721 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 773 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
722 if (i->first == ipc_exception_cursor_id) 774 if (i->first == ipc_exception_cursor_id)
723 continue; 775 continue;
724 i->second->ResetPrefetchCache(); 776 i->second->ResetPrefetchCache();
725 } 777 }
726 } 778 }
727 779
728 } // namespace content 780 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698