Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MultipartParser_h | |
| 6 #define MultipartParser_h | |
| 7 | |
| 8 #include "modules/ModulesExport.h" | |
| 9 #include "platform/heap/Handle.h" | |
| 10 #include "platform/network/ResourceResponse.h" | |
| 11 #include "wtf/Vector.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 class MODULES_EXPORT MultipartParser : public GarbageCollectedFinalized<Multipar tParser> { | |
|
yhirano
2016/09/07 06:00:16
final
e_hakkinen
2016/09/08 00:06:29
Done.
| |
| 16 WTF_MAKE_NONCOPYABLE(MultipartParser); | |
| 17 | |
| 18 public: | |
| 19 class MODULES_EXPORT Client : public GarbageCollectedMixin { | |
| 20 public: | |
| 21 virtual ~Client() = default; | |
| 22 virtual void partHeaderFieldsInMultipartReceived(const ResourceResponse& ) = 0; | |
| 23 virtual void partDataInMultipartReceived(const char* bytes, size_t) = 0; | |
| 24 virtual void partDataInMultipartFullyReceived() = 0; | |
| 25 DEFINE_INLINE_VIRTUAL_TRACE() {} | |
| 26 }; | |
| 27 | |
| 28 MultipartParser(Vector<char> boundary, Client*); | |
| 29 bool appendData(const char* bytes, size_t); | |
| 30 void cancel(); | |
| 31 bool finish(); | |
| 32 | |
| 33 bool isCancelled() const { return m_state == Cancelled; } | |
| 34 | |
| 35 DECLARE_TRACE(); | |
| 36 | |
| 37 private: | |
| 38 size_t countNonDelimiterBytes(const char* bytes, size_t) const; | |
| 39 size_t countPossibleDelimiterBytes(const char* bytes, size_t) const; | |
| 40 size_t countTransportPaddingBytes(const char* bytes, size_t) const; | |
| 41 bool parseDelimiter(const char* bytes, size_t, size_t* index); | |
| 42 bool parseDelimiterSuffix(const char* bytes, size_t, size_t* index, const ch ar* suffix); | |
| 43 size_t seenDelimiterSuffixLength() const; | |
| 44 | |
| 45 Vector<char> m_delimiter; | |
| 46 Member<Client> m_client; | |
| 47 size_t m_seenDelimiterLength; | |
| 48 size_t m_seenDelimiterOffset; | |
| 49 Vector<char> m_seenHeaderBytes; | |
| 50 | |
| 51 enum State { | |
| 52 ParsingPreamble, | |
| 53 ParsingDelimiterSuffix, | |
| 54 ParsingPartHeaderFields, | |
| 55 ParsingPartOctets, | |
| 56 ParsingDelimiterOrCloseDelimiterSuffix, | |
| 57 ParsingCloseDelimiterSuffix, | |
| 58 ParsingEpilogue, | |
| 59 Cancelled, | |
| 60 Failed, | |
| 61 Finished | |
| 62 } m_state; | |
| 63 }; | |
| 64 | |
| 65 } // namespace blink | |
| 66 | |
| 67 #endif // MultipartParser_h | |
| OLD | NEW |