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