File: source_stream.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (63 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_FILTER_SOURCE_STREAM_H_
#define NET_FILTER_SOURCE_STREAM_H_

#include <string>

#include "net/base/completion_once_callback.h"
#include "net/base/net_export.h"
#include "net/filter/source_stream_type.h"

namespace net {

class IOBuffer;

// The SourceStream class implements a producer of bytes.
class NET_EXPORT_PRIVATE SourceStream {
 public:
  // |type| is the type of the SourceStream.
  explicit SourceStream(SourceStreamType type);

  SourceStream(const SourceStream&) = delete;
  SourceStream& operator=(const SourceStream&) = delete;

  virtual ~SourceStream();

  // Initiaties a read from the stream.
  // If it completes synchronously, it:
  //   - Returns an int representing the number of bytes read. If 0, EOF has
  //     been reached
  //   - Bytes will be written into |*dest_buffer|
  //   - Does not call |callback|
  // If it completes asynchronously, it:
  //   - Returns ERR_IO_PENDING
  //   - Calls |callback| when it does complete, with an error code or a count
  //     of bytes read and written into |*dest_buffer|.
  // This method takes a reference to |*dest_buffer| if it completes
  // asynchronously to ensure it does not get freed mid-read.
  virtual int Read(IOBuffer* dest_buffer,
                   int buffer_size,
                   CompletionOnceCallback callback) = 0;

  // Returns a string that represents stream. This is for UMA and NetLog
  // logging.
  virtual std::string Description() const = 0;

  // Returns true if there may be more bytes to read in this source stream.
  // This is not a guarantee that there are more bytes (in the case that
  // the stream doesn't know).  However, if this returns false, then the stream
  // is guaranteed to be complete.
  virtual bool MayHaveMoreBytes() const = 0;

  SourceStreamType type() const { return type_; }

 private:
  const SourceStreamType type_;
};

}  // namespace net

#endif  // NET_FILTER_SOURCE_STREAM_H_