Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/FileSystemDirectoryReaderSync.cpp

Issue 2297043002: Web expose FileSystemFileEntry, FileSystemDirectoryEntry and friends (Closed)
Patch Set: Rebased Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/DirectoryReaderSync.h" 31 #include "modules/filesystem/FileSystemDirectoryReaderSync.h"
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "modules/filesystem/DirectoryEntry.h"
35 #include "modules/filesystem/DirectoryEntrySync.h"
36 #include "modules/filesystem/EntriesCallback.h"
37 #include "modules/filesystem/EntrySync.h"
38 #include "modules/filesystem/ErrorCallback.h" 34 #include "modules/filesystem/ErrorCallback.h"
39 #include "modules/filesystem/FileEntrySync.h"
40 #include "modules/filesystem/FileSystemCallbacks.h" 35 #include "modules/filesystem/FileSystemCallbacks.h"
36 #include "modules/filesystem/FileSystemDirectoryEntry.h"
37 #include "modules/filesystem/FileSystemDirectoryEntrySync.h"
38 #include "modules/filesystem/FileSystemEntriesCallback.h"
39 #include "modules/filesystem/FileSystemEntrySync.h"
40 #include "modules/filesystem/FileSystemFileEntrySync.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 class DirectoryReaderSync::EntriesCallbackHelper final 44 class FileSystemDirectoryReaderSync::EntriesCallbackHelper final
45 : public EntriesCallback { 45 : public FileSystemEntriesCallback {
46 public: 46 public:
47 explicit EntriesCallbackHelper(DirectoryReaderSync* reader) 47 explicit EntriesCallbackHelper(FileSystemDirectoryReaderSync* reader)
48 : m_reader(reader) {} 48 : m_reader(reader) {}
49 49
50 void handleEvent(const EntryHeapVector& entries) override { 50 void handleEvent(const EntryHeapVector& entries) override {
51 EntrySyncHeapVector syncEntries; 51 EntrySyncHeapVector syncEntries;
52 syncEntries.reserveInitialCapacity(entries.size()); 52 syncEntries.reserveInitialCapacity(entries.size());
53 for (size_t i = 0; i < entries.size(); ++i) 53 for (size_t i = 0; i < entries.size(); ++i) {
54 syncEntries.uncheckedAppend(EntrySync::create(entries[i].get())); 54 syncEntries.uncheckedAppend(
55 FileSystemEntrySync::create(entries[i].get()));
56 }
55 m_reader->addEntries(syncEntries); 57 m_reader->addEntries(syncEntries);
56 } 58 }
57 59
58 DEFINE_INLINE_VIRTUAL_TRACE() { 60 DEFINE_INLINE_VIRTUAL_TRACE() {
59 visitor->trace(m_reader); 61 visitor->trace(m_reader);
60 EntriesCallback::trace(visitor); 62 FileSystemEntriesCallback::trace(visitor);
61 } 63 }
62 64
63 private: 65 private:
64 Member<DirectoryReaderSync> m_reader; 66 Member<FileSystemDirectoryReaderSync> m_reader;
65 }; 67 };
66 68
67 class DirectoryReaderSync::ErrorCallbackHelper final 69 class FileSystemDirectoryReaderSync::ErrorCallbackHelper final
68 : public ErrorCallbackBase { 70 : public ErrorCallbackBase {
69 public: 71 public:
70 explicit ErrorCallbackHelper(DirectoryReaderSync* reader) 72 explicit ErrorCallbackHelper(FileSystemDirectoryReaderSync* reader)
71 : m_reader(reader) {} 73 : m_reader(reader) {}
72 74
73 void invoke(FileError::ErrorCode error) override { 75 void invoke(FileError::ErrorCode error) override {
74 m_reader->setError(error); 76 m_reader->setError(error);
75 } 77 }
76 78
77 DEFINE_INLINE_VIRTUAL_TRACE() { 79 DEFINE_INLINE_VIRTUAL_TRACE() {
78 visitor->trace(m_reader); 80 visitor->trace(m_reader);
79 ErrorCallbackBase::trace(visitor); 81 ErrorCallbackBase::trace(visitor);
80 } 82 }
81 83
82 private: 84 private:
83 Member<DirectoryReaderSync> m_reader; 85 Member<FileSystemDirectoryReaderSync> m_reader;
84 }; 86 };
85 87
86 DirectoryReaderSync::DirectoryReaderSync(DOMFileSystemBase* fileSystem, 88 FileSystemDirectoryReaderSync::FileSystemDirectoryReaderSync(
87 const String& fullPath) 89 FileSystemBase* fileSystem,
88 : DirectoryReaderBase(fileSystem, fullPath), 90 const String& fullPath)
91 : FileSystemDirectoryReaderBase(fileSystem, fullPath),
89 m_callbacksId(0), 92 m_callbacksId(0),
90 m_errorCode(FileError::kOK) {} 93 m_errorCode(FileError::kOK) {}
91 94
92 DirectoryReaderSync::~DirectoryReaderSync() {} 95 FileSystemDirectoryReaderSync::~FileSystemDirectoryReaderSync() {}
93 96
94 EntrySyncHeapVector DirectoryReaderSync::readEntries( 97 EntrySyncHeapVector FileSystemDirectoryReaderSync::readEntries(
95 ExceptionState& exceptionState) { 98 ExceptionState& exceptionState) {
96 if (!m_callbacksId) { 99 if (!m_callbacksId) {
97 m_callbacksId = filesystem()->readDirectory( 100 m_callbacksId = filesystem()->readDirectory(
98 this, m_fullPath, new EntriesCallbackHelper(this), 101 this, m_fullPath, new EntriesCallbackHelper(this),
99 new ErrorCallbackHelper(this), DOMFileSystemBase::Synchronous); 102 new ErrorCallbackHelper(this), FileSystemBase::Synchronous);
100 } 103 }
101 104
102 if (m_errorCode == FileError::kOK && m_hasMoreEntries && m_entries.isEmpty()) 105 if (m_errorCode == FileError::kOK && m_hasMoreEntries && m_entries.isEmpty())
103 m_fileSystem->waitForAdditionalResult(m_callbacksId); 106 m_fileSystem->waitForAdditionalResult(m_callbacksId);
104 107
105 if (m_errorCode != FileError::kOK) { 108 if (m_errorCode != FileError::kOK) {
106 FileError::throwDOMException(exceptionState, m_errorCode); 109 FileError::throwDOMException(exceptionState, m_errorCode);
107 return EntrySyncHeapVector(); 110 return EntrySyncHeapVector();
108 } 111 }
109 112
110 EntrySyncHeapVector result; 113 EntrySyncHeapVector result;
111 result.swap(m_entries); 114 result.swap(m_entries);
112 return result; 115 return result;
113 } 116 }
114 117
115 DEFINE_TRACE(DirectoryReaderSync) { 118 DEFINE_TRACE(FileSystemDirectoryReaderSync) {
116 visitor->trace(m_entries); 119 visitor->trace(m_entries);
117 DirectoryReaderBase::trace(visitor); 120 FileSystemDirectoryReaderBase::trace(visitor);
118 } 121 }
119 122
120 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698