OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/services/network/network_service_impl.h" | 5 #include "mojo/services/network/network_service_impl.h" |
6 | 6 |
7 #include "mojo/public/cpp/application/application_connection.h" | 7 #include "mojo/public/cpp/application/application_connection.h" |
8 #include "mojo/services/network/cookie_store_impl.h" | 8 #include "mojo/services/network/cookie_store_impl.h" |
9 #include "mojo/services/network/net_adapters.h" | 9 #include "mojo/services/network/net_adapters.h" |
10 #include "mojo/services/network/tcp_bound_socket_impl.h" | 10 #include "mojo/services/network/tcp_bound_socket_impl.h" |
11 #include "mojo/services/network/udp_socket_impl.h" | 11 #include "mojo/services/network/udp_socket_impl.h" |
12 #include "mojo/services/network/url_loader_impl.h" | 12 #include "mojo/services/network/url_loader_impl.h" |
13 #include "mojo/services/network/web_socket_impl.h" | 13 #include "mojo/services/network/web_socket_impl.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 | 16 |
17 namespace { | |
18 | |
19 // Allows a Callback<NetworkErrorPtr, NetAddressPtr> to be called by a | |
20 // Callback<NetworkErrorPtr> when the address is already known. | |
21 void BoundAddressCallbackAdapter( | |
22 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback, | |
23 NetAddressPtr address, | |
24 NetworkErrorPtr err) { | |
25 callback.Run(err.Pass(), address.Pass()); | |
26 } | |
27 | |
28 } // namespace | |
29 | |
30 NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection, | 17 NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection, |
31 NetworkContext* context) | 18 NetworkContext* context) |
32 : context_(context), | 19 : context_(context), |
33 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) { | 20 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) { |
34 } | 21 } |
35 | 22 |
36 NetworkServiceImpl::~NetworkServiceImpl() { | 23 NetworkServiceImpl::~NetworkServiceImpl() { |
37 } | 24 } |
38 | 25 |
39 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) { | 26 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) { |
(...skipping 23 matching lines...) Expand all Loading... |
63 BindToRequest(bound.release(), &bound_socket); | 50 BindToRequest(bound.release(), &bound_socket); |
64 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass()); | 51 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass()); |
65 } | 52 } |
66 | 53 |
67 void NetworkServiceImpl::CreateTCPConnectedSocket( | 54 void NetworkServiceImpl::CreateTCPConnectedSocket( |
68 NetAddressPtr remote_address, | 55 NetAddressPtr remote_address, |
69 ScopedDataPipeConsumerHandle send_stream, | 56 ScopedDataPipeConsumerHandle send_stream, |
70 ScopedDataPipeProducerHandle receive_stream, | 57 ScopedDataPipeProducerHandle receive_stream, |
71 InterfaceRequest<TCPConnectedSocket> client_socket, | 58 InterfaceRequest<TCPConnectedSocket> client_socket, |
72 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { | 59 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { |
73 TCPBoundSocketImpl bound_socket; | 60 // TODO(brettw) implement this. We need to know what type of socket to use |
74 int net_error = bound_socket.Bind(NetAddressPtr()); | 61 // so we can create the right one (i.e. to pass to TCPSocket::Open) before |
75 if (net_error != net::OK) { | 62 // doing the connect. |
76 callback.Run(MakeNetworkError(net_error), NetAddressPtr()); | 63 callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr()); |
77 return; | |
78 } | |
79 | |
80 bound_socket.Connect( | |
81 remote_address.Pass(), send_stream.Pass(), receive_stream.Pass(), | |
82 client_socket.Pass(), | |
83 base::Bind(&BoundAddressCallbackAdapter, | |
84 callback, | |
85 base::Passed(bound_socket.GetLocalAddress().Pass()))); | |
86 } | 64 } |
87 | 65 |
88 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> socket) { | 66 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> socket) { |
89 BindToRequest(new UDPSocketImpl(), &socket); | 67 BindToRequest(new UDPSocketImpl(), &socket); |
90 } | 68 } |
91 | 69 |
92 } // namespace mojo | 70 } // namespace mojo |
OLD | NEW |