Bug 43135

Summary: Decouple FileThread from FileStream to support generic file-related async tasks
Product: WebKit Reporter: Kinuko Yasuda <kinuko>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: jianli, levin, michaeln
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Bug Depends on:    
Bug Blocks: 42903    
Attachments:
Description Flags
Patch
none
Patch jianli: review+

Description Kinuko Yasuda 2010-07-28 12:19:42 PDT
Decouple FileThread from FileStream to support generic file-related async tasks.
This is needed for FileSystem API implementation.
Comment 1 Kinuko Yasuda 2010-07-28 12:23:24 PDT
Created attachment 62860 [details]
Patch
Comment 2 Jian Li 2010-07-28 15:01:16 PDT
Comment on attachment 62860 [details]
Patch

It is a good idea to support generic file related async tasks. However, I am thinking if it is possible to make current FileThreadTask support calling any class methods asynchronously. How about something like the following:

// FileThread.h
    ...

    class Task : public Noncopyable {
    public:
        virtual ~Task() { }
        virtual void performTask() = 0;
        void* instance() const { return m_instance; }
    protected:
        Task(void* instance) : m_instance(instance) { }
        void* m_instance;
    };

    void postTask(PassOwnPtr<Task> task);
    void unscheduleTasks(const void* instance);

// FileThreadTask.h

...

template<typename R, typename T>
class FileThreadTask0 : public FileThread::Task {
public:
    typedef R (T::*Method)();
    typedef FileThreadTask0<R, T> FileThreadTask;

    static PassOwnPtr<FileThreadTask> create(T* instance, Method method)
    {
        return new FileThreadTask(instance, method);
    }

private:
    FileThreadTask0(T* instance, Method method)
        : FileThread::Task(instance)
        , m_method(method)
    {
    }

    virtual void performTask()
    {
        (*reinterpret_cast<T*>(instance()).*m_method)();
    }

private:
    Method m_method;
};

...

template<typename R, typename T>
PassOwnPtr<FileThread::Task> createFileThreadTask(
    T* const callee,
    R (T::*method)())
{
    return FileThreadTask0<R, T>::create(
        callee,
        method);
}
Comment 3 Kinuko Yasuda 2010-07-28 18:03:53 PDT
Created attachment 62903 [details]
Patch
Comment 4 Kinuko Yasuda 2010-07-28 18:07:22 PDT
(In reply to comment #2)
> (From update of attachment 62860 [details])
> It is a good idea to support generic file related async tasks. However, I am thinking if it is possible to make current FileThreadTask support calling any class methods asynchronously. How about something like the following:
> 
> // FileThread.h
>     ...

Sounds good, and it would require less changes.   Updated the patch.
Comment 5 Jian Li 2010-07-30 14:44:26 PDT
Comment on attachment 62903 [details]
Patch

Looks good. Please address the following issue before you land.

WebCore/html/FileThreadTask.h: 
 +      R (FileStream::*method)());
Why removing this? I think this forward declaration is needed to get rid of the warning treater as error in snow leopard. See http://trac.webkit.org/changeset/59166 for detail.
Comment 6 Kinuko Yasuda 2010-07-30 22:04:29 PDT
Committed r64406: <http://trac.webkit.org/changeset/64406>