Chromium Code Reviews| Index: content/browser/indexed_db/indexed_db_callbacks.cc |
| diff --git a/content/browser/indexed_db/indexed_db_callbacks.cc b/content/browser/indexed_db/indexed_db_callbacks.cc |
| index 49995fbc5dd294146654c7abcd25d423fe3bd402..bbc575f27a2108e60652ecb541046a588d3420da 100644 |
| --- a/content/browser/indexed_db/indexed_db_callbacks.cc |
| +++ b/content/browser/indexed_db/indexed_db_callbacks.cc |
| @@ -132,6 +132,7 @@ class IndexedDBCallbacks::IOThreadHelper { |
| bool CreateAllBlobs( |
| const std::vector<IndexedDBBlobInfo>& blob_info, |
| std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info); |
| + void OnConnectionError(); |
|
cmumford
2017/01/05 00:29:01
No longer need to include indexed_db_blob_info.h
Reilly Grant (use Gerrit)
2017/01/06 02:23:35
Done.
|
| private: |
| scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
| @@ -256,9 +257,10 @@ void IndexedDBCallbacks::OnSuccess( |
| // Only send a new Database if the connection was not previously sent in |
| // OnUpgradeNeeded. |
| std::unique_ptr<DatabaseImpl> database; |
| - if (!database_sent_) |
| + if (!database_sent_) { |
| database.reset( |
| new DatabaseImpl(std::move(connection), origin_, dispatcher_host_)); |
| + } |
| BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| base::Bind(&IOThreadHelper::SendSuccessDatabase, |
| @@ -431,12 +433,6 @@ void IndexedDBCallbacks::OnSuccess() { |
| dispatcher_host_ = nullptr; |
| } |
| -bool IndexedDBCallbacks::IsValid() const { |
| - DCHECK(dispatcher_host_.get()); |
| - |
| - return dispatcher_host_->IsOpen(); |
| -} |
| - |
| void IndexedDBCallbacks::SetConnectionOpenStartTime( |
| const base::TimeTicks& start_time) { |
| connection_open_start_time_ = start_time; |
| @@ -447,23 +443,30 @@ IndexedDBCallbacks::IOThreadHelper::IOThreadHelper( |
| scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) |
| : dispatcher_host_(std::move(dispatcher_host)) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - callbacks_.Bind(std::move(callbacks_info)); |
| + if (callbacks_info.is_valid()) { |
| + callbacks_.Bind(std::move(callbacks_info)); |
| + callbacks_.set_connection_error_handler( |
| + base::Bind(&IOThreadHelper::OnConnectionError, base::Unretained(this))); |
| + } |
| } |
| IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {} |
| void IndexedDBCallbacks::IOThreadHelper::SendError( |
| const IndexedDBDatabaseError& error) { |
| - callbacks_->Error(error.code(), error.message()); |
| + if (callbacks_) |
| + callbacks_->Error(error.code(), error.message()); |
| } |
| void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList( |
| const std::vector<base::string16>& value) { |
| - callbacks_->SuccessStringList(value); |
| + if (callbacks_) |
| + callbacks_->SuccessStringList(value); |
| } |
| void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) { |
| - callbacks_->Blocked(existing_version); |
| + if (callbacks_) |
| + callbacks_->Blocked(existing_version); |
| } |
| void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( |
| @@ -472,6 +475,9 @@ void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( |
| blink::WebIDBDataLoss data_loss, |
| const std::string& data_loss_message, |
| const content::IndexedDBDatabaseMetadata& metadata) { |
| + if (!callbacks_) |
| + return; |
| + |
| ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; |
| ::indexed_db::mojom::DatabaseAssociatedRequest request; |
| callbacks_.associated_group()->CreateAssociatedInterface( |
| @@ -484,6 +490,9 @@ void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( |
| void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( |
| std::unique_ptr<DatabaseImpl> database, |
| const content::IndexedDBDatabaseMetadata& metadata) { |
| + if (!callbacks_) |
| + return; |
| + |
| ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; |
| if (database) { |
| ::indexed_db::mojom::DatabaseAssociatedRequest request; |
| @@ -500,6 +509,9 @@ void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor( |
| const IndexedDBKey& primary_key, |
| ::indexed_db::mojom::ValuePtr value, |
| const std::vector<IndexedDBBlobInfo>& blob_info) { |
| + if (!callbacks_) |
| + return; |
| + |
| if (value && !CreateAllBlobs(blob_info, &value->blob_or_file_info)) |
| return; |
| @@ -515,6 +527,9 @@ void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor( |
| void IndexedDBCallbacks::IOThreadHelper::SendSuccessValue( |
| ::indexed_db::mojom::ReturnValuePtr value, |
| const std::vector<IndexedDBBlobInfo>& blob_info) { |
| + if (!callbacks_) |
| + return; |
| + |
| if (!value || CreateAllBlobs(blob_info, &value->value->blob_or_file_info)) |
| callbacks_->SuccessValue(std::move(value)); |
| } |
| @@ -524,6 +539,9 @@ void IndexedDBCallbacks::IOThreadHelper::SendSuccessArray( |
| const std::vector<IndexedDBReturnValue>& values) { |
| DCHECK_EQ(mojo_values.size(), values.size()); |
| + if (!callbacks_) |
| + return; |
| + |
| for (size_t i = 0; i < mojo_values.size(); ++i) { |
| if (!CreateAllBlobs(values[i].blob_info, |
| &mojo_values[i]->value->blob_or_file_info)) |
| @@ -537,6 +555,9 @@ void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorContinue( |
| const IndexedDBKey& primary_key, |
| ::indexed_db::mojom::ValuePtr value, |
| const std::vector<IndexedDBBlobInfo>& blob_info) { |
| + if (!callbacks_) |
| + return; |
| + |
| if (!value || CreateAllBlobs(blob_info, &value->blob_or_file_info)) |
| callbacks_->SuccessCursorContinue(key, primary_key, std::move(value)); |
| } |
| @@ -548,6 +569,9 @@ void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorPrefetch( |
| const std::vector<IndexedDBValue>& values) { |
| DCHECK_EQ(mojo_values.size(), values.size()); |
| + if (!callbacks_) |
| + return; |
| + |
| for (size_t i = 0; i < mojo_values.size(); ++i) { |
| if (!CreateAllBlobs(values[i].blob_info, |
| &mojo_values[i]->blob_or_file_info)) { |
| @@ -560,15 +584,18 @@ void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorPrefetch( |
| void IndexedDBCallbacks::IOThreadHelper::SendSuccessKey( |
| const IndexedDBKey& value) { |
| - callbacks_->SuccessKey(value); |
| + if (callbacks_) |
| + callbacks_->SuccessKey(value); |
| } |
| void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { |
| - callbacks_->SuccessInteger(value); |
| + if (callbacks_) |
| + callbacks_->SuccessInteger(value); |
| } |
| void IndexedDBCallbacks::IOThreadHelper::SendSuccess() { |
| - callbacks_->Success(); |
| + if (callbacks_) |
| + callbacks_->Success(); |
| } |
| std::string IndexedDBCallbacks::IOThreadHelper::CreateBlobData( |
| @@ -602,4 +629,9 @@ bool IndexedDBCallbacks::IOThreadHelper::CreateAllBlobs( |
| return true; |
| } |
| +void IndexedDBCallbacks::IOThreadHelper::OnConnectionError() { |
| + callbacks_.reset(); |
| + dispatcher_host_ = nullptr; |
| +} |
| + |
| } // namespace content |