| 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 17 matching lines...) Expand all Loading... |
| 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 "config.h" | 31 #include "config.h" |
| 32 #include "modules/filesystem/FileSystemCallbacks.h" | 32 #include "modules/filesystem/FileSystemCallbacks.h" |
| 33 | 33 |
| 34 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.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 "core/inspector/InspectorInstrumentation.h" | |
| 39 #include "modules/filesystem/DOMFilePath.h" | 38 #include "modules/filesystem/DOMFilePath.h" |
| 40 #include "modules/filesystem/DOMFileSystem.h" | 39 #include "modules/filesystem/DOMFileSystem.h" |
| 41 #include "modules/filesystem/DOMFileSystemBase.h" | 40 #include "modules/filesystem/DOMFileSystemBase.h" |
| 42 #include "modules/filesystem/DirectoryEntry.h" | 41 #include "modules/filesystem/DirectoryEntry.h" |
| 43 #include "modules/filesystem/DirectoryReader.h" | 42 #include "modules/filesystem/DirectoryReader.h" |
| 44 #include "modules/filesystem/Entry.h" | 43 #include "modules/filesystem/Entry.h" |
| 45 #include "modules/filesystem/EntryCallback.h" | 44 #include "modules/filesystem/EntryCallback.h" |
| 46 #include "modules/filesystem/ErrorCallback.h" | 45 #include "modules/filesystem/ErrorCallback.h" |
| 47 #include "modules/filesystem/FileCallback.h" | 46 #include "modules/filesystem/FileCallback.h" |
| 48 #include "modules/filesystem/FileEntry.h" | 47 #include "modules/filesystem/FileEntry.h" |
| 49 #include "modules/filesystem/FileSystemCallback.h" | 48 #include "modules/filesystem/FileSystemCallback.h" |
| 50 #include "modules/filesystem/FileWriterBase.h" | 49 #include "modules/filesystem/FileWriterBase.h" |
| 51 #include "modules/filesystem/FileWriterBaseCallback.h" | 50 #include "modules/filesystem/FileWriterBaseCallback.h" |
| 52 #include "modules/filesystem/Metadata.h" | 51 #include "modules/filesystem/Metadata.h" |
| 53 #include "modules/filesystem/MetadataCallback.h" | 52 #include "modules/filesystem/MetadataCallback.h" |
| 54 #include "platform/FileMetadata.h" | 53 #include "platform/FileMetadata.h" |
| 55 #include "public/platform/WebFileWriter.h" | 54 #include "public/platform/WebFileWriter.h" |
| 56 | 55 |
| 57 namespace WebCore { | 56 namespace WebCore { |
| 58 | 57 |
| 59 namespace { | |
| 60 | |
| 61 class HandleCallbackScope FINAL { | |
| 62 WTF_MAKE_NONCOPYABLE(HandleCallbackScope); | |
| 63 public: | |
| 64 HandleCallbackScope(PassRefPtrWillBeRawPtr<ExecutionContext> executionContex
t, FileSystemCallbacksBase* callback, bool reschedule = false, bool hasMore = fa
lse) | |
| 65 : m_executionContext(executionContext) | |
| 66 , m_callback(callback) | |
| 67 , m_reschedule(reschedule) | |
| 68 { | |
| 69 if (m_executionContext) | |
| 70 InspectorInstrumentation::willHandleAsyncFileSystemCallback(m_execut
ionContext.get(), m_callback, m_reschedule, hasMore); | |
| 71 } | |
| 72 | |
| 73 ~HandleCallbackScope() | |
| 74 { | |
| 75 if (m_executionContext) | |
| 76 InspectorInstrumentation::didHandleAsyncFileSystemCallback(m_executi
onContext.get(), m_callback, m_reschedule); | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 RefPtrWillBePersistent<ExecutionContext> m_executionContext; | |
| 81 FileSystemCallbacksBase* m_callback; | |
| 82 bool m_reschedule; | |
| 83 }; | |
| 84 | |
| 85 } // namespace | |
| 86 | |
| 87 FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> error
Callback, DOMFileSystemBase* fileSystem, ExecutionContext* context) | 58 FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> error
Callback, DOMFileSystemBase* fileSystem, ExecutionContext* context) |
| 88 : m_errorCallback(errorCallback) | 59 : m_errorCallback(errorCallback) |
| 89 , m_fileSystem(fileSystem) | 60 , m_fileSystem(fileSystem) |
| 90 , m_executionContext(context) | 61 , m_executionContext(context) |
| 91 { | 62 { |
| 92 if (m_fileSystem) | 63 if (m_fileSystem) |
| 93 m_fileSystem->addPendingCallbacks(); | 64 m_fileSystem->addPendingCallbacks(); |
| 94 if (m_executionContext) | |
| 95 InspectorInstrumentation::didEnqueueAsyncFileSystemCallback(m_executionC
ontext.get(), this); | |
| 96 } | 65 } |
| 97 | 66 |
| 98 FileSystemCallbacksBase::~FileSystemCallbacksBase() | 67 FileSystemCallbacksBase::~FileSystemCallbacksBase() |
| 99 { | 68 { |
| 100 if (m_executionContext) | |
| 101 InspectorInstrumentation::didRemoveAsyncFileSystemCallback(m_executionCo
ntext.get(), this); | |
| 102 if (m_fileSystem) | 69 if (m_fileSystem) |
| 103 m_fileSystem->removePendingCallbacks(); | 70 m_fileSystem->removePendingCallbacks(); |
| 104 } | 71 } |
| 105 | 72 |
| 106 void FileSystemCallbacksBase::didFail(int code) | 73 void FileSystemCallbacksBase::didFail(int code) |
| 107 { | 74 { |
| 108 if (m_errorCallback) | 75 if (m_errorCallback) |
| 109 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea
te(static_cast<FileError::ErrorCode>(code))); | 76 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea
te(static_cast<FileError::ErrorCode>(code))); |
| 110 } | 77 } |
| 111 | 78 |
| 112 bool FileSystemCallbacksBase::shouldScheduleCallback() const | 79 bool FileSystemCallbacksBase::shouldScheduleCallback() const |
| 113 { | 80 { |
| 114 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon
text->activeDOMObjectsAreSuspended(); | 81 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon
text->activeDOMObjectsAreSuspended(); |
| 115 } | 82 } |
| 116 | 83 |
| 117 template <typename CB, typename CBArg> | 84 template <typename CB, typename CBArg> |
| 118 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb
ack, CBArg* arg) | 85 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb
ack, CBArg* arg) |
| 119 { | 86 { |
| 120 ASSERT(callback.get()); | 87 ASSERT(callback.get()); |
| 121 if (shouldScheduleCallback()) { | 88 if (shouldScheduleCallback()) |
| 122 HandleCallbackScope scope(m_executionContext, this, true /* reschedule *
/); | |
| 123 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg)
; | 89 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg)
; |
| 124 } else { | 90 else if (callback) |
| 125 HandleCallbackScope scope(m_executionContext, this); | 91 callback->handleEvent(arg); |
| 126 if (callback) | |
| 127 callback->handleEvent(arg); | |
| 128 } | |
| 129 m_executionContext.clear(); | 92 m_executionContext.clear(); |
| 130 } | 93 } |
| 131 | 94 |
| 132 template <typename CB, typename CBArg> | 95 template <typename CB, typename CBArg> |
| 133 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb
ack, PassRefPtrWillBeRawPtr<CBArg> arg) | 96 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb
ack, PassRefPtrWillBeRawPtr<CBArg> arg) |
| 134 { | 97 { |
| 135 ASSERT(callback.get()); | 98 ASSERT(callback.get()); |
| 136 if (shouldScheduleCallback()) { | 99 if (shouldScheduleCallback()) |
| 137 HandleCallbackScope scope(m_executionContext, this, true /* reschedule *
/); | |
| 138 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg)
; | 100 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg)
; |
| 139 } else { | 101 else if (callback) |
| 140 HandleCallbackScope scope(m_executionContext, this); | 102 callback->handleEvent(arg.get()); |
| 141 if (callback) | |
| 142 callback->handleEvent(arg.get()); | |
| 143 } | |
| 144 m_executionContext.clear(); | 103 m_executionContext.clear(); |
| 145 } | 104 } |
| 146 | 105 |
| 147 template <typename CB> | 106 template <typename CB> |
| 148 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb
ack) | 107 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb
ack) |
| 149 { | 108 { |
| 150 ASSERT(callback.get()); | 109 ASSERT(callback.get()); |
| 151 if (shouldScheduleCallback()) { | 110 if (shouldScheduleCallback()) |
| 152 HandleCallbackScope scope(m_executionContext, this, true /* reschedule *
/); | |
| 153 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback); | 111 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback); |
| 154 } else { | 112 else if (callback) |
| 155 HandleCallbackScope scope(m_executionContext, this); | 113 callback->handleEvent(); |
| 156 if (callback) | |
| 157 callback->handleEvent(); | |
| 158 } | |
| 159 m_executionContext.clear(); | 114 m_executionContext.clear(); |
| 160 } | 115 } |
| 161 | 116 |
| 162 // EntryCallbacks ------------------------------------------------------------- | 117 // EntryCallbacks ------------------------------------------------------------- |
| 163 | 118 |
| 164 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(PassOwnPtr<EntryCall
back> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext
* context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDir
ectory) | 119 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(PassOwnPtr<EntryCall
back> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext
* context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDir
ectory) |
| 165 { | 120 { |
| 166 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context,
fileSystem, expectedPath, isDirectory)); | 121 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context,
fileSystem, expectedPath, isDirectory)); |
| 167 } | 122 } |
| 168 | 123 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 else | 162 else |
| 208 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF
ilePath::append(m_basePath, name))); | 163 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF
ilePath::append(m_basePath, name))); |
| 209 } | 164 } |
| 210 | 165 |
| 211 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) | 166 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) |
| 212 { | 167 { |
| 213 m_directoryReader->setHasMoreEntries(hasMore); | 168 m_directoryReader->setHasMoreEntries(hasMore); |
| 214 EntryHeapVector entries; | 169 EntryHeapVector entries; |
| 215 entries.swap(m_entries); | 170 entries.swap(m_entries); |
| 216 // FIXME: delay the callback iff shouldScheduleCallback() is true. | 171 // FIXME: delay the callback iff shouldScheduleCallback() is true. |
| 217 HandleCallbackScope scope(m_executionContext, this, false /* reschedule */,
hasMore); | |
| 218 if (m_successCallback) | 172 if (m_successCallback) |
| 219 m_successCallback->handleEvent(entries); | 173 m_successCallback->handleEvent(entries); |
| 220 } | 174 } |
| 221 | 175 |
| 222 // FileSystemCallbacks -------------------------------------------------------- | 176 // FileSystemCallbacks -------------------------------------------------------- |
| 223 | 177 |
| 224 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(PassOwnPtr<File
SystemCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Execut
ionContext* context, FileSystemType type) | 178 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(PassOwnPtr<File
SystemCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Execut
ionContext* context, FileSystemType type) |
| 225 { | 179 { |
| 226 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont
ext, type)); | 180 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont
ext, type)); |
| 227 } | 181 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 { | 316 { |
| 363 } | 317 } |
| 364 | 318 |
| 365 void VoidCallbacks::didSucceed() | 319 void VoidCallbacks::didSucceed() |
| 366 { | 320 { |
| 367 if (m_successCallback) | 321 if (m_successCallback) |
| 368 handleEventOrScheduleCallback(m_successCallback.release()); | 322 handleEventOrScheduleCallback(m_successCallback.release()); |
| 369 } | 323 } |
| 370 | 324 |
| 371 } // namespace | 325 } // namespace |
| OLD | NEW |