Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: mojo/services/network/network_service_impl.cc

Issue 634713002: Implement parts of the Mojo TCP interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing file in gyp Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "mojo/services/network/tcp_bound_socket_impl.h"
9 #include "mojo/services/network/url_loader_impl.h" 11 #include "mojo/services/network/url_loader_impl.h"
10 #include "mojo/services/network/web_socket_impl.h" 12 #include "mojo/services/network/web_socket_impl.h"
11 13
12 namespace mojo { 14 namespace mojo {
13 15
16 namespace {
17
18 // Allows a Callback<NetworkErrorPtr, NetAddressPtr> to be called by a
19 // Callback<NetworkErrorPtr> when the address is already known.
20 void BoundAddressCallbackAdapter(
21 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback,
22 NetAddressPtr address,
23 NetworkErrorPtr err) {
24 callback.Run(err.Pass(), address.Pass());
25 }
26
27 } // namespace
28
14 NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection, 29 NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection,
15 NetworkContext* context) 30 NetworkContext* context)
16 : context_(context), 31 : context_(context),
17 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) { 32 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) {
18 } 33 }
19 34
20 NetworkServiceImpl::~NetworkServiceImpl() { 35 NetworkServiceImpl::~NetworkServiceImpl() {
21 } 36 }
22 37
23 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) { 38 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) {
24 // TODO(darin): Plumb origin_. Use for CORS. 39 // TODO(darin): Plumb origin_. Use for CORS.
25 BindToRequest(new URLLoaderImpl(context_), &loader); 40 BindToRequest(new URLLoaderImpl(context_), &loader);
26 } 41 }
27 42
28 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) { 43 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
29 BindToRequest(new CookieStoreImpl(context_, origin_), &store); 44 BindToRequest(new CookieStoreImpl(context_, origin_), &store);
30 } 45 }
31 46
32 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) { 47 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
33 BindToRequest(new WebSocketImpl(context_), &socket); 48 BindToRequest(new WebSocketImpl(context_), &socket);
34 } 49 }
35 50
36 void NetworkServiceImpl::CreateTCPBoundSocket( 51 void NetworkServiceImpl::CreateTCPBoundSocket(
37 NetAddressPtr local_address, 52 NetAddressPtr local_address,
38 InterfaceRequest<TCPBoundSocket> bound_socket, 53 InterfaceRequest<TCPBoundSocket> bound_socket,
39 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { 54 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) {
40 // TODO(brettw) implement this. 55 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl);
41 callback.Run(NetworkErrorPtr(), NetAddressPtr()); 56 int net_error = bound->Bind(local_address.Pass());
57 if (net_error != net::OK) {
58 callback.Run(MakeNetworkError(net_error), NetAddressPtr());
59 return;
60 }
61 NetAddressPtr resulting_local_address(bound->GetLocalAddress());
62 BindToRequest(bound.release(), &bound_socket);
63 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass());
42 } 64 }
43 65
44 void NetworkServiceImpl::CreateTCPClientSocket( 66 void NetworkServiceImpl::CreateTCPConnectedSocket(
45 NetAddressPtr remote_address, 67 NetAddressPtr remote_address,
46 ScopedDataPipeConsumerHandle send_stream, 68 ScopedDataPipeConsumerHandle send_stream,
47 ScopedDataPipeProducerHandle receive_stream, 69 ScopedDataPipeProducerHandle receive_stream,
48 InterfaceRequest<TCPClientSocket> client_socket, 70 InterfaceRequest<TCPConnectedSocket> client_socket,
49 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { 71 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) {
50 // TODO(brettw) implement this. 72 TCPBoundSocketImpl bound_socket;
51 callback.Run(NetworkErrorPtr(), NetAddressPtr()); 73 int net_error = bound_socket.Bind(NetAddressPtr());
74 if (net_error != net::OK) {
75 callback.Run(MakeNetworkError(net_error), NetAddressPtr());
76 return;
77 }
78
79 bound_socket.Connect(
80 remote_address.Pass(), send_stream.Pass(), receive_stream.Pass(),
81 client_socket.Pass(),
82 base::Bind(&BoundAddressCallbackAdapter,
83 callback,
84 base::Passed(bound_socket.GetLocalAddress().Pass())));
52 } 85 }
53 86
54 } // namespace mojo 87 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/network/network_service_impl.h ('k') | mojo/services/network/tcp_bound_socket_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698