| 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  private: | 
|  | 48   enum SdchStreamState { | 
|  | 49     SDCH_STREAM_ERROR, | 
|  | 50     SDCH_STREAM_MORE_INPUT, | 
|  | 51     SDCH_STREAM_MORE_OUTPUT_SPACE, | 
|  | 52   }; | 
|  | 53 | 
|  | 54   // StreamSource implementation: | 
|  | 55   Error ReadInternal(IOBuffer* dest, | 
|  | 56                      size_t buffer_size, | 
|  | 57                      size_t* bytes_read) override; | 
|  | 58 | 
|  | 59   SdchStreamState Decompress(IOBuffer* dest_buffer, | 
|  | 60                              size_t buffer_size, | 
|  | 61                              size_t* bytes_read); | 
|  | 62   SdchStreamState Passthrough(IOBuffer* dest_buffer, | 
|  | 63                               size_t buffer_size, | 
|  | 64                               size_t* bytes_read); | 
|  | 65   SdchStreamState Flush(IOBuffer* dest_buffer, | 
|  | 66                         size_t buffer_size, | 
|  | 67                         size_t* bytes_read); | 
|  | 68 | 
|  | 69   void OnReadComplete(const OnReadCompleteCallback& callback, | 
|  | 70                       IOBuffer* dest_buffer, | 
|  | 71                       size_t dest_buffer_size, | 
|  | 72                       Error error, | 
|  | 73                       size_t bytes_read); | 
|  | 74 | 
|  | 75   bool LoadDictionary(); | 
|  | 76 | 
|  | 77   // Returns whether |id| looks like a dictionary ID, meaning 8 characters of | 
|  | 78   // base64url followed by a null character. | 
|  | 79   bool CouldBeDictionaryId(const std::string& id) const; | 
|  | 80 | 
|  | 81   bool AskDelegateToHandleDictionaryError(); | 
|  | 82   bool AskDelegateToHandleDecodingError(); | 
|  | 83 | 
|  | 84   scoped_ptr<open_vcdiff::VCDiffStreamingDecoder> decoder_; | 
|  | 85   SdchStreamSourceDelegate* delegate_; | 
|  | 86 | 
|  | 87   // Buffer used to accumulate the dictionary ID. | 
|  | 88   std::string dictionary_id_; | 
|  | 89 | 
|  | 90   // Since vcdiff may generate quite a bit of output at once, SdchStreamSource | 
|  | 91   // has to buffer excess output (more than requested by the caller) here to | 
|  | 92   // return later. This could maybe become quite large. | 
|  | 93   std::string buffered_output_; | 
|  | 94 | 
|  | 95   bool output_replaced_; | 
|  | 96   bool passthrough_; | 
|  | 97   bool dictionary_tried_load_; | 
|  | 98 | 
|  | 99   bool in_delegate_handler_; | 
|  | 100 }; | 
|  | 101 | 
|  | 102 }  // namespace net | 
|  | 103 | 
|  | 104 #endif  // NET_FILTER_SDCH_STREAM_SOURCE_H | 
| OLD | NEW | 
|---|