| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2010 Google Inc. All rights reserved. | 2  * Copyright (C) 2010 Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions are | 5  * modification, are permitted provided that the following conditions are | 
| 6  * met: | 6  * met: | 
| 7  * | 7  * | 
| 8  *     * Redistributions of source code must retain the above copyright | 8  *     * Redistributions of source code must retain the above copyright | 
| 9  * notice, this list of conditions and the following disclaimer. | 9  * notice, this list of conditions and the following disclaimer. | 
| 10  *     * Redistributions in binary form must reproduce the above | 10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 34 #include "WebFileSystemCallbacksImpl.h" | 34 #include "WebFileSystemCallbacksImpl.h" | 
| 35 #include "WebFileWriter.h" | 35 #include "WebFileWriter.h" | 
| 36 #include "WorkerAsyncFileWriterChromium.h" | 36 #include "WorkerAsyncFileWriterChromium.h" | 
| 37 #include "WorkerFileSystemCallbacksBridge.h" | 37 #include "WorkerFileSystemCallbacksBridge.h" | 
| 38 #include "bindings/v8/WorkerScriptController.h" | 38 #include "bindings/v8/WorkerScriptController.h" | 
| 39 #include "core/fileapi/BlobURL.h" | 39 #include "core/fileapi/BlobURL.h" | 
| 40 #include "core/platform/AsyncFileSystemCallbacks.h" | 40 #include "core/platform/AsyncFileSystemCallbacks.h" | 
| 41 #include "core/platform/FileMetadata.h" | 41 #include "core/platform/FileMetadata.h" | 
| 42 #include "core/platform/FileSystem.h" | 42 #include "core/platform/FileSystem.h" | 
| 43 #include "core/platform/NotImplemented.h" | 43 #include "core/platform/NotImplemented.h" | 
| 44 #include "core/workers/WorkerContext.h" | 44 #include "core/workers/WorkerGlobalScope.h" | 
| 45 #include "core/workers/WorkerThread.h" | 45 #include "core/workers/WorkerThread.h" | 
| 46 #include "public/platform/WebFileSystem.h" | 46 #include "public/platform/WebFileSystem.h" | 
| 47 #include <wtf/text/CString.h> | 47 #include <wtf/text/CString.h> | 
| 48 | 48 | 
| 49 using namespace WebKit; | 49 using namespace WebKit; | 
| 50 | 50 | 
| 51 namespace WebCore { | 51 namespace WebCore { | 
| 52 | 52 | 
| 53 static const char fileSystemOperationsMode[] = "fileSystemOperationsMode"; | 53 static const char fileSystemOperationsMode[] = "fileSystemOperationsMode"; | 
| 54 | 54 | 
| 55 WorkerAsyncFileSystemChromium::WorkerAsyncFileSystemChromium(ScriptExecutionCont
     ext* context, FileSystemSynchronousType synchronousType) | 55 WorkerAsyncFileSystemChromium::WorkerAsyncFileSystemChromium(ScriptExecutionCont
     ext* context, FileSystemSynchronousType synchronousType) | 
| 56     : m_scriptExecutionContext(context) | 56     : m_scriptExecutionContext(context) | 
| 57     , m_workerContext(static_cast<WorkerContext*>(context)) | 57     , m_workerGlobalScope(static_cast<WorkerGlobalScope*>(context)) | 
| 58     , m_synchronousType(synchronousType) | 58     , m_synchronousType(synchronousType) | 
| 59 { | 59 { | 
| 60     ASSERT(m_scriptExecutionContext->isWorkerContext()); | 60     ASSERT(m_scriptExecutionContext->isWorkerGlobalScope()); | 
| 61 | 61 | 
| 62     m_workerLoaderProxy = &m_workerContext->thread()->workerLoaderProxy(); | 62     m_workerLoaderProxy = &m_workerGlobalScope->thread()->workerLoaderProxy(); | 
| 63 } | 63 } | 
| 64 | 64 | 
| 65 WorkerAsyncFileSystemChromium::~WorkerAsyncFileSystemChromium() | 65 WorkerAsyncFileSystemChromium::~WorkerAsyncFileSystemChromium() | 
| 66 { | 66 { | 
| 67 } | 67 } | 
| 68 | 68 | 
| 69 bool WorkerAsyncFileSystemChromium::waitForOperationToComplete() | 69 bool WorkerAsyncFileSystemChromium::waitForOperationToComplete() | 
| 70 { | 70 { | 
| 71     if (!m_bridgeForCurrentOperation) | 71     if (!m_bridgeForCurrentOperation) | 
| 72         return false; | 72         return false; | 
| 73 | 73 | 
| 74     RefPtr<WorkerFileSystemCallbacksBridge> bridge = m_bridgeForCurrentOperation
     .release(); | 74     RefPtr<WorkerFileSystemCallbacksBridge> bridge = m_bridgeForCurrentOperation
     .release(); | 
| 75     if (m_workerContext->thread()->runLoop().runInMode(m_workerContext, m_modeFo
     rCurrentOperation) == MessageQueueTerminated) { | 75     if (m_workerGlobalScope->thread()->runLoop().runInMode(m_workerGlobalScope, 
     m_modeForCurrentOperation) == MessageQueueTerminated) { | 
| 76         bridge->stop(); | 76         bridge->stop(); | 
| 77         return false; | 77         return false; | 
| 78     } | 78     } | 
| 79     return true; | 79     return true; | 
| 80 } | 80 } | 
| 81 | 81 | 
| 82 void WorkerAsyncFileSystemChromium::move(const KURL& sourcePath, const KURL& des
     tinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 82 void WorkerAsyncFileSystemChromium::move(const KURL& sourcePath, const KURL& des
     tinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 
| 83 { | 83 { | 
| 84     createWorkerFileSystemCallbacksBridge(callbacks)->postMoveToMainThread(m_web
     FileSystem, sourcePath, destinationPath, m_modeForCurrentOperation); | 84     createWorkerFileSystemCallbacksBridge(callbacks)->postMoveToMainThread(m_web
     FileSystem, sourcePath, destinationPath, m_modeForCurrentOperation); | 
| 85 } | 85 } | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 124     createWorkerFileSystemCallbacksBridge(callbacks)->postDirectoryExistsToMainT
     hread(m_webFileSystem, path, m_modeForCurrentOperation); | 124     createWorkerFileSystemCallbacksBridge(callbacks)->postDirectoryExistsToMainT
     hread(m_webFileSystem, path, m_modeForCurrentOperation); | 
| 125 } | 125 } | 
| 126 | 126 | 
| 127 void WorkerAsyncFileSystemChromium::readDirectory(const KURL& path, PassOwnPtr<A
     syncFileSystemCallbacks> callbacks) | 127 void WorkerAsyncFileSystemChromium::readDirectory(const KURL& path, PassOwnPtr<A
     syncFileSystemCallbacks> callbacks) | 
| 128 { | 128 { | 
| 129     createWorkerFileSystemCallbacksBridge(callbacks)->postReadDirectoryToMainThr
     ead(m_webFileSystem, path, m_modeForCurrentOperation); | 129     createWorkerFileSystemCallbacksBridge(callbacks)->postReadDirectoryToMainThr
     ead(m_webFileSystem, path, m_modeForCurrentOperation); | 
| 130 } | 130 } | 
| 131 | 131 | 
| 132 class WorkerFileWriterHelperCallbacks : public AsyncFileSystemCallbacks { | 132 class WorkerFileWriterHelperCallbacks : public AsyncFileSystemCallbacks { | 
| 133 public: | 133 public: | 
| 134     static PassOwnPtr<WorkerFileWriterHelperCallbacks> create(AsyncFileWriterCli
     ent* client, const WebURL& path, WebKit::WebFileSystem* webFileSystem, PassOwnPt
     r<WebCore::AsyncFileSystemCallbacks> callbacks, WorkerContext* workerContext) | 134     static PassOwnPtr<WorkerFileWriterHelperCallbacks> create(AsyncFileWriterCli
     ent* client, const WebURL& path, WebKit::WebFileSystem* webFileSystem, PassOwnPt
     r<WebCore::AsyncFileSystemCallbacks> callbacks, WorkerGlobalScope* workerGlobalS
     cope) | 
| 135     { | 135     { | 
| 136         return adoptPtr(new WorkerFileWriterHelperCallbacks(client, path, webFil
     eSystem, callbacks, workerContext)); | 136         return adoptPtr(new WorkerFileWriterHelperCallbacks(client, path, webFil
     eSystem, callbacks, workerGlobalScope)); | 
| 137     } | 137     } | 
| 138 | 138 | 
| 139     virtual void didReadMetadata(const FileMetadata& metadata) | 139     virtual void didReadMetadata(const FileMetadata& metadata) | 
| 140     { | 140     { | 
| 141         ASSERT(m_callbacks); | 141         ASSERT(m_callbacks); | 
| 142         if (metadata.type != FileMetadata::TypeFile || metadata.length < 0) | 142         if (metadata.type != FileMetadata::TypeFile || metadata.length < 0) | 
| 143             m_callbacks->didFail(WebKit::WebFileErrorInvalidState); | 143             m_callbacks->didFail(WebKit::WebFileErrorInvalidState); | 
| 144         else { | 144         else { | 
| 145             OwnPtr<WorkerAsyncFileWriterChromium> asyncFileWriterChromium = Work
     erAsyncFileWriterChromium::create(m_webFileSystem, m_path, m_workerContext, m_cl
     ient, WorkerAsyncFileWriterChromium::Asynchronous); | 145             OwnPtr<WorkerAsyncFileWriterChromium> asyncFileWriterChromium = Work
     erAsyncFileWriterChromium::create(m_webFileSystem, m_path, m_workerGlobalScope, 
     m_client, WorkerAsyncFileWriterChromium::Asynchronous); | 
| 146             m_callbacks->didCreateFileWriter(asyncFileWriterChromium.release(), 
     metadata.length); | 146             m_callbacks->didCreateFileWriter(asyncFileWriterChromium.release(), 
     metadata.length); | 
| 147         } | 147         } | 
| 148     } | 148     } | 
| 149 | 149 | 
| 150     virtual void didFail(int code) | 150     virtual void didFail(int code) | 
| 151     { | 151     { | 
| 152         ASSERT(m_callbacks); | 152         ASSERT(m_callbacks); | 
| 153         m_callbacks->didFail(code); | 153         m_callbacks->didFail(code); | 
| 154     } | 154     } | 
| 155 | 155 | 
| 156 private: | 156 private: | 
| 157     WorkerFileWriterHelperCallbacks(AsyncFileWriterClient* client, const WebURL&
      path, WebKit::WebFileSystem* webFileSystem, PassOwnPtr<WebCore::AsyncFileSystem
     Callbacks> callbacks, WorkerContext* workerContext) | 157     WorkerFileWriterHelperCallbacks(AsyncFileWriterClient* client, const WebURL&
      path, WebKit::WebFileSystem* webFileSystem, PassOwnPtr<WebCore::AsyncFileSystem
     Callbacks> callbacks, WorkerGlobalScope* workerGlobalScope) | 
| 158         : m_client(client) | 158         : m_client(client) | 
| 159         , m_path(path) | 159         , m_path(path) | 
| 160         , m_webFileSystem(webFileSystem) | 160         , m_webFileSystem(webFileSystem) | 
| 161         , m_callbacks(callbacks) | 161         , m_callbacks(callbacks) | 
| 162         , m_workerContext(workerContext) | 162         , m_workerGlobalScope(workerGlobalScope) | 
| 163     { | 163     { | 
| 164     } | 164     } | 
| 165 | 165 | 
| 166     AsyncFileWriterClient* m_client; | 166     AsyncFileWriterClient* m_client; | 
| 167     WebURL m_path; | 167     WebURL m_path; | 
| 168     WebKit::WebFileSystem* m_webFileSystem; | 168     WebKit::WebFileSystem* m_webFileSystem; | 
| 169     OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks; | 169     OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks; | 
| 170     WorkerContext* m_workerContext; | 170     WorkerGlobalScope* m_workerGlobalScope; | 
| 171 }; | 171 }; | 
| 172 | 172 | 
| 173 void WorkerAsyncFileSystemChromium::createWriter(AsyncFileWriterClient* client, 
     const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 173 void WorkerAsyncFileSystemChromium::createWriter(AsyncFileWriterClient* client, 
     const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 
| 174 { | 174 { | 
| 175     createWorkerFileSystemCallbacksBridge(WorkerFileWriterHelperCallbacks::creat
     e(client, path, m_webFileSystem, callbacks, m_workerContext))->postReadMetadataT
     oMainThread(m_webFileSystem, path, m_modeForCurrentOperation); | 175     createWorkerFileSystemCallbacksBridge(WorkerFileWriterHelperCallbacks::creat
     e(client, path, m_webFileSystem, callbacks, m_workerGlobalScope))->postReadMetad
     ataToMainThread(m_webFileSystem, path, m_modeForCurrentOperation); | 
| 176 } | 176 } | 
| 177 | 177 | 
| 178 void WorkerAsyncFileSystemChromium::createSnapshotFileAndReadMetadata(const KURL
     & path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 178 void WorkerAsyncFileSystemChromium::createSnapshotFileAndReadMetadata(const KURL
     & path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 
| 179 { | 179 { | 
| 180     createWorkerFileSystemCallbacksBridge(callbacks)->postCreateSnapshotFileToMa
     inThread(m_webFileSystem, path, m_modeForCurrentOperation); | 180     createWorkerFileSystemCallbacksBridge(callbacks)->postCreateSnapshotFileToMa
     inThread(m_webFileSystem, path, m_modeForCurrentOperation); | 
| 181 } | 181 } | 
| 182 | 182 | 
| 183 PassRefPtr<WorkerFileSystemCallbacksBridge> WorkerAsyncFileSystemChromium::creat
     eWorkerFileSystemCallbacksBridge(PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 183 PassRefPtr<WorkerFileSystemCallbacksBridge> WorkerAsyncFileSystemChromium::creat
     eWorkerFileSystemCallbacksBridge(PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 
| 184 { | 184 { | 
| 185     ASSERT_UNUSED(m_synchronousType, m_synchronousType == AsynchronousFileSystem
      || !m_bridgeForCurrentOperation); | 185     ASSERT_UNUSED(m_synchronousType, m_synchronousType == AsynchronousFileSystem
      || !m_bridgeForCurrentOperation); | 
| 186 | 186 | 
| 187     m_modeForCurrentOperation = fileSystemOperationsMode; | 187     m_modeForCurrentOperation = fileSystemOperationsMode; | 
| 188     m_modeForCurrentOperation.append(String::number(m_workerContext->thread()->r
     unLoop().createUniqueId())); | 188     m_modeForCurrentOperation.append(String::number(m_workerGlobalScope->thread(
     )->runLoop().createUniqueId())); | 
| 189 | 189 | 
| 190     m_bridgeForCurrentOperation = WorkerFileSystemCallbacksBridge::create(m_work
     erLoaderProxy, m_scriptExecutionContext, new WebKit::WebFileSystemCallbacksImpl(
     callbacks)); | 190     m_bridgeForCurrentOperation = WorkerFileSystemCallbacksBridge::create(m_work
     erLoaderProxy, m_scriptExecutionContext, new WebKit::WebFileSystemCallbacksImpl(
     callbacks)); | 
| 191     return m_bridgeForCurrentOperation; | 191     return m_bridgeForCurrentOperation; | 
| 192 } | 192 } | 
| 193 | 193 | 
| 194 } // namespace WebCore | 194 } // namespace WebCore | 
| OLD | NEW | 
|---|