Chromium Code Reviews| Index: net/filter/stream_source.h |
| diff --git a/net/filter/stream_source.h b/net/filter/stream_source.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bcea463c685578b12624f4cd2d68279351bc989c |
| --- /dev/null |
| +++ b/net/filter/stream_source.h |
| @@ -0,0 +1,77 @@ |
| +// 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_STREAM_SOURCE_H |
| +#define NET_FILTER_STREAM_SOURCE_H |
| + |
| +#include "base/callback.h" |
| +#include "net/base/io_buffer.h" |
| +#include "net/base/net_errors.h" |
| +#include "net/filter/block_buffer.h" |
| + |
| +namespace net { |
| + |
| +class SdchStreamSourceDelegate; |
| + |
| +// The StreamSource class implements a producer of bytes. Sources often |
| +// incorporate a previous source from which they read undecoded input. Those |
| +// which incorporate a previous source take ownership of the previous source |
| +// when they are created. |
| +class StreamSource { |
| + public: |
| + enum SourceType { |
| +#define STREAM_SOURCE_TYPE(label) TYPE_##label, |
| +#include "net/filter/stream_source_type_list.h" |
| +#undef STREAM_SOURCE_TYPE |
| + // Used for UMA. |
| + TYPE_MAX, |
| + }; |
| + |
| + // |type| is the type of the StreamSource. |previous| is the previous |
| + // StreamSource in the chain. If |previous| is null, |this| is the start of |
| + // the StreamSource chain. |
| + StreamSource(SourceType type, std::unique_ptr<StreamSource> previous); |
| + |
| + virtual ~StreamSource(); |
| + |
| + typedef base::Callback<void(net::Error, size_t)> OnReadCompleteCallback; |
| + |
| + // Initiaties a read from the filter chain starting at this stream source. |
| + // If it completes synchronously, it: |
| + // - Returns an Error other than ERR_IO_PENDING |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
nit: or OK.
xunjieli
2016/07/20 21:00:47
Done.
|
| + // - Writes |*bytes_read| with the count of bytes read |
| + // - Writes bytes into |*dest_buffer| |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
nit: Presumably only if it did return OK for both
xunjieli
2016/07/20 21:00:47
Done.
|
| + // - Does not call |callback| |
| + // If it completes asynchronously, it: |
| + // - Returns ERR_IO_PENDING |
| + // - Does not write |*bytes_read| |
| + // - Calls |callback| when it does complete, with an error code and a count |
| + // of bytes read, which are them placed into |*dest_buffer|. |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
nit, typo: "them" -> "then".
Presuming that's wha
xunjieli
2016/07/20 21:00:48
Done.
|
| + // This method takes a reference to |*dest_buffer| if it completes |
| + // asynchronously to ensure it does not get freed mid-read. |
| + virtual net::Error Read(IOBuffer* dest_buffer, |
| + size_t buffer_size, |
| + size_t* bytes_read, |
| + const OnReadCompleteCallback& callback) = 0; |
| + |
| + SourceType type() const { return type_; } |
| + |
| + StreamSource* previous() const { return previous_.get(); } |
| + |
| + protected: |
|
mmenke
2016/04/29 19:10:54
protected fields aren't allowed.
xunjieli
2016/07/20 21:00:48
Done.
|
| + SourceType type_; |
| + // Previous StreamSource in the chain. |
| + std::unique_ptr<StreamSource> previous_; |
| + // Non-null when there is a read outstanding. |
| + // scoped_refptr<IOBuffer> pending_read_buffer_; |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
nit: Should these lines be removed?
xunjieli
2016/07/20 21:00:47
Done.
|
| + // Buffer for reading data out of |previous_| and then for use by |this| |
| + // before the filtered data is returned through Read(). |
| + std::unique_ptr<BlockBuffer> buffer_; |
| + |
| + private: |
|
mmenke
2016/04/29 19:10:54
DISALLOW_COPY_AND_ASSIGN
xunjieli
2016/07/20 21:00:47
Done.
|
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_FILTER_STREAM_SOURCE_H |