Title: [145771] trunk/Source
Revision
145771
Author
micha...@google.com
Date
2013-03-13 17:01:24 -0700 (Wed, 13 Mar 2013)

Log Message

Source/WebCore: FileSystem mods: Changes to snapshot file creation to reduce dependencies on blob URLs.
Adding a new minimal BlobDataHandle class which will be reimplemented/built upon in later CLs. In this
patch, it's just enough to refactor the FileSystem code to not function in terms of blobURLs.
https://bugs.webkit.org/show_bug.cgi?id=108851

Reviewed by Adam Barth.

No new tests. This is strictly a refactoring of the existing code.

* Modules/filesystem/DOMFileSystem.cpp:
(WebCore):
(WebCore::DOMFileSystem::createFile):
* Modules/filesystem/DOMFileSystemSync.cpp:
(WebCore):
* platform/AsyncFileSystemCallbacks.h:
(AsyncFileSystemCallbacks):
(WebCore::AsyncFileSystemCallbacks::didCreateSnapshotFile):
* platform/gtk/AsyncFileSystemGtk.cpp:
(WebCore::AsyncFileSystemGtk::createSnapshotFileAndReadMetadata):
(WebCore):
* platform/network/BlobData.cpp:
(WebCore):
(WebCore::BlobDataHandle::BlobDataHandle):
(WebCore::BlobDataHandle::~BlobDataHandle):
* platform/network/BlobData.h:
(WebCore):
(BlobDataHandle):
(WebCore::BlobDataHandle::create):

Source/WebKit/chromium: [Chromium] FileSystem mods: Changes to snapshot file creation to reduce dependencies on blobs.
No longer send a |blobURL| to the browser process, no longer expect the browser process
to have registered a blob with that url.
https://bugs.webkit.org/show_bug.cgi?id=108851

Reviewed by Adam Barth.

* src/AsyncFileSystemChromium.cpp:
(WebCore):
(WebCore::FileWriterHelperCallbacks::didCreateSnapshotFile):
(WebCore::AsyncFileSystemChromium::createSnapshotFileAndReadMetadata):
* src/AsyncFileSystemChromium.h:
(AsyncFileSystemChromium):
* src/LocalFileSystemChromium.cpp:
(WebCore):
* src/WebFileSystemCallbacksImpl.cpp:
(WebKit::WebFileSystemCallbacksImpl::didCreateSnapshotFile):
(WebKit):
* src/WebFileSystemCallbacksImpl.h:
(WebCore):
(WebFileSystemCallbacksImpl):
* src/WorkerAsyncFileSystemChromium.cpp:
(WebCore::WorkerAsyncFileSystemChromium::createSnapshotFileAndReadMetadata):
(WebCore::WorkerAsyncFileSystemChromium::createWorkerFileSystemCallbacksBridge):
* src/WorkerFileSystemCallbacksBridge.cpp:
(WebKit::MainThreadFileSystemCallbacks::didCreateSnapshotFile):
(MainThreadFileSystemCallbacks):
(WebKit::WorkerFileSystemCallbacksBridge::postCreateSnapshotFileToMainThread):
(WebKit::WorkerFileSystemCallbacksBridge::createSnapshotFileOnMainThread):
(WebKit::WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnMainThread):
(WebKit):
(WebKit::WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge):
(WebKit::WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnWorkerThread):
* src/WorkerFileSystemCallbacksBridge.h:
(WebCore):
(WebKit):
(WebKit::WorkerFileSystemCallbacksBridge::create):
(WorkerFileSystemCallbacksBridge):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (145770 => 145771)


