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 20 matching lines...) Expand all Loading... | |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/filesystem/DirectoryReader.h" | 32 #include "modules/filesystem/DirectoryReader.h" |
33 | 33 |
34 #include "core/fileapi/FileError.h" | 34 #include "core/fileapi/FileError.h" |
35 #include "modules/filesystem/EntriesCallback.h" | 35 #include "modules/filesystem/EntriesCallback.h" |
36 #include "modules/filesystem/Entry.h" | 36 #include "modules/filesystem/Entry.h" |
37 #include "modules/filesystem/ErrorCallback.h" | 37 #include "modules/filesystem/ErrorCallback.h" |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 class DirectoryReader::EntriesCallbackHelper : public EntriesCallback { | |
42 public: | |
43 EntriesCallbackHelper(PassRefPtr<DirectoryReader> reader) | |
44 : m_reader(reader) | |
45 { | |
46 } | |
47 | |
48 virtual void handleEvent(const Vector<RefPtr<Entry> >& entries) OVERRIDE | |
49 { | |
50 m_reader->addEntries(entries); | |
51 } | |
52 | |
53 private: | |
54 RefPtr<DirectoryReader> m_reader; | |
55 }; | |
56 | |
57 class DirectoryReader::ErrorCallbackHelper : public ErrorCallback { | |
58 public: | |
59 ErrorCallbackHelper(PassRefPtr<DirectoryReader> reader) | |
60 : m_reader(reader) | |
61 { | |
62 } | |
63 | |
64 virtual void handleEvent(FileError* error) OVERRIDE | |
65 { | |
66 m_reader->onError(error); | |
67 } | |
68 | |
69 private: | |
70 RefPtr<DirectoryReader> m_reader; | |
kinuko
2014/03/06 13:13:38
So in the current impl this callback (and Director
hashimoto
2014/03/07 05:21:26
Done.
Please note that EntriesCallbacks (beware o
| |
71 }; | |
72 | |
41 DirectoryReader::DirectoryReader(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath) | 73 DirectoryReader::DirectoryReader(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath) |
42 : DirectoryReaderBase(fileSystem, fullPath) | 74 : DirectoryReaderBase(fileSystem, fullPath) |
75 , m_isReading(false) | |
43 { | 76 { |
44 ScriptWrappable::init(this); | 77 ScriptWrappable::init(this); |
45 } | 78 } |
46 | 79 |
47 void DirectoryReader::readEntries(PassOwnPtr<EntriesCallback> entriesCallback, P assOwnPtr<ErrorCallback> errorCallback) | 80 void DirectoryReader::readEntries(PassOwnPtr<EntriesCallback> entriesCallback, P assOwnPtr<ErrorCallback> errorCallback) |
48 { | 81 { |
49 if (!m_hasMoreEntries) { | 82 if (!m_isReading) { |
50 filesystem()->scheduleCallback(entriesCallback, EntryVector()); | 83 m_isReading = true; |
84 filesystem()->readDirectory(this, m_fullPath, adoptPtr(new EntriesCallba ckHelper(this)), adoptPtr(new ErrorCallbackHelper(this))); | |
85 } | |
86 | |
87 if (m_error) { | |
88 filesystem()->scheduleCallback(errorCallback, m_error.get()); | |
51 return; | 89 return; |
52 } | 90 } |
53 filesystem()->readDirectory(this, m_fullPath, entriesCallback, errorCallback ); | 91 |
92 if (m_entriesCallback) { | |
kinuko
2014/03/06 13:13:38
nit: can you add a comment that non-null m_entries
hashimoto
2014/03/07 05:21:26
Done.
| |
93 filesystem()->scheduleCallback(errorCallback, FileError::create(FileErro r::INVALID_STATE_ERR)); | |
94 return; | |
95 } | |
96 | |
97 if (!m_hasMoreEntries || !m_entries.isEmpty()) { | |
98 filesystem()->scheduleCallback(entriesCallback, m_entries); | |
99 m_entries.clear(); | |
100 return; | |
101 } | |
102 | |
103 m_entriesCallback = entriesCallback; | |
104 m_errorCallback = errorCallback; | |
105 } | |
106 | |
107 void DirectoryReader::addEntries(const Vector<RefPtr<Entry> >& entries) | |
108 { | |
109 m_entries.appendVector(entries); | |
110 if (m_entriesCallback) { | |
111 OwnPtr<EntriesCallback> entriesCallback = m_entriesCallback.release(); | |
112 Vector<RefPtr<Entry> > entries; | |
113 entries.swap(m_entries); | |
114 entriesCallback->handleEvent(entries); | |
115 } | |
116 } | |
117 | |
118 void DirectoryReader::onError(FileError* error) | |
119 { | |
120 m_error = error; | |
121 if (m_errorCallback) | |
122 m_errorCallback->handleEvent(error); | |
54 } | 123 } |
55 | 124 |
56 } | 125 } |
OLD | NEW |