| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "modules/filesystem/FileWriterBaseCallback.h" | 49 #include "modules/filesystem/FileWriterBaseCallback.h" |
| 50 #include "modules/filesystem/Metadata.h" | 50 #include "modules/filesystem/Metadata.h" |
| 51 #include "modules/filesystem/MetadataCallback.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(ErrorCallback* errorCallback, D
OMFileSystemBase* fileSystem, ExecutionContext* context) | 59 FileSystemCallbacksBase::FileSystemCallbacksBase(ErrorCallbackBase* errorCallbac
k, DOMFileSystemBase* fileSystem, ExecutionContext* context) |
| 60 : m_errorCallback(errorCallback) | 60 : m_errorCallback(errorCallback) |
| 61 , m_fileSystem(fileSystem) | 61 , m_fileSystem(fileSystem) |
| 62 , m_executionContext(context) | 62 , m_executionContext(context) |
| 63 { | 63 { |
| 64 if (m_fileSystem) | 64 if (m_fileSystem) |
| 65 m_fileSystem->addPendingCallbacks(); | 65 m_fileSystem->addPendingCallbacks(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 FileSystemCallbacksBase::~FileSystemCallbacksBase() | 68 FileSystemCallbacksBase::~FileSystemCallbacksBase() |
| 69 { | 69 { |
| 70 if (m_fileSystem) | 70 if (m_fileSystem) |
| 71 m_fileSystem->removePendingCallbacks(); | 71 m_fileSystem->removePendingCallbacks(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void FileSystemCallbacksBase::didFail(int code) | 74 void FileSystemCallbacksBase::didFail(int code) |
| 75 { | 75 { |
| 76 if (m_errorCallback) | 76 if (m_errorCallback) |
| 77 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea
te(static_cast<FileError::ErrorCode>(code))); | 77 invokeOrScheduleCallback(m_errorCallback.release(), static_cast<FileErro
r::ErrorCode>(code)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool FileSystemCallbacksBase::shouldScheduleCallback() const | 80 bool FileSystemCallbacksBase::shouldScheduleCallback() const |
| 81 { | 81 { |
| 82 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon
text->activeDOMObjectsAreSuspended(); | 82 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon
text->activeDOMObjectsAreSuspended(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 template <typename CB, typename CBArg> | 85 template <typename CB, typename CBArg> |
| 86 void FileSystemCallbacksBase::invokeOrScheduleCallback(CB* callback, CBArg arg) |
| 87 { |
| 88 DCHECK(callback); |
| 89 if (callback) { |
| 90 if (shouldScheduleCallback()) |
| 91 DOMFileSystem::scheduleCallback(m_executionContext.get(), createSame
ThreadTask(&CB::invoke, wrapPersistent(callback), arg)); |
| 92 else |
| 93 callback->invoke(arg); |
| 94 } |
| 95 m_executionContext.clear(); |
| 96 } |
| 97 |
| 98 template <typename CB, typename CBArg> |
| 86 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback, CBArg*
arg) | 99 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback, CBArg*
arg) |
| 87 { | 100 { |
| 88 ASSERT(callback); | 101 DCHECK(callback); |
| 89 if (callback) { | 102 if (callback) { |
| 90 if (shouldScheduleCallback()) | 103 if (shouldScheduleCallback()) |
| 91 DOMFileSystem::scheduleCallback(m_executionContext.get(), createSame
ThreadTask(&CB::handleEvent, wrapPersistent(callback), wrapPersistent(arg))); | 104 DOMFileSystem::scheduleCallback(m_executionContext.get(), createSame
ThreadTask(&CB::handleEvent, wrapPersistent(callback), wrapPersistent(arg))); |
| 92 else | 105 else |
| 93 callback->handleEvent(arg); | 106 callback->handleEvent(arg); |
| 94 } | 107 } |
| 95 m_executionContext.clear(); | 108 m_executionContext.clear(); |
| 96 } | 109 } |
| 97 | 110 |
| 98 template <typename CB> | 111 template <typename CB> |
| 99 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback) | 112 void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback) |
| 100 { | 113 { |
| 101 ASSERT(callback); | 114 DCHECK(callback); |
| 102 if (callback) { | 115 if (callback) { |
| 103 if (shouldScheduleCallback()) | 116 if (shouldScheduleCallback()) |
| 104 DOMFileSystem::scheduleCallback(m_executionContext.get(), createSame
ThreadTask(&CB::handleEvent, wrapPersistent(callback))); | 117 DOMFileSystem::scheduleCallback(m_executionContext.get(), createSame
ThreadTask(&CB::handleEvent, wrapPersistent(callback))); |
| 105 else | 118 else |
| 106 callback->handleEvent(); | 119 callback->handleEvent(); |
| 107 } | 120 } |
| 108 m_executionContext.clear(); | 121 m_executionContext.clear(); |
| 109 } | 122 } |
| 110 | 123 |
| 124 // ScriptErrorCallback -------------------------------------------------------- |
| 125 |
| 126 // static |
| 127 ScriptErrorCallback* ScriptErrorCallback::wrap(ErrorCallback* callback) |
| 128 { |
| 129 // DOMFileSystem operations take an optional (nullable) callback. If a |
| 130 // script callback was not passed, don't bother creating a dummy wrapper |
| 131 // and checking during invoke(). |
| 132 if (!callback) |
| 133 return nullptr; |
| 134 return new ScriptErrorCallback(callback); |
| 135 } |
| 136 |
| 137 DEFINE_TRACE(ScriptErrorCallback) |
| 138 { |
| 139 ErrorCallbackBase::trace(visitor); |
| 140 visitor->trace(m_callback); |
| 141 } |
| 142 |
| 143 void ScriptErrorCallback::invoke(FileError::ErrorCode error) |
| 144 { |
| 145 m_callback->handleEvent(FileError::createDOMException(error)); |
| 146 }; |
| 147 |
| 148 ScriptErrorCallback::ScriptErrorCallback(ErrorCallback* callback) |
| 149 : m_callback(callback) |
| 150 { |
| 151 } |
| 152 |
| 111 // EntryCallbacks ------------------------------------------------------------- | 153 // EntryCallbacks ------------------------------------------------------------- |
| 112 | 154 |
| 113 std::unique_ptr<AsyncFileSystemCallbacks> EntryCallbacks::create(EntryCallback*
successCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFil
eSystemBase* fileSystem, const String& expectedPath, bool isDirectory) | 155 std::unique_ptr<AsyncFileSystemCallbacks> EntryCallbacks::create(EntryCallback*
successCallback, ErrorCallbackBase* errorCallback, ExecutionContext* context, DO
MFileSystemBase* fileSystem, const String& expectedPath, bool isDirectory) |
| 114 { | 156 { |
| 115 return wrapUnique(new EntryCallbacks(successCallback, errorCallback, context
, fileSystem, expectedPath, isDirectory)); | 157 return wrapUnique(new EntryCallbacks(successCallback, errorCallback, context
, fileSystem, expectedPath, isDirectory)); |
| 116 } | 158 } |
| 117 | 159 |
| 118 EntryCallbacks::EntryCallbacks(EntryCallback* successCallback, ErrorCallback* er
rorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const Str
ing& expectedPath, bool isDirectory) | 160 EntryCallbacks::EntryCallbacks(EntryCallback* successCallback, ErrorCallbackBase
* errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const
String& expectedPath, bool isDirectory) |
| 119 : FileSystemCallbacksBase(errorCallback, fileSystem, context) | 161 : FileSystemCallbacksBase(errorCallback, fileSystem, context) |
| 120 , m_successCallback(successCallback) | 162 , m_successCallback(successCallback) |
| 121 , m_expectedPath(expectedPath) | 163 , m_expectedPath(expectedPath) |
| 122 , m_isDirectory(isDirectory) | 164 , m_isDirectory(isDirectory) |
| 123 { | 165 { |
| 124 } | 166 } |
| 125 | 167 |
| 126 void EntryCallbacks::didSucceed() | 168 void EntryCallbacks::didSucceed() |
| 127 { | 169 { |
| 128 if (m_successCallback) { | 170 if (m_successCallback) { |
| 129 if (m_isDirectory) | 171 if (m_isDirectory) |
| 130 handleEventOrScheduleCallback(m_successCallback.release(), Directory
Entry::create(m_fileSystem, m_expectedPath)); | 172 handleEventOrScheduleCallback(m_successCallback.release(), Directory
Entry::create(m_fileSystem, m_expectedPath)); |
| 131 else | 173 else |
| 132 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry
::create(m_fileSystem, m_expectedPath)); | 174 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry
::create(m_fileSystem, m_expectedPath)); |
| 133 } | 175 } |
| 134 } | 176 } |
| 135 | 177 |
| 136 // EntriesCallbacks ----------------------------------------------------------- | 178 // EntriesCallbacks ----------------------------------------------------------- |
| 137 | 179 |
| 138 std::unique_ptr<AsyncFileSystemCallbacks> EntriesCallbacks::create(EntriesCallba
ck* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, Di
rectoryReaderBase* directoryReader, const String& basePath) | 180 std::unique_ptr<AsyncFileSystemCallbacks> EntriesCallbacks::create(EntriesCallba
ck* successCallback, ErrorCallbackBase* errorCallback, ExecutionContext* context
, DirectoryReaderBase* directoryReader, const String& basePath) |
| 139 { | 181 { |
| 140 return wrapUnique(new EntriesCallbacks(successCallback, errorCallback, conte
xt, directoryReader, basePath)); | 182 return wrapUnique(new EntriesCallbacks(successCallback, errorCallback, conte
xt, directoryReader, basePath)); |
| 141 } | 183 } |
| 142 | 184 |
| 143 EntriesCallbacks::EntriesCallbacks(EntriesCallback* successCallback, ErrorCallba
ck* errorCallback, ExecutionContext* context, DirectoryReaderBase* directoryRead
er, const String& basePath) | 185 EntriesCallbacks::EntriesCallbacks(EntriesCallback* successCallback, ErrorCallba
ckBase* errorCallback, ExecutionContext* context, DirectoryReaderBase* directory
Reader, const String& basePath) |
| 144 : FileSystemCallbacksBase(errorCallback, directoryReader->filesystem(), cont
ext) | 186 : FileSystemCallbacksBase(errorCallback, directoryReader->filesystem(), cont
ext) |
| 145 , m_successCallback(successCallback) | 187 , m_successCallback(successCallback) |
| 146 , m_directoryReader(directoryReader) | 188 , m_directoryReader(directoryReader) |
| 147 , m_basePath(basePath) | 189 , m_basePath(basePath) |
| 148 { | 190 { |
| 149 ASSERT(m_directoryReader); | 191 ASSERT(m_directoryReader); |
| 150 } | 192 } |
| 151 | 193 |
| 152 void EntriesCallbacks::didReadDirectoryEntry(const String& name, bool isDirector
y) | 194 void EntriesCallbacks::didReadDirectoryEntry(const String& name, bool isDirector
y) |
| 153 { | 195 { |
| 154 if (isDirectory) | 196 if (isDirectory) |
| 155 m_entries.append(DirectoryEntry::create(m_directoryReader->filesystem(),
DOMFilePath::append(m_basePath, name))); | 197 m_entries.append(DirectoryEntry::create(m_directoryReader->filesystem(),
DOMFilePath::append(m_basePath, name))); |
| 156 else | 198 else |
| 157 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF
ilePath::append(m_basePath, name))); | 199 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF
ilePath::append(m_basePath, name))); |
| 158 } | 200 } |
| 159 | 201 |
| 160 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) | 202 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) |
| 161 { | 203 { |
| 162 m_directoryReader->setHasMoreEntries(hasMore); | 204 m_directoryReader->setHasMoreEntries(hasMore); |
| 163 EntryHeapVector entries; | 205 EntryHeapVector entries; |
| 164 entries.swap(m_entries); | 206 entries.swap(m_entries); |
| 165 // FIXME: delay the callback iff shouldScheduleCallback() is true. | 207 // FIXME: delay the callback iff shouldScheduleCallback() is true. |
| 166 if (m_successCallback) | 208 if (m_successCallback) |
| 167 m_successCallback->handleEvent(entries); | 209 m_successCallback->handleEvent(entries); |
| 168 } | 210 } |
| 169 | 211 |
| 170 // FileSystemCallbacks -------------------------------------------------------- | 212 // FileSystemCallbacks -------------------------------------------------------- |
| 171 | 213 |
| 172 std::unique_ptr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(FileSystem
Callback* successCallback, ErrorCallback* errorCallback, ExecutionContext* conte
xt, FileSystemType type) | 214 std::unique_ptr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(FileSystem
Callback* successCallback, ErrorCallbackBase* errorCallback, ExecutionContext* c
ontext, FileSystemType type) |
| 173 { | 215 { |
| 174 return wrapUnique(new FileSystemCallbacks(successCallback, errorCallback, co
ntext, type)); | 216 return wrapUnique(new FileSystemCallbacks(successCallback, errorCallback, co
ntext, type)); |
| 175 } | 217 } |
| 176 | 218 |
| 177 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, Er
rorCallback* errorCallback, ExecutionContext* context, FileSystemType type) | 219 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, Er
rorCallbackBase* errorCallback, ExecutionContext* context, FileSystemType type) |
| 178 : FileSystemCallbacksBase(errorCallback, nullptr, context) | 220 : FileSystemCallbacksBase(errorCallback, nullptr, context) |
| 179 , m_successCallback(successCallback) | 221 , m_successCallback(successCallback) |
| 180 , m_type(type) | 222 , m_type(type) |
| 181 { | 223 { |
| 182 } | 224 } |
| 183 | 225 |
| 184 void FileSystemCallbacks::didOpenFileSystem(const String& name, const KURL& root
URL) | 226 void FileSystemCallbacks::didOpenFileSystem(const String& name, const KURL& root
URL) |
| 185 { | 227 { |
| 186 if (m_successCallback) | 228 if (m_successCallback) |
| 187 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystem
::create(m_executionContext.get(), name, m_type, rootURL)); | 229 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystem
::create(m_executionContext.get(), name, m_type, rootURL)); |
| 188 } | 230 } |
| 189 | 231 |
| 190 // ResolveURICallbacks -------------------------------------------------------- | 232 // ResolveURICallbacks -------------------------------------------------------- |
| 191 | 233 |
| 192 std::unique_ptr<AsyncFileSystemCallbacks> ResolveURICallbacks::create(EntryCallb
ack* successCallback, ErrorCallback* errorCallback, ExecutionContext* context) | 234 std::unique_ptr<AsyncFileSystemCallbacks> ResolveURICallbacks::create(EntryCallb
ack* successCallback, ErrorCallbackBase* errorCallback, ExecutionContext* contex
t) |
| 193 { | 235 { |
| 194 return wrapUnique(new ResolveURICallbacks(successCallback, errorCallback, co
ntext)); | 236 return wrapUnique(new ResolveURICallbacks(successCallback, errorCallback, co
ntext)); |
| 195 } | 237 } |
| 196 | 238 |
| 197 ResolveURICallbacks::ResolveURICallbacks(EntryCallback* successCallback, ErrorCa
llback* errorCallback, ExecutionContext* context) | 239 ResolveURICallbacks::ResolveURICallbacks(EntryCallback* successCallback, ErrorCa
llbackBase* errorCallback, ExecutionContext* context) |
| 198 : FileSystemCallbacksBase(errorCallback, nullptr, context) | 240 : FileSystemCallbacksBase(errorCallback, nullptr, context) |
| 199 , m_successCallback(successCallback) | 241 , m_successCallback(successCallback) |
| 200 { | 242 { |
| 201 } | 243 } |
| 202 | 244 |
| 203 void ResolveURICallbacks::didResolveURL(const String& name, const KURL& rootURL,
FileSystemType type, const String& filePath, bool isDirectory) | 245 void ResolveURICallbacks::didResolveURL(const String& name, const KURL& rootURL,
FileSystemType type, const String& filePath, bool isDirectory) |
| 204 { | 246 { |
| 205 DOMFileSystem* filesystem = DOMFileSystem::create(m_executionContext.get(),
name, type, rootURL); | 247 DOMFileSystem* filesystem = DOMFileSystem::create(m_executionContext.get(),
name, type, rootURL); |
| 206 DirectoryEntry* root = filesystem->root(); | 248 DirectoryEntry* root = filesystem->root(); |
| 207 | 249 |
| 208 String absolutePath; | 250 String absolutePath; |
| 209 if (!DOMFileSystemBase::pathToAbsolutePath(type, root, filePath, absolutePat
h)) { | 251 if (!DOMFileSystemBase::pathToAbsolutePath(type, root, filePath, absolutePat
h)) { |
| 210 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea
te(FileError::INVALID_MODIFICATION_ERR)); | 252 invokeOrScheduleCallback(m_errorCallback.release(), FileError::INVALID_M
ODIFICATION_ERR); |
| 211 return; | 253 return; |
| 212 } | 254 } |
| 213 | 255 |
| 214 if (isDirectory) | 256 if (isDirectory) |
| 215 handleEventOrScheduleCallback(m_successCallback.release(), DirectoryEntr
y::create(filesystem, absolutePath)); | 257 handleEventOrScheduleCallback(m_successCallback.release(), DirectoryEntr
y::create(filesystem, absolutePath)); |
| 216 else | 258 else |
| 217 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry::cr
eate(filesystem, absolutePath)); | 259 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry::cr
eate(filesystem, absolutePath)); |
| 218 } | 260 } |
| 219 | 261 |
| 220 // MetadataCallbacks ---------------------------------------------------------- | 262 // MetadataCallbacks ---------------------------------------------------------- |
| 221 | 263 |
| 222 std::unique_ptr<AsyncFileSystemCallbacks> MetadataCallbacks::create(MetadataCall
back* successCallback, ErrorCallback* errorCallback, ExecutionContext* context,
DOMFileSystemBase* fileSystem) | 264 std::unique_ptr<AsyncFileSystemCallbacks> MetadataCallbacks::create(MetadataCall
back* successCallback, ErrorCallbackBase* errorCallback, ExecutionContext* conte
xt, DOMFileSystemBase* fileSystem) |
| 223 { | 265 { |
| 224 return wrapUnique(new MetadataCallbacks(successCallback, errorCallback, cont
ext, fileSystem)); | 266 return wrapUnique(new MetadataCallbacks(successCallback, errorCallback, cont
ext, fileSystem)); |
| 225 } | 267 } |
| 226 | 268 |
| 227 MetadataCallbacks::MetadataCallbacks(MetadataCallback* successCallback, ErrorCal
lback* errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem) | 269 MetadataCallbacks::MetadataCallbacks(MetadataCallback* successCallback, ErrorCal
lbackBase* errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSyst
em) |
| 228 : FileSystemCallbacksBase(errorCallback, fileSystem, context) | 270 : FileSystemCallbacksBase(errorCallback, fileSystem, context) |
| 229 , m_successCallback(successCallback) | 271 , m_successCallback(successCallback) |
| 230 { | 272 { |
| 231 } | 273 } |
| 232 | 274 |
| 233 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) | 275 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) |
| 234 { | 276 { |
| 235 if (m_successCallback) | 277 if (m_successCallback) |
| 236 handleEventOrScheduleCallback(m_successCallback.release(), Metadata::cre
ate(metadata)); | 278 handleEventOrScheduleCallback(m_successCallback.release(), Metadata::cre
ate(metadata)); |
| 237 } | 279 } |
| 238 | 280 |
| 239 // FileWriterBaseCallbacks ---------------------------------------------------- | 281 // FileWriterBaseCallbacks ---------------------------------------------------- |
| 240 | 282 |
| 241 std::unique_ptr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create(FileWr
iterBase* fileWriter, FileWriterBaseCallback* successCallback, ErrorCallback* er
rorCallback, ExecutionContext* context) | 283 std::unique_ptr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create(FileWr
iterBase* fileWriter, FileWriterBaseCallback* successCallback, ErrorCallbackBase
* errorCallback, ExecutionContext* context) |
| 242 { | 284 { |
| 243 return wrapUnique(new FileWriterBaseCallbacks(fileWriter, successCallback, e
rrorCallback, context)); | 285 return wrapUnique(new FileWriterBaseCallbacks(fileWriter, successCallback, e
rrorCallback, context)); |
| 244 } | 286 } |
| 245 | 287 |
| 246 FileWriterBaseCallbacks::FileWriterBaseCallbacks(FileWriterBase* fileWriter, Fil
eWriterBaseCallback* successCallback, ErrorCallback* errorCallback, ExecutionCon
text* context) | 288 FileWriterBaseCallbacks::FileWriterBaseCallbacks(FileWriterBase* fileWriter, Fil
eWriterBaseCallback* successCallback, ErrorCallbackBase* errorCallback, Executio
nContext* context) |
| 247 : FileSystemCallbacksBase(errorCallback, nullptr, context) | 289 : FileSystemCallbacksBase(errorCallback, nullptr, context) |
| 248 , m_fileWriter(fileWriter) | 290 , m_fileWriter(fileWriter) |
| 249 , m_successCallback(successCallback) | 291 , m_successCallback(successCallback) |
| 250 { | 292 { |
| 251 } | 293 } |
| 252 | 294 |
| 253 void FileWriterBaseCallbacks::didCreateFileWriter(std::unique_ptr<WebFileWriter>
fileWriter, long long length) | 295 void FileWriterBaseCallbacks::didCreateFileWriter(std::unique_ptr<WebFileWriter>
fileWriter, long long length) |
| 254 { | 296 { |
| 255 m_fileWriter->initialize(std::move(fileWriter), length); | 297 m_fileWriter->initialize(std::move(fileWriter), length); |
| 256 if (m_successCallback) | 298 if (m_successCallback) |
| 257 handleEventOrScheduleCallback(m_successCallback.release(), m_fileWriter.
release()); | 299 handleEventOrScheduleCallback(m_successCallback.release(), m_fileWriter.
release()); |
| 258 } | 300 } |
| 259 | 301 |
| 260 // SnapshotFileCallback ------------------------------------------------------- | 302 // SnapshotFileCallback ------------------------------------------------------- |
| 261 | 303 |
| 262 std::unique_ptr<AsyncFileSystemCallbacks> SnapshotFileCallback::create(DOMFileSy
stemBase* filesystem, const String& name, const KURL& url, BlobCallback* success
Callback, ErrorCallback* errorCallback, ExecutionContext* context) | 304 std::unique_ptr<AsyncFileSystemCallbacks> SnapshotFileCallback::create(DOMFileSy
stemBase* filesystem, const String& name, const KURL& url, BlobCallback* success
Callback, ErrorCallbackBase* errorCallback, ExecutionContext* context) |
| 263 { | 305 { |
| 264 return wrapUnique(new SnapshotFileCallback(filesystem, name, url, successCal
lback, errorCallback, context)); | 306 return wrapUnique(new SnapshotFileCallback(filesystem, name, url, successCal
lback, errorCallback, context)); |
| 265 } | 307 } |
| 266 | 308 |
| 267 SnapshotFileCallback::SnapshotFileCallback(DOMFileSystemBase* filesystem, const
String& name, const KURL& url, BlobCallback* successCallback, ErrorCallback* err
orCallback, ExecutionContext* context) | 309 SnapshotFileCallback::SnapshotFileCallback(DOMFileSystemBase* filesystem, const
String& name, const KURL& url, BlobCallback* successCallback, ErrorCallbackBase*
errorCallback, ExecutionContext* context) |
| 268 : FileSystemCallbacksBase(errorCallback, filesystem, context) | 310 : FileSystemCallbacksBase(errorCallback, filesystem, context) |
| 269 , m_name(name) | 311 , m_name(name) |
| 270 , m_url(url) | 312 , m_url(url) |
| 271 , m_successCallback(successCallback) | 313 , m_successCallback(successCallback) |
| 272 { | 314 { |
| 273 } | 315 } |
| 274 | 316 |
| 275 void SnapshotFileCallback::didCreateSnapshotFile(const FileMetadata& metadata, P
assRefPtr<BlobDataHandle> snapshot) | 317 void SnapshotFileCallback::didCreateSnapshotFile(const FileMetadata& metadata, P
assRefPtr<BlobDataHandle> snapshot) |
| 276 { | 318 { |
| 277 if (!m_successCallback) | 319 if (!m_successCallback) |
| 278 return; | 320 return; |
| 279 | 321 |
| 280 // We can't directly use the snapshot blob data handle because the content t
ype on it hasn't been set. | 322 // We can't directly use the snapshot blob data handle because the content t
ype on it hasn't been set. |
| 281 // The |snapshot| param is here to provide a a chain of custody thru thread
bridging that is held onto until | 323 // The |snapshot| param is here to provide a a chain of custody thru thread
bridging that is held onto until |
| 282 // *after* we've coined a File with a new handle that has the correct type s
et on it. This allows the | 324 // *after* we've coined a File with a new handle that has the correct type s
et on it. This allows the |
| 283 // blob storage system to track when a temp file can and can't be safely del
eted. | 325 // blob storage system to track when a temp file can and can't be safely del
eted. |
| 284 | 326 |
| 285 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystemBase
::createFile(metadata, m_url, m_fileSystem->type(), m_name)); | 327 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystemBase
::createFile(metadata, m_url, m_fileSystem->type(), m_name)); |
| 286 } | 328 } |
| 287 | 329 |
| 288 // VoidCallbacks -------------------------------------------------------------- | 330 // VoidCallbacks -------------------------------------------------------------- |
| 289 | 331 |
| 290 std::unique_ptr<AsyncFileSystemCallbacks> VoidCallbacks::create(VoidCallback* su
ccessCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFileS
ystemBase* fileSystem) | 332 std::unique_ptr<AsyncFileSystemCallbacks> VoidCallbacks::create(VoidCallback* su
ccessCallback, ErrorCallbackBase* errorCallback, ExecutionContext* context, DOMF
ileSystemBase* fileSystem) |
| 291 { | 333 { |
| 292 return wrapUnique(new VoidCallbacks(successCallback, errorCallback, context,
fileSystem)); | 334 return wrapUnique(new VoidCallbacks(successCallback, errorCallback, context,
fileSystem)); |
| 293 } | 335 } |
| 294 | 336 |
| 295 VoidCallbacks::VoidCallbacks(VoidCallback* successCallback, ErrorCallback* error
Callback, ExecutionContext* context, DOMFileSystemBase* fileSystem) | 337 VoidCallbacks::VoidCallbacks(VoidCallback* successCallback, ErrorCallbackBase* e
rrorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem) |
| 296 : FileSystemCallbacksBase(errorCallback, fileSystem, context) | 338 : FileSystemCallbacksBase(errorCallback, fileSystem, context) |
| 297 , m_successCallback(successCallback) | 339 , m_successCallback(successCallback) |
| 298 { | 340 { |
| 299 } | 341 } |
| 300 | 342 |
| 301 void VoidCallbacks::didSucceed() | 343 void VoidCallbacks::didSucceed() |
| 302 { | 344 { |
| 303 if (m_successCallback) | 345 if (m_successCallback) |
| 304 handleEventOrScheduleCallback(m_successCallback.release()); | 346 handleEventOrScheduleCallback(m_successCallback.release()); |
| 305 } | 347 } |
| 306 | 348 |
| 307 } // namespace blink | 349 } // namespace blink |
| OLD | NEW |