--- trunk/Source/WebCore/ChangeLog	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebCore/ChangeLog	2013-03-14 00:01:24 UTC (rev 145771)
@@ -1,3 +1,34 @@
+2013-03-13  Michael Nordman  <micha...@google.com>
+
+        FileSystem mods: Changes to snapshot file creation to reduce dependencies on blob URLs.
+        Adding a new minimal BlobDataHandle class which will be reimplemented/built upon in later CLs. In this
+        patch, it's just enough to refactor the FileSystem code to not function in terms of blobURLs.
+        https://bugs.webkit.org/show_bug.cgi?id=108851
+
+        Reviewed by Adam Barth.
+
+        No new tests. This is strictly a refactoring of the existing code.
+
+        * Modules/filesystem/DOMFileSystem.cpp:
+        (WebCore):
+        (WebCore::DOMFileSystem::createFile):
+        * Modules/filesystem/DOMFileSystemSync.cpp:
+        (WebCore):
+        * platform/AsyncFileSystemCallbacks.h:
+        (AsyncFileSystemCallbacks):
+        (WebCore::AsyncFileSystemCallbacks::didCreateSnapshotFile):
+        * platform/gtk/AsyncFileSystemGtk.cpp:
+        (WebCore::AsyncFileSystemGtk::createSnapshotFileAndReadMetadata):
+        (WebCore):
+        * platform/network/BlobData.cpp:
+        (WebCore):
+        (WebCore::BlobDataHandle::BlobDataHandle):
+        (WebCore::BlobDataHandle::~BlobDataHandle):
+        * platform/network/BlobData.h:
+        (WebCore):
+        (BlobDataHandle):
+        (WebCore::BlobDataHandle::create):
+
 2013-03-13  Ryosuke Niwa  <rn...@webkit.org>
 
         Threaded HTML Parser is missing feature define flags in all but Chromium port's build files

Modified: trunk/Source/WebCore/Modules/filesystem/DOMFileSystem.cpp (145770 => 145771)


