| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 wrapper_(wrapper), | 382 wrapper_(wrapper), |
| 383 has_callback_(frontend_->HasCallback()), | 383 has_callback_(frontend_->HasCallback()), |
| 384 has_success_callback_(frontend_->HasSuccessCallback()), | 384 has_success_callback_(frontend_->HasSuccessCallback()), |
| 385 has_error_callback_(frontend_->HasErrorCallback()), | 385 has_error_callback_(frontend_->HasErrorCallback()), |
| 386 should_retry_current_statement_(false), | 386 should_retry_current_statement_(false), |
| 387 modified_database_(false), | 387 modified_database_(false), |
| 388 lock_acquired_(false), | 388 lock_acquired_(false), |
| 389 read_only_(read_only), | 389 read_only_(read_only), |
| 390 has_version_mismatch_(false) { | 390 has_version_mismatch_(false) { |
| 391 DCHECK(IsMainThread()); | 391 DCHECK(IsMainThread()); |
| 392 ASSERT(database_); | 392 DCHECK(database_); |
| 393 frontend_->SetBackend(this); | 393 frontend_->SetBackend(this); |
| 394 requested_state_ = SQLTransactionState::kAcquireLock; | 394 requested_state_ = SQLTransactionState::kAcquireLock; |
| 395 } | 395 } |
| 396 | 396 |
| 397 SQLTransactionBackend::~SQLTransactionBackend() { | 397 SQLTransactionBackend::~SQLTransactionBackend() { |
| 398 ASSERT(!sqlite_transaction_); | 398 DCHECK(!sqlite_transaction_); |
| 399 } | 399 } |
| 400 | 400 |
| 401 DEFINE_TRACE(SQLTransactionBackend) { | 401 DEFINE_TRACE(SQLTransactionBackend) { |
| 402 visitor->Trace(database_); | 402 visitor->Trace(database_); |
| 403 visitor->Trace(wrapper_); | 403 visitor->Trace(wrapper_); |
| 404 } | 404 } |
| 405 | 405 |
| 406 void SQLTransactionBackend::DoCleanup() { | 406 void SQLTransactionBackend::DoCleanup() { |
| 407 if (!frontend_) | 407 if (!frontend_) |
| 408 return; | 408 return; |
| 409 // Break the reference cycle. See comment about the life-cycle above. | 409 // Break the reference cycle. See comment about the life-cycle above. |
| 410 frontend_ = nullptr; | 410 frontend_ = nullptr; |
| 411 | 411 |
| 412 ASSERT(GetDatabase() | 412 DCHECK(GetDatabase() |
| 413 ->GetDatabaseContext() | 413 ->GetDatabaseContext() |
| 414 ->GetDatabaseThread() | 414 ->GetDatabaseThread() |
| 415 ->IsDatabaseThread()); | 415 ->IsDatabaseThread()); |
| 416 | 416 |
| 417 MutexLocker locker(statement_mutex_); | 417 MutexLocker locker(statement_mutex_); |
| 418 statement_queue_.Clear(); | 418 statement_queue_.Clear(); |
| 419 | 419 |
| 420 if (sqlite_transaction_) { | 420 if (sqlite_transaction_) { |
| 421 // In the event we got here because of an interruption or error (i.e. if | 421 // In the event we got here because of an interruption or error (i.e. if |
| 422 // the transaction is in progress), we should roll it back here. Clearing | 422 // the transaction is in progress), we should roll it back here. Clearing |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 SQLStatement* SQLTransactionBackend::CurrentStatement() { | 459 SQLStatement* SQLTransactionBackend::CurrentStatement() { |
| 460 return current_statement_backend_->GetFrontend(); | 460 return current_statement_backend_->GetFrontend(); |
| 461 } | 461 } |
| 462 | 462 |
| 463 SQLErrorData* SQLTransactionBackend::TransactionError() { | 463 SQLErrorData* SQLTransactionBackend::TransactionError() { |
| 464 return transaction_error_.get(); | 464 return transaction_error_.get(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 void SQLTransactionBackend::SetShouldRetryCurrentStatement(bool should_retry) { | 467 void SQLTransactionBackend::SetShouldRetryCurrentStatement(bool should_retry) { |
| 468 ASSERT(!should_retry_current_statement_); | 468 DCHECK(!should_retry_current_statement_); |
| 469 should_retry_current_statement_ = should_retry; | 469 should_retry_current_statement_ = should_retry; |
| 470 } | 470 } |
| 471 | 471 |
| 472 SQLTransactionBackend::StateFunction SQLTransactionBackend::StateFunctionFor( | 472 SQLTransactionBackend::StateFunction SQLTransactionBackend::StateFunctionFor( |
| 473 SQLTransactionState state) { | 473 SQLTransactionState state) { |
| 474 static const StateFunction kStateFunctions[] = { | 474 static const StateFunction kStateFunctions[] = { |
| 475 &SQLTransactionBackend::UnreachableState, // 0. end | 475 &SQLTransactionBackend::UnreachableState, // 0. end |
| 476 &SQLTransactionBackend::UnreachableState, // 1. idle | 476 &SQLTransactionBackend::UnreachableState, // 1. idle |
| 477 &SQLTransactionBackend::AcquireLock, // 2. | 477 &SQLTransactionBackend::AcquireLock, // 2. |
| 478 &SQLTransactionBackend::OpenTransactionAndPreflight, // 3. | 478 &SQLTransactionBackend::OpenTransactionAndPreflight, // 3. |
| 479 &SQLTransactionBackend::RunStatements, // 4. | 479 &SQLTransactionBackend::RunStatements, // 4. |
| 480 &SQLTransactionBackend::PostflightAndCommit, // 5. | 480 &SQLTransactionBackend::PostflightAndCommit, // 5. |
| 481 &SQLTransactionBackend::CleanupAndTerminate, // 6. | 481 &SQLTransactionBackend::CleanupAndTerminate, // 6. |
| 482 &SQLTransactionBackend::CleanupAfterTransactionErrorCallback, // 7. | 482 &SQLTransactionBackend::CleanupAfterTransactionErrorCallback, // 7. |
| 483 // 8. deliverTransactionCallback | 483 // 8. deliverTransactionCallback |
| 484 &SQLTransactionBackend::SendToFrontendState, | 484 &SQLTransactionBackend::SendToFrontendState, |
| 485 // 9. deliverTransactionErrorCallback | 485 // 9. deliverTransactionErrorCallback |
| 486 &SQLTransactionBackend::SendToFrontendState, | 486 &SQLTransactionBackend::SendToFrontendState, |
| 487 // 10. deliverStatementCallback | 487 // 10. deliverStatementCallback |
| 488 &SQLTransactionBackend::SendToFrontendState, | 488 &SQLTransactionBackend::SendToFrontendState, |
| 489 // 11. deliverQuotaIncreaseCallback | 489 // 11. deliverQuotaIncreaseCallback |
| 490 &SQLTransactionBackend::SendToFrontendState, | 490 &SQLTransactionBackend::SendToFrontendState, |
| 491 // 12. deliverSuccessCallback | 491 // 12. deliverSuccessCallback |
| 492 &SQLTransactionBackend::SendToFrontendState, | 492 &SQLTransactionBackend::SendToFrontendState, |
| 493 }; | 493 }; |
| 494 | 494 |
| 495 ASSERT(WTF_ARRAY_LENGTH(kStateFunctions) == | 495 DCHECK(WTF_ARRAY_LENGTH(kStateFunctions) == |
| 496 static_cast<int>(SQLTransactionState::kNumberOfStates)); | 496 static_cast<int>(SQLTransactionState::kNumberOfStates)); |
| 497 ASSERT(state < SQLTransactionState::kNumberOfStates); | 497 DCHECK_LT(state, SQLTransactionState::kNumberOfStates); |
| 498 | 498 |
| 499 return kStateFunctions[static_cast<int>(state)]; | 499 return kStateFunctions[static_cast<int>(state)]; |
| 500 } | 500 } |
| 501 | 501 |
| 502 void SQLTransactionBackend::EnqueueStatementBackend( | 502 void SQLTransactionBackend::EnqueueStatementBackend( |
| 503 SQLStatementBackend* statement_backend) { | 503 SQLStatementBackend* statement_backend) { |
| 504 DCHECK(IsMainThread()); | 504 DCHECK(IsMainThread()); |
| 505 MutexLocker locker(statement_mutex_); | 505 MutexLocker locker(statement_mutex_); |
| 506 statement_queue_.push_back(statement_backend); | 506 statement_queue_.push_back(statement_backend); |
| 507 } | 507 } |
| 508 | 508 |
| 509 void SQLTransactionBackend::ComputeNextStateAndCleanupIfNeeded() { | 509 void SQLTransactionBackend::ComputeNextStateAndCleanupIfNeeded() { |
| 510 DCHECK(GetDatabase() | 510 DCHECK(GetDatabase() |
| 511 ->GetDatabaseContext() | 511 ->GetDatabaseContext() |
| 512 ->GetDatabaseThread() | 512 ->GetDatabaseThread() |
| 513 ->IsDatabaseThread()); | 513 ->IsDatabaseThread()); |
| 514 // Only honor the requested state transition if we're not supposed to be | 514 // Only honor the requested state transition if we're not supposed to be |
| 515 // cleaning up and shutting down: | 515 // cleaning up and shutting down: |
| 516 if (database_->Opened()) { | 516 if (database_->Opened()) { |
| 517 SetStateToRequestedState(); | 517 SetStateToRequestedState(); |
| 518 ASSERT(next_state_ == SQLTransactionState::kAcquireLock || | 518 DCHECK(next_state_ == SQLTransactionState::kAcquireLock || |
| 519 next_state_ == SQLTransactionState::kOpenTransactionAndPreflight || | 519 next_state_ == SQLTransactionState::kOpenTransactionAndPreflight || |
| 520 next_state_ == SQLTransactionState::kRunStatements || | 520 next_state_ == SQLTransactionState::kRunStatements || |
| 521 next_state_ == SQLTransactionState::kPostflightAndCommit || | 521 next_state_ == SQLTransactionState::kPostflightAndCommit || |
| 522 next_state_ == SQLTransactionState::kCleanupAndTerminate || | 522 next_state_ == SQLTransactionState::kCleanupAndTerminate || |
| 523 next_state_ == | 523 next_state_ == |
| 524 SQLTransactionState::kCleanupAfterTransactionErrorCallback); | 524 SQLTransactionState::kCleanupAfterTransactionErrorCallback); |
| 525 #if DCHECK_IS_ON() | 525 #if DCHECK_IS_ON() |
| 526 STORAGE_DVLOG(1) << "State " << NameForSQLTransactionState(next_state_); | 526 STORAGE_DVLOG(1) << "State " << NameForSQLTransactionState(next_state_); |
| 527 #endif | 527 #endif |
| 528 return; | 528 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 void SQLTransactionBackend::ExecuteSQL(SQLStatement* statement, | 560 void SQLTransactionBackend::ExecuteSQL(SQLStatement* statement, |
| 561 const String& sql_statement, | 561 const String& sql_statement, |
| 562 const Vector<SQLValue>& arguments, | 562 const Vector<SQLValue>& arguments, |
| 563 int permissions) { | 563 int permissions) { |
| 564 DCHECK(IsMainThread()); | 564 DCHECK(IsMainThread()); |
| 565 EnqueueStatementBackend(SQLStatementBackend::Create(statement, sql_statement, | 565 EnqueueStatementBackend(SQLStatementBackend::Create(statement, sql_statement, |
| 566 arguments, permissions)); | 566 arguments, permissions)); |
| 567 } | 567 } |
| 568 | 568 |
| 569 void SQLTransactionBackend::NotifyDatabaseThreadIsShuttingDown() { | 569 void SQLTransactionBackend::NotifyDatabaseThreadIsShuttingDown() { |
| 570 ASSERT(GetDatabase() | 570 DCHECK(GetDatabase() |
| 571 ->GetDatabaseContext() | 571 ->GetDatabaseContext() |
| 572 ->GetDatabaseThread() | 572 ->GetDatabaseThread() |
| 573 ->IsDatabaseThread()); | 573 ->IsDatabaseThread()); |
| 574 | 574 |
| 575 // If the transaction is in progress, we should roll it back here, since this | 575 // If the transaction is in progress, we should roll it back here, since this |
| 576 // is our last opportunity to do something related to this transaction on the | 576 // is our last opportunity to do something related to this transaction on the |
| 577 // DB thread. Amongst other work, doCleanup() will clear m_sqliteTransaction | 577 // DB thread. Amongst other work, doCleanup() will clear m_sqliteTransaction |
| 578 // which invokes SQLiteTransaction's destructor, which will do the roll back | 578 // which invokes SQLiteTransaction's destructor, which will do the roll back |
| 579 // if necessary. | 579 // if necessary. |
| 580 DoCleanup(); | 580 DoCleanup(); |
| 581 } | 581 } |
| 582 | 582 |
| 583 SQLTransactionState SQLTransactionBackend::AcquireLock() { | 583 SQLTransactionState SQLTransactionBackend::AcquireLock() { |
| 584 database_->TransactionCoordinator()->AcquireLock(this); | 584 database_->TransactionCoordinator()->AcquireLock(this); |
| 585 return SQLTransactionState::kIdle; | 585 return SQLTransactionState::kIdle; |
| 586 } | 586 } |
| 587 | 587 |
| 588 void SQLTransactionBackend::LockAcquired() { | 588 void SQLTransactionBackend::LockAcquired() { |
| 589 lock_acquired_ = true; | 589 lock_acquired_ = true; |
| 590 RequestTransitToState(SQLTransactionState::kOpenTransactionAndPreflight); | 590 RequestTransitToState(SQLTransactionState::kOpenTransactionAndPreflight); |
| 591 } | 591 } |
| 592 | 592 |
| 593 SQLTransactionState SQLTransactionBackend::OpenTransactionAndPreflight() { | 593 SQLTransactionState SQLTransactionBackend::OpenTransactionAndPreflight() { |
| 594 DCHECK(GetDatabase() | 594 DCHECK(GetDatabase() |
| 595 ->GetDatabaseContext() | 595 ->GetDatabaseContext() |
| 596 ->GetDatabaseThread() | 596 ->GetDatabaseThread() |
| 597 ->IsDatabaseThread()); | 597 ->IsDatabaseThread()); |
| 598 ASSERT(!database_->SqliteDatabase().TransactionInProgress()); | 598 DCHECK(!database_->SqliteDatabase().TransactionInProgress()); |
| 599 ASSERT(lock_acquired_); | 599 DCHECK(lock_acquired_); |
| 600 | 600 |
| 601 STORAGE_DVLOG(1) << "Opening and preflighting transaction " << this; | 601 STORAGE_DVLOG(1) << "Opening and preflighting transaction " << this; |
| 602 | 602 |
| 603 // Set the maximum usage for this transaction if this transactions is not | 603 // Set the maximum usage for this transaction if this transactions is not |
| 604 // read-only. | 604 // read-only. |
| 605 if (!read_only_) | 605 if (!read_only_) |
| 606 database_->SqliteDatabase().SetMaximumSize(database_->MaximumSize()); | 606 database_->SqliteDatabase().SetMaximumSize(database_->MaximumSize()); |
| 607 | 607 |
| 608 ASSERT(!sqlite_transaction_); | 608 DCHECK(!sqlite_transaction_); |
| 609 sqlite_transaction_ = WTF::WrapUnique( | 609 sqlite_transaction_ = WTF::WrapUnique( |
| 610 new SQLiteTransaction(database_->SqliteDatabase(), read_only_)); | 610 new SQLiteTransaction(database_->SqliteDatabase(), read_only_)); |
| 611 | 611 |
| 612 database_->ResetDeletes(); | 612 database_->ResetDeletes(); |
| 613 database_->DisableAuthorizer(); | 613 database_->DisableAuthorizer(); |
| 614 sqlite_transaction_->begin(); | 614 sqlite_transaction_->begin(); |
| 615 database_->EnableAuthorizer(); | 615 database_->EnableAuthorizer(); |
| 616 | 616 |
| 617 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error | 617 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error |
| 618 // callback if that fails. | 618 // callback if that fails. |
| 619 if (!sqlite_transaction_->InProgress()) { | 619 if (!sqlite_transaction_->InProgress()) { |
| 620 ASSERT(!database_->SqliteDatabase().TransactionInProgress()); | 620 DCHECK(!database_->SqliteDatabase().TransactionInProgress()); |
| 621 database_->ReportStartTransactionResult( | 621 database_->ReportStartTransactionResult( |
| 622 2, SQLError::kDatabaseErr, database_->SqliteDatabase().LastError()); | 622 2, SQLError::kDatabaseErr, database_->SqliteDatabase().LastError()); |
| 623 transaction_error_ = SQLErrorData::Create( | 623 transaction_error_ = SQLErrorData::Create( |
| 624 SQLError::kDatabaseErr, "unable to begin transaction", | 624 SQLError::kDatabaseErr, "unable to begin transaction", |
| 625 database_->SqliteDatabase().LastError(), | 625 database_->SqliteDatabase().LastError(), |
| 626 database_->SqliteDatabase().LastErrorMsg()); | 626 database_->SqliteDatabase().LastErrorMsg()); |
| 627 sqlite_transaction_.reset(); | 627 sqlite_transaction_.reset(); |
| 628 return NextStateForTransactionError(); | 628 return NextStateForTransactionError(); |
| 629 } | 629 } |
| 630 | 630 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 672 |
| 673 // If we have no callback to make, skip pass to the state after: | 673 // If we have no callback to make, skip pass to the state after: |
| 674 return SQLTransactionState::kRunStatements; | 674 return SQLTransactionState::kRunStatements; |
| 675 } | 675 } |
| 676 | 676 |
| 677 SQLTransactionState SQLTransactionBackend::RunStatements() { | 677 SQLTransactionState SQLTransactionBackend::RunStatements() { |
| 678 DCHECK(GetDatabase() | 678 DCHECK(GetDatabase() |
| 679 ->GetDatabaseContext() | 679 ->GetDatabaseContext() |
| 680 ->GetDatabaseThread() | 680 ->GetDatabaseThread() |
| 681 ->IsDatabaseThread()); | 681 ->IsDatabaseThread()); |
| 682 ASSERT(lock_acquired_); | 682 DCHECK(lock_acquired_); |
| 683 SQLTransactionState next_state; | 683 SQLTransactionState next_state; |
| 684 | 684 |
| 685 // If there is a series of statements queued up that are all successful and | 685 // If there is a series of statements queued up that are all successful and |
| 686 // have no associated SQLStatementCallback objects, then we can burn through | 686 // have no associated SQLStatementCallback objects, then we can burn through |
| 687 // the queue. | 687 // the queue. |
| 688 do { | 688 do { |
| 689 if (should_retry_current_statement_ && | 689 if (should_retry_current_statement_ && |
| 690 !sqlite_transaction_->WasRolledBackBySqlite()) { | 690 !sqlite_transaction_->WasRolledBackBySqlite()) { |
| 691 should_retry_current_statement_ = false; | 691 should_retry_current_statement_ = false; |
| 692 // FIXME - Another place that needs fixing up after | 692 // FIXME - Another place that needs fixing up after |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 SQLErrorData::Create(*current_statement_backend_->SqlError()); | 777 SQLErrorData::Create(*current_statement_backend_->SqlError()); |
| 778 } else { | 778 } else { |
| 779 database_->ReportCommitTransactionResult(1, SQLError::kDatabaseErr, 0); | 779 database_->ReportCommitTransactionResult(1, SQLError::kDatabaseErr, 0); |
| 780 transaction_error_ = SQLErrorData::Create( | 780 transaction_error_ = SQLErrorData::Create( |
| 781 SQLError::kDatabaseErr, "the statement failed to execute"); | 781 SQLError::kDatabaseErr, "the statement failed to execute"); |
| 782 } | 782 } |
| 783 return NextStateForTransactionError(); | 783 return NextStateForTransactionError(); |
| 784 } | 784 } |
| 785 | 785 |
| 786 SQLTransactionState SQLTransactionBackend::PostflightAndCommit() { | 786 SQLTransactionState SQLTransactionBackend::PostflightAndCommit() { |
| 787 ASSERT(lock_acquired_); | 787 DCHECK(lock_acquired_); |
| 788 | 788 |
| 789 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if | 789 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if |
| 790 // they fail. | 790 // they fail. |
| 791 if (wrapper_ && !wrapper_->PerformPostflight(this)) { | 791 if (wrapper_ && !wrapper_->PerformPostflight(this)) { |
| 792 if (wrapper_->SqlError()) { | 792 if (wrapper_->SqlError()) { |
| 793 transaction_error_ = SQLErrorData::Create(*wrapper_->SqlError()); | 793 transaction_error_ = SQLErrorData::Create(*wrapper_->SqlError()); |
| 794 } else { | 794 } else { |
| 795 database_->ReportCommitTransactionResult(3, SQLError::kUnknownErr, 0); | 795 database_->ReportCommitTransactionResult(3, SQLError::kUnknownErr, 0); |
| 796 transaction_error_ = SQLErrorData::Create( | 796 transaction_error_ = SQLErrorData::Create( |
| 797 SQLError::kUnknownErr, | 797 SQLError::kUnknownErr, |
| 798 "unknown error occurred during transaction postflight"); | 798 "unknown error occurred during transaction postflight"); |
| 799 } | 799 } |
| 800 return NextStateForTransactionError(); | 800 return NextStateForTransactionError(); |
| 801 } | 801 } |
| 802 | 802 |
| 803 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if that | 803 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if that |
| 804 // fails. | 804 // fails. |
| 805 ASSERT(sqlite_transaction_); | 805 DCHECK(sqlite_transaction_); |
| 806 | 806 |
| 807 database_->DisableAuthorizer(); | 807 database_->DisableAuthorizer(); |
| 808 sqlite_transaction_->Commit(); | 808 sqlite_transaction_->Commit(); |
| 809 database_->EnableAuthorizer(); | 809 database_->EnableAuthorizer(); |
| 810 | 810 |
| 811 // If the commit failed, the transaction will still be marked as "in progress" | 811 // If the commit failed, the transaction will still be marked as "in progress" |
| 812 if (sqlite_transaction_->InProgress()) { | 812 if (sqlite_transaction_->InProgress()) { |
| 813 if (wrapper_) | 813 if (wrapper_) |
| 814 wrapper_->HandleCommitFailedAfterPostflight(this); | 814 wrapper_->HandleCommitFailedAfterPostflight(this); |
| 815 database_->ReportCommitTransactionResult( | 815 database_->ReportCommitTransactionResult( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 830 // The commit was successful. If the transaction modified this database, | 830 // The commit was successful. If the transaction modified this database, |
| 831 // notify the delegates. | 831 // notify the delegates. |
| 832 if (modified_database_) | 832 if (modified_database_) |
| 833 database_->TransactionClient()->DidCommitWriteTransaction(GetDatabase()); | 833 database_->TransactionClient()->DidCommitWriteTransaction(GetDatabase()); |
| 834 | 834 |
| 835 // Spec 4.3.2.8: Deliver success callback, if there is one. | 835 // Spec 4.3.2.8: Deliver success callback, if there is one. |
| 836 return SQLTransactionState::kDeliverSuccessCallback; | 836 return SQLTransactionState::kDeliverSuccessCallback; |
| 837 } | 837 } |
| 838 | 838 |
| 839 SQLTransactionState SQLTransactionBackend::CleanupAndTerminate() { | 839 SQLTransactionState SQLTransactionBackend::CleanupAndTerminate() { |
| 840 ASSERT(lock_acquired_); | 840 DCHECK(lock_acquired_); |
| 841 | 841 |
| 842 // Spec 4.3.2.9: End transaction steps. There is no next step. | 842 // Spec 4.3.2.9: End transaction steps. There is no next step. |
| 843 STORAGE_DVLOG(1) << "Transaction " << this << " is complete"; | 843 STORAGE_DVLOG(1) << "Transaction " << this << " is complete"; |
| 844 ASSERT(!database_->SqliteDatabase().TransactionInProgress()); | 844 DCHECK(!database_->SqliteDatabase().TransactionInProgress()); |
| 845 | 845 |
| 846 // Phase 5 cleanup. See comment on the SQLTransaction life-cycle above. | 846 // Phase 5 cleanup. See comment on the SQLTransaction life-cycle above. |
| 847 DoCleanup(); | 847 DoCleanup(); |
| 848 database_->InProgressTransactionCompleted(); | 848 database_->InProgressTransactionCompleted(); |
| 849 return SQLTransactionState::kEnd; | 849 return SQLTransactionState::kEnd; |
| 850 } | 850 } |
| 851 | 851 |
| 852 SQLTransactionState SQLTransactionBackend::NextStateForTransactionError() { | 852 SQLTransactionState SQLTransactionBackend::NextStateForTransactionError() { |
| 853 ASSERT(transaction_error_); | 853 DCHECK(transaction_error_); |
| 854 if (has_error_callback_) | 854 if (has_error_callback_) |
| 855 return SQLTransactionState::kDeliverTransactionErrorCallback; | 855 return SQLTransactionState::kDeliverTransactionErrorCallback; |
| 856 | 856 |
| 857 // No error callback, so fast-forward to the next state and rollback the | 857 // No error callback, so fast-forward to the next state and rollback the |
| 858 // transaction. | 858 // transaction. |
| 859 return SQLTransactionState::kCleanupAfterTransactionErrorCallback; | 859 return SQLTransactionState::kCleanupAfterTransactionErrorCallback; |
| 860 } | 860 } |
| 861 | 861 |
| 862 SQLTransactionState | 862 SQLTransactionState |
| 863 SQLTransactionBackend::CleanupAfterTransactionErrorCallback() { | 863 SQLTransactionBackend::CleanupAfterTransactionErrorCallback() { |
| 864 ASSERT(lock_acquired_); | 864 DCHECK(lock_acquired_); |
| 865 | 865 |
| 866 STORAGE_DVLOG(1) << "Transaction " << this << " is complete with an error"; | 866 STORAGE_DVLOG(1) << "Transaction " << this << " is complete with an error"; |
| 867 database_->DisableAuthorizer(); | 867 database_->DisableAuthorizer(); |
| 868 if (sqlite_transaction_) { | 868 if (sqlite_transaction_) { |
| 869 // Spec 4.3.2.10: Rollback the transaction. | 869 // Spec 4.3.2.10: Rollback the transaction. |
| 870 sqlite_transaction_->Rollback(); | 870 sqlite_transaction_->Rollback(); |
| 871 | 871 |
| 872 ASSERT(!database_->SqliteDatabase().TransactionInProgress()); | 872 DCHECK(!database_->SqliteDatabase().TransactionInProgress()); |
| 873 sqlite_transaction_.reset(); | 873 sqlite_transaction_.reset(); |
| 874 } | 874 } |
| 875 database_->EnableAuthorizer(); | 875 database_->EnableAuthorizer(); |
| 876 | 876 |
| 877 ASSERT(!database_->SqliteDatabase().TransactionInProgress()); | 877 DCHECK(!database_->SqliteDatabase().TransactionInProgress()); |
| 878 | 878 |
| 879 return SQLTransactionState::kCleanupAndTerminate; | 879 return SQLTransactionState::kCleanupAndTerminate; |
| 880 } | 880 } |
| 881 | 881 |
| 882 // requestTransitToState() can be called from the frontend. Hence, it should | 882 // requestTransitToState() can be called from the frontend. Hence, it should |
| 883 // NOT be modifying SQLTransactionBackend in general. The only safe field to | 883 // NOT be modifying SQLTransactionBackend in general. The only safe field to |
| 884 // modify is m_requestedState which is meant for this purpose. | 884 // modify is m_requestedState which is meant for this purpose. |
| 885 void SQLTransactionBackend::RequestTransitToState( | 885 void SQLTransactionBackend::RequestTransitToState( |
| 886 SQLTransactionState next_state) { | 886 SQLTransactionState next_state) { |
| 887 #if DCHECK_IS_ON() | 887 #if DCHECK_IS_ON() |
| 888 STORAGE_DVLOG(1) << "Scheduling " << NameForSQLTransactionState(next_state) | 888 STORAGE_DVLOG(1) << "Scheduling " << NameForSQLTransactionState(next_state) |
| 889 << " for transaction " << this; | 889 << " for transaction " << this; |
| 890 #endif | 890 #endif |
| 891 requested_state_ = next_state; | 891 requested_state_ = next_state; |
| 892 ASSERT(requested_state_ != SQLTransactionState::kEnd); | 892 DCHECK_NE(requested_state_, SQLTransactionState::kEnd); |
| 893 database_->ScheduleTransactionStep(this); | 893 database_->ScheduleTransactionStep(this); |
| 894 } | 894 } |
| 895 | 895 |
| 896 // This state function is used as a stub function to plug unimplemented states | 896 // This state function is used as a stub function to plug unimplemented states |
| 897 // in the state dispatch table. They are unimplemented because they should | 897 // in the state dispatch table. They are unimplemented because they should |
| 898 // never be reached in the course of correct execution. | 898 // never be reached in the course of correct execution. |
| 899 SQLTransactionState SQLTransactionBackend::UnreachableState() { | 899 SQLTransactionState SQLTransactionBackend::UnreachableState() { |
| 900 ASSERT_NOT_REACHED(); | 900 NOTREACHED(); |
| 901 return SQLTransactionState::kEnd; | 901 return SQLTransactionState::kEnd; |
| 902 } | 902 } |
| 903 | 903 |
| 904 SQLTransactionState SQLTransactionBackend::SendToFrontendState() { | 904 SQLTransactionState SQLTransactionBackend::SendToFrontendState() { |
| 905 ASSERT(next_state_ != SQLTransactionState::kIdle); | 905 DCHECK_NE(next_state_, SQLTransactionState::kIdle); |
| 906 frontend_->RequestTransitToState(next_state_); | 906 frontend_->RequestTransitToState(next_state_); |
| 907 return SQLTransactionState::kIdle; | 907 return SQLTransactionState::kIdle; |
| 908 } | 908 } |
| 909 | 909 |
| 910 } // namespace blink | 910 } // namespace blink |
| OLD | NEW |