Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / mojo / services / network / tcp_connected_socket_impl.h
blob6e71499d1c8643aa4971cd67a35675923c0be5a1
1 // Copyright 2014 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.
5 #ifndef MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_
6 #define MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "mojo/common/handle_watcher.h"
11 #include "mojo/services/network/public/interfaces/tcp_connected_socket.mojom.h"
12 #include "net/socket/tcp_socket.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
15 namespace mojo {
17 class MojoToNetPendingBuffer;
18 class NetToMojoPendingBuffer;
20 class TCPConnectedSocketImpl : public TCPConnectedSocket, public ErrorHandler {
21 public:
22 TCPConnectedSocketImpl(scoped_ptr<net::TCPSocket> socket,
23 ScopedDataPipeConsumerHandle send_stream,
24 ScopedDataPipeProducerHandle receive_stream,
25 InterfaceRequest<TCPConnectedSocket> request);
26 ~TCPConnectedSocketImpl() override;
28 private:
29 // ErrorHandler methods:
30 void OnConnectionError() override;
32 // "Receiving" in this context means reading from TCPSocket and writing to
33 // the Mojo receive_stream.
34 void ReceiveMore();
35 void OnReceiveStreamReady(MojoResult result);
36 void DidReceive(bool completed_synchronously, int result);
37 void ShutdownReceive();
38 void ListenForReceivePeerClosed();
39 void OnReceiveDataPipeClosed(MojoResult result);
41 // "Writing" is reading from the Mojo send_stream and writing to the
42 // TCPSocket.
43 void SendMore();
44 void OnSendStreamReady(MojoResult result);
45 void DidSend(bool completed_asynchronously, int result);
46 void ShutdownSend();
47 void ListenForSendPeerClosed();
48 void OnSendDataPipeClosed(MojoResult result);
50 void DeleteIfNeeded();
52 scoped_ptr<net::TCPSocket> socket_;
54 // The *stream handles will be null while there is an in-progress transation
55 // between net and mojo. During this time, the handle will be owned by the
56 // *PendingBuffer.
58 // For reading from the network and writing to Mojo pipe.
59 ScopedDataPipeConsumerHandle send_stream_;
60 scoped_refptr<NetToMojoPendingBuffer> pending_receive_;
61 common::HandleWatcher receive_handle_watcher_;
63 // For reading from the Mojo pipe and writing to the network.
64 ScopedDataPipeProducerHandle receive_stream_;
65 scoped_refptr<MojoToNetPendingBuffer> pending_send_;
66 common::HandleWatcher send_handle_watcher_;
68 // To bind to the message pipe.
69 Binding<TCPConnectedSocket> binding_;
71 base::WeakPtrFactory<TCPConnectedSocketImpl> weak_ptr_factory_;
74 } // namespace mojo
76 #endif // MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_