--- trunk/Source/WebCore/Modules/filesystem/DOMFileSystem.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebCore/Modules/filesystem/DOMFileSystem.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -148,19 +148,24 @@
 
 namespace {
 
-class GetMetadataCallback : public FileSystemCallbacksBase {
+class SnapshotFileCallback : public FileSystemCallbacksBase {
 public:
-    static PassOwnPtr<GetMetadataCallback> create(PassRefPtr<DOMFileSystem> filesystem, const String& name, const KURL& url, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+    static PassOwnPtr<SnapshotFileCallback> create(PassRefPtr<DOMFileSystem> filesystem, const String& name, const KURL& url, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
     {
-        return adoptPtr(new GetMetadataCallback(filesystem, name, url, successCallback, errorCallback));
+        return adoptPtr(new SnapshotFileCallback(filesystem, name, url, successCallback, errorCallback));
     }
 
-    virtual void didReadMetadata(const FileMetadata& metadata)
+    virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr<BlobDataHandle> snapshot)
     {
         ASSERT(!metadata.platformPath.isEmpty());
         if (!m_successCallback)
             return;
 
+        // We can't directly use the snapshot blob data handle because the content type on it hasn't been set.
+        // The |snapshot| param is here to provide a a chain of custody thru thread bridging that is held onto until
+        // *after* we've coined a File with a new handle that has the correct type set on it. This allows the
+        // blob storage system to track when a temp file can and can't be safely deleted.
+
         // For regular filesystem types (temporary or persistent), we should not cache file metadata as it could change File semantics.
         // For other filesystem types (which could be platform-specific ones), there's a chance that the files are on remote filesystem. If the port has returned metadata just pass it to File constructor (so we may cache the metadata).
         // FIXME: We should use the snapshot metadata for all files.
@@ -179,7 +184,7 @@
     }
 
 private:
-    GetMetadataCallback(PassRefPtr<DOMFileSystem> filesystem, const String& name,  const KURL& url, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+    SnapshotFileCallback(PassRefPtr<DOMFileSystem> filesystem, const String& name,  const KURL& url, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
         : FileSystemCallbacksBase(errorCallback)
         , m_filesystem(filesystem)
         , m_name(name)
@@ -199,7 +204,7 @@
 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
 {
     KURL fileSystemURL = createFileSystemURL(fileEntry);
-    m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileSystemURL, GetMetadataCallback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCallback));
+    m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCallback));
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/filesystem/DOMFileSystemSync.cpp (145770 => 145771)


--- trunk/Source/WebCore/Modules/filesystem/DOMFileSystemSync.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebCore/Modules/filesystem/DOMFileSystemSync.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -113,10 +113,16 @@
     {
     }
 
-    void didReadMetadata(const FileMetadata& metadata)
+    virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr<BlobDataHandle> snapshot)
     {
+        // We can't directly use the snapshot blob data handle because the content type on it hasn't been set.
+        // The |snapshot| param is here to provide a a chain of custody thru thread bridging that is held onto until
+        // *after* we've coined a File with a new handle that has the correct type set on it. This allows the
+        // blob storage system to track when a temp file can and can't be safely deleted.
+
         // For regular filesystem types (temporary or persistent), we should not cache file metadata as it could change File semantics.
-        // For other filesystem types (which could be platform-specific ones), there's a chance that the files are on remote filesystem. If the port has returned metadata just pass it to File constructor (so we may cache the metadata).
+        // For other filesystem types (which could be platform-specific ones), there's a chance that the files are on remote filesystem.
+        // If the port has returned metadata just pass it to File constructor (so we may cache the metadata).
         // FIXME: We should use the snapshot metadata for all files.
         // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746
         if (m_type == FileSystemTypeTemporary || m_type == FileSystemTypePersistent) {

Modified: trunk/Source/WebCore/platform/AsyncFileSystemCallbacks.h (145770 => 145771)


--- trunk/Source/WebCore/platform/AsyncFileSystemCallbacks.h	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebCore/platform/AsyncFileSystemCallbacks.h	2013-03-14 00:01:24 UTC (rev 145771)
@@ -35,6 +35,7 @@
 
 #include "AsyncFileSystem.h"
 #include "AsyncFileWriter.h"
+#include "BlobData.h"
 #include "FileMetadata.h"
 #include <wtf/text/WTFString.h>
 
@@ -54,6 +55,9 @@
     // Called when a file metadata is read successfully.
     virtual void didReadMetadata(const FileMetadata&) { ASSERT_NOT_REACHED(); }
 
+    // Called when a snapshot file is created successfully.
+    virtual void didCreateSnapshotFile(const FileMetadata&, PassRefPtr<BlobDataHandle> snapshot) { ASSERT_NOT_REACHED(); }
+
     // Called when a directory entry is read.
     virtual void didReadDirectoryEntry(const String& name, bool isDirectory) { ASSERT_NOT_REACHED(); }
 

Modified: trunk/Source/WebCore/platform/gtk/AsyncFileSystemGtk.cpp (145770 => 145771)


--- trunk/Source/WebCore/platform/gtk/AsyncFileSystemGtk.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebCore/platform/gtk/AsyncFileSystemGtk.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -118,6 +118,11 @@
     notImplemented();
 }
 
+void AsyncFileSystemGtk::createSnapshotFileAndReadMetadata(const KURL&, PassOwnPtr<AsyncFileSystemCallbacks>)
+{
+    notImplemented();
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/platform/network/BlobData.cpp (145770 => 145771)


--- trunk/Source/WebCore/platform/network/BlobData.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebCore/platform/network/BlobData.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -30,6 +30,8 @@
 
 #include "config.h"
 #include "BlobData.h"
+#include "BlobURL.h"
+#include "ThreadableBlobRegistry.h"
 
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -101,4 +103,17 @@
     m_items.swap(items);
 }
 
+
+BlobDataHandle::BlobDataHandle(PassOwnPtr<BlobData> data, long long size)
+{
+    UNUSED_PARAM(size);
+    m_internalURL = BlobURL::createInternalURL();
+    ThreadableBlobRegistry::registerBlobURL(m_internalURL, data);
+}
+
+BlobDataHandle::~BlobDataHandle()
+{
+    ThreadableBlobRegistry::unregisterBlobURL(m_internalURL);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/network/BlobData.h (145770 => 145771)


--- trunk/Source/WebCore/platform/network/BlobData.h	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebCore/platform/network/BlobData.h	2013-03-14 00:01:24 UTC (rev 145771)
@@ -202,6 +202,23 @@
     BlobDataItemList m_items;
 };
 
+// FIXME: This class is mostly place holder until I get farther along with
+// https://bugs.webkit.org/show_bug.cgi?id=108733 and more specifically with landing
+// https://codereview.chromium.org/11192017/.
+class BlobDataHandle : public ThreadSafeRefCounted<BlobDataHandle> {
+public:
+    static PassRefPtr<BlobDataHandle> create(PassOwnPtr<BlobData> data, long long size)
+    {
+        return adoptRef(new BlobDataHandle(data, size));
+    }
+
+    ~BlobDataHandle();
+
+private:
+    BlobDataHandle(PassOwnPtr<BlobData>, long long size);
+    KURL m_internalURL;
+};
+
 } // namespace WebCore
 
 #endif // BlobData_h

Modified: trunk/Source/WebKit/chromium/ChangeLog (145770 => 145771)


--- trunk/Source/WebKit/chromium/ChangeLog	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/ChangeLog	2013-03-14 00:01:24 UTC (rev 145771)
@@ -1,3 +1,44 @@
+2013-03-13  Michael Nordman  <micha...@google.com>
+
+        [Chromium] FileSystem mods: Changes to snapshot file creation to reduce dependencies on blobs.
+        No longer send a |blobURL| to the browser process, no longer expect the browser process
+        to have registered a blob with that url.
+        https://bugs.webkit.org/show_bug.cgi?id=108851
+
+        Reviewed by Adam Barth.
+
+        * src/AsyncFileSystemChromium.cpp:
+        (WebCore):
+        (WebCore::FileWriterHelperCallbacks::didCreateSnapshotFile):
+        (WebCore::AsyncFileSystemChromium::createSnapshotFileAndReadMetadata):
+        * src/AsyncFileSystemChromium.h:
+        (AsyncFileSystemChromium):
+        * src/LocalFileSystemChromium.cpp:
+        (WebCore):
+        * src/WebFileSystemCallbacksImpl.cpp:
+        (WebKit::WebFileSystemCallbacksImpl::didCreateSnapshotFile):
+        (WebKit):
+        * src/WebFileSystemCallbacksImpl.h:
+        (WebCore):
+        (WebFileSystemCallbacksImpl):
+        * src/WorkerAsyncFileSystemChromium.cpp:
+        (WebCore::WorkerAsyncFileSystemChromium::createSnapshotFileAndReadMetadata):
+        (WebCore::WorkerAsyncFileSystemChromium::createWorkerFileSystemCallbacksBridge):
+        * src/WorkerFileSystemCallbacksBridge.cpp:
+        (WebKit::MainThreadFileSystemCallbacks::didCreateSnapshotFile):
+        (MainThreadFileSystemCallbacks):
+        (WebKit::WorkerFileSystemCallbacksBridge::postCreateSnapshotFileToMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::createSnapshotFileOnMainThread):
+        (WebKit::WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnMainThread):
+        (WebKit):
+        (WebKit::WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge):
+        (WebKit::WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnWorkerThread):
+        * src/WorkerFileSystemCallbacksBridge.h:
+        (WebCore):
+        (WebKit):
+        (WebKit::WorkerFileSystemCallbacksBridge::create):
+        (WorkerFileSystemCallbacksBridge):
+
 2013-03-13  Adam Barth  <aba...@webkit.org>
 
         [Chromium] Restrict WebNode::addEventListener and friends to a whitelist of event types

Modified: trunk/Source/WebKit/chromium/src/AsyncFileSystemChromium.cpp (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/AsyncFileSystemChromium.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/AsyncFileSystemChromium.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -48,46 +48,6 @@
 
 namespace WebCore {
 
-namespace {
-
-// Specialized callback class for createSnapshotFileAndReadMetadata.
-class SnapshotFileCallbacks : public AsyncFileSystemCallbacks {
-public:
-    static PassOwnPtr<SnapshotFileCallbacks> create(const KURL& internalBlobURL, PassOwnPtr<WebCore::AsyncFileSystemCallbacks> callbacks)
-    {
-        return adoptPtr(new SnapshotFileCallbacks(internalBlobURL, callbacks));
-    }
-
-    virtual void didReadMetadata(const FileMetadata& metadata)
-    {
-        ASSERT(m_callbacks);
-
-        // This will create a new File object using the metadata.
-        m_callbacks->didReadMetadata(metadata);
-
-        // Now that we've registered the snapshot file, we can unregister our internalBlobURL which has played a placeholder for the file during the IPC.
-        ThreadableBlobRegistry::unregisterBlobURL(m_internalBlobURL);
-    }
-
-    virtual void didFail(int error)
-    {
-        ASSERT(m_callbacks);
-        m_callbacks->didFail(error);
-    }
-
-private:
-    SnapshotFileCallbacks(const KURL& internalBlobURL, PassOwnPtr<WebCore::AsyncFileSystemCallbacks> callbacks)
-        : m_internalBlobURL(internalBlobURL)
-        , m_callbacks(callbacks)
-    {
-    }
-
-    KURL m_internalBlobURL;
-    OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks;
-};
-
-} // namespace
-
 bool AsyncFileSystem::isAvailable()
 {
     return true;
@@ -186,7 +146,11 @@
         }
         delete this;
     }
-
+    virtual void didCreateSnapshotFile(const WebKit::WebFileInfo& info)
+    {
+        ASSERT_NOT_REACHED();
+        delete this;
+    }
     virtual void didReadDirectory(const WebKit::WebVector<WebKit::WebFileSystemEntry>& entries, bool hasMore)
     {
         ASSERT_NOT_REACHED();
@@ -219,17 +183,9 @@
 
 void AsyncFileSystemChromium::createSnapshotFileAndReadMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
 {
-    KURL internalBlobURL = BlobURL::createInternalURL();
-
-    // This will create a snapshot file and register the file to a blob using the given internalBlobURL.
-    m_webFileSystem->createSnapshotFileAndReadMetadata(internalBlobURL, path, new WebKit::WebFileSystemCallbacksImpl(createSnapshotFileCallback(internalBlobURL, callbacks)));
+    m_webFileSystem->createSnapshotFileAndReadMetadata(path, new WebKit::WebFileSystemCallbacksImpl(callbacks));
 }
 
-PassOwnPtr<AsyncFileSystemCallbacks> AsyncFileSystemChromium::createSnapshotFileCallback(const KURL& internalBlobURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) const
-{
-    return SnapshotFileCallbacks::create(internalBlobURL, callbacks);
-}
-
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebKit/chromium/src/AsyncFileSystemChromium.h (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/AsyncFileSystemChromium.h	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/AsyncFileSystemChromium.h	2013-03-14 00:01:24 UTC (rev 145771)
@@ -69,8 +69,6 @@
 protected:
     AsyncFileSystemChromium();
 
-    PassOwnPtr<AsyncFileSystemCallbacks> createSnapshotFileCallback(const KURL& internalBlobURL, PassOwnPtr<AsyncFileSystemCallbacks>) const;
-
     WebKit::WebFileSystem* m_webFileSystem;
 };
 

Modified: trunk/Source/WebKit/chromium/src/LocalFileSystemChromium.cpp (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/LocalFileSystemChromium.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/LocalFileSystemChromium.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -153,7 +153,7 @@
     return bridge->result();
 }
 
-void openFileSystemForWorker(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, WebFileSystemCallbacks* callbacks, FileSystemSynchronousType synchronousType)
+void openFileSystemForWorker(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, WebFileSystemCallbacksImpl* callbacks, FileSystemSynchronousType synchronousType)
 {
     WorkerScriptController* controller = WorkerScriptController::controllerForContext();
     WorkerContext* workerContext = controller->workerContext();

Modified: trunk/Source/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -76,6 +76,27 @@
     delete this;
 }
 
+void WebFileSystemCallbacksImpl::didCreateSnapshotFile(const WebFileInfo& webFileInfo)
+{
+    // It's important to create a BlobDataHandle that refers to the platform file path prior
+    // to return from this method so the underlying file will not be deleted.
+    OwnPtr<BlobData> blobData = BlobData::create();
+    blobData->appendFile(webFileInfo.platformPath);
+    RefPtr<BlobDataHandle> snapshotBlob = BlobDataHandle::create(blobData.release(), webFileInfo.length);
+    didCreateSnapshotFile(webFileInfo, snapshotBlob);
+}
+
+void WebFileSystemCallbacksImpl::didCreateSnapshotFile(const WebFileInfo& webFileInfo, PassRefPtr<WebCore::BlobDataHandle> snapshot)
+{
+    FileMetadata fileMetadata;
+    fileMetadata.modificationTime = webFileInfo.modificationTime;
+    fileMetadata.length = webFileInfo.length;
+    fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type);
+    fileMetadata.platformPath = webFileInfo.platformPath;
+    m_callbacks->didCreateSnapshotFile(fileMetadata, snapshot);
+    delete this;
+}
+
 void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
 {
     for (size_t i = 0; i < entries.size(); ++i)

Modified: trunk/Source/WebKit/chromium/src/WebFileSystemCallbacksImpl.h (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/WebFileSystemCallbacksImpl.h	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/WebFileSystemCallbacksImpl.h	2013-03-14 00:01:24 UTC (rev 145771)
@@ -40,6 +40,7 @@
 
 namespace WebCore {
 class AsyncFileSystemCallbacks;
+class BlobDataHandle;
 class ScriptExecutionContext;
 }
 
@@ -56,11 +57,17 @@
     virtual ~WebFileSystemCallbacksImpl();
 
     virtual void didSucceed();
-    virtual void didReadMetadata(const WebFileInfo& info);
+    virtual void didReadMetadata(const WebFileInfo&);
+    virtual void didCreateSnapshotFile(const WebFileInfo&);
     virtual void didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore);
     virtual void didOpenFileSystem(const WebString& name, const WebURL& rootURL);
     virtual void didFail(WebFileError error);
 
+    // This internal overload is used by WorkerFileSystemCallbacksBridge to deliver a blob data handle
+    // created on the main thread to an AsyncFileSystemCallback on a background worker thread. The other
+    // virtual method is invoked by the embedder.
+    void didCreateSnapshotFile(const WebFileInfo&, PassRefPtr<WebCore::BlobDataHandle> snapshot);
+
 private:
     OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks;
 

Modified: trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -179,15 +179,12 @@
 
 void WorkerAsyncFileSystemChromium::createSnapshotFileAndReadMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
 {
-    KURL internalBlobURL = BlobURL::createInternalURL();
-
-    createWorkerFileSystemCallbacksBridge(createSnapshotFileCallback(internalBlobURL, callbacks))->postCreateSnapshotFileToMainThread(m_webFileSystem, internalBlobURL, path, m_modeForCurrentOperation);
+    createWorkerFileSystemCallbacksBridge(callbacks)->postCreateSnapshotFileToMainThread(m_webFileSystem, path, m_modeForCurrentOperation);
 }
 
 PassRefPtr<WorkerFileSystemCallbacksBridge> WorkerAsyncFileSystemChromium::createWorkerFileSystemCallbacksBridge(PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
 {
     ASSERT(m_synchronousType == AsynchronousFileSystem || !m_bridgeForCurrentOperation);
-    (void)m_synchronousType;
 
     m_modeForCurrentOperation = fileSystemOperationsMode;
     m_modeForCurrentOperation.append(String::number(m_workerContext->thread()->runLoop().createUniqueId()));

Modified: trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp	2013-03-14 00:01:24 UTC (rev 145771)
@@ -33,16 +33,17 @@
 
 #if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
 
+#include "BlobData.h"
 #include "CrossThreadTask.h"
 #include "KURL.h"
 #include "WebCommonWorkerClient.h"
+#include "WebFileSystemCallbacksImpl.h"
 #include "WebWorkerBase.h"
 #include "WorkerContext.h"
 #include "WorkerLoaderProxy.h"
 #include "WorkerScriptController.h"
 #include "WorkerThread.h"
 #include <public/WebFileInfo.h>
-#include <public/WebFileSystemCallbacks.h>
 #include <public/WebFileSystemEntry.h>
 #include <public/WebString.h>
 #include <public/WebURL.h>
@@ -124,6 +125,17 @@
         delete this;
     }
 
+    virtual void didCreateSnapshotFile(const WebFileInfo& info)
+    {
+        // It's important to create a BlobDataHandle that refers to the platform file path prior
+        // to return from this method so the underlying file will not be deleted.
+        OwnPtr<BlobData> blobData = BlobData::create();
+        blobData->appendFile(info.platformPath);
+        RefPtr<BlobDataHandle> snapshotBlob = BlobDataHandle::create(blobData.release(), info.length);
+        m_bridge->didCreateSnapshotFileOnMainThread(info, m_mode, snapshotBlob);
+        delete this;
+    }
+
     virtual void didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
     {
         m_bridge->didReadDirectoryOnMainThread(entries, hasMore, m_mode);
@@ -289,13 +301,13 @@
                            this, mode));
 }
 
-void WorkerFileSystemCallbacksBridge::postCreateSnapshotFileToMainThread(WebFileSystem* fileSystem, const KURL& internalBlobURL, const KURL& path, const String& mode)
+void WorkerFileSystemCallbacksBridge::postCreateSnapshotFileToMainThread(WebFileSystem* fileSystem, const KURL& path, const String& mode)
 {
     ASSERT(fileSystem);
     dispatchTaskToMainThread(
         createCallbackTask(&createSnapshotFileOnMainThread,
                            AllowCrossThreadAccess(fileSystem),
-                           internalBlobURL, path, this, mode));
+                           path, this, mode));
 }
 
 void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
@@ -357,9 +369,9 @@
     fileSystem->readDirectory(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
 }
 
-void WorkerFileSystemCallbacksBridge::createSnapshotFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const KURL& internalBlobURL, const KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
+void WorkerFileSystemCallbacksBridge::createSnapshotFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
 {
-    fileSystem->createSnapshotFileAndReadMetadata(internalBlobURL, path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
+    fileSystem->createSnapshotFileAndReadMetadata(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
 }
 
 void WorkerFileSystemCallbacksBridge::didFailOnMainThread(WebFileError error, const String& mode)
@@ -383,6 +395,11 @@
     mayPostTaskToWorker(createCallbackTask(&didReadMetadataOnWorkerThread, this, info), mode);
 }
 
+void WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnMainThread(const WebFileInfo& info, const String& mode, PassRefPtr<BlobDataHandle> snapshotBlob)
+{
+    mayPostTaskToWorker(createCallbackTask(&didCreateSnapshotFileOnWorkerThread, this, info, snapshotBlob), mode);
+}
+
 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>& entries, bool hasMore, const String& mode)
 {
     mayPostTaskToWorker(
@@ -390,7 +407,7 @@
                            this, entries, hasMore), mode);
 }
 
-WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge(WebCore::WorkerLoaderProxy* workerLoaderProxy, ScriptExecutionContext* scriptExecutionContext, WebFileSystemCallbacks* callbacks)
+WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge(WebCore::WorkerLoaderProxy* workerLoaderProxy, ScriptExecutionContext* scriptExecutionContext, WebFileSystemCallbacksImpl* callbacks)
     : m_workerLoaderProxy(workerLoaderProxy)
     , m_workerContext(scriptExecutionContext)
     , m_workerContextObserver(WorkerFileSystemContextObserver::create(static_cast<WorkerContext*>(m_workerContext), this).leakPtr())
@@ -424,6 +441,11 @@
     bridge->m_callbacksOnWorkerThread->didReadMetadata(info);
 }
 
+void WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const WebFileInfo& info, PassRefPtr<BlobDataHandle> snapshotBlob)
+{
+    bridge->m_callbacksOnWorkerThread->didCreateSnapshotFile(info, snapshotBlob);
+}
+
 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const WebVector<WebFileSystemEntry>& entries, bool hasMore)
 {
     bridge->m_callbacksOnWorkerThread->didReadDirectory(entries, hasMore);

Modified: trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h (145770 => 145771)


--- trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h	2013-03-13 23:16:28 UTC (rev 145770)
+++ trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h	2013-03-14 00:01:24 UTC (rev 145771)
@@ -43,6 +43,7 @@
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
+class BlobDataHandle;
 class WorkerLoaderProxy;
 }
 
