Changeset 30184 in webkit


Ignore:
Timestamp:
Feb 12, 2008 5:10:42 PM (16 years ago)
Author:
beidson@apple.com
Message:

Reviewed by Darin Adler

Fix for <rdar://problem/5737692> - Database API needs to support SuccessCallback

Layout tests will come shortly with a mess of DRT changes

  • platform/SecurityOrigin.cpp: (WebCore::SecurityOrigin::SecurityOrigin): Standardize on "empty string" instead of null string as different paths of constructing a SecurityOrigin were causing different hashes for the "same" SecurityOrigin
  • storage/Database.cpp: (WebCore::Database::changeVersion): Pass in the successCallback (WebCore::Database::transaction): Ditto
  • storage/SQLTransaction.cpp: (WebCore::SQLTransaction::SQLTransaction): (WebCore::SQLTransaction::debugStepName): (WebCore::SQLTransaction::performNextStep): Update ASSERTs for the new valid steps (WebCore::SQLTransaction::performPendingCallback): Ditto (WebCore::SQLTransaction::postflightAndCommit): Schedule the success callback if it exists - otherwise skip straight to cleanupAfterSuccessCallback() (WebCore::SQLTransaction::deliverSuccessCallback): Deliver success callback on the main thread, then schedule cleanupAfterSuccessCallback() (WebCore::SQLTransaction::cleanupAfterSuccessCallback): Cleanup and end the transaction (WebCore::SQLTransaction::handleTransactionError): (WebCore::SQLTransaction::deliverTransactionErrorCallback): (WebCore::SQLTransaction::cleanupAfterTransactionErrorCallback):
  • storage/SQLTransaction.h:
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r30182 r30184  
     12008-02-12  Brady Eidson  <beidson@apple.com>
     2
     3        Reviewed by Darin Adler
     4
     5        Fix for <rdar://problem/5737692> - Database API needs to support SuccessCallback
     6
     7        Layout tests will come shortly with a mess of DRT changes
     8
     9        * platform/SecurityOrigin.cpp:
     10        (WebCore::SecurityOrigin::SecurityOrigin): Standardize on "empty string" instead of null string
     11          as different paths of constructing a SecurityOrigin were causing different hashes for the "same"
     12          SecurityOrigin
     13
     14        * storage/Database.cpp:
     15        (WebCore::Database::changeVersion): Pass in the successCallback
     16        (WebCore::Database::transaction): Ditto
     17
     18        * storage/SQLTransaction.cpp:
     19        (WebCore::SQLTransaction::SQLTransaction):
     20        (WebCore::SQLTransaction::debugStepName):
     21        (WebCore::SQLTransaction::performNextStep): Update ASSERTs for the new valid steps
     22        (WebCore::SQLTransaction::performPendingCallback): Ditto
     23        (WebCore::SQLTransaction::postflightAndCommit): Schedule the success callback if it exists - otherwise
     24          skip straight to cleanupAfterSuccessCallback()
     25        (WebCore::SQLTransaction::deliverSuccessCallback): Deliver success callback on the main thread, then
     26          schedule cleanupAfterSuccessCallback()
     27        (WebCore::SQLTransaction::cleanupAfterSuccessCallback): Cleanup and end the transaction
     28        (WebCore::SQLTransaction::handleTransactionError):
     29        (WebCore::SQLTransaction::deliverTransactionErrorCallback):
     30        (WebCore::SQLTransaction::cleanupAfterTransactionErrorCallback):
     31        * storage/SQLTransaction.h:
     32
    1332008-02-12  Steve Falkenburg  <sfalken@apple.com>
    234
  • trunk/WebCore/platform/SecurityOrigin.cpp

    r30009 r30184  
    5555
    5656SecurityOrigin::SecurityOrigin(const String& protocol, const String& host, unsigned short port)
    57     : m_protocol(protocol.lower())
    58     , m_host(host.lower())
     57    : m_protocol(protocol.isNull() ? "" : protocol.lower())
     58    , m_host(host.isNull() ? "" : host.lower())
    5959    , m_port(port)
    6060    , m_portSet(port)
     
    6464    // These protocols do not create security origins; the owner frame provides the origin
    6565    if (m_protocol == "about" || m_protocol == "javascript")
    66         m_protocol = String();
     66        m_protocol = "";
    6767
    6868    // data: URLs are not allowed access to anything other than themselves.
  • trunk/WebCore/storage/Database.cpp

    r30172 r30184  
    425425                             PassRefPtr<VoidCallback> successCallback)
    426426{
    427     // FIXME: pass successCallback, too.
    428     m_transactionQueue.append(new SQLTransaction(this, callback, errorCallback, new ChangeVersionWrapper(oldVersion, newVersion)));
     427    m_transactionQueue.append(new SQLTransaction(this, callback, errorCallback, successCallback, new ChangeVersionWrapper(oldVersion, newVersion)));
    429428    MutexLocker locker(m_transactionInProgressMutex);
    430429    if (!m_transactionInProgress)
     
    435434                           PassRefPtr<VoidCallback> successCallback)
    436435{
    437     // FIXME: pass successCallback, too.
    438     m_transactionQueue.append(new SQLTransaction(this, callback, errorCallback, 0));
     436    m_transactionQueue.append(new SQLTransaction(this, callback, errorCallback, successCallback, 0));
    439437    MutexLocker locker(m_transactionInProgressMutex);
    440438    if (!m_transactionInProgress)
  • trunk/WebCore/storage/SQLTransaction.cpp

    r30172 r30184  
    5757namespace WebCore {
    5858
    59 SQLTransaction::SQLTransaction(Database* db, PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback, PassRefPtr<SQLTransactionWrapper> wrapper)
     59SQLTransaction::SQLTransaction(Database* db, PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback, PassRefPtr<VoidCallback> successCallback,
     60                               PassRefPtr<SQLTransactionWrapper> wrapper)
    6061    : m_nextStep(&SQLTransaction::openTransactionAndPreflight)
    6162    , m_executeSqlAllowed(false)
     
    6364    , m_wrapper(wrapper)
    6465    , m_callback(callback)
     66    , m_successCallback(successCallback)
    6567    , m_errorCallback(errorCallback)
    6668    , m_shouldRetryCurrentStatement(false)
     
    119121    else if (step == &SQLTransaction::deliverQuotaIncreaseCallback)
    120122        return "deliverQuotaIncreaseCallback";
     123    else if (step == &SQLTransaction::deliverSuccessCallback)
     124        return "deliverSuccessCallback";
     125    else if (step == &SQLTransaction::cleanupAfterSuccessCallback)
     126        return "cleanupAfterSuccessCallback";
    121127    else
    122128        return "UNKNOWN";
     
    131137           m_nextStep == &SQLTransaction::runStatements ||
    132138           m_nextStep == &SQLTransaction::postflightAndCommit ||
     139           m_nextStep == &SQLTransaction::cleanupAfterSuccessCallback ||
    133140           m_nextStep == &SQLTransaction::cleanupAfterTransactionErrorCallback);
    134141               
     
    146153           m_nextStep == &SQLTransaction::deliverTransactionErrorCallback ||
    147154           m_nextStep == &SQLTransaction::deliverStatementCallback ||
    148            m_nextStep == &SQLTransaction::deliverQuotaIncreaseCallback);
     155           m_nextStep == &SQLTransaction::deliverQuotaIncreaseCallback ||
     156           m_nextStep == &SQLTransaction::deliverSuccessCallback);
    149157           
    150158    (this->*m_nextStep)();
     
    395403        DatabaseTracker::tracker().scheduleNotifyDatabaseChanged(m_database->m_securityOrigin.get(), m_database->m_name);
    396404   
    397     // Transaction Step 10 - End transaction steps
     405    // Now release our unneeded callbacks, to break reference cycles.
     406    m_callback = 0;
     407    m_errorCallback = 0;
     408   
     409    // Transaction Step 10 - Deliver success callback, if there is one
     410    if (m_successCallback) {
     411        m_nextStep = &SQLTransaction::deliverSuccessCallback;
     412        LOG(StorageAPI, "Scheduling deliverSuccessCallback for transaction %p\n", this);
     413        m_database->scheduleTransactionCallback(this);
     414    } else
     415        cleanupAfterSuccessCallback();
     416}
     417
     418void SQLTransaction::deliverSuccessCallback()
     419{
     420    // Transaction Step 10 - Deliver success callback
     421    ASSERT(m_successCallback);
     422    m_successCallback->handleEvent();
     423   
     424    // Release the last callback to break reference cycle
     425    m_successCallback = 0;
     426
     427    // Schedule a "post-success callback" step to return control to the database thread in case there
     428    // are further transactions queued up for this Database
     429    m_nextStep = &SQLTransaction::cleanupAfterSuccessCallback;
     430    LOG(StorageAPI, "Scheduling cleanupAfterSuccessCallback for transaction %p\n", this);
     431    m_database->scheduleTransactionStep(this);
     432}
     433
     434void SQLTransaction::cleanupAfterSuccessCallback()
     435{
     436    // Transaction Step 11 - End transaction steps
    398437    // There is no next step
    399438    LOG(StorageAPI, "Transaction %p is complete\n", this);
    400439    ASSERT(!m_database->m_sqliteDatabase.transactionInProgress());
    401440    m_nextStep = 0;
    402 
    403     // Now release our callbacks, to break reference cycles.
    404     m_callback = 0;
    405     m_errorCallback = 0;
    406441}
    407442
     
    419454    }
    420455   
    421     // Transaction Step 11 - If the callback couldn't be called, then rollback the transaction.
     456    // Transaction Step 12 - If the callback couldn't be called, then rollback the transaction.
    422457    m_shouldCommitAfterErrorCallback = false;
    423458    if (inCallback) {
     
    434469    ASSERT(m_transactionError);
    435470   
    436     // Transaction Step 11 - If the callback didn't return false, then rollback the transaction.
     471    // Transaction Step 12 - If the callback didn't return false, then rollback the transaction.
    437472    // This includes the callback not existing, returning true, or throwing an exception
    438473    if (!m_errorCallback || m_errorCallback->handleEvent(m_transactionError.get()))
     
    448483    m_database->m_databaseAuthorizer->disable();
    449484    if (m_sqliteTransaction) {
    450         // Transaction Step 11 -If the error callback returned false, and the last error wasn't itself a
     485        // Transaction Step 12 -If the error callback returned false, and the last error wasn't itself a
    451486        // failure when committing the transaction, then try to commit the transaction
    452487        if (m_shouldCommitAfterErrorCallback)
     
    454489       
    455490        if (m_sqliteTransaction->inProgress()) {
    456             // Transaction Step 11 - If that fails, or if the callback couldn't be called
     491            // Transaction Step 12 - If that fails, or if the callback couldn't be called
    457492            // or if it didn't return false, then rollback the transaction.
    458493            m_sqliteTransaction->rollback();
     
    467502    m_database->m_databaseAuthorizer->enable();
    468503   
    469     // Transaction Step 11 - Any still-pending statements in the transaction are discarded.
     504    // Transaction Step 12 - Any still-pending statements in the transaction are discarded.
    470505    {
    471506        MutexLocker locker(m_statementMutex);
  • trunk/WebCore/storage/SQLTransaction.h

    r30172 r30184  
    5252class SQLValue;
    5353class String;
     54class VoidCallback;
    5455
    5556class SQLTransactionWrapper : public ThreadSafeShared<SQLTransactionWrapper> {
     
    6465class SQLTransaction : public ThreadSafeShared<SQLTransaction> {
    6566public:
    66     SQLTransaction(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<SQLTransactionWrapper>);
     67    SQLTransaction(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback>, PassRefPtr<SQLTransactionWrapper>);
    6768    ~SQLTransaction();
    6869   
     
    9192    void deliverQuotaIncreaseCallback();
    9293    void postflightAndCommit();
     94    void deliverSuccessCallback();
     95    void cleanupAfterSuccessCallback();
    9396    void handleTransactionError(bool inCallback);
    9497    void deliverTransactionErrorCallback();
     
    106109    RefPtr<SQLTransactionWrapper> m_wrapper;
    107110    RefPtr<SQLTransactionCallback> m_callback;
     111    RefPtr<VoidCallback> m_successCallback;
    108112    RefPtr<SQLTransactionErrorCallback> m_errorCallback;
    109113    RefPtr<SQLError> m_transactionError;
Note: See TracChangeset for help on using the changeset viewer.