Add ICU message format support
[chromium-blink-merge.git] / mojo / services / network / tcp_connected_socket_impl.h
blobb1c072e18ad143b08d0b0f1ff2c637ec9fd4ecb7
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/application/public/cpp/app_lifetime_helper.h"
11 #include "mojo/message_pump/handle_watcher.h"
12 #include "mojo/services/network/public/interfaces/tcp_connected_socket.mojom.h"
13 #include "net/socket/tcp_socket.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
16 namespace mojo {
18 class MojoToNetPendingBuffer;
19 class NetToMojoPendingBuffer;
21 class TCPConnectedSocketImpl : public TCPConnectedSocket {
22 public:
23 TCPConnectedSocketImpl(scoped_ptr<net::TCPSocket> socket,
24 ScopedDataPipeConsumerHandle send_stream,
25 ScopedDataPipeProducerHandle receive_stream,
26 InterfaceRequest<TCPConnectedSocket> request,
27 scoped_ptr<mojo::AppRefCount> app_refcount);
28 ~TCPConnectedSocketImpl() override;
30 private:
31 void OnConnectionError();
33 // "Receiving" in this context means reading from TCPSocket and writing to
34 // the Mojo receive_stream.
35 void ReceiveMore();
36 void OnReceiveStreamReady(MojoResult result);
37 void DidReceive(bool completed_synchronously, int result);
38 void ShutdownReceive();
39 void ListenForReceivePeerClosed();
40 void OnReceiveDataPipeClosed(MojoResult result);
42 // "Writing" is reading from the Mojo send_stream and writing to the
43 // TCPSocket.
44 void SendMore();
45 void OnSendStreamReady(MojoResult result);
46 void DidSend(bool completed_asynchronously, int result);
47 void ShutdownSend();
48 void ListenForSendPeerClosed();
49 void OnSendDataPipeClosed(MojoResult result);
51 void DeleteIfNeeded();
53 scoped_ptr<net::TCPSocket> socket_;
55 // The *stream handles will be null while there is an in-progress transation
56 // between net and mojo. During this time, the handle will be owned by the
57 // *PendingBuffer.
59 // For reading from the network and writing to Mojo pipe.
60 ScopedDataPipeConsumerHandle send_stream_;
61 scoped_refptr<NetToMojoPendingBuffer> pending_receive_;
62 common::HandleWatcher receive_handle_watcher_;
64 // For reading from the Mojo pipe and writing to the network.
65 ScopedDataPipeProducerHandle receive_stream_;
66 scoped_refptr<MojoToNetPendingBuffer> pending_send_;
67 common::HandleWatcher send_handle_watcher_;
69 // To bind to the message pipe.
70 Binding<TCPConnectedSocket> binding_;
72 scoped_ptr<mojo::AppRefCount> app_refcount_;
74 base::WeakPtrFactory<TCPConnectedSocketImpl> weak_ptr_factory_;
77 } // namespace mojo
79 #endif // MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_