2011-03-03 Jeff Miller <jeffm@apple.com>
authorjeffm@apple.com <jeffm@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2011 05:36:03 +0000 (05:36 +0000)
committerjeffm@apple.com <jeffm@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2011 05:36:03 +0000 (05:36 +0000)
        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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@80322 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/GenericCallback.h

index 6cbcc6f..354ead5 100644 (file)
@@ -1,3 +1,38 @@
+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):
+
 2011-03-03  Adam Roben  <aroben@apple.com>
 
         Don't assume the web process has had a chance to paint before the view has to paint
index c34414a..b0d7b9b 100644 (file)
 
 namespace WebKit {
 
-class VoidCallback : public RefCounted<VoidCallback> {
+class CallbackBase : public RefCounted<CallbackBase> {
+public:
+    virtual ~CallbackBase()
+    {
+    }
+
+    uint64_t callbackID() const { return m_callbackID; }
+
+protected:
+    CallbackBase(void* context)
+        : m_context(context)
+        , m_callbackID(generateCallbackID())
+    {
+    }
+
+    void* context() const { return m_context; }
+
+private:
+    static uint64_t generateCallbackID()
+    {
+        static uint64_t uniqueCallbackID = 1;
+        return uniqueCallbackID++;
+    }
+
+    void* m_context;
+    uint64_t m_callbackID;
+};
+
+class VoidCallback : public CallbackBase {
 public:
     typedef void (*CallbackFunction)(WKErrorRef, void*);
 
@@ -44,7 +72,7 @@ public:
         return adoptRef(new VoidCallback(context, callback));
     }
 
-    VoidCallback()
+    virtual ~VoidCallback()
     {
         ASSERT(!m_callback);
     }
@@ -53,7 +81,7 @@ public:
     {
         ASSERT(m_callback);
 
-        m_callback(0, m_context);
+        m_callback(0, context());
 
         m_callback = 0;
     }
@@ -63,52 +91,41 @@ public:
         ASSERT(m_callback);
 
         RefPtr<WebError> error = WebError::create();
-        m_callback(toAPI(error.get()), m_context);
+        m_callback(toAPI(error.get()), context());
         
         m_callback = 0;
     }
 
-    uint64_t callbackID() const { return m_callbackID; }
-
 private:
-    static uint64_t generateCallbackID()
-    {
-        static uint64_t uniqueCallbackID = 1;
-        return uniqueCallbackID++;
-    }
-
     VoidCallback(void* context, CallbackFunction callback)
-        : m_context(context)
+        : CallbackBase(context)
         , m_callback(callback)
-        , m_callbackID(generateCallbackID())
     {
     }
 
-    void* m_context;
     CallbackFunction m_callback;
-    uint64_t m_callbackID;
 };
 
-// FIXME: Make a version of GenericCallback with two arguments, and define ComputedPagesCallback as a specialization.
-class ComputedPagesCallback : public RefCounted<ComputedPagesCallback> {
+template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType>
+class GenericCallback : public CallbackBase {
 public:
-    typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*);
+    typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*);
 
-    static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback)
+    static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback)
     {
-        return adoptRef(new ComputedPagesCallback(context, callback));
+        return adoptRef(new GenericCallback(context, callback));
     }
 
-    ~ComputedPagesCallback()
+    virtual ~GenericCallback()
     {
         ASSERT(!m_callback);
     }
 
-    void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2)
+    void performCallbackWithReturnValue(InternalReturnValueType returnValue)
     {
         ASSERT(m_callback);
 
-        m_callback(returnValue1, returnValue2, 0, m_context);
+        m_callback(toAPI(returnValue), 0, context());
 
         m_callback = 0;
     }
@@ -118,52 +135,41 @@ public:
         ASSERT(m_callback);
 
         RefPtr<WebError> error = WebError::create();
-        m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), m_context);
+        m_callback(0, toAPI(error.get()), context());
         
         m_callback = 0;
     }
 
-    uint64_t callbackID() const { return m_callbackID; }
-
 private:
-    static uint64_t generateCallbackID()
-    {
-        static uint64_t uniqueCallbackID = 1;
-        return uniqueCallbackID++;
-    }
-
-    ComputedPagesCallback(void* context, CallbackFunction callback)
-        : m_context(context)
+    GenericCallback(void* context, CallbackFunction callback)
+        : CallbackBase(context)
         , m_callback(callback)
-        , m_callbackID(generateCallbackID())
     {
     }
 
-    void* m_context;
     CallbackFunction m_callback;
-    uint64_t m_callbackID;
 };
 
-template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType>
-class GenericCallback : public RefCounted<GenericCallback<APIReturnValueType, InternalReturnValueType> > {
+// FIXME: Make a version of CallbackBase with two arguments, and define ComputedPagesCallback as a specialization.
+class ComputedPagesCallback : public CallbackBase {
 public:
-    typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*);
+    typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*);
 
-    static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback)
+    static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback)
     {
-        return adoptRef(new GenericCallback(context, callback));
+        return adoptRef(new ComputedPagesCallback(context, callback));
     }
 
-    ~GenericCallback()
+    virtual ~ComputedPagesCallback()
     {
         ASSERT(!m_callback);
     }
 
-    void performCallbackWithReturnValue(InternalReturnValueType returnValue)
+    void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2)
     {
         ASSERT(m_callback);
 
-        m_callback(toAPI(returnValue), 0, m_context);
+        m_callback(returnValue1, returnValue2, 0, context());
 
         m_callback = 0;
     }
@@ -173,30 +179,20 @@ public:
         ASSERT(m_callback);
 
         RefPtr<WebError> error = WebError::create();
-        m_callback(0, toAPI(error.get()), m_context);
+        m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), context());
         
         m_callback = 0;
     }
 
-    uint64_t callbackID() const { return m_callbackID; }
-
 private:
-    static uint64_t generateCallbackID()
-    {
-        static uint64_t uniqueCallbackID = 1;
-        return uniqueCallbackID++;
-    }
 
-    GenericCallback(void* context, CallbackFunction callback)
-        : m_context(context)
+    ComputedPagesCallback(void* context, CallbackFunction callback)
+        : CallbackBase(context)
         , m_callback(callback)
-        , m_callbackID(generateCallbackID())
     {
     }
 
-    void* m_context;
     CallbackFunction m_callback;
-    uint64_t m_callbackID;
 };
 
 template<typename T>