| 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 "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 "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/FileEntry.h" | 46 #include "modules/filesystem/FileEntry.h" |
| 48 #include "modules/filesystem/FileSystemCallback.h" | 47 #include "modules/filesystem/FileSystemCallback.h" |
| 49 #include "modules/filesystem/FileWriterBase.h" | 48 #include "modules/filesystem/FileWriterBase.h" |
| 50 #include "modules/filesystem/FileWriterBaseCallback.h" | 49 #include "modules/filesystem/FileWriterBaseCallback.h" |
| 51 #include "modules/filesystem/Metadata.h" | 50 #include "modules/filesystem/Metadata.h" |
| 52 #include "modules/filesystem/MetadataCallback.h" | 51 #include "modules/filesystem/MetadataCallback.h" |
| 53 #include "platform/FileMetadata.h" | 52 #include "platform/FileMetadata.h" |
| 54 #include "public/platform/WebFileWriter.h" | 53 #include "public/platform/WebFileWriter.h" |
| 55 | 54 |
| 56 namespace blink { | 55 namespace blink { |
| 57 | 56 |
| 58 FileSystemCallbacksBase::FileSystemCallbacksBase(ErrorCallback* errorCallback, D
OMFileSystemBase* fileSystem, ExecutionContext* context) | 57 FileSystemCallbacksBase::FileSystemCallbacksBase(ErrorCallback* errorCallback, D
OMFileSystemBase* fileSystem, ExecutionContext* context) |
| 59 : m_errorCallback(errorCallback) | 58 : m_errorCallback(errorCallback) |
| 60 , m_fileSystem(fileSystem) | 59 , m_fileSystem(fileSystem) |
| 61 , m_executionContext(context) | 60 , m_executionContext(context) |
| 62 , m_asyncOperationId(0) | |
| 63 { | 61 { |
| 64 if (m_fileSystem) | 62 if (m_fileSystem) |
| 65 m_fileSystem->addPendingCallbacks(); | 63 m_fileSystem->addPendingCallbacks(); |
| 66 if (m_executionContext) | |
| 67 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti
ng(m_executionContext.get(), "FileSystem"); | |
| 68 } | 64 } |
| 69 | 65 |
| 70 FileSystemCallbacksBase::~FileSystemCallbacksBase() | 66 FileSystemCallbacksBase::~FileSystemCallbacksBase() |
| 71 { | 67 { |
| 72 if (m_fileSystem) | 68 if (m_fileSystem) |
| 73 m_fileSystem->removePendingCallbacks(); | 69 m_fileSystem->removePendingCallbacks(); |
| 74 if (m_asyncOperationId && m_executionContext) | |
| 75 InspectorInstrumentation::traceAsyncOperationCompleted(m_executionContex
t.get(), m_asyncOperationId); | |
| 76 } | 70 } |
| 77 | 71 |
| 78 void FileSystemCallbacksBase::didFail(int code) | 72 void FileSystemCallbacksBase::didFail(int code) |
| 79 { | 73 { |
| 80 if (m_errorCallback) | 74 if (m_errorCallback) |
| 81 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea
te(static_cast<FileError::ErrorCode>(code))); | 75 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea
te(static_cast<FileError::ErrorCode>(code))); |
| 82 } | 76 } |
| 83 | 77 |
| 84 bool FileSystemCallbacksBase::shouldScheduleCallback() const | 78 bool FileSystemCallbacksBase::shouldScheduleCallback() const |
| 85 { | 79 { |
| 86 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon
text->activeDOMObjectsAreSuspended(); | 80 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon
text->activeDOMObjectsAreSuspended(); |
| 87 } | 81 } |
| 88 | 82 |
| 89 template <typename CB, typename CBArg> | 83 template <typename CB, typename CBArg> |
| 90 void FileSystemCallbacksBase::handleEventOrScheduleCallback(RawPtr<CB> callback,
CBArg* arg) | 84 void FileSystemCallbacksBase::handleEventOrScheduleCallback(RawPtr<CB> callback,
CBArg* arg) |
| 91 { | 85 { |
| 92 ASSERT(callback); | 86 ASSERT(callback); |
| 93 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
OperationCompletedCallbackStarting(m_executionContext.get(), m_asyncOperationId)
; | |
| 94 if (shouldScheduleCallback()) | 87 if (shouldScheduleCallback()) |
| 95 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback.get()
, arg); | 88 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback.get()
, arg); |
| 96 else if (callback) | 89 else if (callback) |
| 97 callback->handleEvent(arg); | 90 callback->handleEvent(arg); |
| 98 m_executionContext.clear(); | 91 m_executionContext.clear(); |
| 99 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 100 } | 92 } |
| 101 | 93 |
| 102 template <typename CB> | 94 template <typename CB> |
| 103 void FileSystemCallbacksBase::handleEventOrScheduleCallback(RawPtr<CB> callback) | 95 void FileSystemCallbacksBase::handleEventOrScheduleCallback(RawPtr<CB> callback) |
| 104 { | 96 { |
| 105 ASSERT(callback); | 97 ASSERT(callback); |
| 106 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
OperationCompletedCallbackStarting(m_executionContext.get(), m_asyncOperationId)
; | |
| 107 if (shouldScheduleCallback()) | 98 if (shouldScheduleCallback()) |
| 108 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback.get()
); | 99 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback.get()
); |
| 109 else if (callback) | 100 else if (callback) |
| 110 callback->handleEvent(); | 101 callback->handleEvent(); |
| 111 m_executionContext.clear(); | 102 m_executionContext.clear(); |
| 112 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 113 } | 103 } |
| 114 | 104 |
| 115 // EntryCallbacks ------------------------------------------------------------- | 105 // EntryCallbacks ------------------------------------------------------------- |
| 116 | 106 |
| 117 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(EntryCallback* succe
ssCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFileSyst
emBase* fileSystem, const String& expectedPath, bool isDirectory) | 107 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(EntryCallback* succe
ssCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFileSyst
emBase* fileSystem, const String& expectedPath, bool isDirectory) |
| 118 { | 108 { |
| 119 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context,
fileSystem, expectedPath, isDirectory)); | 109 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context,
fileSystem, expectedPath, isDirectory)); |
| 120 } | 110 } |
| 121 | 111 |
| 122 EntryCallbacks::EntryCallbacks(EntryCallback* successCallback, ErrorCallback* er
rorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const Str
ing& expectedPath, bool isDirectory) | 112 EntryCallbacks::EntryCallbacks(EntryCallback* successCallback, ErrorCallback* er
rorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const Str
ing& expectedPath, bool isDirectory) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 else | 150 else |
| 161 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF
ilePath::append(m_basePath, name))); | 151 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF
ilePath::append(m_basePath, name))); |
| 162 } | 152 } |
| 163 | 153 |
| 164 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) | 154 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) |
| 165 { | 155 { |
| 166 m_directoryReader->setHasMoreEntries(hasMore); | 156 m_directoryReader->setHasMoreEntries(hasMore); |
| 167 EntryHeapVector entries; | 157 EntryHeapVector entries; |
| 168 entries.swap(m_entries); | 158 entries.swap(m_entries); |
| 169 // FIXME: delay the callback iff shouldScheduleCallback() is true. | 159 // FIXME: delay the callback iff shouldScheduleCallback() is true. |
| 170 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
CallbackStarting(m_executionContext.get(), m_asyncOperationId); | |
| 171 if (m_successCallback) | 160 if (m_successCallback) |
| 172 m_successCallback->handleEvent(entries); | 161 m_successCallback->handleEvent(entries); |
| 173 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 174 if (!hasMore) | |
| 175 InspectorInstrumentation::traceAsyncOperationCompleted(m_executionContex
t.get(), m_asyncOperationId); | |
| 176 } | 162 } |
| 177 | 163 |
| 178 // FileSystemCallbacks -------------------------------------------------------- | 164 // FileSystemCallbacks -------------------------------------------------------- |
| 179 | 165 |
| 180 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(FileSystemCallb
ack* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, F
ileSystemType type) | 166 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(FileSystemCallb
ack* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, F
ileSystemType type) |
| 181 { | 167 { |
| 182 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont
ext, type)); | 168 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont
ext, type)); |
| 183 } | 169 } |
| 184 | 170 |
| 185 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, Er
rorCallback* errorCallback, ExecutionContext* context, FileSystemType type) | 171 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, Er
rorCallback* errorCallback, ExecutionContext* context, FileSystemType type) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 { | 292 { |
| 307 } | 293 } |
| 308 | 294 |
| 309 void VoidCallbacks::didSucceed() | 295 void VoidCallbacks::didSucceed() |
| 310 { | 296 { |
| 311 if (m_successCallback) | 297 if (m_successCallback) |
| 312 handleEventOrScheduleCallback(m_successCallback.release()); | 298 handleEventOrScheduleCallback(m_successCallback.release()); |
| 313 } | 299 } |
| 314 | 300 |
| 315 } // namespace blink | 301 } // namespace blink |
| OLD | NEW |