Changeset 57275 in webkit


Ignore:
Timestamp:
Apr 8, 2010 7:14:34 AM (14 years ago)
Author:
jorlow@chromium.org
Message:

2010-04-08 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Yury Semikhatsky.

IDB callbacks should fire asynchronously
https://bugs.webkit.org/show_bug.cgi?id=37265

Fix the firing behavior of the callbacks to not be synchronous.

There's still a major bug that I'm trying to track down that is keeping
us from testing this stuff. Promise lots of tests ASAP.

  • bindings/v8/custom/V8CustomIDBCallbacks.h: (WebCore::V8CustomIDBCallbacks::onSuccessAsync): (WebCore::V8CustomIDBCallbacks::onErrorAsync):
  • storage/IDBCallbacks.h: (WebCore::IDBCallbacks::IDBCallbacks): (WebCore::IDBCallbacks::onSuccess): (WebCore::IDBCallbacks::onError): (WebCore::IDBCallbacks::timerFired):
  • storage/IndexedDatabaseRequest.cpp:
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57274 r57275  
     12010-04-08  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        IDB callbacks should fire asynchronously
     6        https://bugs.webkit.org/show_bug.cgi?id=37265
     7
     8        Fix the firing behavior of the callbacks to not be synchronous.
     9
     10        There's still a major bug that I'm trying to track down that is keeping
     11        us from testing this stuff.  Promise lots of tests ASAP.
     12
     13        * bindings/v8/custom/V8CustomIDBCallbacks.h:
     14        (WebCore::V8CustomIDBCallbacks::onSuccessAsync):
     15        (WebCore::V8CustomIDBCallbacks::onErrorAsync):
     16        * storage/IDBCallbacks.h:
     17        (WebCore::IDBCallbacks::IDBCallbacks):
     18        (WebCore::IDBCallbacks::onSuccess):
     19        (WebCore::IDBCallbacks::onError):
     20        (WebCore::IDBCallbacks::timerFired):
     21        * storage/IndexedDatabaseRequest.cpp:
     22
    1232010-04-08  Kent Tamura  <tkent@chromium.org>
    224
  • trunk/WebCore/bindings/v8/custom/V8CustomIDBCallbacks.h

    r57203 r57275  
    6262    }
    6363
    64     virtual void onSuccess(PassRefPtr<ResultType> result)
    65     {
    66         onEvent(m_onSuccess, ResultWrapperType::create(result));
    67     }
    68 
    69     virtual void onError(PassRefPtr<IDBDatabaseError> error)
    70     {
    71         onEvent(m_onError, error);
    72     }
    73 
    7464    // FIXME: Handle suspend/resume correctly.
    7565
     
    110100    }
    111101
     102    virtual void onSuccessAsync(PassRefPtr<ResultType> result)
     103    {
     104        onEvent(m_onSuccess, ResultWrapperType::create(result));
     105    }
     106
     107    virtual void onErrorAsync(PassRefPtr<IDBDatabaseError> error)
     108    {
     109        onEvent(m_onError, error);
     110    }
     111
    112112    // FIXME: Use OwnHandles.
    113113    v8::Persistent<v8::Object> m_onSuccess;
  • trunk/WebCore/storage/IDBCallbacks.h

    r57203 r57275  
    3131
    3232#include "ActiveDOMObject.h"
     33#include "IDBDatabaseError.h"
     34#include "Timer.h"
    3335#include <wtf/PassRefPtr.h>
    3436#include <wtf/RefCounted.h>
    3537
     38#if ENABLE(INDEXED_DATABASE)
     39
    3640namespace WebCore {
    3741
    38 class IDBDatabaseError;
    39 
     42// All IndexedDB callbacks must implement this class.  It handles the asynchronous firing of
     43// the callbacks.
    4044template <typename ResultType>
    4145class IDBCallbacks : public RefCounted<IDBCallbacks<ResultType> >, public ActiveDOMObject {
    4246public:
    4347    IDBCallbacks(ScriptExecutionContext* scriptExecutionContext, void* upcastPointer)
    44         : ActiveDOMObject(scriptExecutionContext, upcastPointer) { }
     48        : ActiveDOMObject(scriptExecutionContext, upcastPointer)
     49        , m_timer(this, &IDBCallbacks::timerFired)
     50    {
     51    }
     52
    4553    virtual ~IDBCallbacks() { }
    4654
    47     virtual void onSuccess(PassRefPtr<ResultType>) = 0;
    48     virtual void onError(PassRefPtr<IDBDatabaseError>) = 0;
     55    void onSuccess(PassRefPtr<ResultType> result)
     56    {
     57        ASSERT(!m_result);
     58        ASSERT(!m_error);
     59        m_result = result;
     60        ASSERT(m_result);
     61
     62        ASSERT(!m_timer.isActive());
     63        m_selfRef = this;
     64        m_timer.startOneShot(0);
     65    }
     66
     67    void onError(PassRefPtr<IDBDatabaseError> error)
     68    {
     69        ASSERT(!m_result);
     70        ASSERT(!m_error);
     71        m_error = error;
     72        ASSERT(m_error);
     73
     74        ASSERT(!m_timer.isActive());
     75        m_selfRef = this;
     76        m_timer.startOneShot(0);
     77    }
     78
     79protected:
     80    virtual void onSuccessAsync(PassRefPtr<ResultType>) = 0;
     81    virtual void onErrorAsync(PassRefPtr<IDBDatabaseError>) = 0;
     82
     83    void timerFired(Timer<IDBCallbacks>*)
     84    {
     85        if (m_result) {
     86            onSuccessAsync(m_result);
     87            m_result = 0;
     88        } else {
     89            onErrorAsync(m_error);
     90            m_error = 0;
     91        }
     92        m_selfRef = 0; // May trigger a delete immediately.
     93    }
     94
     95private:
     96    Timer<IDBCallbacks> m_timer;
     97    RefPtr<IDBCallbacks> m_selfRef;
     98    RefPtr<ResultType> m_result;
     99    RefPtr<IDBDatabaseError> m_error;
    49100};
    50101
    51102} // namespace WebCore
    52103
     104#endif
     105
    53106#endif // IDBCallbacks_h
    54 
  • trunk/WebCore/storage/IndexedDatabaseRequest.cpp

    r56907 r57275  
    3131
    3232#include "ExceptionCode.h"
     33#include "IDBDatabase.h"
    3334#include "IndexedDatabase.h"
    3435
Note: See TracChangeset for help on using the changeset viewer.