Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/DOMFileSystem.cpp

Issue 2645473005: FileSystem: Migrate ExecutionContextTask to WTF::Closure (Closed)
Patch Set: wrapWeakPersistent Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "modules/filesystem/DOMFileSystem.h" 31 #include "modules/filesystem/DOMFileSystem.h"
32 32
33 #include "core/fileapi/BlobCallback.h" 33 #include "core/fileapi/BlobCallback.h"
34 #include "core/inspector/InspectorInstrumentation.h"
34 #include "modules/filesystem/DOMFilePath.h" 35 #include "modules/filesystem/DOMFilePath.h"
35 #include "modules/filesystem/DirectoryEntry.h" 36 #include "modules/filesystem/DirectoryEntry.h"
36 #include "modules/filesystem/FileEntry.h" 37 #include "modules/filesystem/FileEntry.h"
37 #include "modules/filesystem/FileSystemCallbacks.h" 38 #include "modules/filesystem/FileSystemCallbacks.h"
38 #include "modules/filesystem/FileWriter.h" 39 #include "modules/filesystem/FileWriter.h"
39 #include "modules/filesystem/FileWriterBaseCallback.h" 40 #include "modules/filesystem/FileWriterBaseCallback.h"
40 #include "modules/filesystem/FileWriterCallback.h" 41 #include "modules/filesystem/FileWriterCallback.h"
41 #include "modules/filesystem/MetadataCallback.h" 42 #include "modules/filesystem/MetadataCallback.h"
42 #include "platform/FileMetadata.h" 43 #include "platform/FileMetadata.h"
44 #include "platform/WebTaskRunner.h"
43 #include "platform/weborigin/SecurityOrigin.h" 45 #include "platform/weborigin/SecurityOrigin.h"
44 #include "public/platform/Platform.h" 46 #include "public/platform/Platform.h"
45 #include "public/platform/WebFileSystem.h" 47 #include "public/platform/WebFileSystem.h"
46 #include "public/platform/WebFileSystemCallbacks.h" 48 #include "public/platform/WebFileSystemCallbacks.h"
47 #include "public/platform/WebSecurityOrigin.h" 49 #include "public/platform/WebSecurityOrigin.h"
48 #include "wtf/text/StringBuilder.h" 50 #include "wtf/text/StringBuilder.h"
49 #include "wtf/text/WTFString.h" 51 #include "wtf/text/WTFString.h"
50 #include <memory> 52 #include <memory>
51 53
52 namespace blink { 54 namespace blink {
53 55
56 namespace {
57
58 void runCallback(ExecutionContext* executionContext,
59 std::unique_ptr<WTF::Closure> task) {
60 if (!executionContext)
61 return;
62 DCHECK(executionContext->isContextThread());
63 InspectorInstrumentation::AsyncTask asyncTask(executionContext, task.get(),
64 true /* isInstrumented */);
65 (*task)();
66 }
67
68 } // namespace
69
54 // static 70 // static
55 DOMFileSystem* DOMFileSystem::create(ExecutionContext* context, 71 DOMFileSystem* DOMFileSystem::create(ExecutionContext* context,
56 const String& name, 72 const String& name,
57 FileSystemType type, 73 FileSystemType type,
58 const KURL& rootURL) { 74 const KURL& rootURL) {
59 return new DOMFileSystem(context, name, type, rootURL); 75 return new DOMFileSystem(context, name, type, rootURL);
60 } 76 }
61 77
62 DOMFileSystem* DOMFileSystem::createIsolatedFileSystem( 78 DOMFileSystem* DOMFileSystem::createIsolatedFileSystem(
63 ExecutionContext* context, 79 ExecutionContext* context,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 131 }
116 132
117 void DOMFileSystem::reportError(ErrorCallbackBase* errorCallback, 133 void DOMFileSystem::reportError(ErrorCallbackBase* errorCallback,
118 FileError::ErrorCode fileError) { 134 FileError::ErrorCode fileError) {
119 reportError(getExecutionContext(), errorCallback, fileError); 135 reportError(getExecutionContext(), errorCallback, fileError);
120 } 136 }
121 137
122 void DOMFileSystem::reportError(ExecutionContext* executionContext, 138 void DOMFileSystem::reportError(ExecutionContext* executionContext,
123 ErrorCallbackBase* errorCallback, 139 ErrorCallbackBase* errorCallback,
124 FileError::ErrorCode fileError) { 140 FileError::ErrorCode fileError) {
125 if (errorCallback) 141 if (!errorCallback)
126 scheduleCallback( 142 return;
127 executionContext, 143 scheduleCallback(executionContext,
128 createSameThreadTask(&ErrorCallbackBase::invoke, 144 WTF::bind(&ErrorCallbackBase::invoke,
129 wrapPersistent(errorCallback), fileError)); 145 wrapPersistent(errorCallback), fileError));
130 } 146 }
131 147
132 namespace { 148 namespace {
133 149
134 class ConvertToFileWriterCallback : public FileWriterBaseCallback { 150 class ConvertToFileWriterCallback : public FileWriterBaseCallback {
135 public: 151 public:
136 static ConvertToFileWriterCallback* create(FileWriterCallback* callback) { 152 static ConvertToFileWriterCallback* create(FileWriterCallback* callback) {
137 return new ConvertToFileWriterCallback(callback); 153 return new ConvertToFileWriterCallback(callback);
138 } 154 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 reportError(errorCallback, FileError::kAbortErr); 198 reportError(errorCallback, FileError::kAbortErr);
183 return; 199 return;
184 } 200 }
185 201
186 fileSystem()->createSnapshotFileAndReadMetadata( 202 fileSystem()->createSnapshotFileAndReadMetadata(
187 fileSystemURL, 203 fileSystemURL,
188 SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL, 204 SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL,
189 successCallback, errorCallback, m_context)); 205 successCallback, errorCallback, m_context));
190 } 206 }
191 207
208 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext,
209 std::unique_ptr<WTF::Closure> task) {
210 DCHECK(executionContext->isContextThread());
211 InspectorInstrumentation::asyncTaskScheduled(
212 executionContext, taskNameForInstrumentation(), task.get());
213 TaskRunnerHelper::get(TaskType::FileReading, executionContext)
214 ->postTask(BLINK_FROM_HERE,
215 WTF::bind(&runCallback, wrapWeakPersistent(executionContext),
216 WTF::passed(std::move(task))));
217 }
218
192 DEFINE_TRACE(DOMFileSystem) { 219 DEFINE_TRACE(DOMFileSystem) {
193 DOMFileSystemBase::trace(visitor); 220 DOMFileSystemBase::trace(visitor);
194 ContextLifecycleObserver::trace(visitor); 221 ContextLifecycleObserver::trace(visitor);
195 visitor->trace(m_rootEntry); 222 visitor->trace(m_rootEntry);
196 } 223 }
197 224
198 } // namespace blink 225 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698