<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175782] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175782">175782</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2014-11-08 17:01:22 -0800 (Sat, 08 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Replace FileThread class with a single function
https://bugs.webkit.org/show_bug.cgi?id=138282

Reviewed by Alexey Proskuryakov.

Source/WebCore:

* CMakeLists.txt: Removed FileThread.cpp.

* WebCore.vcxproj/WebCore.vcxproj: Removed FileThread.cpp/.h.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto.

* bindings/generic/ActiveDOMCallback.cpp: Removed unneeded includes.
* dom/ActiveDOMObject.cpp: Ditto.

* fileapi/AsyncFileStream.cpp:
(WebCore::callOnFileThread): Added. Implements the file thread.
(WebCore::AsyncFileStream::AsyncFileStream): Take a reference to the client.
Make m_internals. Use the destroyed flag instead of trickier techniques to
handle stopping. Once the stream is destroyed, there will be no further callbacks.
(WebCore::AsyncFileStream::~AsyncFileStream): Added assertions and merged in the
stop behavior here. This class no longer requires an explicit stop function.
(WebCore::AsyncFileStream::perform): Added. Helper used for all the operations
below. Takes a function that performs an operation and then returns a client
callback function. Respects the m_stopped boolean on the file thread (so we
don't do extra operations) and on the client thread (so we are guaranteed not
to get any client callbacks even if the file thread was partway through an
operation).
(WebCore::AsyncFileStream::getSize): Changed to use the perform function.
(WebCore::AsyncFileStream::openForRead): Ditto. Also fixed reference count
thread safety issue by capturing a StringCapture rather than a String.
(WebCore::AsyncFileStream::openForWrite): Ditto.
(WebCore::AsyncFileStream::close): Changed to use callOnFileThread.
(WebCore::AsyncFileStream::read): Changed to use the perform function.
(WebCore::AsyncFileStream::write): Ditto. Also fixed reference count
thread safety issue by capturing a StringCapture rather than a URL.
(WebCore::AsyncFileStream::truncate): Ditto.

* fileapi/AsyncFileStream.h: Removed use of RefCounted since we only need
single ownership. Removed the stop function, since we can now stop when
the stream is destroyed since we have single ownership. Made a new Internals
object to handle destruction while operations are still going on the file thread.

* fileapi/FileThread.cpp: Removed.
* fileapi/FileThread.h: Removed.

* loader/ResourceLoader.cpp: Removed unneeded include.

* platform/FileStream.cpp:
(WebCore::FileStream::~FileStream): Merged the stop function in here.

* platform/FileStream.h: Removed use of RefCounted since we only need
single ownership. Removed the empty start function. Removed the stop function,
since we can now stop when the stream is destroyed since we have single ownership.

* platform/FileStreamClient.h: Removed unneeded didStart and didStop.

* platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::BlobResourceHandle): Use make_unique to make the
stream objects instead of custom create functions.
(WebCore::BlobResourceHandle::~BlobResourceHandle): Removed now-unneeded code
to call stop functions. Destroying the objects now takes care of the this, and
that's done by the unique_ptrs.
(WebCore::BlobResourceHandle::cancel): Removed the rest of the code to stop the
m_asyncStream, keeping only the code that sets it to null. That now stops the
stream by destroying it.

* platform/network/BlobResourceHandle.h: Use std::unique_ptr rather than
RefPtr for the file stream objects.

* storage/StorageThread.h: Tweaked formatting of std::function&lt;void()&gt; to
match the format used elsewhere in WebKit.

Source/WebKit:

* WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in:
Removed exports of obsolete threading functions.

Source/WTF:

* wtf/MessageQueue.h: Made queue work on any type and not require wrapping
everything in a unique_ptr.

* wtf/Threading.cpp:
(WTF::threadEntryPoint): Changed to use a std::function instead of a function pointer.
(WTF::createThread): Add a version that takes a std::function. Reimplemented the
old version using lambdas. Removed the obsolete versions that were there just to support
binary compatibility with very old versions of Safari.