@@ -52,7 +53,7 @@
 class MainThreadFileSystemCallbacks;
 class WebCommonWorkerClient;
 class ThreadableCallbacksBridgeWrapper;
-class WebFileSystemCallbacks;
+class WebFileSystemCallbacksImpl;
 class WorkerFileSystemContextObserver;
 struct WebFileInfo;
 struct WebFileSystemEntry;
@@ -77,7 +78,7 @@
 
     void stop();
 
-    static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebCore::WorkerLoaderProxy* workerLoaderProxy, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacks* callbacks)
+    static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebCore::WorkerLoaderProxy* workerLoaderProxy, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacksImpl* callbacks)
     {
         return adoptRef(new WorkerFileSystemCallbacksBridge(workerLoaderProxy, workerContext, callbacks));
     }
@@ -94,17 +95,18 @@
     void postFileExistsToMainThread(WebFileSystem*, const WebCore::KURL& path, const String& mode);
     void postDirectoryExistsToMainThread(WebFileSystem*, const WebCore::KURL& path, const String& mode);
     void postReadDirectoryToMainThread(WebFileSystem*, const WebCore::KURL& path, const String& mode);
-    void postCreateSnapshotFileToMainThread(WebFileSystem*, const WebCore::KURL& internalBlobURL, const WebCore::KURL& path, const String& mode);
+    void postCreateSnapshotFileToMainThread(WebFileSystem*, const WebCore::KURL& 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 WebCore::KURL& rootURL, const String& mode);
     void didSucceedOnMainThread(const String& mode);
     void didReadMetadataOnMainThread(const WebFileInfo&, const String& mode);
