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

kinuko at chromium.org kinuko at chromium.org
Wed Dec 22 13:55:20 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 196c168e90f1c8e71d3b0c99de778d000bd665e8
Author: kinuko at chromium.org <kinuko at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Sep 29 18:12:36 2010 +0000

    2010-09-29  Kinuko Yasuda  <kinuko at chromium.org>
    
            Reviewed by David Levin.
    
            Bridge all FileSystem operations on Workers to the MainThread
            https://bugs.webkit.org/show_bug.cgi?id=46524
    
            * src/LocalFileSystemChromium.cpp:
            (WebCore::LocalFileSystem::requestFileSystem): Changed the worker case
            code to create WebFileSystemCallbacksImpl with the current
            ScriptExecutionContext (WorkerContext).
            * src/WebFileSystemCallbacksImpl.cpp:
            (WebKit::WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl): Added
            a new constructor that takes ScriptExecutionContext (WorkerContext)
            for workers.
            (WebKit::WebFileSystemCallbacksImpl::didOpenFileSystem): Added the
            code for workers that creates WorkerAsyncFileSystemChromium.
            * src/WebFileSystemCallbacksImpl.h:
            * src/WorkerAsyncFileSystemChromium.cpp: Added.
            * src/WorkerAsyncFileSystemChromium.h: Added.
            * src/WorkerFileSystemCallbacksBridge.cpp: Added methods for regular
            file system operations to proxy them to the main thread.
            (WebKit::WorkerFileSystemCallbacksBridge::createForOpenFileSystem):
            (WebKit::WorkerFileSystemCallbacksBridge::createForMove):
            (WebKit::WorkerFileSystemCallbacksBridge::createForCopy):
            (WebKit::WorkerFileSystemCallbacksBridge::createForRemove):
            (WebKit::WorkerFileSystemCallbacksBridge::createForReadMetadata):
            (WebKit::WorkerFileSystemCallbacksBridge::createForCreateFile):
            (WebKit::WorkerFileSystemCallbacksBridge::createForCreateDirectory):
            (WebKit::WorkerFileSystemCallbacksBridge::createForFileExists):
            (WebKit::WorkerFileSystemCallbacksBridge::createForDirectoryExists):
            (WebKit::WorkerFileSystemCallbacksBridge::createForReadDirectory):
            (WebKit::MainThreadFileSystemCallbacks::didSucceed):
            (WebKit::MainThreadFileSystemCallbacks::didReadMetadata):
            (WebKit::MainThreadFileSystemCallbacks::didReadDirectory):
            (WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::moveOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::copyOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::removeOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::readMetadataOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::createFileOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::createDirectoryOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::fileExistsOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread):
            (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread):
            (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread):
            (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread):
            (WebKit::WorkerFileSystemCallbacksBridge::derefIfWorkerIsStopped):
            * src/WorkerFileSystemCallbacksBridge.h:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68669 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index cc725dc..d7777e4 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,57 @@
+2010-09-29  Kinuko Yasuda  <kinuko at chromium.org>
+
+        Reviewed by David Levin.
+
+        Bridge all FileSystem operations on Workers to the MainThread
+        https://bugs.webkit.org/show_bug.cgi?id=46524
+
+        * src/LocalFileSystemChromium.cpp:
+        (WebCore::LocalFileSystem::requestFileSystem): Changed the worker case
+        code to create WebFileSystemCallbacksImpl with the current
+        ScriptExecutionContext (WorkerContext).
+        * src/WebFileSystemCallbacksImpl.cpp:
+        (WebKit::WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl): Added
+        a new constructor that takes ScriptExecutionContext (WorkerContext)
+        for workers.
+        (WebKit::WebFileSystemCallbacksImpl::didOpenFileSystem): Added the
+        code for workers that creates WorkerAsyncFileSystemChromium.
+        * src/WebFileSystemCallbacksImpl.h:
+        * src/WorkerAsyncFileSystemChromium.cpp: Added.
+        * src/WorkerAsyncFileSystemChromium.h: Added.
+        * src/WorkerFileSystemCallbacksBridge.cpp: Added methods for regular
+        file system operations to proxy them to the main thread.
+        (WebKit::WorkerFileSystemCallbacksBridge::createForOpenFileSystem):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForMove):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForCopy):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForRemove):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForReadMetadata):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForCreateFile):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForCreateDirectory):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForFileExists):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForDirectoryExists):
+        (WebKit::WorkerFileSystemCallbacksBridge::createForReadDirectory):
+        (WebKit::MainThreadFileSystemCallbacks::didSucceed):
+        (WebKit::MainThreadFileSystemCallbacks::didReadMetadata):
+        (WebKit::MainThreadFileSystemCallbacks::didReadDirectory):
+        (WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::moveOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::copyOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::removeOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::readMetadataOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::createFileOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::createDirectoryOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::fileExistsOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::derefIfWorkerIsStopped):
+        * src/WorkerFileSystemCallbacksBridge.h:
+
 2010-09-29  Matt Perry  <mpcomplete at chromium.org>
 
         Reviewed by Darin Fisher.
