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

Side by Side Diff: content/browser/indexed_db/indexed_db_callbacks.cc

Issue 2601163002: Remove indexed_db_messages.h. (Closed)
Patch Set: Addressed cmumford's feedback. Created 3 years, 11 months 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 (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>
11 11
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "content/browser/child_process_security_policy_impl.h" 16 #include "content/browser/child_process_security_policy_impl.h"
17 #include "content/browser/fileapi/fileapi_message_filter.h" 17 #include "content/browser/fileapi/fileapi_message_filter.h"
18 #include "content/browser/indexed_db/cursor_impl.h" 18 #include "content/browser/indexed_db/cursor_impl.h"
19 #include "content/browser/indexed_db/database_impl.h" 19 #include "content/browser/indexed_db/database_impl.h"
20 #include "content/browser/indexed_db/indexed_db_blob_info.h"
21 #include "content/browser/indexed_db/indexed_db_connection.h" 20 #include "content/browser/indexed_db/indexed_db_connection.h"
22 #include "content/browser/indexed_db/indexed_db_context_impl.h" 21 #include "content/browser/indexed_db/indexed_db_context_impl.h"
23 #include "content/browser/indexed_db/indexed_db_cursor.h" 22 #include "content/browser/indexed_db/indexed_db_cursor.h"
24 #include "content/browser/indexed_db/indexed_db_database_error.h" 23 #include "content/browser/indexed_db/indexed_db_database_error.h"
25 #include "content/browser/indexed_db/indexed_db_return_value.h" 24 #include "content/browser/indexed_db/indexed_db_return_value.h"
26 #include "content/browser/indexed_db/indexed_db_tracing.h" 25 #include "content/browser/indexed_db/indexed_db_tracing.h"
27 #include "content/browser/indexed_db/indexed_db_transaction.h" 26 #include "content/browser/indexed_db/indexed_db_transaction.h"
28 #include "content/browser/indexed_db/indexed_db_value.h" 27 #include "content/browser/indexed_db/indexed_db_value.h"
29 #include "content/common/indexed_db/indexed_db_constants.h" 28 #include "content/common/indexed_db/indexed_db_constants.h"
30 #include "content/common/indexed_db/indexed_db_metadata.h" 29 #include "content/common/indexed_db/indexed_db_metadata.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 std::vector<::indexed_db::mojom::ReturnValuePtr> mojo_values, 124 std::vector<::indexed_db::mojom::ReturnValuePtr> mojo_values,
126 const std::vector<IndexedDBReturnValue>& values); 125 const std::vector<IndexedDBReturnValue>& values);
127 void SendSuccessKey(const IndexedDBKey& value); 126 void SendSuccessKey(const IndexedDBKey& value);
128 void SendSuccessInteger(int64_t value); 127 void SendSuccessInteger(int64_t value);
129 void SendSuccess(); 128 void SendSuccess();
130 129
131 std::string CreateBlobData(const IndexedDBBlobInfo& blob_info); 130 std::string CreateBlobData(const IndexedDBBlobInfo& blob_info);
132 bool CreateAllBlobs( 131 bool CreateAllBlobs(
133 const std::vector<IndexedDBBlobInfo>& blob_info, 132 const std::vector<IndexedDBBlobInfo>& blob_info,
134 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info); 133 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info);
134 void OnConnectionError();
135 135
136 private: 136 private:
137 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; 137 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
138 ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_; 138 ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_;
139 139
140 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); 140 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
141 }; 141 };
142 142
143 IndexedDBCallbacks::IndexedDBCallbacks( 143 IndexedDBCallbacks::IndexedDBCallbacks(
144 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, 144 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 DCHECK(dispatcher_host_); 249 DCHECK(dispatcher_host_);
250 DCHECK(io_helper_); 250 DCHECK(io_helper_);
251 251
252 DCHECK_EQ(database_sent_, !connection); 252 DCHECK_EQ(database_sent_, !connection);
253 253
254 scoped_refptr<IndexedDBCallbacks> self(this); 254 scoped_refptr<IndexedDBCallbacks> self(this);
255 255
256 // Only send a new Database if the connection was not previously sent in 256 // Only send a new Database if the connection was not previously sent in
257 // OnUpgradeNeeded. 257 // OnUpgradeNeeded.
258 std::unique_ptr<DatabaseImpl> database; 258 std::unique_ptr<DatabaseImpl> database;
259 if (!database_sent_) 259 if (!database_sent_) {
260 database.reset( 260 database.reset(
261 new DatabaseImpl(std::move(connection), origin_, dispatcher_host_)); 261 new DatabaseImpl(std::move(connection), origin_, dispatcher_host_));
262 }
262 263
263 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 264 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
264 base::Bind(&IOThreadHelper::SendSuccessDatabase, 265 base::Bind(&IOThreadHelper::SendSuccessDatabase,
265 base::Unretained(io_helper_.get()), 266 base::Unretained(io_helper_.get()),
266 base::Passed(&database), metadata)); 267 base::Passed(&database), metadata));
267 dispatcher_host_ = nullptr; 268 dispatcher_host_ = nullptr;
268 269
269 if (!connection_open_start_time_.is_null()) { 270 if (!connection_open_start_time_.is_null()) {
270 UMA_HISTOGRAM_MEDIUM_TIMES( 271 UMA_HISTOGRAM_MEDIUM_TIMES(
271 "WebCore.IndexedDB.OpenTime.Success", 272 "WebCore.IndexedDB.OpenTime.Success",
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 DCHECK(io_helper_); 425 DCHECK(io_helper_);
425 426
426 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 427 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
427 428
428 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 429 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
429 base::Bind(&IOThreadHelper::SendSuccess, 430 base::Bind(&IOThreadHelper::SendSuccess,
430 base::Unretained(io_helper_.get()))); 431 base::Unretained(io_helper_.get())));
431 dispatcher_host_ = nullptr; 432 dispatcher_host_ = nullptr;
432 } 433 }
433 434
434 bool IndexedDBCallbacks::IsValid() const {
435 DCHECK(dispatcher_host_.get());
436
437 return dispatcher_host_->IsOpen();
438 }
439
440 void IndexedDBCallbacks::SetConnectionOpenStartTime( 435 void IndexedDBCallbacks::SetConnectionOpenStartTime(
441 const base::TimeTicks& start_time) { 436 const base::TimeTicks& start_time) {
442 connection_open_start_time_ = start_time; 437 connection_open_start_time_ = start_time;
443 } 438 }
444 439
445 IndexedDBCallbacks::IOThreadHelper::IOThreadHelper( 440 IndexedDBCallbacks::IOThreadHelper::IOThreadHelper(
446 CallbacksAssociatedPtrInfo callbacks_info, 441 CallbacksAssociatedPtrInfo callbacks_info,
447 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) 442 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host)
448 : dispatcher_host_(std::move(dispatcher_host)) { 443 : dispatcher_host_(std::move(dispatcher_host)) {
449 DCHECK_CURRENTLY_ON(BrowserThread::IO); 444 DCHECK_CURRENTLY_ON(BrowserThread::IO);
450 callbacks_.Bind(std::move(callbacks_info)); 445 if (callbacks_info.is_valid()) {
446 callbacks_.Bind(std::move(callbacks_info));
447 callbacks_.set_connection_error_handler(
448 base::Bind(&IOThreadHelper::OnConnectionError, base::Unretained(this)));
449 }
451 } 450 }
452 451
453 IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {} 452 IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {}
454 453
455 void IndexedDBCallbacks::IOThreadHelper::SendError( 454 void IndexedDBCallbacks::IOThreadHelper::SendError(
456 const IndexedDBDatabaseError& error) { 455 const IndexedDBDatabaseError& error) {
457 callbacks_->Error(error.code(), error.message()); 456 if (callbacks_)
457 callbacks_->Error(error.code(), error.message());
458 } 458 }
459 459
460 void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList( 460 void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList(
461 const std::vector<base::string16>& value) { 461 const std::vector<base::string16>& value) {
462 callbacks_->SuccessStringList(value); 462 if (callbacks_)
463 callbacks_->SuccessStringList(value);
463 } 464 }
464 465
465 void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) { 466 void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) {
466 callbacks_->Blocked(existing_version); 467 if (callbacks_)
468 callbacks_->Blocked(existing_version);
467 } 469 }
468 470
469 void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( 471 void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded(
470 std::unique_ptr<DatabaseImpl> database, 472 std::unique_ptr<DatabaseImpl> database,
471 int64_t old_version, 473 int64_t old_version,
472 blink::WebIDBDataLoss data_loss, 474 blink::WebIDBDataLoss data_loss,
473 const std::string& data_loss_message, 475 const std::string& data_loss_message,
474 const content::IndexedDBDatabaseMetadata& metadata) { 476 const content::IndexedDBDatabaseMetadata& metadata) {
477 if (!callbacks_)
478 return;
479
475 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; 480 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info;
476 ::indexed_db::mojom::DatabaseAssociatedRequest request; 481 ::indexed_db::mojom::DatabaseAssociatedRequest request;
477 callbacks_.associated_group()->CreateAssociatedInterface( 482 callbacks_.associated_group()->CreateAssociatedInterface(
478 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); 483 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
479 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request)); 484 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request));
480 callbacks_->UpgradeNeeded(std::move(ptr_info), old_version, data_loss, 485 callbacks_->UpgradeNeeded(std::move(ptr_info), old_version, data_loss,
481 data_loss_message, metadata); 486 data_loss_message, metadata);
482 } 487 }
483 488
484 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( 489 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase(
485 std::unique_ptr<DatabaseImpl> database, 490 std::unique_ptr<DatabaseImpl> database,
486 const content::IndexedDBDatabaseMetadata& metadata) { 491 const content::IndexedDBDatabaseMetadata& metadata) {
492 if (!callbacks_)
493 return;
494
487 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; 495 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info;
488 if (database) { 496 if (database) {
489 ::indexed_db::mojom::DatabaseAssociatedRequest request; 497 ::indexed_db::mojom::DatabaseAssociatedRequest request;
490 callbacks_.associated_group()->CreateAssociatedInterface( 498 callbacks_.associated_group()->CreateAssociatedInterface(
491 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); 499 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
492 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request)); 500 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request));
493 } 501 }
494 callbacks_->SuccessDatabase(std::move(ptr_info), metadata); 502 callbacks_->SuccessDatabase(std::move(ptr_info), metadata);
495 } 503 }
496 504
497 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor( 505 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor(
498 std::unique_ptr<CursorImpl> cursor, 506 std::unique_ptr<CursorImpl> cursor,
499 const IndexedDBKey& key, 507 const IndexedDBKey& key,
500 const IndexedDBKey& primary_key, 508 const IndexedDBKey& primary_key,
501 ::indexed_db::mojom::ValuePtr value, 509 ::indexed_db::mojom::ValuePtr value,
502 const std::vector<IndexedDBBlobInfo>& blob_info) { 510 const std::vector<IndexedDBBlobInfo>& blob_info) {
511 if (!callbacks_)
512 return;
513
503 if (value && !CreateAllBlobs(blob_info, &value->blob_or_file_info)) 514 if (value && !CreateAllBlobs(blob_info, &value->blob_or_file_info))
504 return; 515 return;
505 516
506 ::indexed_db::mojom::CursorAssociatedPtrInfo ptr_info; 517 ::indexed_db::mojom::CursorAssociatedPtrInfo ptr_info;
507 ::indexed_db::mojom::CursorAssociatedRequest request; 518 ::indexed_db::mojom::CursorAssociatedRequest request;
508 callbacks_.associated_group()->CreateAssociatedInterface( 519 callbacks_.associated_group()->CreateAssociatedInterface(
509 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); 520 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
510 mojo::MakeStrongAssociatedBinding(std::move(cursor), std::move(request)); 521 mojo::MakeStrongAssociatedBinding(std::move(cursor), std::move(request));
511 callbacks_->SuccessCursor(std::move(ptr_info), key, primary_key, 522 callbacks_->SuccessCursor(std::move(ptr_info), key, primary_key,
512 std::move(value)); 523 std::move(value));
513 } 524 }
514 525
515 void IndexedDBCallbacks::IOThreadHelper::SendSuccessValue( 526 void IndexedDBCallbacks::IOThreadHelper::SendSuccessValue(
516 ::indexed_db::mojom::ReturnValuePtr value, 527 ::indexed_db::mojom::ReturnValuePtr value,
517 const std::vector<IndexedDBBlobInfo>& blob_info) { 528 const std::vector<IndexedDBBlobInfo>& blob_info) {
529 if (!callbacks_)
530 return;
531
518 if (!value || CreateAllBlobs(blob_info, &value->value->blob_or_file_info)) 532 if (!value || CreateAllBlobs(blob_info, &value->value->blob_or_file_info))
519 callbacks_->SuccessValue(std::move(value)); 533 callbacks_->SuccessValue(std::move(value));
520 } 534 }
521 535
522 void IndexedDBCallbacks::IOThreadHelper::SendSuccessArray( 536 void IndexedDBCallbacks::IOThreadHelper::SendSuccessArray(
523 std::vector<::indexed_db::mojom::ReturnValuePtr> mojo_values, 537 std::vector<::indexed_db::mojom::ReturnValuePtr> mojo_values,
524 const std::vector<IndexedDBReturnValue>& values) { 538 const std::vector<IndexedDBReturnValue>& values) {
525 DCHECK_EQ(mojo_values.size(), values.size()); 539 DCHECK_EQ(mojo_values.size(), values.size());
526 540
541 if (!callbacks_)
542 return;
543
527 for (size_t i = 0; i < mojo_values.size(); ++i) { 544 for (size_t i = 0; i < mojo_values.size(); ++i) {
528 if (!CreateAllBlobs(values[i].blob_info, 545 if (!CreateAllBlobs(values[i].blob_info,
529 &mojo_values[i]->value->blob_or_file_info)) 546 &mojo_values[i]->value->blob_or_file_info))
530 return; 547 return;
531 } 548 }
532 callbacks_->SuccessArray(std::move(mojo_values)); 549 callbacks_->SuccessArray(std::move(mojo_values));
533 } 550 }
534 551
535 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorContinue( 552 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorContinue(
536 const IndexedDBKey& key, 553 const IndexedDBKey& key,
537 const IndexedDBKey& primary_key, 554 const IndexedDBKey& primary_key,
538 ::indexed_db::mojom::ValuePtr value, 555 ::indexed_db::mojom::ValuePtr value,
539 const std::vector<IndexedDBBlobInfo>& blob_info) { 556 const std::vector<IndexedDBBlobInfo>& blob_info) {
557 if (!callbacks_)
558 return;
559
540 if (!value || CreateAllBlobs(blob_info, &value->blob_or_file_info)) 560 if (!value || CreateAllBlobs(blob_info, &value->blob_or_file_info))
541 callbacks_->SuccessCursorContinue(key, primary_key, std::move(value)); 561 callbacks_->SuccessCursorContinue(key, primary_key, std::move(value));
542 } 562 }
543 563
544 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorPrefetch( 564 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursorPrefetch(
545 const std::vector<IndexedDBKey>& keys, 565 const std::vector<IndexedDBKey>& keys,
546 const std::vector<IndexedDBKey>& primary_keys, 566 const std::vector<IndexedDBKey>& primary_keys,
547 std::vector<::indexed_db::mojom::ValuePtr> mojo_values, 567 std::vector<::indexed_db::mojom::ValuePtr> mojo_values,
548 const std::vector<IndexedDBValue>& values) { 568 const std::vector<IndexedDBValue>& values) {
549 DCHECK_EQ(mojo_values.size(), values.size()); 569 DCHECK_EQ(mojo_values.size(), values.size());
550 570
571 if (!callbacks_)
572 return;
573
551 for (size_t i = 0; i < mojo_values.size(); ++i) { 574 for (size_t i = 0; i < mojo_values.size(); ++i) {
552 if (!CreateAllBlobs(values[i].blob_info, 575 if (!CreateAllBlobs(values[i].blob_info,
553 &mojo_values[i]->blob_or_file_info)) { 576 &mojo_values[i]->blob_or_file_info)) {
554 return; 577 return;
555 } 578 }
556 } 579 }
557 580
558 callbacks_->SuccessCursorPrefetch(keys, primary_keys, std::move(mojo_values)); 581 callbacks_->SuccessCursorPrefetch(keys, primary_keys, std::move(mojo_values));
559 } 582 }
560 583
561 void IndexedDBCallbacks::IOThreadHelper::SendSuccessKey( 584 void IndexedDBCallbacks::IOThreadHelper::SendSuccessKey(
562 const IndexedDBKey& value) { 585 const IndexedDBKey& value) {
563 callbacks_->SuccessKey(value); 586 if (callbacks_)
587 callbacks_->SuccessKey(value);
564 } 588 }
565 589
566 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { 590 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) {
567 callbacks_->SuccessInteger(value); 591 if (callbacks_)
592 callbacks_->SuccessInteger(value);
568 } 593 }
569 594
570 void IndexedDBCallbacks::IOThreadHelper::SendSuccess() { 595 void IndexedDBCallbacks::IOThreadHelper::SendSuccess() {
571 callbacks_->Success(); 596 if (callbacks_)
597 callbacks_->Success();
572 } 598 }
573 599
574 std::string IndexedDBCallbacks::IOThreadHelper::CreateBlobData( 600 std::string IndexedDBCallbacks::IOThreadHelper::CreateBlobData(
575 const IndexedDBBlobInfo& blob_info) { 601 const IndexedDBBlobInfo& blob_info) {
576 if (!blob_info.uuid().empty()) { 602 if (!blob_info.uuid().empty()) {
577 // We're sending back a live blob, not a reference into our backing store. 603 // We're sending back a live blob, not a reference into our backing store.
578 return dispatcher_host_->HoldBlobData(blob_info); 604 return dispatcher_host_->HoldBlobData(blob_info);
579 } 605 }
580 scoped_refptr<ShareableFileReference> shareable_file = 606 scoped_refptr<ShareableFileReference> shareable_file =
581 ShareableFileReference::Get(blob_info.file_path()); 607 ShareableFileReference::Get(blob_info.file_path());
(...skipping 13 matching lines...) Expand all
595 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info) { 621 std::vector<::indexed_db::mojom::BlobInfoPtr>* blob_or_file_info) {
596 IDB_TRACE("IndexedDBCallbacks::CreateAllBlobs"); 622 IDB_TRACE("IndexedDBCallbacks::CreateAllBlobs");
597 DCHECK_EQ(blob_info.size(), blob_or_file_info->size()); 623 DCHECK_EQ(blob_info.size(), blob_or_file_info->size());
598 if (!dispatcher_host_->blob_storage_context()) 624 if (!dispatcher_host_->blob_storage_context())
599 return false; 625 return false;
600 for (size_t i = 0; i < blob_info.size(); ++i) 626 for (size_t i = 0; i < blob_info.size(); ++i)
601 (*blob_or_file_info)[i]->uuid = CreateBlobData(blob_info[i]); 627 (*blob_or_file_info)[i]->uuid = CreateBlobData(blob_info[i]);
602 return true; 628 return true;
603 } 629 }
604 630
631 void IndexedDBCallbacks::IOThreadHelper::OnConnectionError() {
632 callbacks_.reset();
633 dispatcher_host_ = nullptr;
634 }
635
605 } // namespace content 636 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_callbacks.h ('k') | content/browser/indexed_db/indexed_db_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698