[M73 Dev][EFL] Disable VizDisplayCompositor for EFL port
[platform/framework/web/chromium-efl.git] / components / cast_channel / mojo_data_pump.h
1 // Copyright 2018 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 COMPONENTS_CAST_CHANNEL_MOJO_DATA_PUMP_H_
6 #define COMPONENTS_CAST_CHANNEL_MOJO_DATA_PUMP_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "components/cast_channel/cast_transport.h"
11 #include "mojo/public/cpp/system/data_pipe.h"
12 #include "mojo/public/cpp/system/simple_watcher.h"
13 #include "net/base/completion_once_callback.h"
14
15 namespace net {
16 class IOBuffer;
17 };  // namespace net
18
19 namespace cast_channel {
20
21 // Helper class to read from a mojo consumer handle and write to mojo producer
22 // handle.
23 class MojoDataPump : public CastTransportImpl::Channel {
24  public:
25   MojoDataPump(mojo::ScopedDataPipeConsumerHandle receive_stream,
26                mojo::ScopedDataPipeProducerHandle send_stream);
27
28   ~MojoDataPump() override;
29
30   // CastTransportImpl::Channel implementation:
31   void Read(net::IOBuffer* io_buffer,
32             int count,
33             net::CompletionOnceCallback callback) override;
34   void Write(net::IOBuffer* io_buffer,
35              int io_buffer_size,
36              net::CompletionOnceCallback callback) override;
37
38   // Returns whether a read is pending.
39   bool HasPendingRead() const { return !read_callback_.is_null(); }
40
41   // Returns whether a write is pending.
42   bool HasPendingWrite() const { return !write_callback_.is_null(); }
43
44  private:
45   void OnReadComplete(int result);
46   void StartWatching();
47   void ReceiveMore(MojoResult result, const mojo::HandleSignalsState& state);
48   void SendMore(MojoResult result, const mojo::HandleSignalsState& state);
49
50   mojo::ScopedDataPipeConsumerHandle receive_stream_;
51   mojo::SimpleWatcher receive_stream_watcher_;
52   mojo::ScopedDataPipeProducerHandle send_stream_;
53   mojo::SimpleWatcher send_stream_watcher_;
54
55   net::CompletionOnceCallback read_callback_;
56   net::CompletionOnceCallback write_callback_;
57   scoped_refptr<net::IOBuffer> pending_read_buffer_;
58   scoped_refptr<net::IOBuffer> pending_write_buffer_;
59   int pending_write_buffer_size_ = 0;
60   uint32_t read_size_ = 0;
61
62   DISALLOW_COPY_AND_ASSIGN(MojoDataPump);
63 };
64
65 }  // namespace cast_channel
66
67 #endif  // COMPONENTS_CAST_CHANNEL_MOJO_DATA_PUMP_H_