| Index: net/filter/sdch_stream_source.h | 
| diff --git a/net/filter/sdch_stream_source.h b/net/filter/sdch_stream_source.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..37be587590cf1f85adabadff68b9b4a5f517375b | 
| --- /dev/null | 
| +++ b/net/filter/sdch_stream_source.h | 
| @@ -0,0 +1,104 @@ | 
| +// Copyright 2016 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef NET_FILTER_SDCH_STREAM_SOURCE_H | 
| +#define NET_FILTER_SDCH_STREAM_SOURCE_H | 
| + | 
| +#include "base/memory/scoped_ptr.h" | 
| +#include "net/base/sdch_dictionary.h" | 
| +#include "net/base/sdch_manager.h" | 
| +#include "net/filter/sdch_stream_source_delegate.h" | 
| +#include "net/filter/stream_source.h" | 
| + | 
| +namespace open_vcdiff { | 
| + | 
| +class VCDiffStreamingDecoder; | 
| + | 
| +}  // namespace open_vcdiff | 
| + | 
| +namespace net { | 
| + | 
| +class BlockBuffer; | 
| + | 
| +class SdchStreamSource : public StreamSource { | 
| + public: | 
| +  SdchStreamSource(scoped_ptr<StreamSource> previous, | 
| +                   SdchStreamSourceDelegate* delegate); | 
| +  ~SdchStreamSource() override; | 
| + | 
| +  bool Init(); | 
| + | 
| +  // For use by SdchStreamSourceDelegate. Switches this stream source into | 
| +  // "passthrough" mode, where it will not decode any further output with | 
| +  // vcdiff. This method can only be called during an invocation of the | 
| +  // delegate's HandleDictionaryError or HandleDecodingError functions. | 
| +  virtual void StopDecoding(); | 
| + | 
| +  // For use by SdchStreamSourceDelegate. Replaces the entire output of this | 
| +  // stream | 
| +  // with the supplied |data|, which is of length |size|. Note that calling this | 
| +  // method also stops vcdiff decoding as a side-effect - |data| should not | 
| +  // point to vcdiff-encoded data. This method can only be called during an | 
| +  // invocation of the delegate's HandleDictionaryError or HandleDecodingError | 
| +  // functions. | 
| +  virtual void ReplaceOutput(const char* data, size_t size); | 
| + | 
| + private: | 
| +  enum SdchStreamState { | 
| +    SDCH_STREAM_ERROR, | 
| +    SDCH_STREAM_MORE_INPUT, | 
| +    SDCH_STREAM_MORE_OUTPUT_SPACE, | 
| +  }; | 
| + | 
| +  // StreamSource implementation: | 
| +  Error ReadInternal(IOBuffer* dest, | 
| +                     size_t buffer_size, | 
| +                     size_t* bytes_read) override; | 
| + | 
| +  SdchStreamState Decompress(IOBuffer* dest_buffer, | 
| +                             size_t buffer_size, | 
| +                             size_t* bytes_read); | 
| +  SdchStreamState Passthrough(IOBuffer* dest_buffer, | 
| +                              size_t buffer_size, | 
| +                              size_t* bytes_read); | 
| +  SdchStreamState Flush(IOBuffer* dest_buffer, | 
| +                        size_t buffer_size, | 
| +                        size_t* bytes_read); | 
| + | 
| +  void OnReadComplete(const OnReadCompleteCallback& callback, | 
| +                      IOBuffer* dest_buffer, | 
| +                      size_t dest_buffer_size, | 
| +                      Error error, | 
| +                      size_t bytes_read); | 
| + | 
| +  bool LoadDictionary(); | 
| + | 
| +  // Returns whether |id| looks like a dictionary ID, meaning 8 characters of | 
| +  // base64url followed by a null character. | 
| +  bool CouldBeDictionaryId(const std::string& id) const; | 
| + | 
| +  bool AskDelegateToHandleDictionaryError(); | 
| +  bool AskDelegateToHandleDecodingError(); | 
| + | 
| +  scoped_ptr<open_vcdiff::VCDiffStreamingDecoder> decoder_; | 
| +  SdchStreamSourceDelegate* delegate_; | 
| + | 
| +  // Buffer used to accumulate the dictionary ID. | 
| +  std::string dictionary_id_; | 
| + | 
| +  // Since vcdiff may generate quite a bit of output at once, SdchStreamSource | 
| +  // has to buffer excess output (more than requested by the caller) here to | 
| +  // return later. This could maybe become quite large. | 
| +  std::string buffered_output_; | 
| + | 
| +  bool output_replaced_; | 
| +  bool passthrough_; | 
| +  bool dictionary_tried_load_; | 
| + | 
| +  bool in_delegate_handler_; | 
| +}; | 
| + | 
| +}  // namespace net | 
| + | 
| +#endif  // NET_FILTER_SDCH_STREAM_SOURCE_H | 
|  |