| 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 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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/DirectoryReader.h" | 31 #include "modules/filesystem/FileSystemDirectoryReader.h" |
| 32 | 32 |
| 33 #include "core/fileapi/FileError.h" | 33 #include "core/fileapi/FileError.h" |
| 34 #include "modules/filesystem/EntriesCallback.h" | |
| 35 #include "modules/filesystem/Entry.h" | |
| 36 #include "modules/filesystem/ErrorCallback.h" | 34 #include "modules/filesystem/ErrorCallback.h" |
| 37 #include "modules/filesystem/FileSystemCallbacks.h" | 35 #include "modules/filesystem/FileSystemCallbacks.h" |
| 36 #include "modules/filesystem/FileSystemEntriesCallback.h" |
| 37 #include "modules/filesystem/FileSystemEntry.h" |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 class DirectoryReader::EntriesCallbackHelper final : public EntriesCallback { | 41 class FileSystemDirectoryReader::EntriesCallbackHelper final |
| 42 : public FileSystemEntriesCallback { |
| 42 public: | 43 public: |
| 43 explicit EntriesCallbackHelper(DirectoryReader* reader) : m_reader(reader) {} | 44 explicit EntriesCallbackHelper(FileSystemDirectoryReader* reader) |
| 45 : m_reader(reader) {} |
| 44 | 46 |
| 45 void handleEvent(const EntryHeapVector& entries) override { | 47 void handleEvent(const EntryHeapVector& entries) override { |
| 46 m_reader->addEntries(entries); | 48 m_reader->addEntries(entries); |
| 47 } | 49 } |
| 48 | 50 |
| 49 DEFINE_INLINE_VIRTUAL_TRACE() { | 51 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 50 visitor->trace(m_reader); | 52 visitor->trace(m_reader); |
| 51 EntriesCallback::trace(visitor); | 53 FileSystemEntriesCallback::trace(visitor); |
| 52 } | 54 } |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 // FIXME: This Member keeps the reader alive until all of the readDirectory | 57 // FIXME: This Member keeps the reader alive until all of the readDirectory |
| 56 // results are received. crbug.com/350285 | 58 // results are received. crbug.com/350285 |
| 57 Member<DirectoryReader> m_reader; | 59 Member<FileSystemDirectoryReader> m_reader; |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 class DirectoryReader::ErrorCallbackHelper final : public ErrorCallbackBase { | 62 class FileSystemDirectoryReader::ErrorCallbackHelper final |
| 63 : public ErrorCallbackBase { |
| 61 public: | 64 public: |
| 62 explicit ErrorCallbackHelper(DirectoryReader* reader) : m_reader(reader) {} | 65 explicit ErrorCallbackHelper(FileSystemDirectoryReader* reader) |
| 66 : m_reader(reader) {} |
| 63 | 67 |
| 64 void invoke(FileError::ErrorCode error) override { m_reader->onError(error); } | 68 void invoke(FileError::ErrorCode error) override { m_reader->onError(error); } |
| 65 | 69 |
| 66 DEFINE_INLINE_VIRTUAL_TRACE() { | 70 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 67 visitor->trace(m_reader); | 71 visitor->trace(m_reader); |
| 68 ErrorCallbackBase::trace(visitor); | 72 ErrorCallbackBase::trace(visitor); |
| 69 } | 73 } |
| 70 | 74 |
| 71 private: | 75 private: |
| 72 Member<DirectoryReader> m_reader; | 76 Member<FileSystemDirectoryReader> m_reader; |
| 73 }; | 77 }; |
| 74 | 78 |
| 75 DirectoryReader::DirectoryReader(DOMFileSystemBase* fileSystem, | 79 FileSystemDirectoryReader::FileSystemDirectoryReader(FileSystemBase* fileSystem, |
| 76 const String& fullPath) | 80 const String& fullPath) |
| 77 : DirectoryReaderBase(fileSystem, fullPath), m_isReading(false) {} | 81 : FileSystemDirectoryReaderBase(fileSystem, fullPath), m_isReading(false) {} |
| 78 | 82 |
| 79 DirectoryReader::~DirectoryReader() {} | 83 FileSystemDirectoryReader::~FileSystemDirectoryReader() {} |
| 80 | 84 |
| 81 void DirectoryReader::readEntries(EntriesCallback* entriesCallback, | 85 void FileSystemDirectoryReader::readEntries( |
| 82 ErrorCallback* errorCallback) { | 86 FileSystemEntriesCallback* entriesCallback, |
| 87 ErrorCallback* errorCallback) { |
| 83 if (!m_isReading) { | 88 if (!m_isReading) { |
| 84 m_isReading = true; | 89 m_isReading = true; |
| 85 filesystem()->readDirectory(this, m_fullPath, | 90 filesystem()->readDirectory(this, m_fullPath, |
| 86 new EntriesCallbackHelper(this), | 91 new EntriesCallbackHelper(this), |
| 87 new ErrorCallbackHelper(this)); | 92 new ErrorCallbackHelper(this)); |
| 88 } | 93 } |
| 89 | 94 |
| 90 if (m_error) { | 95 if (m_error) { |
| 91 filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), | 96 filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), |
| 92 m_error); | 97 m_error); |
| 93 return; | 98 return; |
| 94 } | 99 } |
| 95 | 100 |
| 96 if (m_entriesCallback) { | 101 if (m_entriesCallback) { |
| 97 // Non-null m_entriesCallback means multiple readEntries() calls are made | 102 // Non-null m_entriesCallback means multiple readEntries() calls are made |
| 98 // concurrently. We don't allow doing it. | 103 // concurrently. We don't allow doing it. |
| 99 filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), | 104 filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), |
| 100 FileError::kInvalidStateErr); | 105 FileError::kInvalidStateErr); |
| 101 return; | 106 return; |
| 102 } | 107 } |
| 103 | 108 |
| 104 if (!m_hasMoreEntries || !m_entries.isEmpty()) { | 109 if (!m_hasMoreEntries || !m_entries.isEmpty()) { |
| 105 if (entriesCallback) | 110 if (entriesCallback) { |
| 106 DOMFileSystem::scheduleCallback( | 111 FileSystem::scheduleCallback( |
| 107 filesystem()->getExecutionContext(), | 112 filesystem()->getExecutionContext(), |
| 108 createSameThreadTask(&EntriesCallback::handleEvent, | 113 createSameThreadTask( |
| 109 wrapPersistent(entriesCallback), | 114 &FileSystemEntriesCallback::handleEvent, |
| 110 PersistentHeapVector<Member<Entry>>(m_entries))); | 115 wrapPersistent(entriesCallback), |
| 116 PersistentHeapVector<Member<FileSystemEntry>>(m_entries))); |
| 117 } |
| 111 m_entries.clear(); | 118 m_entries.clear(); |
| 112 return; | 119 return; |
| 113 } | 120 } |
| 114 | 121 |
| 115 m_entriesCallback = entriesCallback; | 122 m_entriesCallback = entriesCallback; |
| 116 m_errorCallback = errorCallback; | 123 m_errorCallback = errorCallback; |
| 117 } | 124 } |
| 118 | 125 |
| 119 void DirectoryReader::addEntries(const EntryHeapVector& entries) { | 126 void FileSystemDirectoryReader::addEntries(const EntryHeapVector& entries) { |
| 120 m_entries.appendVector(entries); | 127 m_entries.appendVector(entries); |
| 121 m_errorCallback = nullptr; | 128 m_errorCallback = nullptr; |
| 122 if (m_entriesCallback) { | 129 if (m_entriesCallback) { |
| 123 EntriesCallback* entriesCallback = m_entriesCallback.release(); | 130 FileSystemEntriesCallback* entriesCallback = m_entriesCallback.release(); |
| 124 EntryHeapVector entries; | 131 EntryHeapVector entries; |
| 125 entries.swap(m_entries); | 132 entries.swap(m_entries); |
| 126 entriesCallback->handleEvent(entries); | 133 entriesCallback->handleEvent(entries); |
| 127 } | 134 } |
| 128 } | 135 } |
| 129 | 136 |
| 130 void DirectoryReader::onError(FileError::ErrorCode error) { | 137 void FileSystemDirectoryReader::onError(FileError::ErrorCode error) { |
| 131 m_error = error; | 138 m_error = error; |
| 132 m_entriesCallback = nullptr; | 139 m_entriesCallback = nullptr; |
| 133 if (m_errorCallback) | 140 if (m_errorCallback) |
| 134 m_errorCallback->handleEvent(FileError::createDOMException(error)); | 141 m_errorCallback->handleEvent(FileError::createDOMException(error)); |
| 135 } | 142 } |
| 136 | 143 |
| 137 DEFINE_TRACE(DirectoryReader) { | 144 DEFINE_TRACE(FileSystemDirectoryReader) { |
| 138 visitor->trace(m_entries); | 145 visitor->trace(m_entries); |
| 139 visitor->trace(m_entriesCallback); | 146 visitor->trace(m_entriesCallback); |
| 140 visitor->trace(m_errorCallback); | 147 visitor->trace(m_errorCallback); |
| 141 DirectoryReaderBase::trace(visitor); | 148 FileSystemDirectoryReaderBase::trace(visitor); |
| 142 } | 149 } |
| 143 | 150 |
| 144 } // namespace blink | 151 } // namespace blink |
| OLD | NEW |