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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 , m_clonable(false) | 66 , m_clonable(false) |
67 { | 67 { |
68 } | 68 } |
69 | 69 |
70 DOMFileSystemBase::~DOMFileSystemBase() | 70 DOMFileSystemBase::~DOMFileSystemBase() |
71 { | 71 { |
72 } | 72 } |
73 | 73 |
74 blink::WebFileSystem* DOMFileSystemBase::fileSystem() const | 74 blink::WebFileSystem* DOMFileSystemBase::fileSystem() const |
75 { | 75 { |
76 return blink::Platform::current()->fileSystem(); | 76 blink::Platform* platform = blink::Platform::current(); |
77 if (!platform) | |
78 return 0; | |
nhiroki
2014/08/11 04:56:38
"return nullptr;"?
tzik
2014/08/11 05:12:08
Done.
| |
79 return platform->fileSystem(); | |
77 } | 80 } |
78 | 81 |
79 SecurityOrigin* DOMFileSystemBase::securityOrigin() const | 82 SecurityOrigin* DOMFileSystemBase::securityOrigin() const |
80 { | 83 { |
81 return m_context->securityOrigin(); | 84 return m_context->securityOrigin(); |
82 } | 85 } |
83 | 86 |
84 bool DOMFileSystemBase::isValidType(FileSystemType type) | 87 bool DOMFileSystemBase::isValidType(FileSystemType type) |
85 { | 88 { |
86 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent | | type == FileSystemTypeIsolated || type == FileSystemTypeExternal; | 89 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent | | type == FileSystemTypeIsolated || type == FileSystemTypeExternal; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 return true; | 185 return true; |
183 } | 186 } |
184 | 187 |
185 return false; | 188 return false; |
186 } | 189 } |
187 | 190 |
188 void DOMFileSystemBase::getMetadata(const EntryBase* entry, PassOwnPtr<MetadataC allback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousTy pe synchronousType) | 191 void DOMFileSystemBase::getMetadata(const EntryBase* entry, PassOwnPtr<MetadataC allback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousTy pe synchronousType) |
189 { | 192 { |
190 OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(success Callback, errorCallback, m_context, this)); | 193 OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(success Callback, errorCallback, m_context, this)); |
191 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 194 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
195 if (!fileSystem()) { | |
196 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
197 return; | |
198 } | |
nhiroki
2014/08/11 04:56:38
How about moving this block before creating |callb
tzik
2014/08/11 05:12:08
Done.
| |
192 fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release()); | 199 fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release()); |
193 } | 200 } |
194 | 201 |
195 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En tryBase* parent, const String& newName, String& destinationPath) | 202 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En tryBase* parent, const String& newName, String& destinationPath) |
196 { | 203 { |
197 ASSERT(source); | 204 ASSERT(source); |
198 | 205 |
199 if (!parent || !parent->isDirectory()) | 206 if (!parent || !parent->isDirectory()) |
200 return false; | 207 return false; |
201 | 208 |
(...skipping 20 matching lines...) Expand all Loading... | |
222 } | 229 } |
223 | 230 |
224 void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) | 231 void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) |
225 { | 232 { |
226 String destinationPath; | 233 String destinationPath; |
227 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) { | 234 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) { |
228 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); | 235 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); |
229 return; | 236 return; |
230 } | 237 } |
231 | 238 |
239 if (!fileSystem()) { | |
240 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
241 return; | |
242 } | |
243 | |
232 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, parent->filesystem(), destinationPath, source-> isDirectory())); | 244 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, parent->filesystem(), destinationPath, source-> isDirectory())); |
233 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 245 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
234 | 246 |
235 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release()); | 247 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release()); |
236 } | 248 } |
237 | 249 |
238 void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) | 250 void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) |
239 { | 251 { |
240 String destinationPath; | 252 String destinationPath; |
241 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) { | 253 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) { |
242 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); | 254 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); |
243 return; | 255 return; |
244 } | 256 } |
245 | 257 |
258 if (!fileSystem()) { | |
259 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
260 return; | |
261 } | |
262 | |
246 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, parent->filesystem(), destinationPath, source-> isDirectory())); | 263 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, parent->filesystem(), destinationPath, source-> isDirectory())); |
247 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 264 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
248 | 265 |
249 fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release()); | 266 fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release()); |
250 } | 267 } |
251 | 268 |
252 void DOMFileSystemBase::remove(const EntryBase* entry, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchr onousType) | 269 void DOMFileSystemBase::remove(const EntryBase* entry, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchr onousType) |
253 { | 270 { |
254 ASSERT(entry); | 271 ASSERT(entry); |
255 // We don't allow calling remove() on the root directory. | 272 // We don't allow calling remove() on the root directory. |
256 if (entry->fullPath() == String(DOMFilePath::root)) { | 273 if (entry->fullPath() == String(DOMFilePath::root)) { |
257 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); | 274 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); |
258 return; | 275 return; |
259 } | 276 } |
260 | 277 |
278 if (!fileSystem()) { | |
279 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
280 return; | |
281 } | |
282 | |
261 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall back, errorCallback, m_context, this)); | 283 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall back, errorCallback, m_context, this)); |
262 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 284 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
263 | 285 |
264 fileSystem()->remove(createFileSystemURL(entry), callbacks.release()); | 286 fileSystem()->remove(createFileSystemURL(entry), callbacks.release()); |
265 } | 287 } |
266 | 288 |
267 void DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassOwnPtr<Voi dCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Synchronous Type synchronousType) | 289 void DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassOwnPtr<Voi dCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Synchronous Type synchronousType) |
268 { | 290 { |
269 ASSERT(entry && entry->isDirectory()); | 291 ASSERT(entry && entry->isDirectory()); |
270 // We don't allow calling remove() on the root directory. | 292 // We don't allow calling remove() on the root directory. |
271 if (entry->fullPath() == String(DOMFilePath::root)) { | 293 if (entry->fullPath() == String(DOMFilePath::root)) { |
272 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); | 294 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); |
273 return; | 295 return; |
274 } | 296 } |
275 | 297 |
298 if (!fileSystem()) { | |
299 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
300 return; | |
301 } | |
302 | |
276 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall back, errorCallback, m_context, this)); | 303 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall back, errorCallback, m_context, this)); |
277 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 304 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
278 | 305 |
279 fileSystem()->removeRecursively(createFileSystemURL(entry), callbacks.releas e()); | 306 fileSystem()->removeRecursively(createFileSystemURL(entry), callbacks.releas e()); |
280 } | 307 } |
281 | 308 |
282 void DOMFileSystemBase::getParent(const EntryBase* entry, PassOwnPtr<EntryCallba ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) | 309 void DOMFileSystemBase::getParent(const EntryBase* entry, PassOwnPtr<EntryCallba ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) |
283 { | 310 { |
284 ASSERT(entry); | 311 ASSERT(entry); |
285 String path = DOMFilePath::getDirectory(entry->fullPath()); | 312 String path = DOMFilePath::getDirectory(entry->fullPath()); |
313 | |
314 if (!fileSystem()) { | |
315 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
316 return; | |
317 } | |
318 | |
286 fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::cre ate(successCallback, errorCallback, m_context, this, path, true)); | 319 fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::cre ate(successCallback, errorCallback, m_context, this, path, true)); |
287 } | 320 } |
288 | 321 |
289 void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons t FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr< ErrorCallback> errorCallback, SynchronousType synchronousType) | 322 void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons t FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr< ErrorCallback> errorCallback, SynchronousType synchronousType) |
290 { | 323 { |
291 String absolutePath; | 324 String absolutePath; |
292 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { | 325 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { |
293 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); | 326 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); |
294 return; | 327 return; |
295 } | 328 } |
296 | 329 |
330 if (!fileSystem()) { | |
331 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
332 return; | |
333 } | |
334 | |
297 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, this, absolutePath, false)); | 335 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, this, absolutePath, false)); |
298 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 336 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
299 | 337 |
300 if (flags.create) | 338 if (flags.create) |
301 fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclus ive, callbacks.release()); | 339 fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclus ive, callbacks.release()); |
302 else | 340 else |
303 fileSystem()->fileExists(createFileSystemURL(absolutePath), callbacks.re lease()); | 341 fileSystem()->fileExists(createFileSystemURL(absolutePath), callbacks.re lease()); |
304 } | 342 } |
305 | 343 |
306 void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path, const FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOw nPtr<ErrorCallback> errorCallback, SynchronousType synchronousType) | 344 void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path, const FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOw nPtr<ErrorCallback> errorCallback, SynchronousType synchronousType) |
307 { | 345 { |
308 String absolutePath; | 346 String absolutePath; |
309 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { | 347 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { |
310 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); | 348 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA TION_ERR)); |
311 return; | 349 return; |
312 } | 350 } |
313 | 351 |
352 if (!fileSystem()) { | |
353 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
354 return; | |
355 } | |
356 | |
314 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, this, absolutePath, true)); | 357 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, m_context, this, absolutePath, true)); |
315 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 358 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
316 | 359 |
317 if (flags.create) | 360 if (flags.create) |
318 fileSystem()->createDirectory(createFileSystemURL(absolutePath), flags.e xclusive, callbacks.release()); | 361 fileSystem()->createDirectory(createFileSystemURL(absolutePath), flags.e xclusive, callbacks.release()); |
319 else | 362 else |
320 fileSystem()->directoryExists(createFileSystemURL(absolutePath), callbac ks.release()); | 363 fileSystem()->directoryExists(createFileSystemURL(absolutePath), callbac ks.release()); |
321 } | 364 } |
322 | 365 |
323 int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String& path, PassOwnPtr<EntriesCallback> successCallback, PassOwnPtr<ErrorCallback> err orCallback, SynchronousType synchronousType) | 366 int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String& path, PassOwnPtr<EntriesCallback> successCallback, PassOwnPtr<ErrorCallback> err orCallback, SynchronousType synchronousType) |
324 { | 367 { |
325 ASSERT(DOMFilePath::isAbsolute(path)); | 368 ASSERT(DOMFilePath::isAbsolute(path)); |
326 | 369 |
327 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successC allback, errorCallback, m_context, reader, path)); | 370 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successC allback, errorCallback, m_context, reader, path)); |
328 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 371 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
329 | 372 |
373 if (!fileSystem()) { | |
374 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | |
375 return 0; | |
376 } | |
nhiroki
2014/08/11 04:56:38
ditto.
tzik
2014/08/11 05:12:08
Done.
| |
377 | |
330 return fileSystem()->readDirectory(createFileSystemURL(path), callbacks.rele ase()); | 378 return fileSystem()->readDirectory(createFileSystemURL(path), callbacks.rele ase()); |
331 } | 379 } |
332 | 380 |
333 bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId) | 381 bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId) |
334 { | 382 { |
383 if (!fileSystem()) | |
384 return false; | |
335 return fileSystem()->waitForAdditionalResult(callbacksId); | 385 return fileSystem()->waitForAdditionalResult(callbacksId); |
336 } | 386 } |
337 | 387 |
338 } // namespace blink | 388 } // namespace blink |
OLD | NEW |