Chromium Code Reviews| 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_STREAM_SOURCE_H | |
| 6 #define NET_FILTER_STREAM_SOURCE_H | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "net/base/io_buffer.h" | |
| 10 #include "net/base/net_errors.h" | |
| 11 | |
| 12 namespace net { | |
| 13 | |
| 14 class BlockBuffer; | |
| 15 class SdchStreamSourceDelegate; | |
| 16 | |
| 17 // The StreamSource class implements a producer of bytes. Sources often | |
| 18 // incorporate a previous source from which they read undecoded input. Those | |
| 19 // which incorporate a previous source take ownership of the previous source | |
| 20 // when they are created. | |
| 21 class StreamSource { | |
| 22 public: | |
| 23 enum SourceType { | |
| 24 SOURCE_BROTLI, | |
| 25 SOURCE_DEFLATE, | |
| 26 SOURCE_GZIP, | |
| 27 SOURCE_SDCH, | |
| 28 SOURCE_GZIP_FALLBACK, | |
| 29 SOURCE_INVALID, | |
| 30 SOURCE_NONE, | |
| 31 }; | |
| 32 | |
| 33 // |type| is the type of the StreamSource. |previous| is the previous | |
| 34 // StreamSource in the chain. If |previous| is null, |this| is the start of | |
| 35 // the StreamSource chain. | |
| 36 StreamSource(SourceType type, scoped_ptr<StreamSource> previous); | |
| 37 | |
| 38 virtual ~StreamSource(); | |
|
mmenke
2016/03/04 21:15:57
nit: Blank line after destructor
xunjieli
2016/04/20 19:16:10
Done.
| |
| 39 typedef base::Callback<void(net::Error, size_t)> OnReadCompleteCallback; | |
| 40 | |
| 41 // Loop on reading until either: | |
| 42 // * ReadInternal() returns some data, in which case this method completes | |
| 43 // synchronously, or | |
| 44 // * previous_->Read() does not complete synchronously, in which case | |
| 45 // OnReadComplete() is responsible for finishing the decompression. | |
| 46 // * If there is no |previous_|, subclass should invoke |callback_| | |
| 47 // when done. | |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
This comment reads to me like an implementation co
xunjieli
2016/04/20 19:16:10
Done.
| |
| 48 // | |
| 49 // If it completes synchronously, it: | |
| 50 // - Returns an Error other than ERR_IO_PENDING | |
| 51 // - Writes |*bytes_read| with the count of bytes read | |
| 52 // - Writes bytes into |*dest_buffer| | |
| 53 // - Does not call |callback| | |
| 54 // If it completes asynchronously, it: | |
| 55 // - Returns ERR_IO_PENDING | |
| 56 // - Does not write |*bytes_read| | |
| 57 // - Calls |callback| when it does complete, with an error code and a count | |
| 58 // of bytes read, which are them placed into |*dest_buffer|. | |
| 59 // This method takes a reference to |*dest_buffer| if it completes | |
| 60 // asynchronously to ensure it does not get freed mid-read. | |
| 61 net::Error Read(IOBuffer* dest_buffer, | |
| 62 size_t buffer_size, | |
| 63 size_t* bytes_read, | |
| 64 const OnReadCompleteCallback& callback); | |
| 65 | |
| 66 // Must be called by subclasses when ReadInternal complete asynchronously. | |
| 67 void OnReadComplete(IOBuffer* dest_buffer, | |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
I'm fairly disturbed (read: Please don't do this :
| |
| 68 size_t dest_buffer_size, | |
| 69 Error error, | |
| 70 size_t bytes_read); | |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
Why isn't this protected:?
I'm not sure which int
| |
| 71 | |
| 72 // This method constructs a chain of StreamSources from a vector of | |
| 73 // Content-Type values and an SdchStreamSourceDelegate. If any of the | |
| 74 // constructed StreamSources are SdchStreamSources, they will be constructed | |
| 75 // with |delegate|. | |
| 76 static scoped_ptr<StreamSource> BuildSourceChain( | |
| 77 scoped_ptr<StreamSource> current, | |
| 78 const std::vector<std::string>& type, | |
| 79 SdchStreamSourceDelegate* delegate); | |
| 80 | |
| 81 // Returns a string describing the SourceTypes implemented by this filter. | |
| 82 std::string OrderedStreamSourceList() const; | |
| 83 | |
| 84 SourceType type() const { return type_; } | |
| 85 | |
| 86 protected: | |
| 87 SourceType type_; | |
| 88 // Previous StreamSource in the chain. | |
| 89 scoped_ptr<StreamSource> previous_; | |
| 90 scoped_refptr<IOBuffer> pending_read_buffer_; | |
| 91 OnReadCompleteCallback callback_; | |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
nit: Comment about when non-null? (Presumably whe
xunjieli
2016/04/20 19:16:10
Done.
| |
| 92 | |
| 93 scoped_ptr<BlockBuffer> buffer_; | |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
nit: Comment about how used?
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
Did you consider making this an explicit part of t
xunjieli
2016/04/20 19:16:10
|buffer_| is used for reading from |previous_|, bu
xunjieli
2016/04/20 19:16:10
Done.
| |
| 94 | |
| 95 private: | |
| 96 // Also see Read(). Subclasses should implement this method to read data into | |
| 97 // |dest_buffer| until more input is needed from |previous_|. If |previous_| | |
| 98 // is null, the subclass should also take care of invoking |callback_| upon | |
| 99 // finishing asynchronously. | |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
This comment contradicts the one above on OnReadCo
| |
| 100 virtual net::Error ReadInternal(IOBuffer* dest_buffer, | |
| 101 size_t buffer_size, | |
| 102 size_t* bytes_read) = 0; | |
| 103 }; | |
| 104 | |
| 105 } // namespace net | |
| 106 | |
| 107 #endif // NET_FILTER_STREAM_SOURCE_H | |
| OLD | NEW |