diff --git a/WebKit/chromium/src/AsyncFileSystemChromium.cpp b/WebKit/chromium/src/AsyncFileSystemChromium.cpp
index db65bbd..59e6484 100644
--- a/WebKit/chromium/src/AsyncFileSystemChromium.cpp
+++ b/WebKit/chromium/src/AsyncFileSystemChromium.cpp
@@ -61,14 +61,14 @@ AsyncFileSystemChromium::~AsyncFileSystemChromium()
 {
 }
 
-void AsyncFileSystemChromium::move(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
+void AsyncFileSystemChromium::move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
 {
-    m_webFileSystem->move(srcPath, destPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
+    m_webFileSystem->move(sourcePath, destinationPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
 }
 
-void AsyncFileSystemChromium::copy(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
+void AsyncFileSystemChromium::copy(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
 {
-    m_webFileSystem->copy(srcPath, destPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
+    m_webFileSystem->copy(sourcePath, destinationPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
 }
 
 void AsyncFileSystemChromium::remove(const String& path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
diff --git a/WebKit/chromium/src/AsyncFileSystemChromium.h b/WebKit/chromium/src/AsyncFileSystemChromium.h
index d8698d5..91b1d9c 100644
--- a/WebKit/chromium/src/AsyncFileSystemChromium.h
+++ b/WebKit/chromium/src/AsyncFileSystemChromium.h
@@ -34,7 +34,7 @@
 #if ENABLE(FILE_SYSTEM)
 
 #include "AsyncFileSystem.h"
-#include <wtf/PassRefPtr.h>
+#include <wtf/PassOwnPtr.h>
 
 namespace WebKit {
 class WebFileSystem;
@@ -46,11 +46,15 @@ class AsyncFileSystemCallbacks;
 
 class AsyncFileSystemChromium : public AsyncFileSystem {
 public:
-    AsyncFileSystemChromium(const String& rootPath);
+    static PassOwnPtr<AsyncFileSystem> create(const String& rootPath)
+    {
+        return adoptPtr(new AsyncFileSystemChromium(rootPath));
+    }
+
     virtual ~AsyncFileSystemChromium();
 
-    virtual void move(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks>);
-    virtual void copy(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks>);
+    virtual void move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>);
+    virtual void copy(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>);
     virtual void remove(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
     virtual void readMetadata(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
     virtual void createFile(const String& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>);
@@ -61,6 +65,7 @@ public:
     virtual void createWriter(AsyncFileWriterClient* client, const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
 
 private:
+    explicit AsyncFileSystemChromium(const String& rootPath);
     WebKit::WebFileSystem* m_webFileSystem;
 };
 
diff --git a/WebKit/chromium/src/LocalFileSystemChromium.cpp b/WebKit/chromium/src/LocalFileSystemChromium.cpp
index 7bf4335..a4f2d72 100644
--- a/WebKit/chromium/src/LocalFileSystemChromium.cpp
+++ b/WebKit/chromium/src/LocalFileSystemChromium.cpp
@@ -68,7 +68,7 @@ void LocalFileSystem::requestFileSystem(ScriptExecutionContext* context, AsyncFi
         WorkerContext* workerContext = static_cast<WorkerContext*>(context);
         WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
         WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy);
-        webWorker->openFileSystem(static_cast<WebFileSystem::Type>(type), size, new WebFileSystemCallbacksImpl(callbacks));
+        webWorker->openFileSystem(static_cast<WebFileSystem::Type>(type), size, new WebFileSystemCallbacksImpl(callbacks, context));
     }
 }
 
diff --git a/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp b/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp
index a23add7..faffed0 100644
--- a/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp
+++ b/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp
@@ -34,19 +34,22 @@
 
 #include "AsyncFileSystemCallbacks.h"
 #include "AsyncFileSystemChromium.h"
-#include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 #include "WebFileSystemEntry.h"
 #include "WebFileInfo.h"
 #include "WebString.h"
+#include "WorkerAsyncFileSystemChromium.h"
 #include <wtf/Vector.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
+WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks, WebCore::ScriptExecutionContext* context)
     : m_callbacks(callbacks)
+    , m_context(context)
 {
+    ASSERT(m_callbacks);
 }
 
 WebFileSystemCallbacksImpl::~WebFileSystemCallbacksImpl()
@@ -55,21 +58,18 @@ WebFileSystemCallbacksImpl::~WebFileSystemCallbacksImpl()
 
 void WebFileSystemCallbacksImpl::didSucceed()
 {
-    ASSERT(m_callbacks);
     m_callbacks->didSucceed();
     delete this;
 }
 
 void WebFileSystemCallbacksImpl::didReadMetadata(const WebFileInfo& info)
 {
-    ASSERT(m_callbacks);
     m_callbacks->didReadMetadata(info.modificationTime);
     delete this;
 }
 
 void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
 {
-    ASSERT(m_callbacks);
     for (size_t i = 0; i < entries.size(); ++i)
         m_callbacks->didReadDirectoryEntry(entries[i].name, entries[i].isDirectory);
     m_callbacks->didReadDirectoryEntries(hasMore);
@@ -79,13 +79,15 @@ void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemE
 
 void WebFileSystemCallbacksImpl::didOpenFileSystem(const WebString& name, const WebString& path)
 {
-    m_callbacks->didOpenFileSystem(name, new AsyncFileSystemChromium(path));
+    if (m_context && m_context->isWorkerContext())
+        m_callbacks->didOpenFileSystem(name, WorkerAsyncFileSystemChromium::create(m_context, path));
+    else
+        m_callbacks->didOpenFileSystem(name, AsyncFileSystemChromium::create(path));
     delete this;
 }
 
 void WebFileSystemCallbacksImpl::didFail(WebFileError error)
 {
-    ASSERT(m_callbacks);
     m_callbacks->didFail(error);
     delete this;
 }
diff --git a/WebKit/chromium/src/WebFileSystemCallbacksImpl.h b/WebKit/chromium/src/WebFileSystemCallbacksImpl.h
index 36ab9ff..947fd2f 100644
--- a/WebKit/chromium/src/WebFileSystemCallbacksImpl.h
+++ b/WebKit/chromium/src/WebFileSystemCallbacksImpl.h
@@ -38,6 +38,7 @@
 
 namespace WebCore {
 class AsyncFileSystemCallbacks;
+class ScriptExecutionContext;
 }
 
 namespace WebKit {
@@ -48,7 +49,7 @@ class WebString;
 
 class WebFileSystemCallbacksImpl : public WebFileSystemCallbacks {
 public:
-    WebFileSystemCallbacksImpl(PassOwnPtr<WebCore::AsyncFileSystemCallbacks>);
+    WebFileSystemCallbacksImpl(PassOwnPtr<WebCore::AsyncFileSystemCallbacks>, WebCore::ScriptExecutionContext* = 0);
     virtual ~WebFileSystemCallbacksImpl();
 
     virtual void didSucceed();
@@ -59,6 +60,9 @@ public:
 
 private:
     OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks;
+
+    // Used for worker's openFileSystem callbacks.
+    WebCore::ScriptExecutionContext* m_context;
 };
 
 } // namespace WebKit
diff --git a/WebKit/chromium/src/WebWorkerBase.cpp b/WebKit/chromium/src/WebWorkerBase.cpp
index 622f5c2..f4f5921 100644
--- a/WebKit/chromium/src/WebWorkerBase.cpp
+++ b/WebKit/chromium/src/WebWorkerBase.cpp
@@ -240,9 +240,7 @@ bool WebWorkerBase::allowDatabase(WebFrame*, const WebString& name, const WebStr
 void WebWorkerBase::openFileSystem(WebFileSystem::Type type, long long size, WebFileSystemCallbacks* callbacks)
 {
     WorkerScriptController* controller = WorkerScriptController::controllerForContext();
-    WorkerContext* workerContext = controller->workerContext();
-
-    RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBridge::create(this, workerContext, callbacks);
+    RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBridge::create(this, controller->workerContext(), callbacks);
     bridge->postOpenFileSystemToMainThread(commonClient(), type, size, openFileSystemMode);
 }
 #endif
diff --git a/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp b/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp
index d112886..901f137 100644
--- a/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp
+++ b/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp
@@ -35,7 +35,9 @@
 
 #include "CrossThreadTask.h"
 #include "WebCommonWorkerClient.h"
+#include "WebFileInfo.h"
 #include "WebFileSystemCallbacks.h"
+#include "WebFileSystemEntry.h"
 #include "WebString.h"
 #include "WebWorkerBase.h"
 #include "WorkerContext.h"
@@ -44,6 +46,37 @@
 #include <wtf/MainThread.h>
 #include <wtf/Threading.h>
 
+namespace WebCore {
+
+template<> struct CrossThreadCopierBase<false, false, WebKit::WebFileInfo> {
+    typedef WebKit::WebFileInfo Type;
+    static Type copy(const WebKit::WebFileInfo& info)
+    {
+        // Perform per-field copy to make sure we don't do any (unexpected) non-thread safe copy here.
+        struct WebKit::WebFileInfo newInfo;
+        newInfo.modificationTime = info.modificationTime;
+        newInfo.length = info.length;
+        newInfo.type = info.type;
+        return newInfo;
+    }
+};
+
+template<> struct CrossThreadCopierBase<false, false, WebKit::WebVector<WebKit::WebFileSystemEntry> > {
+    typedef WebKit::WebVector<WebKit::WebFileSystemEntry> Type;
+    static Type copy(const WebKit::WebVector<WebKit::WebFileSystemEntry>& entries)
+    {
+        WebKit::WebVector<WebKit::WebFileSystemEntry> newEntries(entries.size());
+        for (size_t i = 0; i < entries.size(); ++i) {
+            String name = entries[i].name;
+            newEntries[i].isDirectory = entries[i].isDirectory;
+            newEntries[i].name = name.crossThreadString();
+        }
+        return newEntries;
+    }
+};
+
+}
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -51,9 +84,11 @@ namespace WebKit {
 // FileSystemCallbacks that are to be dispatched on the main thread.
 class MainThreadFileSystemCallbacks : public WebFileSystemCallbacks {
 public:
-    static PassOwnPtr<MainThreadFileSystemCallbacks> create(PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
+    // Callbacks are self-destructed and we always return leaked pointer here.
+    static MainThreadFileSystemCallbacks* createLeakedPtr(PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
     {
-        return adoptPtr(new MainThreadFileSystemCallbacks(bridge, mode));
+        OwnPtr<MainThreadFileSystemCallbacks> callbacks = adoptPtr(new MainThreadFileSystemCallbacks(bridge, mode));
+        return callbacks.leakPtr();
     }
 
     virtual ~MainThreadFileSystemCallbacks()
@@ -74,17 +109,20 @@ public:
 
     virtual void didSucceed()
     {
-        WEBKIT_ASSERT_NOT_REACHED();
+        m_bridge->didSucceedOnMainThread(m_mode);
+        delete this;
     }
 
     virtual void didReadMetadata(const WebFileInfo& info)
     {
-        WEBKIT_ASSERT_NOT_REACHED();
+        m_bridge->didReadMetadataOnMainThread(info, m_mode);
+        delete this;
     }
 
     virtual void didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
     {
-        WEBKIT_ASSERT_NOT_REACHED();
+        m_bridge->didReadDirectoryOnMainThread(entries, hasMore, m_mode);
+        delete this;
     }
 
 private:
@@ -114,33 +152,137 @@ void WorkerFileSystemCallbacksBridge::stop()
 
 void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, const String& mode)
 {
-    m_selfRef = this;
-    ASSERT(m_workerContext->isContextThread());
-    ASSERT(m_worker);
-    m_worker->dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, this, mode));
+    dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postMoveToMainThread(WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode)
+{
+    dispatchTaskToMainThread(createCallbackTask(&moveOnMainThread, fileSystem, sourcePath, destinationPath, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postCopyToMainThread(WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode)
+{
+    dispatchTaskToMainThread(createCallbackTask(&copyOnMainThread, fileSystem, sourcePath, destinationPath, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postRemoveToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
+{
+    ASSERT(fileSystem);
+    dispatchTaskToMainThread(createCallbackTask(&removeOnMainThread, fileSystem, path, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postReadMetadataToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
+{
+    ASSERT(fileSystem);
+    dispatchTaskToMainThread(createCallbackTask(&readMetadataOnMainThread, fileSystem, path, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postCreateFileToMainThread(WebFileSystem* fileSystem, const String& path, bool exclusive, const String& mode)
+{
+    dispatchTaskToMainThread(createCallbackTask(&createFileOnMainThread, fileSystem, path, exclusive, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postCreateDirectoryToMainThread(WebFileSystem* fileSystem, const String& path, bool exclusive, const String& mode)
+{
+    ASSERT(fileSystem);
+    dispatchTaskToMainThread(createCallbackTask(&createDirectoryOnMainThread, fileSystem, path, exclusive, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postFileExistsToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
+{
+    ASSERT(fileSystem);
+    dispatchTaskToMainThread(createCallbackTask(&fileExistsOnMainThread, fileSystem, path, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postDirectoryExistsToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
+{
+    ASSERT(fileSystem);
+    dispatchTaskToMainThread(createCallbackTask(&directoryExistsOnMainThread, fileSystem, path, this, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::postReadDirectoryToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
+{
+    ASSERT(fileSystem);
+    dispatchTaskToMainThread(createCallbackTask(&readDirectoryOnMainThread, fileSystem, path, this, mode));
 }
 
 void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
 {
-    ASSERT(isMainThread());
     if (!commonClient)
         bridge->didFailOnMainThread(WebFileErrorAbort, mode);
     else {
-        // MainThreadFileSystemCallbacks is self-destructed, so we leak ptr here.
-        commonClient->openFileSystem(type, size, MainThreadFileSystemCallbacks::create(bridge, mode).leakPtr());
+        commonClient->openFileSystem(type, size, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     }
 }
 
+void WorkerFileSystemCallbacksBridge::moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->move(sourcePath, destinationPath, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->copy(sourcePath, destinationPath, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->remove(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::readMetadataOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->readMetadata(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::createFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->createFile(path, exclusive, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::createDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->createDirectory(path, exclusive, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::fileExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->fileExists(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->directoryExists(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
+void WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
+{
+    fileSystem->readDirectory(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+}
+
 void WorkerFileSystemCallbacksBridge::didFailOnMainThread(WebFileError error, const String& mode)
 {
-    ASSERT(isMainThread());
-    mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, m_selfRef, error), mode);
+    mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, this, error), mode);
 }
 
 void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnMainThread(const String& name, const String& rootPath, const String& mode)
 {
-    ASSERT(isMainThread());
-    mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread, m_selfRef, name, rootPath), mode);
+    mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread, this, name, rootPath), mode);
+}
+
+void WorkerFileSystemCallbacksBridge::didSucceedOnMainThread(const String& mode)
+{
+    mayPostTaskToWorker(createCallbackTask(&didSucceedOnWorkerThread, this), mode);
+}
+
+void WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread(const WebFileInfo& info, const String& mode)
+{
+    mayPostTaskToWorker(createCallbackTask(&didReadMetadataOnWorkerThread, this, info), mode);
+}
+
+void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>& entries, bool hasMore, const String& mode)
+{
+    mayPostTaskToWorker(createCallbackTask(&didReadDirectoryOnWorkerThread, this, entries, hasMore), mode);
 }
 
 WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge(WebWorkerBase* worker, ScriptExecutionContext* scriptExecutionContext, WebFileSystemCallbacks* callbacks)
@@ -157,30 +299,79 @@ WorkerFileSystemCallbacksBridge::~WorkerFileSystemCallbacksBridge()
     ASSERT(!m_callbacksOnWorkerThread);
 }
 
-void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, WebFileError error)
+void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, WebFileError error)
 {
-    if (bridge->m_callbacksOnWorkerThread) {
-        ASSERT(bridge->m_workerContext->isContextThread());
-        bridge->m_callbacksOnWorkerThread->didFail(error);
-        bridge->m_callbacksOnWorkerThread = 0;
-    }
+    bridge->m_callbacksOnWorkerThread->didFail(error);
 }
 
-void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& name, const String& rootPath)
+void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const String& name, const String& rootPath)
 {
-    if (bridge->m_callbacksOnWorkerThread) {
-        ASSERT(bridge->m_workerContext->isContextThread());
-        bridge->m_callbacksOnWorkerThread->didOpenFileSystem(name, rootPath);
-        bridge->m_callbacksOnWorkerThread = 0;
+    bridge->m_callbacksOnWorkerThread->didOpenFileSystem(name, rootPath);
+}
+
+void WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge)
+{
+    bridge->m_callbacksOnWorkerThread->didSucceed();
+}
+
+void WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const WebFileInfo& info)
+{
+    bridge->m_callbacksOnWorkerThread->didReadMetadata(info);
+}
+
+void WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const WebVector<WebFileSystemEntry>& entries, bool hasMore)
+{
+    bridge->m_callbacksOnWorkerThread->didReadDirectory(entries, hasMore);
+}
+
+bool WorkerFileSystemCallbacksBridge::derefIfWorkerIsStopped()
+{
+    WebWorkerBase* worker = 0;
+    {
+        MutexLocker locker(m_mutex);
+        worker = m_worker;
+    }
+
+    if (!worker) {
+        m_selfRef.clear();
+        return true;
     }
+    return false;
+}
+
+void WorkerFileSystemCallbacksBridge::runTaskOnMainThread(WebCore::ScriptExecutionContext* scriptExecutionContext, WorkerFileSystemCallbacksBridge* bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun)
+{
+    ASSERT(isMainThread());
+    if (bridge->derefIfWorkerIsStopped())
+        return;
+    taskToRun->performTask(scriptExecutionContext);
+}
+
+void WorkerFileSystemCallbacksBridge::runTaskOnWorkerThread(WebCore::ScriptExecutionContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun)
+{
+    if (!bridge->m_callbacksOnWorkerThread)
+        return;
+    ASSERT(bridge->m_workerContext->isContextThread());
+    taskToRun->performTask(scriptExecutionContext);
+    bridge->m_callbacksOnWorkerThread = 0;
+}
+
+void WorkerFileSystemCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task> task)
+{
+    ASSERT(!m_selfRef);
+    ASSERT(m_worker);
+    ASSERT(m_workerContext->isContextThread());
+    m_selfRef = this;
+    m_worker->dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThread, this, task));
 }
 
 void WorkerFileSystemCallbacksBridge::mayPostTaskToWorker(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
 {
+    ASSERT(isMainThread());
     { // Let go of the mutex before possibly deleting this due to m_selfRef.clear().
         MutexLocker locker(m_mutex);
         if (m_worker)
-            m_worker->postTaskForModeToWorkerContext(task, mode);
+            m_worker->postTaskForModeToWorkerContext(createCallbackTask(&runTaskOnWorkerThread, m_selfRef, task), mode);
     }
     m_selfRef.clear();
 }
diff --git a/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h b/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h
index 899127e..f692559 100644
--- a/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h
+++ b/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h
@@ -68,10 +68,6 @@ struct WebFileSystemEntry;
 //      releases a self-reference to the bridge.
 class WorkerFileSystemCallbacksBridge : public ThreadSafeShared<WorkerFileSystemCallbacksBridge>, public WebCore::WorkerContext::Observer {
 public:
-    static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebWorkerBase* worker, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacks* callbacks)
-    {
-        return WTF::adoptRef(new WorkerFileSystemCallbacksBridge(worker, workerContext, callbacks));
-    }
     ~WorkerFileSystemCallbacksBridge();
 
     // WorkerContext::Observer method.
@@ -82,26 +78,62 @@ public:
 
     void stop();
 
-    // Posts an initial request task to the main thread. It is supposed to be called immediately after the bridge is constructed. (It doesn't check if the context has been stopped or not.)
+    static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebWorkerBase* worker, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacks* callbacks)
+    {
+        return adoptRef(new WorkerFileSystemCallbacksBridge(worker, workerContext, callbacks));
+    }
+
+    // Methods that create an instance and post an initial request task to the main thread. They must be called on the worker thread.
     void postOpenFileSystemToMainThread(WebCommonWorkerClient*, WebFileSystem::Type, long long size, const String& mode);
+    void postMoveToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode);
+    void postCopyToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode);
+    void postRemoveToMainThread(WebFileSystem*, const String& path, const String& mode);
+    void postReadMetadataToMainThread(WebFileSystem*, const String& path, const String& mode);
+    void postCreateFileToMainThread(WebFileSystem*, const String& path, bool exclusive, const String& mode);
+    void postCreateDirectoryToMainThread(WebFileSystem*, const String& path, bool exclusive, const String& mode);
+    void postFileExistsToMainThread(WebFileSystem*, const String& path, const String& mode);
+    void postDirectoryExistsToMainThread(WebFileSystem*, const String& path, const String& mode);
+    void postReadDirectoryToMainThread(WebFileSystem*, const String& path, const String& mode);
 
     // Callback methods that are called on the main thread.
     void didFailOnMainThread(WebFileError, const String& mode);
     void didOpenFileSystemOnMainThread(const String& name, const String& rootPath, const String& mode);
+    void didSucceedOnMainThread(const String& mode);
+    void didReadMetadataOnMainThread(const WebFileInfo&, const String& mode);
+    void didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>&, bool hasMore, const String& mode);
 
 private:
     WorkerFileSystemCallbacksBridge(WebWorkerBase*, WebCore::ScriptExecutionContext*, WebFileSystemCallbacks*);
 
-    // Method that is to be called on the main thread.
+    // Methods that are to be called on the main thread.
     static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, WebCommonWorkerClient*, WebFileSystem::Type, long long size, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void readMetadataOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void createFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void createDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void fileExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void directoryExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
+    static void readDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
 
     friend class MainThreadFileSystemCallbacks;
 
     // Methods that dispatch WebFileSystemCallbacks on the worker threads.
     // They release a selfRef of the WorkerFileSystemCallbacksBridge.
-    static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, WebFileError);
-    static void didOpenFileSystemOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& name, const String& rootPath);
+    static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, WebFileError);
+    static void didOpenFileSystemOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const String& name, const String& rootPath);
+    static void didSucceedOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*);
+    static void didReadMetadataOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const WebFileInfo&);
+    static void didReadDirectoryOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const WebVector<WebFileSystemEntry>&, bool hasMore);
+
+    // For early-exist; this deref's selfRef and returns true if the worker is already null.
+    bool derefIfWorkerIsStopped();
+
+    static void runTaskOnMainThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
+    static void runTaskOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
 
+    void dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
     void mayPostTaskToWorker(PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const String& mode);
 
     // m_selfRef keeps a reference to itself until a task is created for the worker thread (at which point the task holds the reference).

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list