* wtf/Threading.h: Removed an incorrect license header that covers code that was long ago
moved to a different file. Changed createThread to take a std::function instead of a function
pointer and data pointer. Moved internal functions after public functions.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfThreadingcpp">trunk/Source/WTF/wtf/Threading.cpp</a></li>
<li><a href="#trunkSourceWTFwtfThreadingh">trunk/Source/WTF/wtf/Threading.h</a></li>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxproj">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorebindingsgenericActiveDOMCallbackcpp">trunk/Source/WebCore/bindings/generic/ActiveDOMCallback.cpp</a></li>
<li><a href="#trunkSourceWebCoredomActiveDOMObjectcpp">trunk/Source/WebCore/dom/ActiveDOMObject.cpp</a></li>
<li><a href="#trunkSourceWebCorefileapiAsyncFileStreamcpp">trunk/Source/WebCore/fileapi/AsyncFileStream.cpp</a></li>
<li><a href="#trunkSourceWebCorefileapiAsyncFileStreamh">trunk/Source/WebCore/fileapi/AsyncFileStream.h</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadercpp">trunk/Source/WebCore/loader/ResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformFileStreamcpp">trunk/Source/WebCore/platform/FileStream.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformFileStreamh">trunk/Source/WebCore/platform/FileStream.h</a></li>
<li><a href="#trunkSourceWebCoreplatformFileStreamClienth">trunk/Source/WebCore/platform/FileStreamClient.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkBlobResourceHandlecpp">trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkBlobResourceHandleh">trunk/Source/WebCore/platform/network/BlobResourceHandle.h</a></li>
<li><a href="#trunkSourceWebCorestorageStorageThreadh">trunk/Source/WebCore/storage/StorageThread.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitWebKitvcxprojWebKitExportGeneratorWebKitExportsdefin">trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorefileapiFileThreadcpp">trunk/Source/WebCore/fileapi/FileThread.cpp</a></li>
<li><a href="#trunkSourceWebCorefileapiFileThreadh">trunk/Source/WebCore/fileapi/FileThread.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WTF/ChangeLog        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2014-11-08  Darin Adler  &lt;darin@apple.com&gt;
+
+        Replace FileThread class with a single function
+        https://bugs.webkit.org/show_bug.cgi?id=138282
+
+        Reviewed by Alexey Proskuryakov.
+
+        * wtf/MessageQueue.h: Made queue work on any type and not require wrapping
+        everything in a unique_ptr.
+
+        * wtf/Threading.cpp:
+        (WTF::threadEntryPoint): Changed to use a std::function instead of a function pointer.
+        (WTF::createThread): Add a version that takes a std::function. Reimplemented the
+        old version using lambdas. Removed the obsolete versions that were there just to support
+        binary compatibility with very old versions of Safari.
+
+        * wtf/Threading.h: Removed an incorrect license header that covers code that was long ago
+        moved to a different file. Changed createThread to take a std::function instead of a function
+        pointer and data pointer. Moved internal functions after public functions.
+
</ins><span class="cx"> 2014-11-05  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Assertion hit DOMTimer::updateTimerIntervalIfNecessary()
</span></span></pre></div>
<a id="trunkSourceWTFwtfThreadingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/Threading.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/Threading.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WTF/wtf/Threading.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2008, 2009, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -33,23 +33,14 @@
</span><span class="cx"> struct NewThreadContext {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    NewThreadContext(ThreadFunction entryPoint, void* data, const char* name)
-        : entryPoint(entryPoint)
-        , data(data)
-        , name(name)
-    {
-    }
-
-    ThreadFunction entryPoint;
-    void* data;
</del><span class="cx">     const char* name;
</span><del>-
</del><ins>+    std::function&lt;void()&gt; entryPoint;
</ins><span class="cx">     Mutex creationMutex;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> static void threadEntryPoint(void* contextData)
</span><span class="cx"> {
</span><del>-    NewThreadContext* context = reinterpret_cast&lt;NewThreadContext*&gt;(contextData);
</del><ins>+    NewThreadContext* context = static_cast&lt;NewThreadContext*&gt;(contextData);
</ins><span class="cx"> 
</span><span class="cx">     // Block until our creating thread has completed any extra setup work, including
</span><span class="cx">     // establishing ThreadIdentifier.
</span><span class="lines">@@ -59,15 +50,15 @@
</span><span class="cx"> 
</span><span class="cx">     initializeCurrentThreadInternal(context-&gt;name);
</span><span class="cx"> 
</span><del>-    // Grab the info that we need out of the context, then deallocate it.
-    ThreadFunction entryPoint = context-&gt;entryPoint;
-    void* data = context-&gt;data;
</del><ins>+    auto entryPoint = WTF::move(context-&gt;entryPoint);
+
+    // Delete the context before starting the thread.
</ins><span class="cx">     delete context;
</span><span class="cx"> 
</span><del>-    entryPoint(data);
</del><ins>+    entryPoint();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-ThreadIdentifier createThread(ThreadFunction entryPoint, void* data, const char* name)
</del><ins>+ThreadIdentifier createThread(const char* name, std::function&lt;void()&gt; entryPoint)
</ins><span class="cx"> {
</span><span class="cx">     // Visual Studio has a 31-character limit on thread names. Longer names will
</span><span class="cx">     // be truncated silently, but we'd like callers to know about the limit.
</span><span class="lines">@@ -76,7 +67,7 @@
</span><span class="cx">         LOG_ERROR(&quot;Thread name \&quot;%s\&quot; is longer than 31 characters and will be truncated by Visual Studio&quot;, name);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    NewThreadContext* context = new NewThreadContext(entryPoint, data, name);
</del><ins>+    NewThreadContext* context = new NewThreadContext { name, WTF::move(entryPoint), { } };
</ins><span class="cx"> 
</span><span class="cx">     // Prevent the thread body from executing until we've established the thread identifier.
</span><span class="cx">     MutexLocker locker(context-&gt;creationMutex);
</span><span class="lines">@@ -84,6 +75,13 @@
</span><span class="cx">     return createThreadInternal(threadEntryPoint, context, name);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+ThreadIdentifier createThread(ThreadFunction entryPoint, void* data, const char* name)
+{
+    return createThread(name, [entryPoint, data] {
+        entryPoint(data);
+    });
+}
+
</ins><span class="cx"> void setCurrentThreadIsUserInteractive()
</span><span class="cx"> {
</span><span class="cx"> #if HAVE(QOS_CLASSES)
</span><span class="lines">@@ -98,61 +96,4 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if PLATFORM(MAC) || PLATFORM(WIN)
-
-// For ABI compatibility with Safari on Mac / Windows: Safari uses the private
-// createThread() and waitForThreadCompletion() functions directly and we need
-// to keep the old ABI compatibility until it's been rebuilt.
-
-typedef void* (*ThreadFunctionWithReturnValue)(void* argument);
-
-WTF_EXPORT_PRIVATE ThreadIdentifier createThread(ThreadFunctionWithReturnValue entryPoint, void* data, const char* name);
-
-struct ThreadFunctionWithReturnValueInvocation {
-    ThreadFunctionWithReturnValueInvocation(ThreadFunctionWithReturnValue function, void* data)
-        : function(function)
-        , data(data)
-    {
-    }
-
-    ThreadFunctionWithReturnValue function;
-    void* data;
-};
-
-static void compatEntryPoint(void* param)
-{
-    // Balanced by .release() in createThread.
-    auto invocation = std::unique_ptr&lt;ThreadFunctionWithReturnValueInvocation&gt;(static_cast&lt;ThreadFunctionWithReturnValueInvocation*&gt;(param));
-    invocation-&gt;function(invocation-&gt;data);
-}
-
-ThreadIdentifier createThread(ThreadFunctionWithReturnValue entryPoint, void* data, const char* name)
-{
-    auto invocation = std::make_unique&lt;ThreadFunctionWithReturnValueInvocation&gt;(entryPoint, data);
-
-    // Balanced by std::unique_ptr constructor in compatEntryPoint.
-    return createThread(compatEntryPoint, invocation.release(), name);
-}
-
-WTF_EXPORT_PRIVATE int waitForThreadCompletion(ThreadIdentifier, void**);
-
-int waitForThreadCompletion(ThreadIdentifier threadID, void**)
-{
-    return waitForThreadCompletion(threadID);
-}
-
-// This function is deprecated but needs to be kept around for backward
-// compatibility. Use the 3-argument version of createThread above.
-
-WTF_EXPORT_PRIVATE ThreadIdentifier createThread(ThreadFunctionWithReturnValue entryPoint, void* data);
-
-ThreadIdentifier createThread(ThreadFunctionWithReturnValue entryPoint, void* data)
-{
-    auto invocation = std::make_unique&lt;ThreadFunctionWithReturnValueInvocation&gt;(entryPoint, data);
-
-    // Balanced by adoptPtr() in compatEntryPoint.
-    return createThread(compatEntryPoint, invocation.release(), 0);
-}
-#endif
-
</del><span class="cx"> } // namespace WTF
</span></span></pre></div>
<a id="trunkSourceWTFwtfThreadingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/Threading.h (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/Threading.h        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WTF/wtf/Threading.h        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2007, 2008, 2010, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -25,40 +25,16 @@
</span><span class="cx">  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
</span><span class="cx">  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
</span><span class="cx">  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><del>- *
- *
- * Note: The implementations of InterlockedIncrement and InterlockedDecrement are based
- * on atomic_increment and atomic_exchange_and_add from the Boost C++ Library. The license
- * is virtually identical to the Apple license above but is included here for completeness.
- *
- * Boost Software License - Version 1.0 - August 17th, 2003
- * 
- * Permission is hereby granted, free of charge, to any person or organization
- * obtaining a copy of the software and accompanying documentation covered by
- * this license (the &quot;Software&quot;) to use, reproduce, display, distribute,
- * execute, and transmit the Software, and to prepare derivative works of the
- * Software, and to permit third-parties to whom the Software is furnished to
- * do so, all subject to the following:
- * 
- * The copyright notices in the Software and this entire statement, including
- * the above license grant, this restriction and the following disclaimer,
- * must be included in all copies of the Software, in whole or in part, and
- * all derivative works of the Software, unless such copies or derivative
- * works are solely in the form of machine-executable object code generated by
- * a source language processor.
- * 
- * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
- * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
- * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
</del><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #ifndef Threading_h
</span><span class="cx"> #define Threading_h
</span><span class="cx"> 
</span><ins>+// FIXME: Not sure why there are so many includes here.
+// Is this intended to be convenience so that others don't have to include the individual files?
+// Nothing in this header depends on Assertions, Atomics, Locker, Noncopyable, ThreadSafeRefCounted, or ThreadingPrimitives.
+
+#include &lt;functional&gt;
</ins><span class="cx"> #include &lt;stdint.h&gt;
</span><span class="cx"> #include &lt;wtf/Assertions.h&gt;
</span><span class="cx"> #include &lt;wtf/Atomics.h&gt;
</span><span class="lines">@@ -79,13 +55,20 @@
</span><span class="cx"> 
</span><span class="cx"> // Returns 0 if thread creation failed.
</span><span class="cx"> // The thread name must be a literal since on some platforms it's passed in to the thread.
</span><del>-WTF_EXPORT_PRIVATE ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
</del><ins>+WTF_EXPORT_PRIVATE ThreadIdentifier createThread(const char* threadName, std::function&lt;void()&gt;);
</ins><span class="cx"> 
</span><span class="cx"> // Mark the current thread as requiring UI responsiveness.
</span><span class="cx"> WTF_EXPORT_PRIVATE void setCurrentThreadIsUserInteractive();
</span><del>-
</del><span class="cx"> WTF_EXPORT_PRIVATE void setCurrentThreadIsUserInitiated();
</span><span class="cx"> 
</span><ins>+WTF_EXPORT_PRIVATE ThreadIdentifier currentThread();
+WTF_EXPORT_PRIVATE void changeThreadPriority(ThreadIdentifier, int);
+WTF_EXPORT_PRIVATE int waitForThreadCompletion(ThreadIdentifier);
+WTF_EXPORT_PRIVATE void detachThread(ThreadIdentifier);
+
+// Deprecated function-pointer-based thread creation.
+WTF_EXPORT_PRIVATE ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
+
</ins><span class="cx"> // Internal platform-specific createThread implementation.
</span><span class="cx"> ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName);
</span><span class="cx"> 
</span><span class="lines">@@ -93,11 +76,6 @@
</span><span class="cx"> // Helpful for platforms where the thread name must be set from within the thread.
</span><span class="cx"> void initializeCurrentThreadInternal(const char* threadName);
</span><span class="cx"> 
</span><del>-WTF_EXPORT_PRIVATE ThreadIdentifier currentThread();
-WTF_EXPORT_PRIVATE void changeThreadPriority(ThreadIdentifier, int);
-WTF_EXPORT_PRIVATE int waitForThreadCompletion(ThreadIdentifier);
-WTF_EXPORT_PRIVATE void detachThread(ThreadIdentifier);
-
</del><span class="cx"> } // namespace WTF
</span><span class="cx"> 
</span><span class="cx"> using WTF::ThreadIdentifier;
</span></span></pre></div>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/CMakeLists.txt        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1505,7 +1505,6 @@
</span><span class="cx">     fileapi/FileReader.cpp
</span><span class="cx">     fileapi/FileReaderLoader.cpp
</span><span class="cx">     fileapi/FileReaderSync.cpp
</span><del>-    fileapi/FileThread.cpp
</del><span class="cx">     fileapi/ThreadableBlobRegistry.cpp
</span><span class="cx">     fileapi/WebKitBlobBuilder.cpp
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/ChangeLog        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,3 +1,77 @@
</span><ins>+2014-11-08  Darin Adler  &lt;darin@apple.com&gt;
+
+        Replace FileThread class with a single function
+        https://bugs.webkit.org/show_bug.cgi?id=138282
+
+        Reviewed by Alexey Proskuryakov.
+
+        * CMakeLists.txt: Removed FileThread.cpp.
+
+        * WebCore.vcxproj/WebCore.vcxproj: Removed FileThread.cpp/.h.
+        * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+
+        * bindings/generic/ActiveDOMCallback.cpp: Removed unneeded includes.
+        * dom/ActiveDOMObject.cpp: Ditto.
+
+        * fileapi/AsyncFileStream.cpp:
+        (WebCore::callOnFileThread): Added. Implements the file thread.
+        (WebCore::AsyncFileStream::AsyncFileStream): Take a reference to the client.
+        Make m_internals. Use the destroyed flag instead of trickier techniques to
+        handle stopping. Once the stream is destroyed, there will be no further callbacks.
+        (WebCore::AsyncFileStream::~AsyncFileStream): Added assertions and merged in the
+        stop behavior here. This class no longer requires an explicit stop function.
+        (WebCore::AsyncFileStream::perform): Added. Helper used for all the operations
+        below. Takes a function that performs an operation and then returns a client
+        callback function. Respects the m_stopped boolean on the file thread (so we
+        don't do extra operations) and on the client thread (so we are guaranteed not
+        to get any client callbacks even if the file thread was partway through an
+        operation).
+        (WebCore::AsyncFileStream::getSize): Changed to use the perform function.
+        (WebCore::AsyncFileStream::openForRead): Ditto. Also fixed reference count
+        thread safety issue by capturing a StringCapture rather than a String.
+        (WebCore::AsyncFileStream::openForWrite): Ditto.
+        (WebCore::AsyncFileStream::close): Changed to use callOnFileThread.
+        (WebCore::AsyncFileStream::read): Changed to use the perform function.
+        (WebCore::AsyncFileStream::write): Ditto. Also fixed reference count
+        thread safety issue by capturing a StringCapture rather than a URL.
+        (WebCore::AsyncFileStream::truncate): Ditto.
+
+        * fileapi/AsyncFileStream.h: Removed use of RefCounted since we only need
+        single ownership. Removed the stop function, since we can now stop when
+        the stream is destroyed since we have single ownership. Made a new Internals
+        object to handle destruction while operations are still going on the file thread.
+
+        * fileapi/FileThread.cpp: Removed.
+        * fileapi/FileThread.h: Removed.
+
+        * loader/ResourceLoader.cpp: Removed unneeded include.
+
+        * platform/FileStream.cpp:
+        (WebCore::FileStream::~FileStream): Merged the stop function in here.
+
+        * platform/FileStream.h: Removed use of RefCounted since we only need
+        single ownership. Removed the empty start function. Removed the stop function,
+        since we can now stop when the stream is destroyed since we have single ownership.
+
+        * platform/FileStreamClient.h: Removed unneeded didStart and didStop.
+
+        * platform/network/BlobResourceHandle.cpp:
+        (WebCore::BlobResourceHandle::BlobResourceHandle): Use make_unique to make the
+        stream objects instead of custom create functions.
+        (WebCore::BlobResourceHandle::~BlobResourceHandle): Removed now-unneeded code
+        to call stop functions. Destroying the objects now takes care of the this, and
+        that's done by the unique_ptrs.
+        (WebCore::BlobResourceHandle::cancel): Removed the rest of the code to stop the
+        m_asyncStream, keeping only the code that sets it to null. That now stops the
+        stream by destroying it.
+
+        * platform/network/BlobResourceHandle.h: Use std::unique_ptr rather than
+        RefPtr for the file stream objects.
+
+        * storage/StorageThread.h: Tweaked formatting of std::function&lt;void()&gt; to
+        match the format used elsewhere in WebKit.
+
</ins><span class="cx"> 2014-11-08  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Don't try to schedule a GraphicsLayer flush when propagating changes to replicas inside a flush
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -14935,7 +14935,6 @@
</span><span class="cx">     &lt;ClCompile Include=&quot;..\fileapi\FileReader.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\fileapi\FileReaderLoader.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\fileapi\FileReaderSync.cpp&quot; /&gt;
</span><del>-    &lt;ClCompile Include=&quot;..\fileapi\FileThread.cpp&quot; /&gt;
</del><span class="cx">     &lt;ClCompile Include=&quot;..\html\FormAssociatedElement.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\html\FormController.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\html\FormDataList.cpp&quot; /&gt;
</span><span class="lines">@@ -20714,7 +20713,6 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\fileapi\FileReaderLoader.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\fileapi\FileReaderLoaderClient.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\fileapi\FileReaderSync.h&quot; /&gt;
</span><del>-    &lt;ClInclude Include=&quot;..\fileapi\FileThread.h&quot; /&gt;
</del><span class="cx">     &lt;ClInclude Include=&quot;..\html\FormAssociatedElement.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\html\FormController.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\html\FormDataList.h&quot; /&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -3717,9 +3717,6 @@
</span><span class="cx">     &lt;ClCompile Include=&quot;..\fileapi\FileReaderSync.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;html&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><del>-    &lt;ClCompile Include=&quot;..\fileapi\FileThread.cpp&quot;&gt;
-      &lt;Filter&gt;html&lt;/Filter&gt;
-    &lt;/ClCompile&gt;
</del><span class="cx">     &lt;ClCompile Include=&quot;..\html\FormAssociatedElement.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;html&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><span class="lines">@@ -10869,9 +10866,6 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\fileapi\FileReaderSync.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;html&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span><del>-    &lt;ClInclude Include=&quot;..\fileapi\FileThread.h&quot;&gt;
-      &lt;Filter&gt;html&lt;/Filter&gt;
-    &lt;/ClInclude&gt;
</del><span class="cx">     &lt;ClInclude Include=&quot;..\html\FormAssociatedElement.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;html&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -3475,8 +3475,6 @@
</span><span class="cx">                 976D6C86122B8A3D001FD1F7 /* FileList.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C67122B8A3D001FD1F7 /* FileList.h */; };
</span><span class="cx">                 976D6C88122B8A3D001FD1F7 /* FileReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C69122B8A3D001FD1F7 /* FileReader.cpp */; };
</span><span class="cx">                 976D6C89122B8A3D001FD1F7 /* FileReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C6A122B8A3D001FD1F7 /* FileReader.h */; };
</span><del>-                976D6C8D122B8A3D001FD1F7 /* FileThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C6E122B8A3D001FD1F7 /* FileThread.cpp */; };
-                976D6C8E122B8A3D001FD1F7 /* FileThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C6F122B8A3D001FD1F7 /* FileThread.h */; };
</del><span class="cx">                 976D6C94122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C75122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp */; };
</span><span class="cx">                 976D6C95122B8A3D001FD1F7 /* ThreadableBlobRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C76122B8A3D001FD1F7 /* ThreadableBlobRegistry.h */; };
</span><span class="cx">                 976F36EA14686225005E93B4 /* SecurityContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976F36E814686225005E93B4 /* SecurityContext.cpp */; };
</span><span class="lines">@@ -10641,8 +10639,6 @@
</span><span class="cx">                 976D6C67122B8A3D001FD1F7 /* FileList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileList.h; path = fileapi/FileList.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 976D6C69122B8A3D001FD1F7 /* FileReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileReader.cpp; path = fileapi/FileReader.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 976D6C6A122B8A3D001FD1F7 /* FileReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileReader.h; path = fileapi/FileReader.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                976D6C6E122B8A3D001FD1F7 /* FileThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileThread.cpp; path = fileapi/FileThread.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
-                976D6C6F122B8A3D001FD1F7 /* FileThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileThread.h; path = fileapi/FileThread.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><span class="cx">                 976D6C75122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadableBlobRegistry.cpp; path = fileapi/ThreadableBlobRegistry.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 976D6C76122B8A3D001FD1F7 /* ThreadableBlobRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadableBlobRegistry.h; path = fileapi/ThreadableBlobRegistry.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 976F36E814686225005E93B4 /* SecurityContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityContext.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -18229,8 +18225,6 @@
</span><span class="cx">                                 2EDF369A122C94B4002F7D4E /* FileReaderSync.cpp */,
</span><span class="cx">                                 2EDF369B122C94B4002F7D4E /* FileReaderSync.h */,
</span><span class="cx">                                 E1AB1EBD14E9E3A800449E13 /* FileReaderSync.idl */,
</span><del>-                                976D6C6E122B8A3D001FD1F7 /* FileThread.cpp */,
-                                976D6C6F122B8A3D001FD1F7 /* FileThread.h */,
</del><span class="cx">                                 976D6C75122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp */,
</span><span class="cx">                                 976D6C76122B8A3D001FD1F7 /* ThreadableBlobRegistry.h */,
</span><span class="cx">                                 976D6C5C122B8A3D001FD1F7 /* WebKitBlobBuilder.cpp */,
</span><span class="lines">@@ -24324,7 +24318,6 @@
</span><span class="cx">                                 2EF1BFF9121CB0CE00C27627 /* FileStreamClient.h in Headers */,
</span><span class="cx">                                 514B3F730C722047000530DF /* FileSystem.h in Headers */,
</span><span class="cx">                                 26C17A3E1491D2D400D12BA2 /* FileSystemIOS.h in Headers */,
</span><del>-                                976D6C8E122B8A3D001FD1F7 /* FileThread.h in Headers */,
</del><span class="cx">                                 BC5EB69F0E81DAEB00B25965 /* FillLayer.h in Headers */,
</span><span class="cx">                                 845E72F80FD261EE00A87D79 /* Filter.h in Headers */,
</span><span class="cx">                                 08C9251A0FCC7C4A00480DEC /* FilterEffect.h in Headers */,
</span><span class="lines">@@ -27820,7 +27813,6 @@
</span><span class="cx">                                 26C17A3F1491D2D400D12BA2 /* FileSystemIOS.mm in Sources */,
</span><span class="cx">                                 514B3F760C722055000530DF /* FileSystemMac.mm in Sources */,
</span><span class="cx">                                 5160300B0CC4251200C8AC25 /* FileSystemPOSIX.cpp in Sources */,
</span><del>-                                976D6C8D122B8A3D001FD1F7 /* FileThread.cpp in Sources */,
</del><span class="cx">                                 BC5EB69E0E81DAEB00B25965 /* FillLayer.cpp in Sources */,
</span><span class="cx">                                 08C925190FCC7C4A00480DEC /* FilterEffect.cpp in Sources */,
</span><span class="cx">                                 31313F651443B35F006E2A90 /* FilterEffectRenderer.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsgenericActiveDOMCallbackcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/generic/ActiveDOMCallback.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/generic/ActiveDOMCallback.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/bindings/generic/ActiveDOMCallback.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -31,9 +31,7 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;ActiveDOMCallback.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;ActiveDOMObject.h&quot;
</del><span class="cx"> #include &quot;ScriptExecutionContext.h&quot;
</span><del>-#include &quot;WorkerGlobalScope.h&quot;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomActiveDOMObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ActiveDOMObject.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ActiveDOMObject.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/dom/ActiveDOMObject.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -28,8 +28,6 @@
</span><span class="cx"> #include &quot;ActiveDOMObject.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;ScriptExecutionContext.h&quot;
</span><del>-#include &quot;WorkerGlobalScope.h&quot;
-#include &quot;WorkerThread.h&quot;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiAsyncFileStreamcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/AsyncFileStream.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/AsyncFileStream.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/fileapi/AsyncFileStream.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2010 Google Inc.  All rights reserved.
</span><del>- * Copyright (C) 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions are
</span><span class="lines">@@ -30,162 +30,186 @@
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #include &quot;config.h&quot;
</span><del>-
</del><span class="cx"> #include &quot;AsyncFileStream.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;Blob.h&quot;
</del><span class="cx"> #include &quot;FileStream.h&quot;
</span><span class="cx"> #include &quot;FileStreamClient.h&quot;
</span><del>-#include &quot;FileThread.h&quot;
</del><ins>+#include &quot;URL.h&quot;
+#include &lt;wtf/AutodrainedPool.h&gt;
</ins><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><del>-#include &lt;wtf/text/WTFString.h&gt;
</del><ins>+#include &lt;wtf/MessageQueue.h&gt;
+#include &lt;wtf/NeverDestroyed.h&gt;
</ins><span class="cx"> 
</span><del>-#if PLATFORM(IOS)
-#include &quot;WebCoreThread.h&quot;
-#endif
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-static PassRefPtr&lt;FileThread&gt; createFileThread()
-{
-    RefPtr&lt;FileThread&gt; thread = FileThread::create();
-    if (!thread-&gt;start())
-        return 0;
-    return thread.release();
-}
</del><ins>+struct AsyncFileStream::Internals {
+    explicit Internals(FileStreamClient&amp;);
</ins><span class="cx"> 
</span><del>-static FileThread* fileThread()
</del><ins>+    FileStream stream;
+    FileStreamClient&amp; client;
+#if !COMPILER(MSVC)
+    std::atomic_bool destroyed { false };
+#else
+    std::atomic_bool destroyed;
+#endif
+};
+
+inline AsyncFileStream::Internals::Internals(FileStreamClient&amp; client)
+    : client(client)
</ins><span class="cx"> {
</span><del>-    ASSERT(isMainThread());
-    static FileThread* thread = createFileThread().leakRef();
-    return thread;
</del><ins>+#if COMPILER(MSVC)
+    // Work around a bug that prevents the default value above from compiling.
+    atomic_init(&amp;destroyed, false);
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline AsyncFileStream::AsyncFileStream(FileStreamClient* client)
-    : m_stream(FileStream::create())
-    , m_client(client)
</del><ins>+static void callOnFileThread(std::function&lt;void()&gt;&amp;&amp; function)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><del>-}
</del><ins>+    ASSERT(function);
</ins><span class="cx"> 
</span><del>-PassRefPtr&lt;AsyncFileStream&gt; AsyncFileStream::create(FileStreamClient* client)
-{
-    RefPtr&lt;AsyncFileStream&gt; proxy = adoptRef(new AsyncFileStream(client));
</del><ins>+    static NeverDestroyed&lt;MessageQueue&lt;std::function&lt;void()&gt;&gt;&gt; queue;
</ins><span class="cx"> 
</span><del>-    // Hold a reference so that the instance will not get deleted while there are tasks on the file thread.
-    // This is balanced by the deref in derefProxyOnContext below.
-    proxy-&gt;ref();
</del><ins>+    static std::once_flag createFileThreadOnce;
+    std::call_once(createFileThreadOnce, [] {
+        createThread(&quot;WebCore: AsyncFileStream&quot;, [] {
+            for (;;) {
+                AutodrainedPool pool;
</ins><span class="cx"> 
</span><del>-    AsyncFileStream* proxyPtr = proxy.get();
-    fileThread()-&gt;postTask({ proxyPtr, [=] {
-        // FIXME: It is not correct to check m_client from a secondary thread - stop() could be racing with this check.
-        if (!proxyPtr-&gt;client())
-            return;
</del><ins>+                auto function = queue.get().waitForMessage();
</ins><span class="cx"> 
</span><del>-        proxyPtr-&gt;m_stream-&gt;start();
-        callOnMainThread([proxyPtr] {
-            if (proxyPtr-&gt;client())
-                proxyPtr-&gt;client()-&gt;didStart();
</del><ins>+                // This can never be null because we never kill the MessageQueue.
+                ASSERT(function);
+
+                // This can bever be null because we never queue a function that is null.
+                ASSERT(*function);
+
+                (*function)();
+            }
</ins><span class="cx">         });
</span><del>-    } });
</del><ins>+    });
</ins><span class="cx"> 
</span><del>-    return proxy.release();
</del><ins>+    queue.get().append(std::make_unique&lt;std::function&lt;void()&gt;&gt;(WTF::move(function)));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-AsyncFileStream::~AsyncFileStream()
</del><ins>+AsyncFileStream::AsyncFileStream(FileStreamClient&amp; client)
+    : m_internals(std::make_unique&lt;Internals&gt;(client))
</ins><span class="cx"> {
</span><ins>+    ASSERT(isMainThread());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void AsyncFileStream::stop()
</del><ins>+AsyncFileStream::~AsyncFileStream()
</ins><span class="cx"> {
</span><del>-    // Clear the client so that we won't be invoking callbacks on the client.
-    setClient(0);
</del><ins>+    ASSERT(isMainThread());
</ins><span class="cx"> 
</span><del>-    fileThread()-&gt;unscheduleTasks(m_stream.get());
-    fileThread()-&gt;postTask({ this, [this] {
-        m_stream-&gt;stop();
-        callOnMainThread([this] {
-            ASSERT(hasOneRef());
-            deref();
</del><ins>+    // Release so that we can control the timing of deletion below.
+    auto&amp; internals = *m_internals.release();
+
+    // Set flag to prevent client callbacks and also prevent queued operations from starting.
+    internals.destroyed = true;
+
+    // Call through file thread and back to main thread to make sure deletion happens
+    // after all file thread functions and all main thread functions called from them.
+    callOnFileThread([&amp;internals] {
+        callOnMainThread([&amp;internals] {
+            delete &amp;internals;
</ins><span class="cx">         });
</span><del>-    } });
</del><ins>+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void AsyncFileStream::getSize(const String&amp; path, double expectedModificationTime)
</del><ins>+void AsyncFileStream::perform(std::function&lt;std::function&lt;void(FileStreamClient&amp;)&gt;(FileStream&amp;)&gt; operation)
</ins><span class="cx"> {
</span><del>-    String pathCopy = path.isolatedCopy();
-    fileThread()-&gt;postTask({ this, [this, pathCopy, expectedModificationTime] {
-        long long size = m_stream-&gt;getSize(pathCopy, expectedModificationTime);
-        callOnMainThread([this, size] {
-            if (client())
-                client()-&gt;didGetSize(size);
</del><ins>+    auto&amp; internals = *m_internals;
+    callOnFileThread([&amp;internals, operation] {
+        // Don't do the operation if stop was already called on the main thread. Note that there is
+        // a race here, but since skipping the operation is an optimization it's OK that we can't
+        // guarantee exactly which operations are skipped. Note that this is also the only reason
+        // we use an atomic_bool rather than just a bool for destroyed.
+        if (internals.destroyed)
+            return;
+        auto mainThreadWork = operation(internals.stream);
+        callOnMainThread([&amp;internals, mainThreadWork] {
+            if (internals.destroyed)
+                return;
+            mainThreadWork(internals.client);
</ins><span class="cx">         });
</span><del>-    } });
</del><ins>+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void AsyncFileStream::getSize(const String&amp; path, double expectedModificationTime)
+{
+    StringCapture capturedPath(path);
+    // FIXME: Explicit return type here and in all the other cases like this below is a workaround for a deficiency
+    // in the Windows compiler at the time of this writing. Could remove it if that is resolved.
+    perform([capturedPath, expectedModificationTime](FileStream&amp; stream) -&gt; std::function&lt;void(FileStreamClient&amp;)&gt; {
+        long long size = stream.getSize(capturedPath.string(), expectedModificationTime);
+        return [size](FileStreamClient&amp; client) {
+            client.didGetSize(size);
+        };
+    });
+}
+
</ins><span class="cx"> void AsyncFileStream::openForRead(const String&amp; path, long long offset, long long length)
</span><span class="cx"> {
</span><del>-    String pathCopy = path.isolatedCopy();
-    fileThread()-&gt;postTask({ this, [this, pathCopy, offset, length] {
-        bool success = m_stream-&gt;openForRead(pathCopy, offset, length);
-        callOnMainThread([this, success] {
-            if (client())
-                client()-&gt;didOpen(success);
-        });
-    } });
</del><ins>+    StringCapture capturedPath(path);
+    // FIXME: Explicit return type here is a workaround for a deficiency in the Windows compiler at the time of this writing.
+    perform([capturedPath, offset, length](FileStream&amp; stream) -&gt; std::function&lt;void(FileStreamClient&amp;)&gt; {
+        bool success = stream.openForRead(capturedPath.string(), offset, length);
+        return [success](FileStreamClient&amp; client) {
+            client.didOpen(success);
+        };
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AsyncFileStream::openForWrite(const String&amp; path)
</span><span class="cx"> {
</span><del>-    String pathCopy = path.isolatedCopy();
-    fileThread()-&gt;postTask({ this, [this, pathCopy] {
-        bool success = m_stream-&gt;openForWrite(pathCopy);
-        callOnMainThread([this, success] {
-            if (client())
-                client()-&gt;didOpen(success);
-        });
-    } });
</del><ins>+    StringCapture capturedPath(path);
+    perform([capturedPath](FileStream&amp; stream) -&gt; std::function&lt;void(FileStreamClient&amp;)&gt; {
+        bool success = stream.openForWrite(capturedPath.string());
+        return [success](FileStreamClient&amp; client) {
+            client.didOpen(success);
+        };
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AsyncFileStream::close()
</span><span class="cx"> {
</span><del>-    fileThread()-&gt;postTask({this, [this] {
-        m_stream-&gt;close();
-    } });
</del><ins>+    auto&amp; internals = *m_internals;
+    callOnFileThread([&amp;internals] {
+        internals.stream.close();
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AsyncFileStream::read(char* buffer, int length)
</span><span class="cx"> {
</span><del>-    fileThread()-&gt;postTask({ this, [this, buffer, length] {
-        int bytesRead = m_stream-&gt;read(buffer, length);
-        callOnMainThread([this, bytesRead] {
-            if (client())
-                client()-&gt;didRead(bytesRead);
-        });
-    } });
</del><ins>+    perform([buffer, length](FileStream&amp; stream) -&gt; std::function&lt;void(FileStreamClient&amp;)&gt; {
+        int bytesRead = stream.read(buffer, length);
+        return [bytesRead](FileStreamClient&amp; client) {
+            client.didRead(bytesRead);
+        };
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AsyncFileStream::write(const URL&amp; blobURL, long long position, int length)
</span><span class="cx"> {
</span><del>-    URL blobURLCopy = blobURL.copy();
-    fileThread()-&gt;postTask({ this, [this, blobURLCopy, position, length] {
-        int bytesWritten = m_stream-&gt;write(blobURLCopy, position, length);
-        callOnMainThread([this, bytesWritten] {
-            if (client())
-                client()-&gt;didWrite(bytesWritten);
-        });
-    } });
</del><ins>+    // FIXME: Would be more elegant to have a URLCapture for cases like this to avoid re-parsing the URL.
+    StringCapture capturedURL(blobURL.string());
+    perform([capturedURL, position, length](FileStream&amp; stream) -&gt; std::function&lt;void(FileStreamClient&amp;)&gt; {
+        int bytesWritten = stream.write(URL(ParsedURLString, capturedURL.string()), position, length);
+        return [bytesWritten](FileStreamClient&amp; client) {
+            client.didWrite(bytesWritten);
+        };
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AsyncFileStream::truncate(long long position)
</span><span class="cx"> {
</span><del>-    fileThread()-&gt;postTask({ this, [this, position] {
-        bool success = m_stream-&gt;truncate(position);
-        callOnMainThread([this, success] {
-            if (client())
-                client()-&gt;didTruncate(success);
-        });
-    } });
</del><ins>+    perform([position](FileStream&amp; stream) -&gt; std::function&lt;void(FileStreamClient&amp;)&gt; {
+        bool success = stream.truncate(position);
+        return [success](FileStreamClient&amp; client) {
+            client.didTruncate(success);
+        };
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiAsyncFileStreamh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/AsyncFileStream.h (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/AsyncFileStream.h        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/fileapi/AsyncFileStream.h        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Google Inc.  All rights reserved.
- * Copyright (C) 2010, 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2010, 2012, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions are
</span><span class="lines">@@ -32,9 +32,8 @@
</span><span class="cx"> #ifndef AsyncFileStream_h
</span><span class="cx"> #define AsyncFileStream_h
</span><span class="cx"> 
</span><ins>+#include &lt;functional&gt;
</ins><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><del>-#include &lt;wtf/RefCounted.h&gt;
-#include &lt;wtf/RefPtr.h&gt;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -42,9 +41,9 @@
</span><span class="cx"> class FileStream;
</span><span class="cx"> class URL;
</span><span class="cx"> 
</span><del>-class AsyncFileStream : public RefCounted&lt;AsyncFileStream&gt; {
</del><ins>+class AsyncFileStream {
</ins><span class="cx"> public:
</span><del>-    static PassRefPtr&lt;AsyncFileStream&gt; create(FileStreamClient*);
</del><ins>+    explicit AsyncFileStream(FileStreamClient&amp;);
</ins><span class="cx">     ~AsyncFileStream();
</span><span class="cx"> 
</span><span class="cx">     void getSize(const String&amp; path, double expectedModificationTime);
</span><span class="lines">@@ -55,18 +54,12 @@
</span><span class="cx">     void write(const URL&amp; blobURL, long long position, int length);
</span><span class="cx">     void truncate(long long position);
</span><span class="cx"> 
</span><del>-    // Stops the proxy and schedules it to be destructed. All the pending tasks will be aborted and the file stream will be closed.
-    // Note: the caller should deref the instance immediately after calling stop().
-    void stop();
-
-    FileStreamClient* client() const { return m_client; }
-    void setClient(FileStreamClient* client) { m_client = client; }
-
</del><span class="cx"> private:
</span><del>-    AsyncFileStream(FileStreamClient*);
</del><ins>+    void start();
+    void perform(std::function&lt;std::function&lt;void(FileStreamClient&amp;)&gt;(FileStream&amp;)&gt;);
</ins><span class="cx"> 
</span><del>-    RefPtr&lt;FileStream&gt; m_stream;
-    FileStreamClient* m_client;
</del><ins>+    struct Internals;
+    std::unique_ptr&lt;Internals&gt; m_internals;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiFileThreadcpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/fileapi/FileThread.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/FileThread.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/fileapi/FileThread.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,113 +0,0 @@
</span><del>-/*
- * Copyright (C) 2010 Google Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include &quot;config.h&quot;
-
-#include &quot;FileThread.h&quot;
-
-#include &quot;Logging.h&quot;
-#include &lt;wtf/AutodrainedPool.h&gt;
-
-namespace WebCore {
-
-FileThread::FileThread()
-    : m_threadID(0)
-{
-    m_selfRef = this;
-}
-
-FileThread::~FileThread()
-{
-    ASSERT(m_queue.killed());
-}
-
-bool FileThread::start()
-{
-    MutexLocker lock(m_threadCreationMutex);
-    if (m_threadID)
-        return true;
-    m_threadID = createThread(FileThread::fileThreadStart, this, &quot;WebCore: File&quot;);
-    return m_threadID;
-}
-
-void FileThread::stop()
-{
-    m_queue.kill();
-}
-
-void FileThread::postTask(Task task)
-{
-    m_queue.append(std::make_unique&lt;FileThread::Task&gt;(WTF::move(task)));
-}
-
-class SameInstancePredicate {
-public:
-    SameInstancePredicate(const void* instance) : m_instance(instance) { }
-    bool operator()(FileThread::Task&amp; task) const { return task.instance() == m_instance; }
-private:
-    const void* m_instance;
-};
-
-void FileThread::unscheduleTasks(const void* instance)
-{
-    SameInstancePredicate predicate(instance);
-    m_queue.removeIf(predicate);
-}
-
-void FileThread::fileThreadStart(void* arg)
-{
-    FileThread* fileThread = static_cast&lt;FileThread*&gt;(arg);
-    fileThread-&gt;runLoop();
-}
-
-void FileThread::runLoop()
-{
-    {
-        // Wait for FileThread::start() to complete to have m_threadID
-        // established before starting the main loop.
-        MutexLocker lock(m_threadCreationMutex);
-        LOG(FileAPI, &quot;Started FileThread %p&quot;, this);
-    }
-
-    while (auto task = m_queue.waitForMessage()) {
-        AutodrainedPool pool;
-
-        task-&gt;performTask();
-    }
-
-    LOG(FileAPI, &quot;About to detach thread %i and clear the ref to FileThread %p, which currently has %i ref(s)&quot;, m_threadID, this, refCount());
-
-    detachThread(m_threadID);
-
-    // Clear the self refptr, possibly resulting in deletion
-    m_selfRef = 0;
-}
-
-} // namespace WebCore
</del></span></pre></div>
<a id="trunkSourceWebCorefileapiFileThreadh"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/fileapi/FileThread.h (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/fileapi/FileThread.h        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/fileapi/FileThread.h        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,101 +0,0 @@
</span><del>-/*
- * Copyright (C) 2010 Google Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef FileThread_h
-#define FileThread_h
-
-#include &lt;functional&gt;
-#include &lt;wtf/MessageQueue.h&gt;
-#include &lt;wtf/PassRefPtr.h&gt;
-#include &lt;wtf/Threading.h&gt;
-
-namespace WebCore {
-
-class FileStream;
-
-class FileThread : public ThreadSafeRefCounted&lt;FileThread&gt; {
-public:
-    static PassRefPtr&lt;FileThread&gt; create()
-    {
-        return adoptRef(new FileThread());
-    }
-
-    ~FileThread();
-
-    bool start();
-    void stop();
-
-    class Task {
-        WTF_MAKE_NONCOPYABLE(Task);
-    public:
-        template&lt;typename T, typename U, typename = typename std::enable_if&lt;!std::is_base_of&lt;Task, U&gt;::value &amp;&amp; std::is_convertible&lt;U, std::function&lt;void ()&gt;&gt;::value&gt;::type&gt;
-        Task(T* instance, U method)
-            : m_task(WTF::move(method))
-            , m_instance(instance)
-        {
-        }
-
-        Task(Task&amp;&amp; other)
-            : m_task(WTF::move(other.m_task))
-            , m_instance(other.m_instance)
-        {
-        }
-
-        void performTask()
-        {
-            m_task();
-        }
-        void* instance() const { return m_instance; }
-
-    private:
-        std::function&lt;void ()&gt; m_task;
-        void* m_instance;
-    };
-
-    void postTask(Task);
-
-    void unscheduleTasks(const void* instance);
-
-private:
-    FileThread();
-
-    static void fileThreadStart(void*);
-    void runLoop();
-
-    ThreadIdentifier m_threadID;
-    RefPtr&lt;FileThread&gt; m_selfRef;
-    MessageQueue&lt;Task&gt; m_queue;
-
-    Mutex m_threadCreationMutex;
-};
-
-} // namespace WebCore
-
-#endif // FileThread_h
</del></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoader.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/loader/ResourceLoader.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -31,7 +31,6 @@
</span><span class="cx"> #include &quot;ResourceLoader.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;ApplicationCacheHost.h&quot;
</span><del>-#include &quot;AsyncFileStream.h&quot;
</del><span class="cx"> #include &quot;AuthenticationChallenge.h&quot;
</span><span class="cx"> #include &quot;DocumentLoader.h&quot;
</span><span class="cx"> #include &quot;Frame.h&quot;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformFileStreamcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/FileStream.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/FileStream.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/platform/FileStream.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -46,16 +46,6 @@
</span><span class="cx"> 
</span><span class="cx"> FileStream::~FileStream()
</span><span class="cx"> {
</span><del>-    ASSERT(!isHandleValid(m_handle));
-}
-
-// FIXME: To be removed when we switch to using BlobData.
-void FileStream::start()
-{
-}
-
-void FileStream::stop()
-{
</del><span class="cx">     close();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformFileStreamh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/FileStream.h (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/FileStream.h        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/platform/FileStream.h        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -32,29 +32,17 @@
</span><span class="cx"> #define FileStream_h
</span><span class="cx"> 
</span><span class="cx"> #include &quot;FileSystem.h&quot;
</span><del>-#include &lt;wtf/Forward.h&gt;
-#include &lt;wtf/PassRefPtr.h&gt;
-#include &lt;wtf/RefCounted.h&gt;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class URL;
</span><span class="cx"> 
</span><span class="cx"> // All methods are synchronous.
</span><del>-class FileStream : public RefCounted&lt;FileStream&gt; {
</del><ins>+class FileStream {
</ins><span class="cx"> public:
</span><del>-    static PassRefPtr&lt;FileStream&gt; create()
-    {
-        return adoptRef(new FileStream());
-    }
</del><ins>+    FileStream();
</ins><span class="cx">     ~FileStream();
</span><span class="cx"> 
</span><del>-    // FIXME: To be removed when we switch to using BlobData.
-    void start();
-
-    // Aborts the operation.
-    void stop();
-
</del><span class="cx">     // Gets the size of a file. Also validates if the file has been changed or not if the expected modification time is provided, i.e. non-zero.
</span><span class="cx">     // Returns total number of bytes if successful. -1 otherwise.
</span><span class="cx">     long long getSize(const String&amp; path, double expectedModificationTime);
</span><span class="lines">@@ -84,8 +72,6 @@
</span><span class="cx">     bool truncate(long long position);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    FileStream();
-
</del><span class="cx">     PlatformFileHandle m_handle;
</span><span class="cx">     long long m_bytesProcessed;
</span><span class="cx">     long long m_totalBytesToRead;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformFileStreamClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/FileStreamClient.h (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/FileStreamClient.h        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/platform/FileStreamClient.h        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Google Inc.  All rights reserved.
</del><ins>+ * Copyright (C) 2010 Google Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions are
</span><span class="lines">@@ -36,15 +36,11 @@
</span><span class="cx"> class FileStreamClient {
</span><span class="cx"> public:
</span><span class="cx">     virtual void didOpen(bool) { } // false signals failure.
</span><del>-    virtual void didStop() { }
</del><span class="cx">     virtual void didGetSize(long long) { } // -1 signals failure.
</span><span class="cx">     virtual void didRead(int) { } // -1 signals failure.
</span><span class="cx">     virtual void didWrite(int) { } // -1 signals failure.
</span><span class="cx">     virtual void didTruncate(bool) { } // false signals failure.
</span><span class="cx"> 
</span><del>-    // FIXME: To be removed when we switch to using BlobData.
-    virtual void didStart() { }
-
</del><span class="cx"> protected:
</span><span class="cx">     virtual ~FileStreamClient() { }
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkBlobResourceHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -171,30 +171,18 @@
</span><span class="cx">     , m_fileOpened(false)
</span><span class="cx"> {
</span><span class="cx">     if (m_async)
</span><del>-        m_asyncStream = AsyncFileStream::create(this);
</del><ins>+        m_asyncStream = std::make_unique&lt;AsyncFileStream&gt;(*this);
</ins><span class="cx">     else
</span><del>-        m_stream = FileStream::create();
</del><ins>+        m_stream = std::make_unique&lt;FileStream&gt;();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> BlobResourceHandle::~BlobResourceHandle()
</span><span class="cx"> {
</span><del>-    if (m_async) {
-        if (m_asyncStream)
-            m_asyncStream-&gt;stop();
-    } else {
-        if (m_stream)
-            m_stream-&gt;stop();
-    }
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void BlobResourceHandle::cancel()
</span><span class="cx"> {
</span><del>-    if (m_async) {
-        if (m_asyncStream) {
-            m_asyncStream-&gt;stop();
-            m_asyncStream = 0;
-        }
-    }
</del><ins>+    m_asyncStream = nullptr;
</ins><span class="cx"> 
</span><span class="cx">     m_aborted = true;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkBlobResourceHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/BlobResourceHandle.h (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/BlobResourceHandle.h        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/platform/network/BlobResourceHandle.h        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -92,8 +92,8 @@
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;BlobData&gt; m_blobData;
</span><span class="cx">     bool m_async;
</span><del>-    RefPtr&lt;AsyncFileStream&gt; m_asyncStream; // For asynchronous loading.
-    RefPtr&lt;FileStream&gt; m_stream; // For synchronous loading.
</del><ins>+    std::unique_ptr&lt;AsyncFileStream&gt; m_asyncStream; // For asynchronous loading.
+    std::unique_ptr&lt;FileStream&gt; m_stream; // For synchronous loading.
</ins><span class="cx">     Vector&lt;char&gt; m_buffer;
</span><span class="cx">     Vector&lt;long long&gt; m_itemLengthList;
</span><span class="cx">     int m_errorCode;
</span></span></pre></div>
<a id="trunkSourceWebCorestorageStorageThreadh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/storage/StorageThread.h (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/storage/StorageThread.h        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebCore/storage/StorageThread.h        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx">     bool start();
</span><span class="cx">     void terminate();
</span><span class="cx"> 
</span><del>-    void dispatch(const std::function&lt;void ()&gt;&amp;);
</del><ins>+    void dispatch(const std::function&lt;void()&gt;&amp;);
</ins><span class="cx"> 
</span><span class="cx">     static void releaseFastMallocFreeMemoryInAllThreads();
</span><span class="cx"> 
</span><span class="lines">@@ -59,7 +59,7 @@
</span><span class="cx">     void performTerminate();
</span><span class="cx"> 
</span><span class="cx">     ThreadIdentifier m_threadID;
</span><del>-    MessageQueue&lt;std::function&lt;void ()&gt;&gt; m_queue;
</del><ins>+    MessageQueue&lt;std::function&lt;void()&gt;&gt; m_queue;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebKit/ChangeLog        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2014-11-08  Darin Adler  &lt;darin@apple.com&gt;
+
+        Replace FileThread class with a single function
+        https://bugs.webkit.org/show_bug.cgi?id=138282
+
+        Reviewed by Alexey Proskuryakov.
+
+        * WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in:
+        Removed exports of obsolete threading functions.
+
</ins><span class="cx"> 2014-11-05  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Removed references to deletion UI resources that have been removed.
</span></span></pre></div>
<a id="trunkSourceWebKitWebKitvcxprojWebKitExportGeneratorWebKitExportsdefin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in (175781 => 175782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in        2014-11-08 23:50:43 UTC (rev 175781)
+++ trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in        2014-11-09 01:01:22 UTC (rev 175782)
</span><span class="lines">@@ -125,7 +125,6 @@
</span><span class="cx">         symbolWithPointer(?broadcast@ThreadCondition@WTF@@QAEXXZ, ?broadcast@ThreadCondition@WTF@@QEAAXXZ)
</span><span class="cx">         symbolWithPointer(?callOnMainThread@WTF@@YAXP6AXPAX@Z0@Z, ?callOnMainThread@WTF@@YAXP6AXPEAX@Z0@Z)
</span><span class="cx">         symbolWithPointer(?counterValueForElement@WebCore@@YA?AVString@WTF@@PAVElement@1@@Z, ?counterValueForElement@WebCore@@YA?AVString@WTF@@PEAVElement@1@@Z)
</span><del>-        symbolWithPointer(?createThread@WTF@@YAIP6APAXPAX@Z0PBD@Z, ?createThread@WTF@@YAIP6APEAXPEAX@Z0PEBD@Z)
</del><span class="cx">         symbolWithPointer(?createThread@WTF@@YAIP6AXPAX@Z0PBD@Z, ?createThread@WTF@@YAIP6AXPEAX@Z0PEBD@Z)
</span><span class="cx">         ?currentThread@WTF@@YAIXZ
</span><span class="cx">         ?detachThread@WTF@@YAXI@Z
</span><span class="lines">@@ -144,8 +143,6 @@
</span><span class="cx">         symbolWithPointer(?unlock@Mutex@WTF@@QAEXXZ, ?unlock@Mutex@WTF@@QEAAXXZ)
</span><span class="cx">         symbolWithPointer(?wait@ThreadCondition@WTF@@QAEXAAVMutex@2@@Z, ?wait@ThreadCondition@WTF@@QEAAXAEAVMutex@2@@Z)
</span><span class="cx">         ?waitForThreadCompletion@WTF@@YAHI@Z
</span><del>-        symbolWithPointer(?waitForThreadCompletion@WTF@@YAHIPAPAX@Z, ?waitForThreadCompletion@WTF@@YAHIPEAPEAX@Z)
-        symbolWithPointer(?createThread@WTF@@YAIP6APAXPAX@Z0@Z, ?createThread@WTF@@YAIP6APEAXPEAX@Z0@Z)
</del><span class="cx"> 
</span><span class="cx">         ; Re-exports from WebCore for test harnesses
</span><span class="cx">         symbolWithPointer(??0HitTestResult@WebCore@@QAE@ABVLayoutPoint@1@@Z, ??0HitTestResult@WebCore@@QEAA@AEBVLayoutPoint@1@@Z)
</span></span></pre>
</div>
</div>

</body>
</html>