Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 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 DCHECK(executionContext->isContextThread()); | |
| 61 InspectorInstrumentation::AsyncTask asyncTask(executionContext, task.get(), | |
| 62 true /* isInstrumented */); | |
| 63 (*task)(); | |
| 64 } | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 54 // static | 68 // static |
| 55 DOMFileSystem* DOMFileSystem::create(ExecutionContext* context, | 69 DOMFileSystem* DOMFileSystem::create(ExecutionContext* context, |
| 56 const String& name, | 70 const String& name, |
| 57 FileSystemType type, | 71 FileSystemType type, |
| 58 const KURL& rootURL) { | 72 const KURL& rootURL) { |
| 59 return new DOMFileSystem(context, name, type, rootURL); | 73 return new DOMFileSystem(context, name, type, rootURL); |
| 60 } | 74 } |
| 61 | 75 |
| 62 DOMFileSystem* DOMFileSystem::createIsolatedFileSystem( | 76 DOMFileSystem* DOMFileSystem::createIsolatedFileSystem( |
| 63 ExecutionContext* context, | 77 ExecutionContext* context, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 129 } |
| 116 | 130 |
| 117 void DOMFileSystem::reportError(ErrorCallbackBase* errorCallback, | 131 void DOMFileSystem::reportError(ErrorCallbackBase* errorCallback, |
| 118 FileError::ErrorCode fileError) { | 132 FileError::ErrorCode fileError) { |
| 119 reportError(getExecutionContext(), errorCallback, fileError); | 133 reportError(getExecutionContext(), errorCallback, fileError); |
| 120 } | 134 } |
| 121 | 135 |
| 122 void DOMFileSystem::reportError(ExecutionContext* executionContext, | 136 void DOMFileSystem::reportError(ExecutionContext* executionContext, |
| 123 ErrorCallbackBase* errorCallback, | 137 ErrorCallbackBase* errorCallback, |
| 124 FileError::ErrorCode fileError) { | 138 FileError::ErrorCode fileError) { |
| 125 if (errorCallback) | 139 if (!errorCallback) |
| 126 scheduleCallback( | 140 return; |
| 127 executionContext, | 141 scheduleCallback(executionContext, |
| 128 createSameThreadTask(&ErrorCallbackBase::invoke, | 142 WTF::bind(&ErrorCallbackBase::invoke, |
| 129 wrapPersistent(errorCallback), fileError)); | 143 wrapPersistent(errorCallback), fileError)); |
| 130 } | 144 } |
| 131 | 145 |
| 132 namespace { | 146 namespace { |
| 133 | 147 |
| 134 class ConvertToFileWriterCallback : public FileWriterBaseCallback { | 148 class ConvertToFileWriterCallback : public FileWriterBaseCallback { |
| 135 public: | 149 public: |
| 136 static ConvertToFileWriterCallback* create(FileWriterCallback* callback) { | 150 static ConvertToFileWriterCallback* create(FileWriterCallback* callback) { |
| 137 return new ConvertToFileWriterCallback(callback); | 151 return new ConvertToFileWriterCallback(callback); |
| 138 } | 152 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 reportError(errorCallback, FileError::kAbortErr); | 196 reportError(errorCallback, FileError::kAbortErr); |
| 183 return; | 197 return; |
| 184 } | 198 } |
| 185 | 199 |
| 186 fileSystem()->createSnapshotFileAndReadMetadata( | 200 fileSystem()->createSnapshotFileAndReadMetadata( |
| 187 fileSystemURL, | 201 fileSystemURL, |
| 188 SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL, | 202 SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL, |
| 189 successCallback, errorCallback, m_context)); | 203 successCallback, errorCallback, m_context)); |
| 190 } | 204 } |
| 191 | 205 |
| 206 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, | |
| 207 std::unique_ptr<WTF::Closure> task) { | |
| 208 DCHECK(executionContext->isContextThread()); | |
| 209 InspectorInstrumentation::asyncTaskScheduled( | |
| 210 executionContext, taskNameForInstrumentation(), task.get()); | |
| 211 TaskRunnerHelper::get(TaskType::FileReading, executionContext) | |
| 212 ->postTask(BLINK_FROM_HERE, | |
| 213 WTF::bind(&runCallback, wrapPersistent(executionContext), | |
|
tzik
2017/01/19 04:16:09
Can we use wrapWeakPersistent and check its value
nhiroki
2017/01/19 04:33:40
Done.
| |
| 214 WTF::passed(std::move(task)))); | |
| 215 } | |
| 216 | |
| 192 DEFINE_TRACE(DOMFileSystem) { | 217 DEFINE_TRACE(DOMFileSystem) { |
| 193 DOMFileSystemBase::trace(visitor); | 218 DOMFileSystemBase::trace(visitor); |
| 194 ContextLifecycleObserver::trace(visitor); | 219 ContextLifecycleObserver::trace(visitor); |
| 195 visitor->trace(m_rootEntry); | 220 visitor->trace(m_rootEntry); |
| 196 } | 221 } |
| 197 | 222 |
| 198 } // namespace blink | 223 } // namespace blink |
| OLD | NEW |