| 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_SOURCE_STREAM_H_ |
| 6 #define NET_FILTER_SOURCE_STREAM_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "net/base/completion_callback.h" |
| 14 #include "net/base/net_errors.h" |
| 15 |
| 16 namespace net { |
| 17 |
| 18 class IOBuffer; |
| 19 |
| 20 // The SourceStream class implements a producer of bytes. |
| 21 class NET_EXPORT_PRIVATE SourceStream { |
| 22 public: |
| 23 enum SourceType { |
| 24 #define SOURCE_STREAM_TYPE(label) TYPE_##label, |
| 25 #include "net/filter/source_stream_type_list.h" |
| 26 #undef SOURCE_STREAM_TYPE |
| 27 // Used for UMA. |
| 28 TYPE_MAX, |
| 29 }; |
| 30 |
| 31 // |type| is the type of the SourceStream. |
| 32 explicit SourceStream(SourceType type); |
| 33 |
| 34 virtual ~SourceStream(); |
| 35 |
| 36 // Initiaties a read from the stream. |
| 37 // If it completes synchronously, it: |
| 38 // - Returns an int representing the number of bytes read. If 0, EOF has |
| 39 // been reached |
| 40 // - Bytes will be written into |*dest_buffer| |
| 41 // - Does not call |callback| |
| 42 // If it completes asynchronously, it: |
| 43 // - Returns ERR_IO_PENDING |
| 44 // - Calls |callback| when it does complete, with an error code or a count |
| 45 // of bytes read and written into |*dest_buffer|. |
| 46 // This method takes a reference to |*dest_buffer| if it completes |
| 47 // asynchronously to ensure it does not get freed mid-read. |
| 48 virtual int Read(IOBuffer* dest_buffer, |
| 49 int buffer_size, |
| 50 const CompletionCallback& callback) = 0; |
| 51 |
| 52 // Returns a string that represents stream. This is for UMA and NetLog |
| 53 // logging. |
| 54 virtual std::string Description() const = 0; |
| 55 |
| 56 SourceType type() const { return type_; } |
| 57 |
| 58 private: |
| 59 SourceType type_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(SourceStream); |
| 62 }; |
| 63 |
| 64 } // namespace net |
| 65 |
| 66 #endif // NET_FILTER_SOURCE_STREAM_H_ |
| OLD | NEW |