| 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 NET_FILTER_SDCH_STREAM_SOURCE_H |
| 6 #define NET_FILTER_SDCH_STREAM_SOURCE_H |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "net/base/sdch_dictionary.h" |
| 11 #include "net/base/sdch_manager.h" |
| 12 #include "net/filter/filter_stream_source.h" |
| 13 #include "net/filter/sdch_stream_source_delegate.h" |
| 14 |
| 15 namespace open_vcdiff { |
| 16 |
| 17 class VCDiffStreamingDecoder; |
| 18 |
| 19 } // namespace open_vcdiff |
| 20 |
| 21 namespace net { |
| 22 |
| 23 class BlockBuffer; |
| 24 |
| 25 class SdchStreamSource : public FilterStreamSource { |
| 26 public: |
| 27 SdchStreamSource(std::unique_ptr<StreamSource> previous, |
| 28 SdchStreamSourceDelegate* delegate); |
| 29 ~SdchStreamSource() override; |
| 30 |
| 31 bool Init() override; |
| 32 |
| 33 // For use by SdchStreamSourceDelegate. Switches this stream source into |
| 34 // "passthrough" mode, where it will not decode any further output with |
| 35 // vcdiff. This method can only be called during an invocation of the |
| 36 // delegate's HandleDictionaryError or HandleDecodingError functions. |
| 37 virtual void StopDecoding(); |
| 38 |
| 39 // For use by SdchStreamSourceDelegate. Replaces the entire output of this |
| 40 // stream |
| 41 // with the supplied |data|, which is of length |size|. Note that calling this |
| 42 // method also stops vcdiff decoding as a side-effect - |data| should not |
| 43 // point to vcdiff-encoded data. This method can only be called during an |
| 44 // invocation of the delegate's HandleDictionaryError or HandleDecodingError |
| 45 // functions. |
| 46 virtual void ReplaceOutput(const char* data, size_t size); |
| 47 |
| 48 private: |
| 49 enum SdchStreamState { |
| 50 SDCH_STREAM_ERROR, |
| 51 SDCH_STREAM_MORE_INPUT, |
| 52 SDCH_STREAM_MORE_OUTPUT_SPACE, |
| 53 }; |
| 54 |
| 55 // StreamSource implementation: |
| 56 Error ReadInternal(IOBuffer* dest, |
| 57 size_t buffer_size, |
| 58 size_t* bytes_read) override; |
| 59 |
| 60 SdchStreamState Decompress(IOBuffer* dest_buffer, |
| 61 size_t buffer_size, |
| 62 size_t* bytes_read); |
| 63 SdchStreamState Passthrough(IOBuffer* dest_buffer, |
| 64 size_t buffer_size, |
| 65 size_t* bytes_read); |
| 66 SdchStreamState Flush(IOBuffer* dest_buffer, |
| 67 size_t buffer_size, |
| 68 size_t* bytes_read); |
| 69 |
| 70 bool LoadDictionary(); |
| 71 |
| 72 // Returns whether |id| looks like a dictionary ID, meaning 8 characters of |
| 73 // base64url followed by a null character. |
| 74 bool CouldBeDictionaryId(const std::string& id) const; |
| 75 |
| 76 bool AskDelegateToHandleDictionaryError(); |
| 77 bool AskDelegateToHandleDecodingError(); |
| 78 |
| 79 std::unique_ptr<open_vcdiff::VCDiffStreamingDecoder> decoder_; |
| 80 SdchStreamSourceDelegate* delegate_; |
| 81 |
| 82 // Buffer used to accumulate the dictionary ID. |
| 83 std::string dictionary_id_; |
| 84 |
| 85 // Since vcdiff may generate quite a bit of output at once, SdchStreamSource |
| 86 // has to buffer excess output (more than requested by the caller) here to |
| 87 // return later. This could maybe become quite large. |
| 88 std::string buffered_output_; |
| 89 |
| 90 bool output_replaced_; |
| 91 bool passthrough_; |
| 92 bool dictionary_tried_load_; |
| 93 |
| 94 bool in_delegate_handler_; |
| 95 }; |
| 96 |
| 97 } // namespace net |
| 98 |
| 99 #endif // NET_FILTER_SDCH_STREAM_SOURCE_H |
| OLD | NEW |