Changeset 68669 in webkit


Ignore:
Timestamp:
Sep 29, 2010 11:12:36 AM (14 years ago)
Author:
kinuko@chromium.org
Message:

2010-09-29 Kinuko Yasuda <kinuko@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:
Location:
trunk/WebKit/chromium
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r68666 r68669  
     12010-09-29  Kinuko Yasuda  <kinuko@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Bridge all FileSystem operations on Workers to the MainThread
     6        https://bugs.webkit.org/show_bug.cgi?id=46524
     7
     8        * src/LocalFileSystemChromium.cpp:
     9        (WebCore::LocalFileSystem::requestFileSystem): Changed the worker case
     10        code to create WebFileSystemCallbacksImpl with the current
     11        ScriptExecutionContext (WorkerContext).
     12        * src/WebFileSystemCallbacksImpl.cpp:
     13        (WebKit::WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl): Added
     14        a new constructor that takes ScriptExecutionContext (WorkerContext)
     15        for workers.
     16        (WebKit::WebFileSystemCallbacksImpl::didOpenFileSystem): Added the
     17        code for workers that creates WorkerAsyncFileSystemChromium.
     18        * src/WebFileSystemCallbacksImpl.h:
     19        * src/WorkerAsyncFileSystemChromium.cpp: Added.
     20        * src/WorkerAsyncFileSystemChromium.h: Added.
     21        * src/WorkerFileSystemCallbacksBridge.cpp: Added methods for regular
     22        file system operations to proxy them to the main thread.
     23        (WebKit::WorkerFileSystemCallbacksBridge::createForOpenFileSystem):
     24        (WebKit::WorkerFileSystemCallbacksBridge::createForMove):
     25        (WebKit::WorkerFileSystemCallbacksBridge::createForCopy):
     26        (WebKit::WorkerFileSystemCallbacksBridge::createForRemove):
     27        (WebKit::WorkerFileSystemCallbacksBridge::createForReadMetadata):
     28        (WebKit::WorkerFileSystemCallbacksBridge::createForCreateFile):
     29        (WebKit::WorkerFileSystemCallbacksBridge::createForCreateDirectory):
     30        (WebKit::WorkerFileSystemCallbacksBridge::createForFileExists):
     31        (WebKit::WorkerFileSystemCallbacksBridge::createForDirectoryExists):
     32        (WebKit::WorkerFileSystemCallbacksBridge::createForReadDirectory):
     33        (WebKit::MainThreadFileSystemCallbacks::didSucceed):
     34        (WebKit::MainThreadFileSystemCallbacks::didReadMetadata):
     35        (WebKit::MainThreadFileSystemCallbacks::didReadDirectory):
     36        (WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread):
     37        (WebKit::WorkerFileSystemCallbacksBridge::moveOnMainThread):
     38        (WebKit::WorkerFileSystemCallbacksBridge::copyOnMainThread):
     39        (WebKit::WorkerFileSystemCallbacksBridge::removeOnMainThread):
     40        (WebKit::WorkerFileSystemCallbacksBridge::readMetadataOnMainThread):
     41        (WebKit::WorkerFileSystemCallbacksBridge::createFileOnMainThread):
     42        (WebKit::WorkerFileSystemCallbacksBridge::createDirectoryOnMainThread):
     43        (WebKit::WorkerFileSystemCallbacksBridge::fileExistsOnMainThread):
     44        (WebKit::WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread):
     45        (WebKit::WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread):
     46        (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnMainThread):
     47        (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread):
     48        (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread):
     49        (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread):
     50        (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread):
     51        (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread):
     52        (WebKit::WorkerFileSystemCallbacksBridge::derefIfWorkerIsStopped):
     53        * src/WorkerFileSystemCallbacksBridge.h:
     54
    1552010-09-29  Matt Perry  <mpcomplete@chromium.org>
    256
  • trunk/WebKit/chromium/src/AsyncFileSystemChromium.cpp

    r68222 r68669  
    6262}
    6363
    64 void AsyncFileSystemChromium::move(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
     64void AsyncFileSystemChromium::move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
    6565{
    66     m_webFileSystem->move(srcPath, destPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
     66    m_webFileSystem->move(sourcePath, destinationPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
    6767}
    6868
    69 void AsyncFileSystemChromium::copy(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
     69void AsyncFileSystemChromium::copy(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
    7070{
    71     m_webFileSystem->copy(srcPath, destPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
     71    m_webFileSystem->copy(sourcePath, destinationPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));
    7272}
    7373
  • trunk/WebKit/chromium/src/AsyncFileSystemChromium.h

    r68180 r68669  
    3535
    3636#include "AsyncFileSystem.h"
    37 #include <wtf/PassRefPtr.h>
     37#include <wtf/PassOwnPtr.h>
    3838
    3939namespace WebKit {
     
    4747class AsyncFileSystemChromium : public AsyncFileSystem {
    4848public:
    49     AsyncFileSystemChromium(const String& rootPath);
     49    static PassOwnPtr<AsyncFileSystem> create(const String& rootPath)
     50    {
     51        return adoptPtr(new AsyncFileSystemChromium(rootPath));
     52    }
     53
    5054    virtual ~AsyncFileSystemChromium();
    5155
    52     virtual void move(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks>);
    53     virtual void copy(const String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks>);
     56    virtual void move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>);
     57    virtual void copy(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>);
    5458    virtual void remove(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
    5559    virtual void readMetadata(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>);
     
    6266
    6367private:
     68    explicit AsyncFileSystemChromium(const String& rootPath);
    6469    WebKit::WebFileSystem* m_webFileSystem;
    6570};
  • trunk/WebKit/chromium/src/LocalFileSystemChromium.cpp

    r68411 r68669  
    6969        WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
    7070        WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy);
    71         webWorker->openFileSystem(static_cast<WebFileSystem::Type>(type), size, new WebFileSystemCallbacksImpl(callbacks));
     71        webWorker->openFileSystem(static_cast<WebFileSystem::Type>(type), size, new WebFileSystemCallbacksImpl(callbacks, context));
    7272    }
    7373}
  • trunk/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp

    r66280 r68669  
    3535#include "AsyncFileSystemCallbacks.h"
    3636#include "AsyncFileSystemChromium.h"
    37 #include "ExceptionCode.h"
     37#include "ScriptExecutionContext.h"
    3838#include "WebFileSystemEntry.h"
    3939#include "WebFileInfo.h"
    4040#include "WebString.h"
     41#include "WorkerAsyncFileSystemChromium.h"
    4142#include <wtf/Vector.h>
    4243
     
    4546namespace WebKit {
    4647
    47 WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
     48WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks, WebCore::ScriptExecutionContext* context)
    4849    : m_callbacks(callbacks)
     50    , m_context(context)
    4951{
     52    ASSERT(m_callbacks);
    5053}
    5154
     
    5659void WebFileSystemCallbacksImpl::didSucceed()
    5760{
    58     ASSERT(m_callbacks);
    5961    m_callbacks->didSucceed();
    6062    delete this;
     
    6365void WebFileSystemCallbacksImpl::didReadMetadata(const WebFileInfo& info)
    6466{
    65     ASSERT(m_callbacks);
    6667    m_callbacks->didReadMetadata(info.modificationTime);
    6768    delete this;
     
    7071void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
    7172{
    72     ASSERT(m_callbacks);
    7373    for (size_t i = 0; i < entries.size(); ++i)
    7474        m_callbacks->didReadDirectoryEntry(entries[i].name, entries[i].isDirectory);
     
    8080void WebFileSystemCallbacksImpl::didOpenFileSystem(const WebString& name, const WebString& path)
    8181{
    82     m_callbacks->didOpenFileSystem(name, new AsyncFileSystemChromium(path));
     82    if (m_context && m_context->isWorkerContext())
     83        m_callbacks->didOpenFileSystem(name, WorkerAsyncFileSystemChromium::create(m_context, path));
     84    else
     85        m_callbacks->didOpenFileSystem(name, AsyncFileSystemChromium::create(path));
    8386    delete this;
    8487}
     
    8689void WebFileSystemCallbacksImpl::didFail(WebFileError error)
    8790{
    88     ASSERT(m_callbacks);
    8991    m_callbacks->didFail(error);
    9092    delete this;
  • trunk/WebKit/chromium/src/WebFileSystemCallbacksImpl.h

    r67919 r68669  
    3939namespace WebCore {
    4040class AsyncFileSystemCallbacks;
     41class ScriptExecutionContext;
    4142}
    4243
     
    4950class WebFileSystemCallbacksImpl : public WebFileSystemCallbacks {
    5051public:
    51     WebFileSystemCallbacksImpl(PassOwnPtr<WebCore::AsyncFileSystemCallbacks>);
     52    WebFileSystemCallbacksImpl(PassOwnPtr<WebCore::AsyncFileSystemCallbacks>, WebCore::ScriptExecutionContext* = 0);
    5253    virtual ~WebFileSystemCallbacksImpl();
    5354
     
    6061private:
    6162    OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks;
     63
     64    // Used for worker's openFileSystem callbacks.
     65    WebCore::ScriptExecutionContext* m_context;
    6266};
    6367
  • trunk/WebKit/chromium/src/WebWorkerBase.cpp

    r68226 r68669  
    241241{
    242242    WorkerScriptController* controller = WorkerScriptController::controllerForContext();
    243     WorkerContext* workerContext = controller->workerContext();
    244 
    245     RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBridge::create(this, workerContext, callbacks);
     243    RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBridge::create(this, controller->workerContext(), callbacks);
    246244    bridge->postOpenFileSystemToMainThread(commonClient(), type, size, openFileSystemMode);
    247245}
  • trunk/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp

    r68222 r68669  
    3636#include "CrossThreadTask.h"
    3737#include "WebCommonWorkerClient.h"
     38#include "WebFileInfo.h"
    3839#include "WebFileSystemCallbacks.h"
     40#include "WebFileSystemEntry.h"
    3941#include "WebString.h"
    4042#include "WebWorkerBase.h"
     
    4547#include <wtf/Threading.h>
    4648
     49namespace WebCore {
     50
     51template<> struct CrossThreadCopierBase<false, false, WebKit::WebFileInfo> {
     52    typedef WebKit::WebFileInfo Type;
     53    static Type copy(const WebKit::WebFileInfo& info)
     54    {
     55        // Perform per-field copy to make sure we don't do any (unexpected) non-thread safe copy here.
     56        struct WebKit::WebFileInfo newInfo;
     57        newInfo.modificationTime = info.modificationTime;
     58        newInfo.length = info.length;
     59        newInfo.type = info.type;
     60        return newInfo;
     61    }
     62};
     63
     64template<> struct CrossThreadCopierBase<false, false, WebKit::WebVector<WebKit::WebFileSystemEntry> > {
     65    typedef WebKit::WebVector<WebKit::WebFileSystemEntry> Type;
     66    static Type copy(const WebKit::WebVector<WebKit::WebFileSystemEntry>& entries)
     67    {
     68        WebKit::WebVector<WebKit::WebFileSystemEntry> newEntries(entries.size());
     69        for (size_t i = 0; i < entries.size(); ++i) {
     70            String name = entries[i].name;
     71            newEntries[i].isDirectory = entries[i].isDirectory;
     72            newEntries[i].name = name.crossThreadString();
     73        }
     74        return newEntries;
     75    }
     76};
     77
     78}
     79
    4780using namespace WebCore;
    4881
     
    5285class MainThreadFileSystemCallbacks : public WebFileSystemCallbacks {
    5386public:
    54     static PassOwnPtr<MainThreadFileSystemCallbacks> create(PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
    55     {
    56         return adoptPtr(new MainThreadFileSystemCallbacks(bridge, mode));
     87    // Callbacks are self-destructed and we always return leaked pointer here.
     88    static MainThreadFileSystemCallbacks* createLeakedPtr(PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
     89    {
     90        OwnPtr<MainThreadFileSystemCallbacks> callbacks = adoptPtr(new MainThreadFileSystemCallbacks(bridge, mode));
     91        return callbacks.leakPtr();
    5792    }
    5893
     
    75110    virtual void didSucceed()
    76111    {
    77         WEBKIT_ASSERT_NOT_REACHED();
     112        m_bridge->didSucceedOnMainThread(m_mode);
     113        delete this;
    78114    }
    79115
    80116    virtual void didReadMetadata(const WebFileInfo& info)
    81117    {
    82         WEBKIT_ASSERT_NOT_REACHED();
     118        m_bridge->didReadMetadataOnMainThread(info, m_mode);
     119        delete this;
    83120    }
    84121
    85122    virtual void didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
    86123    {
    87         WEBKIT_ASSERT_NOT_REACHED();
     124        m_bridge->didReadDirectoryOnMainThread(entries, hasMore, m_mode);
     125        delete this;
    88126    }
    89127
     
    115153void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, const String& mode)
    116154{
    117     m_selfRef = this;
    118     ASSERT(m_workerContext->isContextThread());
    119     ASSERT(m_worker);
    120     m_worker->dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, this, mode));
     155    dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, this, mode));
     156}
     157
     158void WorkerFileSystemCallbacksBridge::postMoveToMainThread(WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode)
     159{
     160    dispatchTaskToMainThread(createCallbackTask(&moveOnMainThread, fileSystem, sourcePath, destinationPath, this, mode));
     161}
     162
     163void WorkerFileSystemCallbacksBridge::postCopyToMainThread(WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode)
     164{
     165    dispatchTaskToMainThread(createCallbackTask(&copyOnMainThread, fileSystem, sourcePath, destinationPath, this, mode));
     166}
     167
     168void WorkerFileSystemCallbacksBridge::postRemoveToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
     169{
     170    ASSERT(fileSystem);
     171    dispatchTaskToMainThread(createCallbackTask(&removeOnMainThread, fileSystem, path, this, mode));
     172}
     173
     174void WorkerFileSystemCallbacksBridge::postReadMetadataToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
     175{
     176    ASSERT(fileSystem);
     177    dispatchTaskToMainThread(createCallbackTask(&readMetadataOnMainThread, fileSystem, path, this, mode));
     178}
     179
     180void WorkerFileSystemCallbacksBridge::postCreateFileToMainThread(WebFileSystem* fileSystem, const String& path, bool exclusive, const String& mode)
     181{
     182    dispatchTaskToMainThread(createCallbackTask(&createFileOnMainThread, fileSystem, path, exclusive, this, mode));
     183}
     184
     185void WorkerFileSystemCallbacksBridge::postCreateDirectoryToMainThread(WebFileSystem* fileSystem, const String& path, bool exclusive, const String& mode)
     186{
     187    ASSERT(fileSystem);
     188    dispatchTaskToMainThread(createCallbackTask(&createDirectoryOnMainThread, fileSystem, path, exclusive, this, mode));
     189}
     190
     191void WorkerFileSystemCallbacksBridge::postFileExistsToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
     192{
     193    ASSERT(fileSystem);
     194    dispatchTaskToMainThread(createCallbackTask(&fileExistsOnMainThread, fileSystem, path, this, mode));
     195}
     196
     197void WorkerFileSystemCallbacksBridge::postDirectoryExistsToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
     198{
     199    ASSERT(fileSystem);
     200    dispatchTaskToMainThread(createCallbackTask(&directoryExistsOnMainThread, fileSystem, path, this, mode));
     201}
     202
     203void WorkerFileSystemCallbacksBridge::postReadDirectoryToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode)
     204{
     205    ASSERT(fileSystem);
     206    dispatchTaskToMainThread(createCallbackTask(&readDirectoryOnMainThread, fileSystem, path, this, mode));
    121207}
    122208
    123209void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
    124210{
    125     ASSERT(isMainThread());
    126211    if (!commonClient)
    127212        bridge->didFailOnMainThread(WebFileErrorAbort, mode);
    128213    else {
    129         // MainThreadFileSystemCallbacks is self-destructed, so we leak ptr here.
    130         commonClient->openFileSystem(type, size, MainThreadFileSystemCallbacks::create(bridge, mode).leakPtr());
    131     }
     214        commonClient->openFileSystem(type, size, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     215    }
     216}
     217
     218void WorkerFileSystemCallbacksBridge::moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     219{
     220    fileSystem->move(sourcePath, destinationPath, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     221}
     222
     223void WorkerFileSystemCallbacksBridge::copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     224{
     225    fileSystem->copy(sourcePath, destinationPath, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     226}
     227
     228void WorkerFileSystemCallbacksBridge::removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     229{
     230    fileSystem->remove(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     231}
     232
     233void WorkerFileSystemCallbacksBridge::readMetadataOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     234{
     235    fileSystem->readMetadata(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     236}
     237
     238void WorkerFileSystemCallbacksBridge::createFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     239{
     240    fileSystem->createFile(path, exclusive, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     241}
     242
     243void WorkerFileSystemCallbacksBridge::createDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     244{
     245    fileSystem->createDirectory(path, exclusive, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     246}
     247
     248void WorkerFileSystemCallbacksBridge::fileExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     249{
     250    fileSystem->fileExists(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     251}
     252
     253void WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     254{
     255    fileSystem->directoryExists(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     256}
     257
     258void WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     259{
     260    fileSystem->readDirectory(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
    132261}
    133262
    134263void WorkerFileSystemCallbacksBridge::didFailOnMainThread(WebFileError error, const String& mode)
    135264{
    136     ASSERT(isMainThread());
    137     mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, m_selfRef, error), mode);
     265    mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, this, error), mode);
    138266}
    139267
    140268void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnMainThread(const String& name, const String& rootPath, const String& mode)
    141269{
    142     ASSERT(isMainThread());
    143     mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread, m_selfRef, name, rootPath), mode);
     270    mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread, this, name, rootPath), mode);
     271}
     272
     273void WorkerFileSystemCallbacksBridge::didSucceedOnMainThread(const String& mode)
     274{
     275    mayPostTaskToWorker(createCallbackTask(&didSucceedOnWorkerThread, this), mode);
     276}
     277
     278void WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread(const WebFileInfo& info, const String& mode)
     279{
     280    mayPostTaskToWorker(createCallbackTask(&didReadMetadataOnWorkerThread, this, info), mode);
     281}
     282
     283void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>& entries, bool hasMore, const String& mode)
     284{
     285    mayPostTaskToWorker(createCallbackTask(&didReadDirectoryOnWorkerThread, this, entries, hasMore), mode);
    144286}
    145287
     
    158300}
    159301
    160 void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, WebFileError error)
    161 {
    162     if (bridge->m_callbacksOnWorkerThread) {
    163         ASSERT(bridge->m_workerContext->isContextThread());
    164         bridge->m_callbacksOnWorkerThread->didFail(error);
    165         bridge->m_callbacksOnWorkerThread = 0;
    166     }
    167 }
    168 
    169 void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& name, const String& rootPath)
    170 {
    171     if (bridge->m_callbacksOnWorkerThread) {
    172         ASSERT(bridge->m_workerContext->isContextThread());
    173         bridge->m_callbacksOnWorkerThread->didOpenFileSystem(name, rootPath);
    174         bridge->m_callbacksOnWorkerThread = 0;
    175     }
     302void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, WebFileError error)
     303{
     304    bridge->m_callbacksOnWorkerThread->didFail(error);
     305}
     306
     307void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const String& name, const String& rootPath)
     308{
     309    bridge->m_callbacksOnWorkerThread->didOpenFileSystem(name, rootPath);
     310}
     311
     312void WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge)
     313{
     314    bridge->m_callbacksOnWorkerThread->didSucceed();
     315}
     316
     317void WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const WebFileInfo& info)
     318{
     319    bridge->m_callbacksOnWorkerThread->didReadMetadata(info);
     320}
     321
     322void WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const WebVector<WebFileSystemEntry>& entries, bool hasMore)
     323{
     324    bridge->m_callbacksOnWorkerThread->didReadDirectory(entries, hasMore);
     325}
     326
     327bool WorkerFileSystemCallbacksBridge::derefIfWorkerIsStopped()
     328{
     329    WebWorkerBase* worker = 0;
     330    {
     331        MutexLocker locker(m_mutex);
     332        worker = m_worker;
     333    }
     334
     335    if (!worker) {
     336        m_selfRef.clear();
     337        return true;
     338    }
     339    return false;
     340}
     341
     342void WorkerFileSystemCallbacksBridge::runTaskOnMainThread(WebCore::ScriptExecutionContext* scriptExecutionContext, WorkerFileSystemCallbacksBridge* bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun)
     343{
     344    ASSERT(isMainThread());
     345    if (bridge->derefIfWorkerIsStopped())
     346        return;
     347    taskToRun->performTask(scriptExecutionContext);
     348}
     349
     350void WorkerFileSystemCallbacksBridge::runTaskOnWorkerThread(WebCore::ScriptExecutionContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun)
     351{
     352    if (!bridge->m_callbacksOnWorkerThread)
     353        return;
     354    ASSERT(bridge->m_workerContext->isContextThread());
     355    taskToRun->performTask(scriptExecutionContext);
     356    bridge->m_callbacksOnWorkerThread = 0;
     357}
     358
     359void WorkerFileSystemCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task> task)
     360{
     361    ASSERT(!m_selfRef);
     362    ASSERT(m_worker);
     363    ASSERT(m_workerContext->isContextThread());
     364    m_selfRef = this;
     365    m_worker->dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThread, this, task));
    176366}
    177367
    178368void WorkerFileSystemCallbacksBridge::mayPostTaskToWorker(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
    179369{
     370    ASSERT(isMainThread());
    180371    { // Let go of the mutex before possibly deleting this due to m_selfRef.clear().
    181372        MutexLocker locker(m_mutex);
    182373        if (m_worker)
    183             m_worker->postTaskForModeToWorkerContext(task, mode);
     374            m_worker->postTaskForModeToWorkerContext(createCallbackTask(&runTaskOnWorkerThread, m_selfRef, task), mode);
    184375    }
    185376    m_selfRef.clear();
  • trunk/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h

    r68333 r68669  
    6969class WorkerFileSystemCallbacksBridge : public ThreadSafeShared<WorkerFileSystemCallbacksBridge>, public WebCore::WorkerContext::Observer {
    7070public:
    71     static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebWorkerBase* worker, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacks* callbacks)
    72     {
    73         return WTF::adoptRef(new WorkerFileSystemCallbacksBridge(worker, workerContext, callbacks));
    74     }
    7571    ~WorkerFileSystemCallbacksBridge();
    7672
     
    8379    void stop();
    8480
    85     // 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.)
     81    static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebWorkerBase* worker, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacks* callbacks)
     82    {
     83        return adoptRef(new WorkerFileSystemCallbacksBridge(worker, workerContext, callbacks));
     84    }
     85
     86    // Methods that create an instance and post an initial request task to the main thread. They must be called on the worker thread.
    8687    void postOpenFileSystemToMainThread(WebCommonWorkerClient*, WebFileSystem::Type, long long size, const String& mode);
     88    void postMoveToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode);
     89    void postCopyToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode);
     90    void postRemoveToMainThread(WebFileSystem*, const String& path, const String& mode);
     91    void postReadMetadataToMainThread(WebFileSystem*, const String& path, const String& mode);
     92    void postCreateFileToMainThread(WebFileSystem*, const String& path, bool exclusive, const String& mode);
     93    void postCreateDirectoryToMainThread(WebFileSystem*, const String& path, bool exclusive, const String& mode);
     94    void postFileExistsToMainThread(WebFileSystem*, const String& path, const String& mode);
     95    void postDirectoryExistsToMainThread(WebFileSystem*, const String& path, const String& mode);
     96    void postReadDirectoryToMainThread(WebFileSystem*, const String& path, const String& mode);
    8797
    8898    // Callback methods that are called on the main thread.
    8999    void didFailOnMainThread(WebFileError, const String& mode);
    90100    void didOpenFileSystemOnMainThread(const String& name, const String& rootPath, const String& mode);
     101    void didSucceedOnMainThread(const String& mode);
     102    void didReadMetadataOnMainThread(const WebFileInfo&, const String& mode);
     103    void didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>&, bool hasMore, const String& mode);
    91104
    92105private:
    93106    WorkerFileSystemCallbacksBridge(WebWorkerBase*, WebCore::ScriptExecutionContext*, WebFileSystemCallbacks*);
    94107
    95     // Method that is to be called on the main thread.
     108    // Methods that are to be called on the main thread.
    96109    static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, WebCommonWorkerClient*, WebFileSystem::Type, long long size, WorkerFileSystemCallbacksBridge*, const String& mode);
     110    static void moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
     111    static void copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
     112    static void removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
     113    static void readMetadataOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
     114    static void createFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge*, const String& mode);
     115    static void createDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge*, const String& mode);
     116    static void fileExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
     117    static void directoryExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
     118    static void readDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode);
    97119
    98120    friend class MainThreadFileSystemCallbacks;
     
    100122    // Methods that dispatch WebFileSystemCallbacks on the worker threads.
    101123    // They release a selfRef of the WorkerFileSystemCallbacksBridge.
    102     static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, WebFileError);
    103     static void didOpenFileSystemOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& name, const String& rootPath);
     124    static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, WebFileError);
     125    static void didOpenFileSystemOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const String& name, const String& rootPath);
     126    static void didSucceedOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*);
     127    static void didReadMetadataOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const WebFileInfo&);
     128    static void didReadDirectoryOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const WebVector<WebFileSystemEntry>&, bool hasMore);
    104129
     130    // For early-exist; this deref's selfRef and returns true if the worker is already null.
     131    bool derefIfWorkerIsStopped();
     132
     133    static void runTaskOnMainThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
     134    static void runTaskOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
     135
     136    void dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
    105137    void mayPostTaskToWorker(PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const String& mode);
    106138
Note: See TracChangeset for help on using the changeset viewer.