Changeset 80322 in webkit


Ignore:
Timestamp:
Mar 3, 2011 9:36:03 PM (13 years ago)
Author:
jeffm@apple.com
Message:

2011-03-03 Jeff Miller <jeffm@apple.com>

Reviewed by Darin Adler.

Refactor classes in GenericCallback.h
https://bugs.webkit.org/show_bug.cgi?id=55732


Since we're going to need to add additional callback classes, make a CallbackBase class that manages
the context and the callback ID. The existing callback classes (VoidCallback, GenericCallback, and
ComputedPagesCallback) now all derive from CallbackBase.


Fix bug in VoidCallback where we meant to implement the destructor, but we were implementing the default
constructor instead (we forgot the leading ~).


  • UIProcess/GenericCallback.h: (WebKit::CallbackBase::~CallbackBase): (WebKit::CallbackBase::callbackID): (WebKit::CallbackBase::CallbackBase): (WebKit::CallbackBase::context): (WebKit::CallbackBase::generateCallbackID): (WebKit::VoidCallback::~VoidCallback): (WebKit::VoidCallback::performCallback): (WebKit::VoidCallback::invalidate): (WebKit::VoidCallback::VoidCallback): (WebKit::GenericCallback::create): (WebKit::GenericCallback::~GenericCallback): (WebKit::GenericCallback::performCallbackWithReturnValue): (WebKit::GenericCallback::invalidate): (WebKit::GenericCallback::GenericCallback): (WebKit::ComputedPagesCallback::create): (WebKit::ComputedPagesCallback::~ComputedPagesCallback): (WebKit::ComputedPagesCallback::performCallbackWithReturnValue): (WebKit::ComputedPagesCallback::invalidate): (WebKit::ComputedPagesCallback::ComputedPagesCallback):
Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r80309 r80322  
     12011-03-03  Jeff Miller  <jeffm@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Refactor classes in GenericCallback.h
     6        https://bugs.webkit.org/show_bug.cgi?id=55732
     7       
     8        Since we're going to need to add additional callback classes, make a CallbackBase class that manages
     9        the context and the callback ID.  The existing callback classes (VoidCallback, GenericCallback, and
     10        ComputedPagesCallback) now all derive from CallbackBase.
     11       
     12        Fix bug in VoidCallback where we meant to implement the destructor, but we were implementing the default
     13        constructor instead (we forgot the leading ~).
     14 
     15        * UIProcess/GenericCallback.h:
     16        (WebKit::CallbackBase::~CallbackBase):
     17        (WebKit::CallbackBase::callbackID):
     18        (WebKit::CallbackBase::CallbackBase):
     19        (WebKit::CallbackBase::context):
     20        (WebKit::CallbackBase::generateCallbackID):
     21        (WebKit::VoidCallback::~VoidCallback):
     22        (WebKit::VoidCallback::performCallback):
     23        (WebKit::VoidCallback::invalidate):
     24        (WebKit::VoidCallback::VoidCallback):
     25        (WebKit::GenericCallback::create):
     26        (WebKit::GenericCallback::~GenericCallback):
     27        (WebKit::GenericCallback::performCallbackWithReturnValue):
     28        (WebKit::GenericCallback::invalidate):
     29        (WebKit::GenericCallback::GenericCallback):
     30        (WebKit::ComputedPagesCallback::create):
     31        (WebKit::ComputedPagesCallback::~ComputedPagesCallback):
     32        (WebKit::ComputedPagesCallback::performCallbackWithReturnValue):
     33        (WebKit::ComputedPagesCallback::invalidate):
     34        (WebKit::ComputedPagesCallback::ComputedPagesCallback):
     35
    1362011-03-03  Adam Roben  <aroben@apple.com>
    237
  • trunk/Source/WebKit2/UIProcess/GenericCallback.h

    r76821 r80322  
    3636namespace WebKit {
    3737
    38 class VoidCallback : public RefCounted<VoidCallback> {
     38class CallbackBase : public RefCounted<CallbackBase> {
     39public:
     40    virtual ~CallbackBase()
     41    {
     42    }
     43
     44    uint64_t callbackID() const { return m_callbackID; }
     45
     46protected:
     47    CallbackBase(void* context)
     48        : m_context(context)
     49        , m_callbackID(generateCallbackID())
     50    {
     51    }
     52
     53    void* context() const { return m_context; }
     54
     55private:
     56    static uint64_t generateCallbackID()
     57    {
     58        static uint64_t uniqueCallbackID = 1;
     59        return uniqueCallbackID++;
     60    }
     61
     62    void* m_context;
     63    uint64_t m_callbackID;
     64};
     65
     66class VoidCallback : public CallbackBase {
    3967public:
    4068    typedef void (*CallbackFunction)(WKErrorRef, void*);
     
    4573    }
    4674
    47     VoidCallback()
     75    virtual ~VoidCallback()
    4876    {
    4977        ASSERT(!m_callback);
     
    5482        ASSERT(m_callback);
    5583
    56         m_callback(0, m_context);
     84        m_callback(0, context());
    5785
    5886        m_callback = 0;
     
    6492
    6593        RefPtr<WebError> error = WebError::create();
    66         m_callback(toAPI(error.get()), m_context);
     94        m_callback(toAPI(error.get()), context());
    6795       
    6896        m_callback = 0;
    6997    }
    7098
    71     uint64_t callbackID() const { return m_callbackID; }
    72 
    73 private:
    74     static uint64_t generateCallbackID()
    75     {
    76         static uint64_t uniqueCallbackID = 1;
    77         return uniqueCallbackID++;
    78     }
    79 
     99private:
    80100    VoidCallback(void* context, CallbackFunction callback)
    81         : m_context(context)
     101        : CallbackBase(context)
    82102        , m_callback(callback)
    83         , m_callbackID(generateCallbackID())
    84     {
    85     }
    86 
    87     void* m_context;
     103    {
     104    }
     105
    88106    CallbackFunction m_callback;
    89     uint64_t m_callbackID;
    90 };
    91 
    92 // FIXME: Make a version of GenericCallback with two arguments, and define ComputedPagesCallback as a specialization.
    93 class ComputedPagesCallback : public RefCounted<ComputedPagesCallback> {
    94 public:
    95     typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*);
    96 
    97     static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback)
    98     {
    99         return adoptRef(new ComputedPagesCallback(context, callback));
    100     }
    101 
    102     ~ComputedPagesCallback()
     107};
     108
     109template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType>
     110class GenericCallback : public CallbackBase {
     111public:
     112    typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*);
     113
     114    static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback)
     115    {
     116        return adoptRef(new GenericCallback(context, callback));
     117    }
     118
     119    virtual ~GenericCallback()
    103120    {
    104121        ASSERT(!m_callback);
    105122    }
    106123
    107     void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2)
    108     {
    109         ASSERT(m_callback);
    110 
    111         m_callback(returnValue1, returnValue2, 0, m_context);
     124    void performCallbackWithReturnValue(InternalReturnValueType returnValue)
     125    {
     126        ASSERT(m_callback);
     127
     128        m_callback(toAPI(returnValue), 0, context());
    112129
    113130        m_callback = 0;
     
    119136
    120137        RefPtr<WebError> error = WebError::create();
    121         m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), m_context);
     138        m_callback(0, toAPI(error.get()), context());
    122139       
    123140        m_callback = 0;
    124141    }
    125142
    126     uint64_t callbackID() const { return m_callbackID; }
    127 
    128 private:
    129     static uint64_t generateCallbackID()
    130     {
    131         static uint64_t uniqueCallbackID = 1;
    132         return uniqueCallbackID++;
    133     }
    134 
    135     ComputedPagesCallback(void* context, CallbackFunction callback)
    136         : m_context(context)
     143private:
     144    GenericCallback(void* context, CallbackFunction callback)
     145        : CallbackBase(context)
    137146        , m_callback(callback)
    138         , m_callbackID(generateCallbackID())
    139     {
    140     }
    141 
    142     void* m_context;
     147    {
     148    }
     149
    143150    CallbackFunction m_callback;
    144     uint64_t m_callbackID;
    145 };
    146 
    147 template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType>
    148 class GenericCallback : public RefCounted<GenericCallback<APIReturnValueType, InternalReturnValueType> > {
    149 public:
    150     typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*);
    151 
    152     static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback)
    153     {
    154         return adoptRef(new GenericCallback(context, callback));
    155     }
    156 
    157     ~GenericCallback()
     151};
     152
     153// FIXME: Make a version of CallbackBase with two arguments, and define ComputedPagesCallback as a specialization.
     154class ComputedPagesCallback : public CallbackBase {
     155public:
     156    typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*);
     157
     158    static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback)
     159    {
     160        return adoptRef(new ComputedPagesCallback(context, callback));
     161    }
     162
     163    virtual ~ComputedPagesCallback()
    158164    {
    159165        ASSERT(!m_callback);
    160166    }
    161167
    162     void performCallbackWithReturnValue(InternalReturnValueType returnValue)
    163     {
    164         ASSERT(m_callback);
    165 
    166         m_callback(toAPI(returnValue), 0, m_context);
     168    void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2)
     169    {
     170        ASSERT(m_callback);
     171
     172        m_callback(returnValue1, returnValue2, 0, context());
    167173
    168174        m_callback = 0;
     
    174180
    175181        RefPtr<WebError> error = WebError::create();
    176         m_callback(0, toAPI(error.get()), m_context);
     182        m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), context());
    177183       
    178184        m_callback = 0;
    179185    }
    180186
    181     uint64_t callbackID() const { return m_callbackID; }
    182 
    183 private:
    184     static uint64_t generateCallbackID()
    185     {
    186         static uint64_t uniqueCallbackID = 1;
    187         return uniqueCallbackID++;
    188     }
    189 
    190     GenericCallback(void* context, CallbackFunction callback)
    191         : m_context(context)
     187private:
     188
     189    ComputedPagesCallback(void* context, CallbackFunction callback)
     190        : CallbackBase(context)
    192191        , m_callback(callback)
    193         , m_callbackID(generateCallbackID())
    194     {
    195     }
    196 
    197     void* m_context;
     192    {
     193    }
     194
    198195    CallbackFunction m_callback;
    199     uint64_t m_callbackID;
    200196};
    201197
Note: See TracChangeset for help on using the changeset viewer.