| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/indexed_db/indexed_db_callbacks.h" | 5 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 swap(mojo_value->value->bits, value->bits); | 74 swap(mojo_value->value->bits, value->bits); |
| 75 ConvertBlobInfo(value->blob_info, &mojo_value->value->blob_or_file_info); | 75 ConvertBlobInfo(value->blob_info, &mojo_value->value->blob_or_file_info); |
| 76 return mojo_value; | 76 return mojo_value; |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 class IndexedDBCallbacks::IOThreadHelper { | 81 class IndexedDBCallbacks::IOThreadHelper { |
| 82 public: | 82 public: |
| 83 IOThreadHelper(CallbacksAssociatedPtrInfo callbacks_info, | 83 IOThreadHelper(CallbacksAssociatedPtrInfo callbacks_info, |
| 84 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host); | 84 IndexedDBDispatcherHost* dispatcher_host); |
| 85 ~IOThreadHelper(); | 85 ~IOThreadHelper(); |
| 86 | 86 |
| 87 void SendError(const IndexedDBDatabaseError& error); | 87 void SendError(const IndexedDBDatabaseError& error); |
| 88 void SendSuccessStringList(const std::vector<base::string16>& value); | 88 void SendSuccessStringList(const std::vector<base::string16>& value); |
| 89 void SendBlocked(int64_t existing_version); | 89 void SendBlocked(int64_t existing_version); |
| 90 void SendUpgradeNeeded(std::unique_ptr<DatabaseImpl> database, | 90 void SendUpgradeNeeded(std::unique_ptr<DatabaseImpl> database, |
| 91 int64_t old_version, | 91 int64_t old_version, |
| 92 blink::WebIDBDataLoss data_loss, | 92 blink::WebIDBDataLoss data_loss, |
| 93 const std::string& data_loss_message, | 93 const std::string& data_loss_message, |
| 94 const content::IndexedDBDatabaseMetadata& metadata); | 94 const content::IndexedDBDatabaseMetadata& metadata); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 118 void SendSuccessInteger(int64_t value); | 118 void SendSuccessInteger(int64_t value); |
| 119 void SendSuccess(); | 119 void SendSuccess(); |
| 120 | 120 |
| 121 std::string CreateBlobData(const IndexedDBBlobInfo& blob_info); | 121 std::string CreateBlobData(const IndexedDBBlobInfo& blob_info); |
| 122 bool CreateAllBlobs( | 122 bool CreateAllBlobs( |
| 123 const std::vector<IndexedDBBlobInfo>& blob_info, | 123 const std::vector<IndexedDBBlobInfo>& blob_info, |
| 124 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info); | 124 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info); |
| 125 void OnConnectionError(); | 125 void OnConnectionError(); |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 128 base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host_; |
| 129 ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_; | 129 ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_; |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); | 131 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 // static | 134 // static |
| 135 ::indexed_db::mojom::ValuePtr IndexedDBCallbacks::ConvertAndEraseValue( | 135 ::indexed_db::mojom::ValuePtr IndexedDBCallbacks::ConvertAndEraseValue( |
| 136 IndexedDBValue* value) { | 136 IndexedDBValue* value) { |
| 137 auto mojo_value = ::indexed_db::mojom::Value::New(); | 137 auto mojo_value = ::indexed_db::mojom::Value::New(); |
| 138 if (!value->empty()) | 138 if (!value->empty()) |
| 139 swap(mojo_value->bits, value->bits); | 139 swap(mojo_value->bits, value->bits); |
| 140 ConvertBlobInfo(value->blob_info, &mojo_value->blob_or_file_info); | 140 ConvertBlobInfo(value->blob_info, &mojo_value->blob_or_file_info); |
| 141 return mojo_value; | 141 return mojo_value; |
| 142 } | 142 } |
| 143 | 143 |
| 144 IndexedDBCallbacks::IndexedDBCallbacks( | 144 IndexedDBCallbacks::IndexedDBCallbacks( |
| 145 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 145 IndexedDBDispatcherHost* dispatcher_host, |
| 146 const url::Origin& origin, | 146 const url::Origin& origin, |
| 147 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) | 147 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) |
| 148 : dispatcher_host_(std::move(dispatcher_host)), | 148 : dispatcher_host_(dispatcher_host), |
| 149 origin_(origin), | 149 origin_(origin), |
| 150 data_loss_(blink::WebIDBDataLossNone), | 150 data_loss_(blink::WebIDBDataLossNone), |
| 151 sent_blocked_(false), | 151 sent_blocked_(false), |
| 152 io_helper_( | 152 io_helper_( |
| 153 new IOThreadHelper(std::move(callbacks_info), dispatcher_host_)) { | 153 new IOThreadHelper(std::move(callbacks_info), dispatcher_host_)) { |
| 154 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 154 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 155 thread_checker_.DetachFromThread(); | 155 thread_checker_.DetachFromThread(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 IndexedDBCallbacks::~IndexedDBCallbacks() { | 158 IndexedDBCallbacks::~IndexedDBCallbacks() { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 dispatcher_host_ = nullptr; | 433 dispatcher_host_ = nullptr; |
| 434 } | 434 } |
| 435 | 435 |
| 436 void IndexedDBCallbacks::SetConnectionOpenStartTime( | 436 void IndexedDBCallbacks::SetConnectionOpenStartTime( |
| 437 const base::TimeTicks& start_time) { | 437 const base::TimeTicks& start_time) { |
| 438 connection_open_start_time_ = start_time; | 438 connection_open_start_time_ = start_time; |
| 439 } | 439 } |
| 440 | 440 |
| 441 IndexedDBCallbacks::IOThreadHelper::IOThreadHelper( | 441 IndexedDBCallbacks::IOThreadHelper::IOThreadHelper( |
| 442 CallbacksAssociatedPtrInfo callbacks_info, | 442 CallbacksAssociatedPtrInfo callbacks_info, |
| 443 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | 443 IndexedDBDispatcherHost* dispatcher_host) |
| 444 : dispatcher_host_(std::move(dispatcher_host)) { | 444 : dispatcher_host_(dispatcher_host->AsWeakPtr()) { |
| 445 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 445 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 446 if (callbacks_info.is_valid()) { | 446 if (callbacks_info.is_valid()) { |
| 447 callbacks_.Bind(std::move(callbacks_info)); | 447 callbacks_.Bind(std::move(callbacks_info)); |
| 448 callbacks_.set_connection_error_handler( | 448 callbacks_.set_connection_error_handler( |
| 449 base::Bind(&IOThreadHelper::OnConnectionError, base::Unretained(this))); | 449 base::Bind(&IOThreadHelper::OnConnectionError, base::Unretained(this))); |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {} | 453 IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {} |
| 454 | 454 |
| 455 void IndexedDBCallbacks::IOThreadHelper::SendError( | 455 void IndexedDBCallbacks::IOThreadHelper::SendError( |
| 456 const IndexedDBDatabaseError& error) { | 456 const IndexedDBDatabaseError& error) { |
| 457 if (!dispatcher_host_) { |
| 458 OnConnectionError(); |
| 459 return; |
| 460 } |
| 457 if (callbacks_) | 461 if (callbacks_) |
| 458 callbacks_->Error(error.code(), error.message()); | 462 callbacks_->Error(error.code(), error.message()); |
| 459 } | 463 } |
| 460 | 464 |
| 461 void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList( | 465 void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList( |
| 462 const std::vector<base::string16>& value) { | 466 const std::vector<base::string16>& value) { |
| 467 if (!dispatcher_host_) { |
| 468 OnConnectionError(); |
| 469 return; |
| 470 } |
| 463 if (callbacks_) | 471 if (callbacks_) |
| 464 callbacks_->SuccessStringList(value); | 472 callbacks_->SuccessStringList(value); |
| 465 } | 473 } |
| 466 | 474 |
| 467 void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) { | 475 void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) { |
| 476 if (!dispatcher_host_) { |
| 477 OnConnectionError(); |
| 478 return; |
| 479 } |
| 468 if (callbacks_) | 480 if (callbacks_) |
| 469 callbacks_->Blocked(existing_version); | 481 callbacks_->Blocked(existing_version); |
| 470 } | 482 } |
| 471 | 483 |
| 472 void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( | 484 void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( |
| 473 std::unique_ptr<DatabaseImpl> database, | 485 std::unique_ptr<DatabaseImpl> database, |
| 474 int64_t old_version, | 486 int64_t old_version, |
| 475 blink::WebIDBDataLoss data_loss, | 487 blink::WebIDBDataLoss data_loss, |
| 476 const std::string& data_loss_message, | 488 const std::string& data_loss_message, |
| 477 const content::IndexedDBDatabaseMetadata& metadata) { | 489 const content::IndexedDBDatabaseMetadata& metadata) { |
| 490 if (!dispatcher_host_) { |
| 491 OnConnectionError(); |
| 492 return; |
| 493 } |
| 478 if (!callbacks_) | 494 if (!callbacks_) |
| 479 return; | 495 return; |
| 480 | 496 |
| 481 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; | 497 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; |
| 482 auto request = mojo::MakeRequest(&ptr_info); | 498 auto request = mojo::MakeRequest(&ptr_info); |
| 483 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request)); | 499 |
| 500 dispatcher_host_->AddDatabaseBinding(std::move(database), std::move(request)); |
| 484 callbacks_->UpgradeNeeded(std::move(ptr_info), old_version, data_loss, | 501 callbacks_->UpgradeNeeded(std::move(ptr_info), old_version, data_loss, |
| 485 data_loss_message, metadata); | 502 data_loss_message, metadata); |
| 486 } | 503 } |
| 487 | 504 |
| 488 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( | 505 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( |
| 489 std::unique_ptr<DatabaseImpl> database, | 506 std::unique_ptr<DatabaseImpl> database, |
| 490 const content::IndexedDBDatabaseMetadata& metadata) { | 507 const content::IndexedDBDatabaseMetadata& metadata) { |
| 508 if (!dispatcher_host_) { |
| 509 OnConnectionError(); |
| 510 return; |
| 511 } |
| 491 if (!callbacks_) | 512 if (!callbacks_) |
| 492 return; | 513 return; |
| 493 | 514 |
| 494 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; | 515 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; |
| 495 if (database) { | 516 if (database) { |
| 496 auto request = mojo::MakeRequest(&ptr_info); | 517 auto request = mojo::MakeRequest(&ptr_info); |
| 497 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request)); | 518 dispatcher_host_->AddDatabaseBinding(std::move(database), |
| 519 std::move(request)); |
| 498 } | 520 } |
| 499 callbacks_->SuccessDatabase(std::move(ptr_info), metadata); | 521 callbacks_->SuccessDatabase(std::move(ptr_info), metadata); |
| 500 } | 522 } |
| 501 | 523 |
| 502 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor( | 524 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor( |
| 503 std::unique_ptr<CursorImpl> cursor, | 525 std::unique_ptr<CursorImpl> cursor, |
| 504 const IndexedDBKey& key, | 526 const IndexedDBKey& key, |
| 505 const IndexedDBKey& primary_key, | 527 const IndexedDBKey& primary_key, |
| 506 ::indexed_db::mojom::ValuePtr value, | 528 ::indexed_db::mojom::ValuePtr value, |
| 507 const std::vector<IndexedDBBlobInfo>& blob_info) { | 529 const std::vector<IndexedDBBlobInfo>& blob_info) { |
| 530 if (!dispatcher_host_) { |
| 531 OnConnectionError(); |
| 532 return; |
| 533 } |
| 508 if (!callbacks_) | 534 if (!callbacks_) |
| 509 return; | 535 return; |
| 510 | 536 |
| 511 if (value && !CreateAllBlobs(blob_info, &value->blob_or_file_info)) | 537 if (value && !CreateAllBlobs(blob_info, &value->blob_or_file_info)) |
| 512 return; | 538 return; |
| 513 | 539 |
| 514 ::indexed_db::mojom::CursorAssociatedPtrInfo ptr_info; | 540 ::indexed_db::mojom::CursorAssociatedPtrInfo ptr_info; |
| 515 auto request = mojo::MakeRequest(&ptr_info); | 541 auto request = mojo::MakeRequest(&ptr_info); |
| 516 mojo::MakeStrongAssociatedBinding(std::move(cursor), std::move(request)); | 542 dispatcher_host_->AddCursorBinding(std::move(cursor), std::move(request)); |
| 517 callbacks_->SuccessCursor(std::move(ptr_info), key, primary_key, | 543 callbacks_->SuccessCursor(std::move(ptr_info), key, primary_key, |
| 518 std::move(value)); | 544 std::move(value)); |
| 519 } | 545 } |
| 520 | 546 |
| 521 void IndexedDBCallbacks::IOThreadHelper::SendSuccessValue( | 547 void IndexedDBCallbacks::IOThreadHelper::SendSuccessValue( |
| 522 ::indexed_db::mojom::ReturnValuePtr value, | 548 ::indexed_db::mojom::ReturnValuePtr value, |
| 523 const std::vector<IndexedDBBlobInfo>& blob_info) { | 549 const std::vector<IndexedDBBlobInfo>& blob_info) { |
| 550 if (!dispatcher_host_) { |
| 551 OnConnectionError(); |
| 552 return; |
| 553 } |
| 524 if (!callbacks_) | 554 if (!callbacks_) |
| 525 return; | 555 return; |
| 526 | 556 |
| 527 if (!value || CreateAllBlobs(blob_info, &value->value->blob_or_file_info)) | 557 if (!value || CreateAllBlobs(blob_info, &value->value->blob_or_file_info)) |
| 528 callbacks_->SuccessValue(std::move(value)); | 558 callbacks_->SuccessValue(std::move(value)); |
| 529 } | 559 } |
| 530 | 560 |
| 531 void IndexedDBCallbacks::IOThreadHelper::SendSuccessArray( | 561 void IndexedDBCallbacks::IOThreadHelper::SendSuccessArray( |
| 532 std::vector<::indexed_db::mojom::ReturnValuePtr> mojo_values, | 562 std::vector<::indexed_db::mojom::ReturnValuePtr> mojo_values, |
| 533 const std::vector<IndexedDBReturnValue>& values) { | 563 const std::vector<IndexedDBReturnValue>& values) { |
| 534 DCHECK_EQ(mojo_values.size(), values.size()); | 564 DCHECK_EQ(mojo_values.size(), values.size()); |
| 535 | 565 |
| 566 if (!dispatcher_host_) { |
| 567 OnConnectionError(); |
| 568 return; |
| 569 } |
| 536 if (!callbacks_) | 570 if (!callbacks_) |
| 537 return; | 571 return; |
| 538 | 572 |
| 539 for (size_t i = 0; i < mojo_values.size(); ++i) { | 573 for (size_t i = 0; i < mojo_values.size(); ++i) { |
| 540 if (!CreateAllBlobs(values[i].blob_info, | 574 if (!CreateAllBlobs(values[i].blob_info, |
| 541 &mojo_values[i]->value->blob_or_file_info)) | 575 &mojo_values[i]->value->blob_or_file_info)) |
| 542 return; | 576 return; |
| 543 } | 577 } |
| 544 callbacks_->SuccessArray(std::move(mojo_values)); | 578 callbacks_->SuccessArray(std::move(mojo_values)); |
| 545 } | 579 } |
| 546 | 580 |
| 547 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorContinue( | 581 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorContinue( |
| 548 const IndexedDBKey& key, | 582 const IndexedDBKey& key, |
| 549 const IndexedDBKey& primary_key, | 583 const IndexedDBKey& primary_key, |
| 550 ::indexed_db::mojom::ValuePtr value, | 584 ::indexed_db::mojom::ValuePtr value, |
| 551 const std::vector<IndexedDBBlobInfo>& blob_info) { | 585 const std::vector<IndexedDBBlobInfo>& blob_info) { |
| 586 if (!dispatcher_host_) { |
| 587 OnConnectionError(); |
| 588 return; |
| 589 } |
| 552 if (!callbacks_) | 590 if (!callbacks_) |
| 553 return; | 591 return; |
| 554 | 592 |
| 555 if (!value || CreateAllBlobs(blob_info, &value->blob_or_file_info)) | 593 if (!value || CreateAllBlobs(blob_info, &value->blob_or_file_info)) |
| 556 callbacks_->SuccessCursorContinue(key, primary_key, std::move(value)); | 594 callbacks_->SuccessCursorContinue(key, primary_key, std::move(value)); |
| 557 } | 595 } |
| 558 | 596 |
| 559 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorPrefetch( | 597 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorPrefetch( |
| 560 const std::vector<IndexedDBKey>& keys, | 598 const std::vector<IndexedDBKey>& keys, |
| 561 const std::vector<IndexedDBKey>& primary_keys, | 599 const std::vector<IndexedDBKey>& primary_keys, |
| 562 std::vector<::indexed_db::mojom::ValuePtr> mojo_values, | 600 std::vector<::indexed_db::mojom::ValuePtr> mojo_values, |
| 563 const std::vector<IndexedDBValue>& values) { | 601 const std::vector<IndexedDBValue>& values) { |
| 564 DCHECK_EQ(mojo_values.size(), values.size()); | 602 DCHECK_EQ(mojo_values.size(), values.size()); |
| 565 | 603 |
| 604 if (!dispatcher_host_) { |
| 605 OnConnectionError(); |
| 606 return; |
| 607 } |
| 566 if (!callbacks_) | 608 if (!callbacks_) |
| 567 return; | 609 return; |
| 568 | 610 |
| 569 for (size_t i = 0; i < mojo_values.size(); ++i) { | 611 for (size_t i = 0; i < mojo_values.size(); ++i) { |
| 570 if (!CreateAllBlobs(values[i].blob_info, | 612 if (!CreateAllBlobs(values[i].blob_info, |
| 571 &mojo_values[i]->blob_or_file_info)) { | 613 &mojo_values[i]->blob_or_file_info)) { |
| 572 return; | 614 return; |
| 573 } | 615 } |
| 574 } | 616 } |
| 575 | 617 |
| 576 callbacks_->SuccessCursorPrefetch(keys, primary_keys, std::move(mojo_values)); | 618 callbacks_->SuccessCursorPrefetch(keys, primary_keys, std::move(mojo_values)); |
| 577 } | 619 } |
| 578 | 620 |
| 579 void IndexedDBCallbacks::IOThreadHelper::SendSuccessKey( | 621 void IndexedDBCallbacks::IOThreadHelper::SendSuccessKey( |
| 580 const IndexedDBKey& value) { | 622 const IndexedDBKey& value) { |
| 623 if (!dispatcher_host_) { |
| 624 OnConnectionError(); |
| 625 return; |
| 626 } |
| 581 if (callbacks_) | 627 if (callbacks_) |
| 582 callbacks_->SuccessKey(value); | 628 callbacks_->SuccessKey(value); |
| 583 } | 629 } |
| 584 | 630 |
| 585 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { | 631 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { |
| 632 if (!dispatcher_host_) { |
| 633 OnConnectionError(); |
| 634 return; |
| 635 } |
| 586 if (callbacks_) | 636 if (callbacks_) |
| 587 callbacks_->SuccessInteger(value); | 637 callbacks_->SuccessInteger(value); |
| 588 } | 638 } |
| 589 | 639 |
| 590 void IndexedDBCallbacks::IOThreadHelper::SendSuccess() { | 640 void IndexedDBCallbacks::IOThreadHelper::SendSuccess() { |
| 641 if (!dispatcher_host_) { |
| 642 OnConnectionError(); |
| 643 return; |
| 644 } |
| 591 if (callbacks_) | 645 if (callbacks_) |
| 592 callbacks_->Success(); | 646 callbacks_->Success(); |
| 593 } | 647 } |
| 594 | 648 |
| 595 std::string IndexedDBCallbacks::IOThreadHelper::CreateBlobData( | 649 std::string IndexedDBCallbacks::IOThreadHelper::CreateBlobData( |
| 596 const IndexedDBBlobInfo& blob_info) { | 650 const IndexedDBBlobInfo& blob_info) { |
| 597 if (!blob_info.uuid().empty()) { | 651 if (!blob_info.uuid().empty()) { |
| 598 // We're sending back a live blob, not a reference into our backing store. | 652 // We're sending back a live blob, not a reference into our backing store. |
| 599 return dispatcher_host_->HoldBlobData(blob_info); | 653 return dispatcher_host_->HoldBlobData(blob_info); |
| 600 } | 654 } |
| 601 scoped_refptr<ShareableFileReference> shareable_file = | 655 scoped_refptr<ShareableFileReference> shareable_file = |
| 602 ShareableFileReference::Get(blob_info.file_path()); | 656 ShareableFileReference::Get(blob_info.file_path()); |
| 603 if (!shareable_file) { | 657 if (!shareable_file) { |
| 604 shareable_file = ShareableFileReference::GetOrCreate( | 658 shareable_file = ShareableFileReference::GetOrCreate( |
| 605 blob_info.file_path(), | 659 blob_info.file_path(), |
| 606 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, | 660 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, |
| 607 dispatcher_host_->context()->TaskRunner()); | 661 dispatcher_host_->context()->TaskRunner()); |
| 608 if (!blob_info.release_callback().is_null()) | 662 if (!blob_info.release_callback().is_null()) |
| 609 shareable_file->AddFinalReleaseCallback(blob_info.release_callback()); | 663 shareable_file->AddFinalReleaseCallback(blob_info.release_callback()); |
| 610 } | 664 } |
| 611 return dispatcher_host_->HoldBlobData(blob_info); | 665 return dispatcher_host_->HoldBlobData(blob_info); |
| 612 } | 666 } |
| 613 | 667 |
| 614 bool IndexedDBCallbacks::IOThreadHelper::CreateAllBlobs( | 668 bool IndexedDBCallbacks::IOThreadHelper::CreateAllBlobs( |
| 615 const std::vector<IndexedDBBlobInfo>& blob_info, | 669 const std::vector<IndexedDBBlobInfo>& blob_info, |
| 616 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info) { | 670 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info) { |
| 671 if (!dispatcher_host_) { |
| 672 OnConnectionError(); |
| 673 return false; |
| 674 } |
| 617 IDB_TRACE("IndexedDBCallbacks::CreateAllBlobs"); | 675 IDB_TRACE("IndexedDBCallbacks::CreateAllBlobs"); |
| 618 DCHECK_EQ(blob_info.size(), blob_or_file_info->size()); | 676 DCHECK_EQ(blob_info.size(), blob_or_file_info->size()); |
| 619 if (!dispatcher_host_->blob_storage_context()) | 677 if (!dispatcher_host_->blob_storage_context()) |
| 620 return false; | 678 return false; |
| 621 for (size_t i = 0; i < blob_info.size(); ++i) | 679 for (size_t i = 0; i < blob_info.size(); ++i) |
| 622 (*blob_or_file_info)[i]->uuid = CreateBlobData(blob_info[i]); | 680 (*blob_or_file_info)[i]->uuid = CreateBlobData(blob_info[i]); |
| 623 return true; | 681 return true; |
| 624 } | 682 } |
| 625 | 683 |
| 626 void IndexedDBCallbacks::IOThreadHelper::OnConnectionError() { | 684 void IndexedDBCallbacks::IOThreadHelper::OnConnectionError() { |
| 627 callbacks_.reset(); | 685 callbacks_.reset(); |
| 628 dispatcher_host_ = nullptr; | 686 dispatcher_host_ = nullptr; |
| 629 } | 687 } |
| 630 | 688 |
| 631 } // namespace content | 689 } // namespace content |
| OLD | NEW |