+    void didCreateSnapshotFileOnMainThread(const WebFileInfo&, const String& mode, PassRefPtr<WebCore::BlobDataHandle> snapshotBlob);
     void didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>&, bool hasMore, const String& mode);
 
 private:
-    WorkerFileSystemCallbacksBridge(WebCore::WorkerLoaderProxy*, WebCore::ScriptExecutionContext*, WebFileSystemCallbacks*);
+    WorkerFileSystemCallbacksBridge(WebCore::WorkerLoaderProxy*, WebCore::ScriptExecutionContext*, WebFileSystemCallbacksImpl*);
 
     // Methods that are to be called on the main thread.
     static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, WebCommonWorkerClient*, WebFileSystem::Type, long long size, bool create, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& mode);
@@ -118,7 +120,7 @@
     static void fileExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& mode);
     static void directoryExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& mode);
     static void readDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& mode);
-    static void createSnapshotFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& internalBlobURL, const WebCore::KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& mode);
+    static void createSnapshotFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& mode);
 
     friend class MainThreadFileSystemCallbacks;
 
@@ -127,6 +129,7 @@
     static void didOpenFileSystemOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& name, const WebCore::KURL& rootPath);
     static void didSucceedOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>);
     static void didReadMetadataOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, const WebFileInfo&);
+    static void didCreateSnapshotFileOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, const WebFileInfo&, PassRefPtr<WebCore::BlobDataHandle> snapshotBlob);
     static void didReadDirectoryOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, const WebVector<WebFileSystemEntry>&, bool hasMore);
 
     static void runTaskOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
@@ -146,7 +149,7 @@
     WorkerFileSystemContextObserver* m_workerContextObserver;
 
     // This is self-destructed and must be fired on the worker thread.
-    WebFileSystemCallbacks* m_callbacksOnWorkerThread;
+    WebFileSystemCallbacksImpl* m_callbacksOnWorkerThread;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to