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 16 matching lines...) Expand all Loading... | |
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/DirectoryReader.h" |
32 | 32 |
33 #include "core/fileapi/FileError.h" | 33 #include "core/fileapi/FileError.h" |
34 #include "modules/filesystem/EntriesCallback.h" | 34 #include "modules/filesystem/EntriesCallback.h" |
35 #include "modules/filesystem/Entry.h" | 35 #include "modules/filesystem/Entry.h" |
36 #include "modules/filesystem/ErrorCallback.h" | 36 #include "modules/filesystem/ErrorCallback.h" |
37 #include "modules/filesystem/FileSystemCallbacks.h" | |
37 | 38 |
38 namespace blink { | 39 namespace blink { |
39 | 40 |
40 class DirectoryReader::EntriesCallbackHelper final : public EntriesCallback { | 41 class DirectoryReader::EntriesCallbackHelper final : public EntriesCallback { |
41 public: | 42 public: |
42 explicit EntriesCallbackHelper(DirectoryReader* reader) | 43 explicit EntriesCallbackHelper(DirectoryReader* reader) |
43 : m_reader(reader) | 44 : m_reader(reader) |
44 { | 45 { |
45 } | 46 } |
46 | 47 |
47 void handleEvent(const EntryHeapVector& entries) override | 48 void handleEvent(const EntryHeapVector& entries) override |
48 { | 49 { |
49 m_reader->addEntries(entries); | 50 m_reader->addEntries(entries); |
50 } | 51 } |
51 | 52 |
52 DEFINE_INLINE_VIRTUAL_TRACE() | 53 DEFINE_INLINE_VIRTUAL_TRACE() |
53 { | 54 { |
54 visitor->trace(m_reader); | 55 visitor->trace(m_reader); |
55 EntriesCallback::trace(visitor); | 56 EntriesCallback::trace(visitor); |
56 } | 57 } |
57 | 58 |
58 private: | 59 private: |
59 // FIXME: This Member keeps the reader alive until all of the readDirectory results are received. crbug.com/350285 | 60 // FIXME: This Member keeps the reader alive until all of the readDirectory results are received. crbug.com/350285 |
60 Member<DirectoryReader> m_reader; | 61 Member<DirectoryReader> m_reader; |
61 }; | 62 }; |
62 | 63 |
63 class DirectoryReader::ErrorCallbackHelper final : public ErrorCallback { | 64 class DirectoryReader::ErrorCallbackHelper final : public ErrorCallbackBase { |
64 public: | 65 public: |
65 explicit ErrorCallbackHelper(DirectoryReader* reader) | 66 explicit ErrorCallbackHelper(DirectoryReader* reader) |
66 : m_reader(reader) | 67 : m_reader(reader) |
67 { | 68 { |
68 } | 69 } |
69 | 70 |
70 void handleEvent(FileError* error) override | 71 void handleEvent(FileError::ErrorCode error) override |
71 { | 72 { |
72 m_reader->onError(error); | 73 m_reader->onError(error); |
73 } | 74 } |
74 | 75 |
75 DEFINE_INLINE_VIRTUAL_TRACE() | 76 DEFINE_INLINE_VIRTUAL_TRACE() |
76 { | 77 { |
77 visitor->trace(m_reader); | 78 visitor->trace(m_reader); |
78 ErrorCallback::trace(visitor); | 79 ErrorCallbackBase::trace(visitor); |
79 } | 80 } |
80 | 81 |
81 private: | 82 private: |
82 Member<DirectoryReader> m_reader; | 83 Member<DirectoryReader> m_reader; |
83 }; | 84 }; |
84 | 85 |
85 DirectoryReader::DirectoryReader(DOMFileSystemBase* fileSystem, const String& fu llPath) | 86 DirectoryReader::DirectoryReader(DOMFileSystemBase* fileSystem, const String& fu llPath) |
86 : DirectoryReaderBase(fileSystem, fullPath) | 87 : DirectoryReaderBase(fileSystem, fullPath) |
87 , m_isReading(false) | 88 , m_isReading(false) |
88 { | 89 { |
89 } | 90 } |
90 | 91 |
91 DirectoryReader::~DirectoryReader() | 92 DirectoryReader::~DirectoryReader() |
92 { | 93 { |
93 } | 94 } |
94 | 95 |
95 void DirectoryReader::readEntries(EntriesCallback* entriesCallback, ErrorCallbac k* errorCallback) | 96 void DirectoryReader::readEntries(EntriesCallback* entriesCallback, ErrorCallbac k* errorCallback) |
96 { | 97 { |
97 if (!m_isReading) { | 98 if (!m_isReading) { |
98 m_isReading = true; | 99 m_isReading = true; |
99 filesystem()->readDirectory(this, m_fullPath, new EntriesCallbackHelper( this), new ErrorCallbackHelper(this)); | 100 filesystem()->readDirectory(this, m_fullPath, new EntriesCallbackHelper( this), new ErrorCallbackHelper(this)); |
100 } | 101 } |
101 | 102 |
102 if (m_error) { | 103 if (m_error) { |
103 filesystem()->reportError(errorCallback, m_error.get()); | 104 filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), m_er ror); |
104 return; | 105 return; |
105 } | 106 } |
106 | 107 |
107 if (m_entriesCallback) { | 108 if (m_entriesCallback) { |
108 // Non-null m_entriesCallback means multiple readEntries() calls are mad e concurrently. We don't allow doing it. | 109 // Non-null m_entriesCallback means multiple readEntries() calls are mad e concurrently. We don't allow doing it. |
109 filesystem()->reportError(errorCallback, FileError::create(FileError::IN VALID_STATE_ERR)); | 110 filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), File Error::INVALID_STATE_ERR); |
110 return; | 111 return; |
111 } | 112 } |
112 | 113 |
113 if (!m_hasMoreEntries || !m_entries.isEmpty()) { | 114 if (!m_hasMoreEntries || !m_entries.isEmpty()) { |
114 if (entriesCallback) | 115 if (entriesCallback) |
115 DOMFileSystem::scheduleCallback(filesystem()->getExecutionContext(), createSameThreadTask(&EntriesCallback::handleEvent, wrapPersistent(entriesCallb ack), PersistentHeapVector<Member<Entry>>(m_entries))); | 116 DOMFileSystem::scheduleCallback(filesystem()->getExecutionContext(), createSameThreadTask(&EntriesCallback::handleEvent, wrapPersistent(entriesCallb ack), PersistentHeapVector<Member<Entry>>(m_entries))); |
116 m_entries.clear(); | 117 m_entries.clear(); |
117 return; | 118 return; |
118 } | 119 } |
119 | 120 |
120 m_entriesCallback = entriesCallback; | 121 m_entriesCallback = entriesCallback; |
121 m_errorCallback = errorCallback; | 122 m_errorCallback = errorCallback; |
122 } | 123 } |
123 | 124 |
124 void DirectoryReader::addEntries(const EntryHeapVector& entries) | 125 void DirectoryReader::addEntries(const EntryHeapVector& entries) |
125 { | 126 { |
126 m_entries.appendVector(entries); | 127 m_entries.appendVector(entries); |
127 m_errorCallback = nullptr; | 128 m_errorCallback = nullptr; |
128 if (m_entriesCallback) { | 129 if (m_entriesCallback) { |
129 EntriesCallback* entriesCallback = m_entriesCallback.release(); | 130 EntriesCallback* entriesCallback = m_entriesCallback.release(); |
130 EntryHeapVector entries; | 131 EntryHeapVector entries; |
131 entries.swap(m_entries); | 132 entries.swap(m_entries); |
132 entriesCallback->handleEvent(entries); | 133 entriesCallback->handleEvent(entries); |
133 } | 134 } |
134 } | 135 } |
135 | 136 |
136 void DirectoryReader::onError(FileError* error) | 137 void DirectoryReader::onError(FileError::ErrorCode error) |
137 { | 138 { |
138 m_error = error; | 139 m_error = error; |
139 m_entriesCallback = nullptr; | 140 m_entriesCallback = nullptr; |
140 if (m_errorCallback) { | 141 if (m_errorCallback) { |
141 ErrorCallback* errorCallback = m_errorCallback.release(); | 142 // TODO(jsbell): Just call m_errorCallback->handleEvent(FileError::creat eDOMException(error)) directly? |
foolip
2016/07/12 12:42:53
Is that blocked on some additional refactoring?
jsbell
2016/07/12 17:43:51
Ah yes, I meant to ask for opinions. I'm waffling
foolip
2016/07/13 14:39:17
This looks good, an extra wrapper just to avoid th
| |
143 ErrorCallbackBase* errorCallback = ScriptErrorCallback::wrap(m_errorCall back.release()); | |
142 errorCallback->handleEvent(error); | 144 errorCallback->handleEvent(error); |
143 } | 145 } |
144 } | 146 } |
145 | 147 |
146 DEFINE_TRACE(DirectoryReader) | 148 DEFINE_TRACE(DirectoryReader) |
147 { | 149 { |
148 visitor->trace(m_entries); | 150 visitor->trace(m_entries); |
149 visitor->trace(m_error); | |
150 visitor->trace(m_entriesCallback); | 151 visitor->trace(m_entriesCallback); |
151 visitor->trace(m_errorCallback); | 152 visitor->trace(m_errorCallback); |
152 DirectoryReaderBase::trace(visitor); | 153 DirectoryReaderBase::trace(visitor); |
153 } | 154 } |
154 | 155 |
155 } // namespace blink | 156 } // namespace blink |
OLD | NEW |