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/DirectoryReaderSync.h" | 32 #include "modules/filesystem/DirectoryReaderSync.h" |
33 | 33 |
34 #include "bindings/v8/ExceptionState.h" | 34 #include "bindings/v8/ExceptionState.h" |
35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
36 #include "modules/filesystem/DirectoryEntry.h" | 36 #include "modules/filesystem/DirectoryEntry.h" |
37 #include "modules/filesystem/DirectoryEntrySync.h" | 37 #include "modules/filesystem/DirectoryEntrySync.h" |
| 38 #include "modules/filesystem/EntriesCallback.h" |
38 #include "modules/filesystem/EntrySync.h" | 39 #include "modules/filesystem/EntrySync.h" |
| 40 #include "modules/filesystem/ErrorCallback.h" |
39 #include "modules/filesystem/FileEntrySync.h" | 41 #include "modules/filesystem/FileEntrySync.h" |
40 #include "modules/filesystem/SyncCallbackHelper.h" | |
41 | 42 |
42 namespace WebCore { | 43 namespace WebCore { |
43 | 44 |
| 45 class DirectoryReaderSync::EntriesCallbackHelper : public EntriesCallback { |
| 46 public: |
| 47 EntriesCallbackHelper(PassRefPtr<DirectoryReaderSync> reader) |
| 48 : m_reader(reader) |
| 49 { |
| 50 } |
| 51 |
| 52 virtual void handleEvent(const Vector<RefPtr<Entry> >& entries) OVERRIDE |
| 53 { |
| 54 EntrySyncVector syncEntries; |
| 55 syncEntries.reserveInitialCapacity(entries.size()); |
| 56 for (size_t i = 0; i < entries.size(); ++i) |
| 57 syncEntries.uncheckedAppend(EntrySync::create(entries[i].get())); |
| 58 m_reader->addEntries(syncEntries); |
| 59 } |
| 60 |
| 61 private: |
| 62 RefPtr<DirectoryReaderSync> m_reader; |
| 63 }; |
| 64 |
| 65 class DirectoryReaderSync::ErrorCallbackHelper : public ErrorCallback { |
| 66 public: |
| 67 ErrorCallbackHelper(PassRefPtr<DirectoryReaderSync> reader) |
| 68 : m_reader(reader) |
| 69 { |
| 70 } |
| 71 |
| 72 virtual void handleEvent(FileError* error) OVERRIDE |
| 73 { |
| 74 m_reader->setError(error->code()); |
| 75 } |
| 76 |
| 77 private: |
| 78 RefPtr<DirectoryReaderSync> m_reader; |
| 79 }; |
| 80 |
44 DirectoryReaderSync::DirectoryReaderSync(PassRefPtr<DOMFileSystemBase> fileSyste
m, const String& fullPath) | 81 DirectoryReaderSync::DirectoryReaderSync(PassRefPtr<DOMFileSystemBase> fileSyste
m, const String& fullPath) |
45 : DirectoryReaderBase(fileSystem, fullPath) | 82 : DirectoryReaderBase(fileSystem, fullPath) |
| 83 , m_callbacksId(0) |
| 84 , m_errorCode(FileError::OK) |
46 { | 85 { |
47 ScriptWrappable::init(this); | 86 ScriptWrappable::init(this); |
48 } | 87 } |
49 | 88 |
50 EntrySyncVector DirectoryReaderSync::readEntries(ExceptionState& exceptionState) | 89 EntrySyncVector DirectoryReaderSync::readEntries(ExceptionState& exceptionState) |
51 { | 90 { |
52 if (!m_hasMoreEntries) | 91 if (!m_callbacksId) { |
53 return EntrySyncVector(); | 92 m_callbacksId = filesystem()->readDirectory(this, m_fullPath, adoptPtr(n
ew EntriesCallbackHelper(this)), adoptPtr(new ErrorCallbackHelper(this)), DOMFil
eSystemBase::Synchronous); |
| 93 } |
54 | 94 |
55 EntriesSyncCallbackHelper helper; | 95 if (m_errorCode == FileError::OK && m_hasMoreEntries && m_entries.isEmpty()) |
56 if (!m_fileSystem->readDirectory(this, m_fullPath, helper.successCallback(),
helper.errorCallback(), DOMFileSystemBase::Synchronous)) { | 96 m_fileSystem->waitForAdditionalResult(m_callbacksId); |
57 exceptionState.throwDOMException(InvalidModificationError, "Failed to re
ad the directory."); | 97 |
58 setHasMoreEntries(false); | 98 if (m_errorCode != FileError::OK) { |
| 99 FileError::throwDOMException(exceptionState, m_errorCode); |
59 return EntrySyncVector(); | 100 return EntrySyncVector(); |
60 } | 101 } |
61 return helper.getResult(exceptionState); | 102 |
| 103 EntrySyncVector result; |
| 104 result.swap(m_entries); |
| 105 return result; |
62 } | 106 } |
63 | 107 |
64 } // namespace | 108 } // namespace |
OLD | NEW |