| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "modules/filesystem/FileSystemCallbacks.h" | 31 #include "modules/filesystem/FileSystemCallbacks.h" |
| 32 | 32 |
| 33 #include "core/dom/ExecutionContext.h" | 33 #include "core/dom/ExecutionContext.h" |
| 34 #include "core/fileapi/BlobCallback.h" | 34 #include "core/fileapi/BlobCallback.h" |
| 35 #include "core/fileapi/File.h" | 35 #include "core/fileapi/File.h" |
| 36 #include "core/fileapi/FileError.h" | 36 #include "core/fileapi/FileError.h" |
| 37 #include "core/html/VoidCallback.h" | 37 #include "core/html/VoidCallback.h" |
| 38 #include "modules/filesystem/DOMFilePath.h" | 38 #include "modules/filesystem/DOMFilePath.h" |
| 39 #include "modules/filesystem/DOMFileSystem.h" | |
| 40 #include "modules/filesystem/DOMFileSystemBase.h" | |
| 41 #include "modules/filesystem/DirectoryEntry.h" | |
| 42 #include "modules/filesystem/DirectoryReader.h" | |
| 43 #include "modules/filesystem/Entry.h" | |
| 44 #include "modules/filesystem/EntryCallback.h" | |
| 45 #include "modules/filesystem/ErrorCallback.h" | 39 #include "modules/filesystem/ErrorCallback.h" |
| 46 #include "modules/filesystem/FileEntry.h" | 40 #include "modules/filesystem/FileSystem.h" |
| 41 #include "modules/filesystem/FileSystemBase.h" |
| 47 #include "modules/filesystem/FileSystemCallback.h" | 42 #include "modules/filesystem/FileSystemCallback.h" |
| 43 #include "modules/filesystem/FileSystemDirectoryEntry.h" |
| 44 #include "modules/filesystem/FileSystemDirectoryReader.h" |
| 45 #include "modules/filesystem/FileSystemEntry.h" |
| 46 #include "modules/filesystem/FileSystemEntryCallback.h" |
| 47 #include "modules/filesystem/FileSystemFileEntry.h" |
| 48 #include "modules/filesystem/FileSystemMetadata.h" |
| 49 #include "modules/filesystem/FileSystemMetadataCallback.h" |
| 48 #include "modules/filesystem/FileWriterBase.h" | 50 #include "modules/filesystem/FileWriterBase.h" |
| 49 #include "modules/filesystem/FileWriterBaseCallback.h" | 51 #include "modules/filesystem/FileWriterBaseCallback.h" |
| 50 #include "modules/filesystem/Metadata.h" | |
| 51 #include "modules/filesystem/MetadataCallback.h" | |
| 52 #include "platform/FileMetadata.h" | 52 #include "platform/FileMetadata.h" |
| 53 #include "public/platform/WebFileWriter.h" | 53 #include "public/platform/WebFileWriter.h" |
| 54 #include "wtf/PtrUtil.h" | 54 #include "wtf/PtrUtil.h" |
| 55 #include <memory> | 55 #include <memory> |
| 56 | 56 |
| 57 namespace blink { | 57 namespace blink { |
| 58 | 58 |
| 59 FileSystemCallbacksBase::FileSystemCallbacksBase( | 59 FileSystemCallbacksBase::FileSystemCallbacksBase( |
| 60 ErrorCallbackBase* errorCallback, | 60 ErrorCallbackBase* errorCallback, |
| 61 DOMFileSystemBase* fileSystem, | 61 FileSystemBase* fileSystem, |
| 62 ExecutionContext* context) | 62 ExecutionContext* context) |
| 63 : m_errorCallback(errorCallback), | 63 : m_errorCallback(errorCallback), |
| 64 m_fileSystem(fileSystem), | 64 m_fileSystem(fileSystem), |
| 65 m_executionContext(context) { | 65 m_executionContext(context) { |
| 66 if (m_fileSystem) | 66 if (m_fileSystem) |
| 67 m_fileSystem->addPendingCallbacks(); | 67 m_fileSystem->addPendingCallbacks(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 FileSystemCallbacksBase::~FileSystemCallbacksBase() { | 70 FileSystemCallbacksBase::~FileSystemCallbacksBase() { |
| 71 if (m_fileSystem) | 71 if (m_fileSystem) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 return !shouldBlockUntilCompletion() && m_executionContext && | 82 return !shouldBlockUntilCompletion() && m_executionContext && |
| 83 m_executionContext->activeDOMObjectsAreSuspended(); | 83 m_executionContext->activeDOMObjectsAreSuspended(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 template <typename CB, typename CBArg> | 86 template <typename CB, typename CBArg> |
| 87 void FileSystemCallbacksBase::invokeOrScheduleCallback(CB* callback, | 87 void FileSystemCallbacksBase::invokeOrScheduleCallback(CB* callback, |
| 88 CBArg arg) { | 88 CBArg arg) { |
| 89 DCHECK(callback); | 89 DCHECK(callback); |
| 90 if (callback) { | 90 if (callback) { |
| 91 if (shouldScheduleCallback()) | 91 if (shouldScheduleCallback()) |
| 92 DOMFileSystem::scheduleCallback( | 92 FileSystem::scheduleCallback( |
| 93 m_executionContext.get(), | 93 m_executionContext.get(), |
| 94 createSameThreadTask(&CB::invoke, wrapPersistent(callback), arg)); | 94 createSameThreadTask(&CB::invoke, wrapPersistent(callback), arg)); |
| 95 else | 95 else |
| 96 callback->invoke(arg); | 96 callback->invoke(arg); |
| 97 } | 97 } |
| 98 m_executionContext.clear(); | 98 m_executionContext.clear(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 template <typename CB, typename CBArg> | 101 template <typename CB, typename CBArg> |
| 102 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback, | 102 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback, |
| 103 CBArg* arg) { | 103 CBArg* arg) { |
| 104 DCHECK(callback); | 104 DCHECK(callback); |
| 105 if (callback) { | 105 if (callback) { |
| 106 if (shouldScheduleCallback()) | 106 if (shouldScheduleCallback()) |
| 107 DOMFileSystem::scheduleCallback( | 107 FileSystem::scheduleCallback( |
| 108 m_executionContext.get(), | 108 m_executionContext.get(), |
| 109 createSameThreadTask(&CB::handleEvent, wrapPersistent(callback), | 109 createSameThreadTask(&CB::handleEvent, wrapPersistent(callback), |
| 110 wrapPersistent(arg))); | 110 wrapPersistent(arg))); |
| 111 else | 111 else |
| 112 callback->handleEvent(arg); | 112 callback->handleEvent(arg); |
| 113 } | 113 } |
| 114 m_executionContext.clear(); | 114 m_executionContext.clear(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 template <typename CB> | 117 template <typename CB> |
| 118 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback) { | 118 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback) { |
| 119 DCHECK(callback); | 119 DCHECK(callback); |
| 120 if (callback) { | 120 if (callback) { |
| 121 if (shouldScheduleCallback()) | 121 if (shouldScheduleCallback()) |
| 122 DOMFileSystem::scheduleCallback( | 122 FileSystem::scheduleCallback( |
| 123 m_executionContext.get(), | 123 m_executionContext.get(), |
| 124 createSameThreadTask(&CB::handleEvent, wrapPersistent(callback))); | 124 createSameThreadTask(&CB::handleEvent, wrapPersistent(callback))); |
| 125 else | 125 else |
| 126 callback->handleEvent(); | 126 callback->handleEvent(); |
| 127 } | 127 } |
| 128 m_executionContext.clear(); | 128 m_executionContext.clear(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // ScriptErrorCallback -------------------------------------------------------- | 131 // ScriptErrorCallback -------------------------------------------------------- |
| 132 | 132 |
| 133 // static | 133 // static |
| 134 ScriptErrorCallback* ScriptErrorCallback::wrap(ErrorCallback* callback) { | 134 ScriptErrorCallback* ScriptErrorCallback::wrap(ErrorCallback* callback) { |
| 135 // DOMFileSystem operations take an optional (nullable) callback. If a | 135 // FileSystem operations take an optional (nullable) callback. If a |
| 136 // script callback was not passed, don't bother creating a dummy wrapper | 136 // script callback was not passed, don't bother creating a dummy wrapper |
| 137 // and checking during invoke(). | 137 // and checking during invoke(). |
| 138 if (!callback) | 138 if (!callback) |
| 139 return nullptr; | 139 return nullptr; |
| 140 return new ScriptErrorCallback(callback); | 140 return new ScriptErrorCallback(callback); |
| 141 } | 141 } |
| 142 | 142 |
| 143 DEFINE_TRACE(ScriptErrorCallback) { | 143 DEFINE_TRACE(ScriptErrorCallback) { |
| 144 ErrorCallbackBase::trace(visitor); | 144 ErrorCallbackBase::trace(visitor); |
| 145 visitor->trace(m_callback); | 145 visitor->trace(m_callback); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ScriptErrorCallback::invoke(FileError::ErrorCode error) { | 148 void ScriptErrorCallback::invoke(FileError::ErrorCode error) { |
| 149 m_callback->handleEvent(FileError::createDOMException(error)); | 149 m_callback->handleEvent(FileError::createDOMException(error)); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 ScriptErrorCallback::ScriptErrorCallback(ErrorCallback* callback) | 152 ScriptErrorCallback::ScriptErrorCallback(ErrorCallback* callback) |
| 153 : m_callback(callback) {} | 153 : m_callback(callback) {} |
| 154 | 154 |
| 155 // EntryCallbacks ------------------------------------------------------------- | 155 // EntryCallbacks ------------------------------------------------------------- |
| 156 | 156 |
| 157 std::unique_ptr<AsyncFileSystemCallbacks> EntryCallbacks::create( | 157 std::unique_ptr<AsyncFileSystemCallbacks> EntryCallbacks::create( |
| 158 EntryCallback* successCallback, | 158 FileSystemEntryCallback* successCallback, |
| 159 ErrorCallbackBase* errorCallback, | 159 ErrorCallbackBase* errorCallback, |
| 160 ExecutionContext* context, | 160 ExecutionContext* context, |
| 161 DOMFileSystemBase* fileSystem, | 161 FileSystemBase* fileSystem, |
| 162 const String& expectedPath, | 162 const String& expectedPath, |
| 163 bool isDirectory) { | 163 bool isDirectory) { |
| 164 return wrapUnique(new EntryCallbacks(successCallback, errorCallback, context, | 164 return wrapUnique(new EntryCallbacks(successCallback, errorCallback, context, |
| 165 fileSystem, expectedPath, isDirectory)); | 165 fileSystem, expectedPath, isDirectory)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 EntryCallbacks::EntryCallbacks(EntryCallback* successCallback, | 168 EntryCallbacks::EntryCallbacks(FileSystemEntryCallback* successCallback, |
| 169 ErrorCallbackBase* errorCallback, | 169 ErrorCallbackBase* errorCallback, |
| 170 ExecutionContext* context, | 170 ExecutionContext* context, |
| 171 DOMFileSystemBase* fileSystem, | 171 FileSystemBase* fileSystem, |
| 172 const String& expectedPath, | 172 const String& expectedPath, |
| 173 bool isDirectory) | 173 bool isDirectory) |
| 174 : FileSystemCallbacksBase(errorCallback, fileSystem, context), | 174 : FileSystemCallbacksBase(errorCallback, fileSystem, context), |
| 175 m_successCallback(successCallback), | 175 m_successCallback(successCallback), |
| 176 m_expectedPath(expectedPath), | 176 m_expectedPath(expectedPath), |
| 177 m_isDirectory(isDirectory) {} | 177 m_isDirectory(isDirectory) {} |
| 178 | 178 |
| 179 void EntryCallbacks::didSucceed() { | 179 void EntryCallbacks::didSucceed() { |
| 180 if (m_successCallback) { | 180 if (m_successCallback) { |
| 181 if (m_isDirectory) | 181 if (m_isDirectory) { |
| 182 handleEventOrScheduleCallback( | 182 handleEventOrScheduleCallback( |
| 183 m_successCallback.release(), | 183 m_successCallback.release(), |
| 184 DirectoryEntry::create(m_fileSystem, m_expectedPath)); | 184 FileSystemDirectoryEntry::create(m_fileSystem, m_expectedPath)); |
| 185 else | 185 } else { |
| 186 handleEventOrScheduleCallback( | 186 handleEventOrScheduleCallback( |
| 187 m_successCallback.release(), | 187 m_successCallback.release(), |
| 188 FileEntry::create(m_fileSystem, m_expectedPath)); | 188 FileSystemFileEntry::create(m_fileSystem, m_expectedPath)); |
| 189 } |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 // EntriesCallbacks ----------------------------------------------------------- | 193 // EntriesCallbacks ----------------------------------------------------------- |
| 193 | 194 |
| 194 std::unique_ptr<AsyncFileSystemCallbacks> EntriesCallbacks::create( | 195 std::unique_ptr<AsyncFileSystemCallbacks> EntriesCallbacks::create( |
| 195 EntriesCallback* successCallback, | 196 FileSystemEntriesCallback* successCallback, |
| 196 ErrorCallbackBase* errorCallback, | 197 ErrorCallbackBase* errorCallback, |
| 197 ExecutionContext* context, | 198 ExecutionContext* context, |
| 198 DirectoryReaderBase* directoryReader, | 199 FileSystemDirectoryReaderBase* directoryReader, |
| 199 const String& basePath) { | 200 const String& basePath) { |
| 200 return wrapUnique(new EntriesCallbacks(successCallback, errorCallback, | 201 return wrapUnique(new EntriesCallbacks(successCallback, errorCallback, |
| 201 context, directoryReader, basePath)); | 202 context, directoryReader, basePath)); |
| 202 } | 203 } |
| 203 | 204 |
| 204 EntriesCallbacks::EntriesCallbacks(EntriesCallback* successCallback, | 205 EntriesCallbacks::EntriesCallbacks( |
| 205 ErrorCallbackBase* errorCallback, | 206 FileSystemEntriesCallback* successCallback, |
| 206 ExecutionContext* context, | 207 ErrorCallbackBase* errorCallback, |
| 207 DirectoryReaderBase* directoryReader, | 208 ExecutionContext* context, |
| 208 const String& basePath) | 209 FileSystemDirectoryReaderBase* directoryReader, |
| 210 const String& basePath) |
| 209 : FileSystemCallbacksBase(errorCallback, | 211 : FileSystemCallbacksBase(errorCallback, |
| 210 directoryReader->filesystem(), | 212 directoryReader->filesystem(), |
| 211 context), | 213 context), |
| 212 m_successCallback(successCallback), | 214 m_successCallback(successCallback), |
| 213 m_directoryReader(directoryReader), | 215 m_directoryReader(directoryReader), |
| 214 m_basePath(basePath) { | 216 m_basePath(basePath) { |
| 215 ASSERT(m_directoryReader); | 217 ASSERT(m_directoryReader); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void EntriesCallbacks::didReadDirectoryEntry(const String& name, | 220 void EntriesCallbacks::didReadDirectoryEntry(const String& name, |
| 219 bool isDirectory) { | 221 bool isDirectory) { |
| 220 if (isDirectory) | 222 if (isDirectory) { |
| 223 m_entries.append(FileSystemDirectoryEntry::create( |
| 224 m_directoryReader->filesystem(), |
| 225 DOMFilePath::append(m_basePath, name))); |
| 226 } else { |
| 221 m_entries.append( | 227 m_entries.append( |
| 222 DirectoryEntry::create(m_directoryReader->filesystem(), | 228 FileSystemFileEntry::create(m_directoryReader->filesystem(), |
| 223 DOMFilePath::append(m_basePath, name))); | 229 DOMFilePath::append(m_basePath, name))); |
| 224 else | 230 } |
| 225 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), | |
| 226 DOMFilePath::append(m_basePath, name))); | |
| 227 } | 231 } |
| 228 | 232 |
| 229 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) { | 233 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) { |
| 230 m_directoryReader->setHasMoreEntries(hasMore); | 234 m_directoryReader->setHasMoreEntries(hasMore); |
| 231 EntryHeapVector entries; | 235 EntryHeapVector entries; |
| 232 entries.swap(m_entries); | 236 entries.swap(m_entries); |
| 233 // FIXME: delay the callback iff shouldScheduleCallback() is true. | 237 // FIXME: delay the callback iff shouldScheduleCallback() is true. |
| 234 if (m_successCallback) | 238 if (m_successCallback) |
| 235 m_successCallback->handleEvent(entries); | 239 m_successCallback->handleEvent(entries); |
| 236 } | 240 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 249 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, | 253 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, |
| 250 ErrorCallbackBase* errorCallback, | 254 ErrorCallbackBase* errorCallback, |
| 251 ExecutionContext* context, | 255 ExecutionContext* context, |
| 252 FileSystemType type) | 256 FileSystemType type) |
| 253 : FileSystemCallbacksBase(errorCallback, nullptr, context), | 257 : FileSystemCallbacksBase(errorCallback, nullptr, context), |
| 254 m_successCallback(successCallback), | 258 m_successCallback(successCallback), |
| 255 m_type(type) {} | 259 m_type(type) {} |
| 256 | 260 |
| 257 void FileSystemCallbacks::didOpenFileSystem(const String& name, | 261 void FileSystemCallbacks::didOpenFileSystem(const String& name, |
| 258 const KURL& rootURL) { | 262 const KURL& rootURL) { |
| 259 if (m_successCallback) | 263 if (m_successCallback) { |
| 260 handleEventOrScheduleCallback( | 264 handleEventOrScheduleCallback( |
| 261 m_successCallback.release(), | 265 m_successCallback.release(), |
| 262 DOMFileSystem::create(m_executionContext.get(), name, m_type, rootURL)); | 266 FileSystem::create(m_executionContext.get(), name, m_type, rootURL)); |
| 267 } |
| 263 } | 268 } |
| 264 | 269 |
| 265 // ResolveURICallbacks -------------------------------------------------------- | 270 // ResolveURICallbacks -------------------------------------------------------- |
| 266 | 271 |
| 267 std::unique_ptr<AsyncFileSystemCallbacks> ResolveURICallbacks::create( | 272 std::unique_ptr<AsyncFileSystemCallbacks> ResolveURICallbacks::create( |
| 268 EntryCallback* successCallback, | 273 FileSystemEntryCallback* successCallback, |
| 269 ErrorCallbackBase* errorCallback, | 274 ErrorCallbackBase* errorCallback, |
| 270 ExecutionContext* context) { | 275 ExecutionContext* context) { |
| 271 return wrapUnique( | 276 return wrapUnique( |
| 272 new ResolveURICallbacks(successCallback, errorCallback, context)); | 277 new ResolveURICallbacks(successCallback, errorCallback, context)); |
| 273 } | 278 } |
| 274 | 279 |
| 275 ResolveURICallbacks::ResolveURICallbacks(EntryCallback* successCallback, | 280 ResolveURICallbacks::ResolveURICallbacks( |
| 276 ErrorCallbackBase* errorCallback, | 281 FileSystemEntryCallback* successCallback, |
| 277 ExecutionContext* context) | 282 ErrorCallbackBase* errorCallback, |
| 283 ExecutionContext* context) |
| 278 : FileSystemCallbacksBase(errorCallback, nullptr, context), | 284 : FileSystemCallbacksBase(errorCallback, nullptr, context), |
| 279 m_successCallback(successCallback) {} | 285 m_successCallback(successCallback) {} |
| 280 | 286 |
| 281 void ResolveURICallbacks::didResolveURL(const String& name, | 287 void ResolveURICallbacks::didResolveURL(const String& name, |
| 282 const KURL& rootURL, | 288 const KURL& rootURL, |
| 283 FileSystemType type, | 289 FileSystemType type, |
| 284 const String& filePath, | 290 const String& filePath, |
| 285 bool isDirectory) { | 291 bool isDirectory) { |
| 286 DOMFileSystem* filesystem = | 292 FileSystem* filesystem = |
| 287 DOMFileSystem::create(m_executionContext.get(), name, type, rootURL); | 293 FileSystem::create(m_executionContext.get(), name, type, rootURL); |
| 288 DirectoryEntry* root = filesystem->root(); | 294 FileSystemDirectoryEntry* root = filesystem->root(); |
| 289 | 295 |
| 290 String absolutePath; | 296 String absolutePath; |
| 291 if (!DOMFileSystemBase::pathToAbsolutePath(type, root, filePath, | 297 if (!FileSystemBase::pathToAbsolutePath(type, root, filePath, absolutePath)) { |
| 292 absolutePath)) { | |
| 293 invokeOrScheduleCallback(m_errorCallback.release(), | 298 invokeOrScheduleCallback(m_errorCallback.release(), |
| 294 FileError::kInvalidModificationErr); | 299 FileError::kInvalidModificationErr); |
| 295 return; | 300 return; |
| 296 } | 301 } |
| 297 | 302 |
| 298 if (isDirectory) | 303 if (isDirectory) { |
| 299 handleEventOrScheduleCallback( | 304 handleEventOrScheduleCallback( |
| 300 m_successCallback.release(), | 305 m_successCallback.release(), |
| 301 DirectoryEntry::create(filesystem, absolutePath)); | 306 FileSystemDirectoryEntry::create(filesystem, absolutePath)); |
| 302 else | 307 } else { |
| 303 handleEventOrScheduleCallback(m_successCallback.release(), | 308 handleEventOrScheduleCallback( |
| 304 FileEntry::create(filesystem, absolutePath)); | 309 m_successCallback.release(), |
| 310 FileSystemFileEntry::create(filesystem, absolutePath)); |
| 311 } |
| 305 } | 312 } |
| 306 | 313 |
| 307 // MetadataCallbacks ---------------------------------------------------------- | 314 // MetadataCallbacks ---------------------------------------------------------- |
| 308 | 315 |
| 309 std::unique_ptr<AsyncFileSystemCallbacks> MetadataCallbacks::create( | 316 std::unique_ptr<AsyncFileSystemCallbacks> MetadataCallbacks::create( |
| 310 MetadataCallback* successCallback, | 317 FileSystemMetadataCallback* successCallback, |
| 311 ErrorCallbackBase* errorCallback, | 318 ErrorCallbackBase* errorCallback, |
| 312 ExecutionContext* context, | 319 ExecutionContext* context, |
| 313 DOMFileSystemBase* fileSystem) { | 320 FileSystemBase* fileSystem) { |
| 314 return wrapUnique(new MetadataCallbacks(successCallback, errorCallback, | 321 return wrapUnique(new MetadataCallbacks(successCallback, errorCallback, |
| 315 context, fileSystem)); | 322 context, fileSystem)); |
| 316 } | 323 } |
| 317 | 324 |
| 318 MetadataCallbacks::MetadataCallbacks(MetadataCallback* successCallback, | 325 MetadataCallbacks::MetadataCallbacks( |
| 319 ErrorCallbackBase* errorCallback, | 326 FileSystemMetadataCallback* successCallback, |
| 320 ExecutionContext* context, | 327 ErrorCallbackBase* errorCallback, |
| 321 DOMFileSystemBase* fileSystem) | 328 ExecutionContext* context, |
| 329 FileSystemBase* fileSystem) |
| 322 : FileSystemCallbacksBase(errorCallback, fileSystem, context), | 330 : FileSystemCallbacksBase(errorCallback, fileSystem, context), |
| 323 m_successCallback(successCallback) {} | 331 m_successCallback(successCallback) {} |
| 324 | 332 |
| 325 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) { | 333 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) { |
| 326 if (m_successCallback) | 334 if (m_successCallback) { |
| 327 handleEventOrScheduleCallback(m_successCallback.release(), | 335 handleEventOrScheduleCallback(m_successCallback.release(), |
| 328 Metadata::create(metadata)); | 336 FileSystemMetadata::create(metadata)); |
| 337 } |
| 329 } | 338 } |
| 330 | 339 |
| 331 // FileWriterBaseCallbacks ---------------------------------------------------- | 340 // FileWriterBaseCallbacks ---------------------------------------------------- |
| 332 | 341 |
| 333 std::unique_ptr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create( | 342 std::unique_ptr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create( |
| 334 FileWriterBase* fileWriter, | 343 FileWriterBase* fileWriter, |
| 335 FileWriterBaseCallback* successCallback, | 344 FileWriterBaseCallback* successCallback, |
| 336 ErrorCallbackBase* errorCallback, | 345 ErrorCallbackBase* errorCallback, |
| 337 ExecutionContext* context) { | 346 ExecutionContext* context) { |
| 338 return wrapUnique(new FileWriterBaseCallbacks(fileWriter, successCallback, | 347 return wrapUnique(new FileWriterBaseCallbacks(fileWriter, successCallback, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 353 long long length) { | 362 long long length) { |
| 354 m_fileWriter->initialize(std::move(fileWriter), length); | 363 m_fileWriter->initialize(std::move(fileWriter), length); |
| 355 if (m_successCallback) | 364 if (m_successCallback) |
| 356 handleEventOrScheduleCallback(m_successCallback.release(), | 365 handleEventOrScheduleCallback(m_successCallback.release(), |
| 357 m_fileWriter.release()); | 366 m_fileWriter.release()); |
| 358 } | 367 } |
| 359 | 368 |
| 360 // SnapshotFileCallback ------------------------------------------------------- | 369 // SnapshotFileCallback ------------------------------------------------------- |
| 361 | 370 |
| 362 std::unique_ptr<AsyncFileSystemCallbacks> SnapshotFileCallback::create( | 371 std::unique_ptr<AsyncFileSystemCallbacks> SnapshotFileCallback::create( |
| 363 DOMFileSystemBase* filesystem, | 372 FileSystemBase* filesystem, |
| 364 const String& name, | 373 const String& name, |
| 365 const KURL& url, | 374 const KURL& url, |
| 366 BlobCallback* successCallback, | 375 BlobCallback* successCallback, |
| 367 ErrorCallbackBase* errorCallback, | 376 ErrorCallbackBase* errorCallback, |
| 368 ExecutionContext* context) { | 377 ExecutionContext* context) { |
| 369 return wrapUnique(new SnapshotFileCallback( | 378 return wrapUnique(new SnapshotFileCallback( |
| 370 filesystem, name, url, successCallback, errorCallback, context)); | 379 filesystem, name, url, successCallback, errorCallback, context)); |
| 371 } | 380 } |
| 372 | 381 |
| 373 SnapshotFileCallback::SnapshotFileCallback(DOMFileSystemBase* filesystem, | 382 SnapshotFileCallback::SnapshotFileCallback(FileSystemBase* filesystem, |
| 374 const String& name, | 383 const String& name, |
| 375 const KURL& url, | 384 const KURL& url, |
| 376 BlobCallback* successCallback, | 385 BlobCallback* successCallback, |
| 377 ErrorCallbackBase* errorCallback, | 386 ErrorCallbackBase* errorCallback, |
| 378 ExecutionContext* context) | 387 ExecutionContext* context) |
| 379 : FileSystemCallbacksBase(errorCallback, filesystem, context), | 388 : FileSystemCallbacksBase(errorCallback, filesystem, context), |
| 380 m_name(name), | 389 m_name(name), |
| 381 m_url(url), | 390 m_url(url), |
| 382 m_successCallback(successCallback) {} | 391 m_successCallback(successCallback) {} |
| 383 | 392 |
| 384 void SnapshotFileCallback::didCreateSnapshotFile( | 393 void SnapshotFileCallback::didCreateSnapshotFile( |
| 385 const FileMetadata& metadata, | 394 const FileMetadata& metadata, |
| 386 PassRefPtr<BlobDataHandle> snapshot) { | 395 PassRefPtr<BlobDataHandle> snapshot) { |
| 387 if (!m_successCallback) | 396 if (!m_successCallback) |
| 388 return; | 397 return; |
| 389 | 398 |
| 390 // We can't directly use the snapshot blob data handle because the content | 399 // We can't directly use the snapshot blob data handle because the content |
| 391 // type on it hasn't been set. The |snapshot| param is here to provide a a | 400 // type on it hasn't been set. The |snapshot| param is here to provide a a |
| 392 // chain of custody thru thread bridging that is held onto until *after* we've | 401 // chain of custody thru thread bridging that is held onto until *after* we've |
| 393 // coined a File with a new handle that has the correct type set on it. This | 402 // coined a File with a new handle that has the correct type set on it. This |
| 394 // allows the blob storage system to track when a temp file can and can't be | 403 // allows the blob storage system to track when a temp file can and can't be |
| 395 // safely deleted. | 404 // safely deleted. |
| 396 | 405 |
| 397 handleEventOrScheduleCallback( | 406 handleEventOrScheduleCallback( |
| 398 m_successCallback.release(), | 407 m_successCallback.release(), |
| 399 DOMFileSystemBase::createFile(metadata, m_url, m_fileSystem->type(), | 408 FileSystemBase::createFile(metadata, m_url, m_fileSystem->type(), |
| 400 m_name)); | 409 m_name)); |
| 401 } | 410 } |
| 402 | 411 |
| 403 // VoidCallbacks -------------------------------------------------------------- | 412 // VoidCallbacks -------------------------------------------------------------- |
| 404 | 413 |
| 405 std::unique_ptr<AsyncFileSystemCallbacks> VoidCallbacks::create( | 414 std::unique_ptr<AsyncFileSystemCallbacks> VoidCallbacks::create( |
| 406 VoidCallback* successCallback, | 415 VoidCallback* successCallback, |
| 407 ErrorCallbackBase* errorCallback, | 416 ErrorCallbackBase* errorCallback, |
| 408 ExecutionContext* context, | 417 ExecutionContext* context, |
| 409 DOMFileSystemBase* fileSystem) { | 418 FileSystemBase* fileSystem) { |
| 410 return wrapUnique( | 419 return wrapUnique( |
| 411 new VoidCallbacks(successCallback, errorCallback, context, fileSystem)); | 420 new VoidCallbacks(successCallback, errorCallback, context, fileSystem)); |
| 412 } | 421 } |
| 413 | 422 |
| 414 VoidCallbacks::VoidCallbacks(VoidCallback* successCallback, | 423 VoidCallbacks::VoidCallbacks(VoidCallback* successCallback, |
| 415 ErrorCallbackBase* errorCallback, | 424 ErrorCallbackBase* errorCallback, |
| 416 ExecutionContext* context, | 425 ExecutionContext* context, |
| 417 DOMFileSystemBase* fileSystem) | 426 FileSystemBase* fileSystem) |
| 418 : FileSystemCallbacksBase(errorCallback, fileSystem, context), | 427 : FileSystemCallbacksBase(errorCallback, fileSystem, context), |
| 419 m_successCallback(successCallback) {} | 428 m_successCallback(successCallback) {} |
| 420 | 429 |
| 421 void VoidCallbacks::didSucceed() { | 430 void VoidCallbacks::didSucceed() { |
| 422 if (m_successCallback) | 431 if (m_successCallback) |
| 423 handleEventOrScheduleCallback(m_successCallback.release()); | 432 handleEventOrScheduleCallback(m_successCallback.release()); |
| 424 } | 433 } |
| 425 | 434 |
| 426 } // namespace blink | 435 } // namespace blink |
| OLD | NEW |