[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

commit-queue at webkit.org commit-queue at webkit.org
Wed Dec 22 15:58:45 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 6687a623d090d85d337e1fae39b0ee2c2c4e4906
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Nov 17 13:30:20 2010 +0000

    2010-11-17  Eric Uhrhane  <ericu at chromium.org>
    
            Reviewed by David Levin.
    
            [Chromium] implementation of async FileWriter for workers
            https://bugs.webkit.org/show_bug.cgi?id=47681
    
            Tests are in a separate changelist.
    
            * platform/CrossThreadCopier.h: Changed CrossThreadCopier[Base] to support PassRefPtrs
    2010-11-17  Eric Uhrhane  <ericu at chromium.org>
    
            Reviewed by David Levin.
    
            [Chromium] implementation of async FileWriter for workers
            https://bugs.webkit.org/show_bug.cgi?id=47681
    
            Tests are in a separate changelist.
    
            Added new files.
            * WebKit.gyp:
    
            * src/WorkerAsyncFileSystemChromium.cpp: Added WorkerAsyncFileWriterChromium construction.
            * src/WorkerAsyncFileWriterChromium.cpp: Added.
            * src/WorkerAsyncFileWriterChromium.h: Added.
    
            This class bridges between the context and main threads for the WorkerAsyncFileWriterChromium.
            * src/WorkerFileWriterCallbacksBridge.cpp: Added.
            * src/WorkerFileWriterCallbacksBridge.h: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72200 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index d84c2e2..53a2ff6 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,14 @@
+2010-11-17  Eric Uhrhane  <ericu at chromium.org>
+
+        Reviewed by David Levin.
+
+        [Chromium] implementation of async FileWriter for workers
+        https://bugs.webkit.org/show_bug.cgi?id=47681
+
+        Tests are in a separate changelist.
+
+        * platform/CrossThreadCopier.h: Changed CrossThreadCopier[Base] to support PassRefPtrs
+
 2010-11-17  Alejandro G. Castro  <alex at igalia.com>
 
         Reviewed by Martin Robinson.
diff --git a/WebCore/platform/CrossThreadCopier.h b/WebCore/platform/CrossThreadCopier.h
index 6f7bb25..5eb40ee 100644
--- a/WebCore/platform/CrossThreadCopier.h
+++ b/WebCore/platform/CrossThreadCopier.h
@@ -71,7 +71,8 @@ namespace WebCore {
 
     // Custom copy methods.
     template<typename T> struct CrossThreadCopierBase<false, true, T> {
-        typedef typename WTF::RemoveTemplate<T, RefPtr>::Type RefCountedType;
+        typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr;
+        typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type RefCountedType;
         typedef PassRefPtr<RefCountedType> Type;
         static Type copy(const T& refPtr)
         {
@@ -113,7 +114,8 @@ namespace WebCore {
     };
 
     template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase<WTF::IsConvertibleToInteger<T>::value,
-                                                                                 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, ThreadSafeShared>::value,
+                                                                                 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, ThreadSafeShared>::value
+                                                                                     || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Type, ThreadSafeShared>::value,
                                                                                  T> {
     };
 
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index fbbb449..3b48c03 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,23 @@
+2010-11-17  Eric Uhrhane  <ericu at chromium.org>
+
+        Reviewed by David Levin.
+
+        [Chromium] implementation of async FileWriter for workers
+        https://bugs.webkit.org/show_bug.cgi?id=47681
+
+        Tests are in a separate changelist.
+
+        Added new files.
+        * WebKit.gyp:
+
+        * src/WorkerAsyncFileSystemChromium.cpp: Added WorkerAsyncFileWriterChromium construction.
+        * src/WorkerAsyncFileWriterChromium.cpp: Added.
+        * src/WorkerAsyncFileWriterChromium.h: Added.
+
+        This class bridges between the context and main threads for the WorkerAsyncFileWriterChromium.
+        * src/WorkerFileWriterCallbacksBridge.cpp: Added.
+        * src/WorkerFileWriterCallbacksBridge.h: Added.
+
 2010-11-17  John Mellor  <johnme at chromium.org>
 
         Reviewed by Darin Fisher.
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index 8686e05..a95b88f 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -547,8 +547,12 @@
                 'src/WebWorkerImpl.h',
                 'src/WorkerAsyncFileSystemChromium.cpp',
                 'src/WorkerAsyncFileSystemChromium.h',
+                'src/WorkerAsyncFileWriterChromium.cpp',
+                'src/WorkerAsyncFileWriterChromium.h',
                 'src/WorkerFileSystemCallbacksBridge.cpp',
                 'src/WorkerFileSystemCallbacksBridge.h',
+                'src/WorkerFileWriterCallbacksBridge.cpp',
+                'src/WorkerFileWriterCallbacksBridge.h',
                 'src/WrappedResourceRequest.h',
                 'src/WrappedResourceResponse.h',
                 'src/win/WebInputEventFactory.cpp',
diff --git a/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp b/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp
index 1e70619..058e947 100644
--- a/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp
+++ b/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp
@@ -34,13 +34,16 @@
 #if ENABLE(FILE_SYSTEM)
 
 #include "AsyncFileSystemCallbacks.h"
+#include "FileMetadata.h"
 #include "FileSystem.h"
 #include "NotImplemented.h"
 #include "WebFileSystem.h"
 #include "WebFileSystemCallbacksImpl.h"
+#include "WebFileWriter.h"
 #include "WebKit.h"
 #include "WebKitClient.h"
 #include "WebWorkerBase.h"
+#include "WorkerAsyncFileWriterChromium.h"
 #include "WorkerContext.h"
 #include "WorkerFileSystemCallbacksBridge.h"
 #include "WorkerScriptController.h"
@@ -134,9 +137,76 @@ void WorkerAsyncFileSystemChromium::readDirectory(const String& path, PassOwnPtr
     createWorkerFileSystemCallbacksBridge(callbacks)->postReadDirectoryToMainThread(m_webFileSystem, path, m_modeForCurrentOperation);
 }
 
-void WorkerAsyncFileSystemChromium::createWriter(AsyncFileWriterClient*, const String&, PassOwnPtr<AsyncFileSystemCallbacks>)
+class WorkerFileWriterHelperCallbacks : public AsyncFileSystemCallbacks {
+public:
+    static PassOwnPtr<WorkerFileWriterHelperCallbacks> create(AsyncFileWriterClient* client, const String& path, WebKit::WebFileSystem* webFileSystem, PassOwnPtr<WebCore::AsyncFileSystemCallbacks> callbacks, WorkerContext* workerContext)
+    {
+        return adoptPtr(new WorkerFileWriterHelperCallbacks(client, path, webFileSystem, callbacks, workerContext));
+    }
+
+    virtual void didSucceed()
+    {
+        ASSERT_NOT_REACHED();
+    }
+
+    virtual void didReadMetadata(const FileMetadata& metadata)
+    {
+        ASSERT(m_callbacks);
+        if (metadata.type != FileMetadata::TypeFile || metadata.length < 0)
+            m_callbacks->didFail(WebKit::WebFileErrorInvalidState);
+        else {
+            OwnPtr<WorkerAsyncFileWriterChromium> asyncFileWriterChromium = WorkerAsyncFileWriterChromium::create(m_webFileSystem, m_path, m_workerContext, m_client, WorkerAsyncFileWriterChromium::Asynchronous);
+            m_callbacks->didCreateFileWriter(asyncFileWriterChromium.release(), metadata.length);
+        }
+    }
+
+    virtual void didReadDirectoryEntry(const String& name, bool isDirectory)
+    {
+        ASSERT_NOT_REACHED();
+    }
+
+    virtual void didReadDirectoryEntries(bool hasMore)
+    {
+        ASSERT_NOT_REACHED();
+    }
+
+    virtual void didOpenFileSystem(const String&, PassOwnPtr<AsyncFileSystem>)
+    {
+        ASSERT_NOT_REACHED();
+    }
+
+    // Called when an AsyncFileWrter has been created successfully.
+    virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long)
+    {
+        ASSERT_NOT_REACHED();
+    }
+
+    virtual void didFail(int code)
+    {
+        ASSERT(m_callbacks);
+        m_callbacks->didFail(code);
+    }
+
+private:
+    WorkerFileWriterHelperCallbacks(AsyncFileWriterClient* client, const String& path, WebKit::WebFileSystem* webFileSystem, PassOwnPtr<WebCore::AsyncFileSystemCallbacks> callbacks, WorkerContext* workerContext)
+        : m_client(client)
+        , m_path(path)
+        , m_webFileSystem(webFileSystem)
+        , m_callbacks(callbacks)
+        , m_workerContext(workerContext)
+    {
+    }
+
+    AsyncFileWriterClient* m_client;
+    String m_path;
+    WebKit::WebFileSystem* m_webFileSystem;
+    OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks;
+    WorkerContext* m_workerContext;
+};
+
+void WorkerAsyncFileSystemChromium::createWriter(AsyncFileWriterClient* client, const String& path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
 {
-    notImplemented();
+    createWorkerFileSystemCallbacksBridge(WorkerFileWriterHelperCallbacks::create(client, path, m_webFileSystem, callbacks, m_workerContext))->postReadMetadataToMainThread(m_webFileSystem, path, m_modeForCurrentOperation);
 }
 
 PassRefPtr<WorkerFileSystemCallbacksBridge> WorkerAsyncFileSystemChromium::createWorkerFileSystemCallbacksBridge(PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
diff --git a/WebKit/chromium/src/WorkerAsyncFileWriterChromium.cpp b/WebKit/chromium/src/WorkerAsyncFileWriterChromium.cpp
new file mode 100644
index 0000000..8d8e469
--- /dev/null
+++ b/WebKit/chromium/src/WorkerAsyncFileWriterChromium.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WorkerAsyncFileWriterChromium.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "Blob.h"
+#include "ScriptExecutionContext.h"
+#include "WebFileSystem.h"
+#include "WebFileWriter.h"
+#include "WebURL.h"
+#include "WebWorkerBase.h"
+#include "WorkerContext.h"
+#include "WorkerFileWriterCallbacksBridge.h"
+#include "WorkerLoaderProxy.h"
+#include "WorkerThread.h"
+#include <wtf/Assertions.h>
+
+using namespace WebKit;
+
+namespace WebCore {
+
+WorkerAsyncFileWriterChromium::WorkerAsyncFileWriterChromium(WebFileSystem* webFileSystem, const String& path, WorkerContext* workerContext, AsyncFileWriterClient* client, WriterType type)
+    : m_type(type)
+{
+    ASSERT(m_type == Asynchronous); // Synchronous is not implemented yet.
+
+    WorkerLoaderProxy* proxy = &workerContext->thread()->workerLoaderProxy();
+    m_bridge = WorkerFileWriterCallbacksBridge::create(path, proxy, workerContext, client);
+}
+
+WorkerAsyncFileWriterChromium::~WorkerAsyncFileWriterChromium()
+{
+    m_bridge->postShutdownToMainThread(m_bridge);
+}
+
+void WorkerAsyncFileWriterChromium::write(long long position, Blob* data)
+{
+    m_bridge->postWriteToMainThread(position, data->url());
+}
+
+void WorkerAsyncFileWriterChromium::truncate(long long length)
+{
+    m_bridge->postTruncateToMainThread(length);
+}
+
+void WorkerAsyncFileWriterChromium::abort()
+{
+    m_bridge->postAbortToMainThread();
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/WebKit/chromium/src/WorkerAsyncFileWriterChromium.h b/WebKit/chromium/src/WorkerAsyncFileWriterChromium.h
new file mode 100644
index 0000000..55d8d24
--- /dev/null
+++ b/WebKit/chromium/src/WorkerAsyncFileWriterChromium.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WorkerAsyncFileWriterChromium_h
+#define WorkerAsyncFileWriterChromium_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileWriter.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace WebKit {
+    class WebFileSystem;
+    class WebFileWriter;
+    class WorkerFileWriterCallbacksBridge;
+}
+
+namespace WTF {
+    class String;
+}
+using WTF::String;
+
+namespace WebCore {
+
+class AsyncFileSystem;
+class AsyncFileWriterClient;
+class Blob;
+class WorkerContext;
+
+class WorkerAsyncFileWriterChromium : public AsyncFileWriter {
+public:
+    enum WriterType {
+        Asynchronous,
+        Synchronous,
+    };
+
+    static PassOwnPtr<WorkerAsyncFileWriterChromium> create(WebKit::WebFileSystem* webFileSystem, const String& path, WorkerContext* workerContext, AsyncFileWriterClient* client, WriterType type)
+    {
+        return adoptPtr(new WorkerAsyncFileWriterChromium(webFileSystem, path, workerContext, client, type));
+    }
+    ~WorkerAsyncFileWriterChromium();
+    
+    // FileWriter
+    virtual void write(long long position, Blob* data);
+    virtual void truncate(long long length);
+    virtual void abort();
+
+private:
+
+    WorkerAsyncFileWriterChromium(WebKit::WebFileSystem*, const String& path, WorkerContext*, AsyncFileWriterClient*, WriterType);
+    RefPtr<WebKit::WorkerFileWriterCallbacksBridge> m_bridge;
+    WriterType m_type;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // AsyncFileWriterChromium_h
diff --git a/WebKit/chromium/src/WorkerFileWriterCallbacksBridge.cpp b/WebKit/chromium/src/WorkerFileWriterCallbacksBridge.cpp
new file mode 100644
index 0000000..827c011
--- /dev/null
+++ b/WebKit/chromium/src/WorkerFileWriterCallbacksBridge.cpp
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WorkerFileWriterCallbacksBridge.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileWriterClient.h"
+#include "CrossThreadTask.h"
+#include "WebCString.h"
+#include "WebFileSystem.h"
+#include "WebFileWriter.h"
+#include "WebKit.h"
+#include "WebKitClient.h"
+#include "WebWorkerBase.h"
+#include "WorkerContext.h"
+#include "WorkerLoaderProxy.h"
+#include "WorkerThread.h"
+#include <wtf/MainThread.h>
+#include <wtf/Threading.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void WorkerFileWriterCallbacksBridge::notifyStop()
+{
+    ASSERT(m_workerContext->isContextThread());
+    m_clientOnWorkerThread = 0;
+}
+
+void WorkerFileWriterCallbacksBridge::postWriteToMainThread(long long position, const KURL& data)
+{
+    dispatchTaskToMainThread(createCallbackTask(&writeOnMainThread, this, position, data));
+}
+
+void WorkerFileWriterCallbacksBridge::postTruncateToMainThread(long long length)
+{
+    dispatchTaskToMainThread(createCallbackTask(&truncateOnMainThread, this, length));
+}
+
+void WorkerFileWriterCallbacksBridge::postAbortToMainThread()
+{
+    dispatchTaskToMainThread(createCallbackTask(&abortOnMainThread, this));
+}
+
+void WorkerFileWriterCallbacksBridge::postShutdownToMainThread(PassRefPtr<WorkerFileWriterCallbacksBridge> bridge)
+{
+    ASSERT(m_workerContext->isContextThread());
+    m_clientOnWorkerThread = 0;
+    dispatchTaskToMainThread(createCallbackTask(&shutdownOnMainThread, bridge));
+}
+
+void WorkerFileWriterCallbacksBridge::writeOnMainThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long position, const KURL& data)
+{
+    bridge->m_writer->write(position, WebURL(data));
+}
+
+void WorkerFileWriterCallbacksBridge::truncateOnMainThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length)
+{
+    bridge->m_writer->truncate(length);
+}
+
+void WorkerFileWriterCallbacksBridge::abortOnMainThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge)
+{
+    bridge->m_writer->cancel();
+}
+
+void WorkerFileWriterCallbacksBridge::initOnMainThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, const String& path)
+{
+    ASSERT(!bridge->m_writer);
+    bridge->m_writer = webKitClient()->fileSystem()->createFileWriter(path, bridge.get());
+}
+
+void WorkerFileWriterCallbacksBridge::shutdownOnMainThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge)
+{
+    bridge->m_writerDeleted = true;
+    bridge->m_writer.clear();
+}
+
+void WorkerFileWriterCallbacksBridge::didWrite(long long bytes, bool complete)
+{
+    dispatchTaskToWorkerThread(createCallbackTask(&didWriteOnWorkerThread, this, bytes, complete));
+}
+
+void WorkerFileWriterCallbacksBridge::didFail(WebFileError error)
+{
+    dispatchTaskToWorkerThread(createCallbackTask(&didFailOnWorkerThread, this, error));
+}
+
+void WorkerFileWriterCallbacksBridge::didTruncate()
+{
+    dispatchTaskToWorkerThread(createCallbackTask(&didTruncateOnWorkerThread, this));
+}
+
+WorkerFileWriterCallbacksBridge::WorkerFileWriterCallbacksBridge(const String& path, WorkerLoaderProxy* proxy, ScriptExecutionContext* scriptExecutionContext, AsyncFileWriterClient* client)
+    : WorkerContext::Observer(static_cast<WorkerContext*>(scriptExecutionContext))
+    , m_proxy(proxy)
+    , m_workerContext(scriptExecutionContext)
+    , m_clientOnWorkerThread(client)
+    , m_writerDeleted(false)
+{
+    ASSERT(m_workerContext->isContextThread());
+    postInitToMainThread(path);
+}
+
+void WorkerFileWriterCallbacksBridge::postInitToMainThread(const String& path)
+{
+    dispatchTaskToMainThread(createCallbackTask(&initOnMainThread, this, path));
+}
+
+WorkerFileWriterCallbacksBridge::~WorkerFileWriterCallbacksBridge()
+{
+    ASSERT(!m_clientOnWorkerThread);
+    ASSERT(!m_writer);
+}
+
+// We know m_clientOnWorkerThread is still valid because it is only cleared on the context thread, and because we check in runTaskOnWorkerThread before calling any of these methods.
+void WorkerFileWriterCallbacksBridge::didWriteOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length, bool complete)
+{
+    ASSERT(bridge->m_workerContext->isContextThread());
+    bridge->m_clientOnWorkerThread->didWrite(length, complete);
+}
+
+void WorkerFileWriterCallbacksBridge::didFailOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, WebFileError error)
+{
+    ASSERT(bridge->m_workerContext->isContextThread());
+    bridge->m_clientOnWorkerThread->didFail(static_cast<FileError::ErrorCode>(error));
+}
+
+void WorkerFileWriterCallbacksBridge::didTruncateOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge)
+{
+    ASSERT(bridge->m_workerContext->isContextThread());
+    bridge->m_clientOnWorkerThread->didTruncate();
+}
+
+void WorkerFileWriterCallbacksBridge::runTaskOnMainThread(ScriptExecutionContext* scriptExecutionContext, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, PassOwnPtr<ScriptExecutionContext::Task> taskToRun)
+{
+    ASSERT(isMainThread());
+    if (!bridge->m_writerDeleted)
+        taskToRun->performTask(scriptExecutionContext);
+}
+
+void WorkerFileWriterCallbacksBridge::runTaskOnWorkerThread(ScriptExecutionContext* scriptExecutionContext, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, PassOwnPtr<ScriptExecutionContext::Task> taskToRun)
+{
+    ASSERT(bridge->m_workerContext->isContextThread());
+    if (bridge->m_clientOnWorkerThread)
+        taskToRun->performTask(scriptExecutionContext);
+}
+
+void WorkerFileWriterCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<ScriptExecutionContext::Task> task)
+{
+    ASSERT(m_workerContext->isContextThread());
+    WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThread, this, task));
+}
+
+void WorkerFileWriterCallbacksBridge::dispatchTaskToWorkerThread(PassOwnPtr<ScriptExecutionContext::Task> task)
+{
+    ASSERT(isMainThread());
+    m_proxy->postTaskForModeToWorkerContext(createCallbackTask(&runTaskOnWorkerThread, this, task), WorkerRunLoop::defaultMode());
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/WebKit/chromium/src/WorkerFileWriterCallbacksBridge.h b/WebKit/chromium/src/WorkerFileWriterCallbacksBridge.h
new file mode 100644
index 0000000..d2e416e
--- /dev/null
+++ b/WebKit/chromium/src/WorkerFileWriterCallbacksBridge.h
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WorkerFileWriterCallbacksBridge_h
+#define WorkerFileWriterCallbacksBridge_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "WebFileError.h"
+#include "WebFileWriterClient.h"
+#include "WorkerContext.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/ThreadSafeShared.h>
+
+namespace WebCore {
+    class AsyncFileWriterClient;
+    class KURL;
+    class WorkerLoaderProxy;
+}
+
+namespace WTF {
+    class String;
+}
+using WTF::String;
+
+namespace WebKit {
+
+class WebFileSystem;
+class WebFileWriter;
+class WebFileWriterClient;
+class WebWorkerBase;
+
+// This class is used as a mechanism to bridge calls between threads.
+// Calls to a WebFileWriter must happen on the main thread, but they come from
+// the context thread. The responses through the WebFileWriterClient interface
+// start on the main thread, but must be sent via the worker context thread.
+//
+// A typical flow for write would look like this:
+// Bridge::postWriteToMainThread() on WorkerThread
+//  --> Bridge::writeOnMainThread() is called on MainThread
+//  --> WebFileWriter::write()
+//      This makes an IPC; the actual operation is down in the browser.
+//  --> Bridge::didWrite is called on MainThread
+//  --> Bridge::didWriteOnWorkerThread is called on WorkerThread
+//      This calls the original client (m_clientOnWorkerThread).
+//
+// The bridge object is refcounted, so that it doesn't get deleted while there
+// are cross-thread calls in flight. Each CrossThreadTask carries a reference
+// to the bridge, which guarantees that the bridge will still be valid when the
+// task is executed. In order to shut down the bridge, the WebFileWriterClient
+// should call postShutdownToMainThread before dropping its reference to the
+// bridge. This ensures that the WebFileWriter will be cleared on the main
+// thread and that no further calls to the WebFileWriterClient will be made.
+class WorkerFileWriterCallbacksBridge : public ThreadSafeShared<WorkerFileWriterCallbacksBridge>, public WebCore::WorkerContext::Observer, public WebFileWriterClient {
+public:
+    ~WorkerFileWriterCallbacksBridge();
+
+    // WorkerContext::Observer method.
+    virtual void notifyStop();
+
+    static PassRefPtr<WorkerFileWriterCallbacksBridge> create(const String& path, WebCore::WorkerLoaderProxy* proxy, WebCore::ScriptExecutionContext* workerContext, WebCore::AsyncFileWriterClient* client)
+    {
+        return adoptRef(new WorkerFileWriterCallbacksBridge(path, proxy, workerContext, client));
+    }
+
+    // Methods that create an instance and post an initial request task to the main thread. They must be called on the worker thread.
+    void postWriteToMainThread(long long position, const WebCore::KURL& data);
+    void postTruncateToMainThread(long long length);
+    void postAbortToMainThread();
+
+    // The owning WorkerAsyncFileWriterChromium should call this method before dropping its last reference to the bridge, on the context thread.
+    // The actual deletion of the WorkerFileWriterCallbacksBridge may happen on either the main or context thread, depending on where the last reference goes away; that's safe as long as this is called first.
+    void postShutdownToMainThread(PassRefPtr<WorkerFileWriterCallbacksBridge>);
+
+    // Callback methods that are called on the main thread.
+    // These are the implementation of WebKit::WebFileWriterClient.
+    void didWrite(long long bytes, bool complete);
+    void didFail(WebFileError);
+    void didTruncate();
+
+private:
+    WorkerFileWriterCallbacksBridge(const String& path, WebCore::WorkerLoaderProxy*, WebCore::ScriptExecutionContext*, WebCore::AsyncFileWriterClient*);
+
+    void postInitToMainThread(const String& path);
+
+    // Methods that are to be called on the main thread.
+    static void writeOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>, long long position, const WebCore::KURL& data);
+    static void truncateOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>, long long length);
+    static void abortOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>);
+    static void initOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>, const String& path);
+    static void shutdownOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>);
+
+    // Methods that dispatch to AsyncFileWriterClient on the worker threads.
+    static void didWriteOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>, long long length, bool complete);
+    static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>, WebFileError);
+    static void didTruncateOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>);
+
+    // Called on the main thread to run the supplied task.
+    static void runTaskOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
+    // Called on the worker thread to run the supplied task.
+    static void runTaskOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
+
+    // Called on the worker thread to dispatch to the main thread.
+    void dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
+    // Called on the main thread to dispatch to the worker thread.
+    void dispatchTaskToWorkerThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
+
+    // Used from the main thread to post tasks to the context thread.
+    WebCore::WorkerLoaderProxy* m_proxy;
+
+    // Used on the context thread, only to check that we're running on the context thread.
+    WebCore::ScriptExecutionContext* m_workerContext;
+
+    // Created and destroyed from the main thread.
+    OwnPtr<WebKit::WebFileWriter> m_writer;
+
+    // Used on the context thread to call back into the client.
+    WebCore::AsyncFileWriterClient* m_clientOnWorkerThread;
+
+    // Used to indicate that shutdown has started on the main thread, and hence the writer has been deleted.
+    bool m_writerDeleted;
+};
+
+} // namespace WebCore
+
+#endif
+
+#endif // WorkerFileWriterCallbacksBridge_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list