Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: net/filter/sdch_source_stream.h

Issue 1662763002: [ON HOLD] Implement pull-based design for content decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/filter/sdch_policy_delegate_unittest.cc ('k') | net/filter/sdch_source_stream.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/filter/sdch_source_stream.h
diff --git a/net/filter/sdch_source_stream.h b/net/filter/sdch_source_stream.h
new file mode 100644
index 0000000000000000000000000000000000000000..e96bb473a51498fe3ab1ca5fceaed3881f2a8980
--- /dev/null
+++ b/net/filter/sdch_source_stream.h
@@ -0,0 +1,149 @@
+// 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_SOURCE_STREAM_H_
+#define NET_FILTER_SDCH_SOURCE_STREAM_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "net/base/net_export.h"
+#include "net/base/sdch_dictionary.h"
+#include "net/base/sdch_manager.h"
+#include "net/filter/filter_source_stream.h"
+
+namespace open_vcdiff {
+
+class VCDiffStreamingDecoder;
+
+} // namespace open_vcdiff
+
+namespace net {
+
+class IOBuffer;
+
+// SdchSourceStream applies open_vcdiff content decoding to a datastream.
+// This decoding uses a pre-cached dictionary of text fragments to decode
+// (expand) the stream back to its original contents.
+//
+// This SdchSourceStream internally uses open_vcdiff/vcdec library to do
+// decoding.
+class NET_EXPORT_PRIVATE SdchSourceStream : public FilterSourceStream {
+ public:
+ // The Delegate interface is responsible for error recovery and stats
+ // gathering. See the methods below for descriptions of which errors the
+ // delegate is expected to handle and what it can do to repair them.
+ class NET_EXPORT_PRIVATE Delegate {
+ public:
+ virtual ~Delegate(){};
+
+ // Called by the SdchSourceStream if an error occurs while parsing the
+ // server-sent dictionary ID, or if the specified dictionary can't be loaded
+ // (i.e., GetDictionary returned false). This method is expected to correct
+ // the error condition by either:
+ // a) returning true and calling ReplaceOutput or Passthrough, or
+ // b) returning false, in which case the SourceStream will return an error
+ // to its caller
+ // Conceptually, the return value is true if the error has been
+ // handled/recovered from and false if not.
+ // This method must not retain a reference to |source| after returning.
+ virtual bool OnDictionaryError(SdchSourceStream* source) = 0;
+
+ // Called by the SdchSourceStream if an error occurs while decoding the
+ // vcdiff-compressed data stream. Semantics are similar to
+ // OnDictionaryError above. This method must not retain a reference to
+ // |source| after returning.
+ virtual bool OnDecodingError(SdchSourceStream* source) = 0;
+
+ // Called by the SdchSourceStream to request the text of the specified
+ // dictionary. This method must either:
+ // * Fill in |*text| and return true, or
+ // * Leave |*text| untouched and return false.
+ // The return value is true if the named dictionary could be found and false
+ // otherwise.
+ //
+ // The |server_id| string is guaranteed to be a syntactically valid SDCH
+ // server-id.
+ virtual bool OnGetDictionary(const std::string& server_id,
+ const std::string** text) = 0;
+ };
+
+ SdchSourceStream(std::unique_ptr<SourceStream> previous, Delegate* delegate);
+ ~SdchSourceStream() override;
+
+ // For use by SdchSourceStreamDelegate. 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 OnDictionaryError or OnDecodingError functions.
+ virtual void StopDecoding();
+
+ // For use by SdchSourceStreamDelegate. 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 OnDictionaryError or
+ // OnDecodingError 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,
+ };
+
+ // SourceStream implementation:
+ std::string GetTypeAsString() const override;
+ int FilterData(IOBuffer* output_buffer,
+ size_t output_buffer_size,
+ DrainableIOBuffer* input_buffer) override;
+
+ SdchStreamState Decompress(IOBuffer* output_buffer,
+ size_t output_buffer_size,
+ DrainableIOBuffer* input_buffer,
+ size_t* bytes_read);
+ // Pass any remaining input through without alteration.
+ SdchStreamState PassThrough(IOBuffer* output_buffer,
+ size_t output_buffer_size,
+ DrainableIOBuffer* input_buffer,
+ size_t* bytes_read);
+
+ // Flushes data in |buffered_output_| to |output_buffer|.
+ SdchStreamState Flush(IOBuffer* output_buffer,
+ size_t output_buffer_size,
+ size_t* bytes_read);
+
+ bool LoadDictionary(DrainableIOBuffer* input_buffer);
+
+ // 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();
+
+ std::unique_ptr<open_vcdiff::VCDiffStreamingDecoder> decoder_;
+ Delegate* delegate_;
+
+ // After the encoded response SDCH header is read, this variable contains
+ // the server hash with trailing null byte.
+ std::string dictionary_id_;
+
+ // Since vcdiff may generate quite a bit of output at once, SdchSourceStream
+ // 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(SdchSourceStream);
+};
+
+} // namespace net
+
+#endif // NET_FILTER_SDCH_SOURCE_STREAM_H_
« no previous file with comments | « net/filter/sdch_policy_delegate_unittest.cc ('k') | net/filter/sdch_source_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698