Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / mojo / services / network / network_service_impl.cc
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.
4
5 #include "mojo/services/network/network_service_impl.h"
6
7 #include "mojo/public/cpp/application/application_connection.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"
11 #include "mojo/services/network/udp_socket_impl.h"
12 #include "mojo/services/network/url_loader_impl.h"
13 #include "mojo/services/network/web_socket_impl.h"
14
15 namespace mojo {
16
17 NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection,
18                                        NetworkContext* context)
19     : context_(context),
20       origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) {
21 }
22
23 NetworkServiceImpl::~NetworkServiceImpl() {
24 }
25
26 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) {
27   // TODO(darin): Plumb origin_. Use for CORS.
28   BindToRequest(new URLLoaderImpl(context_), &loader);
29 }
30
31 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
32   BindToRequest(new CookieStoreImpl(context_, origin_), &store);
33 }
34
35 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
36   BindToRequest(new WebSocketImpl(context_), &socket);
37 }
38
39 void NetworkServiceImpl::CreateTCPBoundSocket(
40     NetAddressPtr local_address,
41     InterfaceRequest<TCPBoundSocket> bound_socket,
42     const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) {
43   scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl);
44   int net_error = bound->Bind(local_address.Pass());
45   if (net_error != net::OK) {
46     callback.Run(MakeNetworkError(net_error), NetAddressPtr());
47     return;
48   }
49   NetAddressPtr resulting_local_address(bound->GetLocalAddress());
50   BindToRequest(bound.release(), &bound_socket);
51   callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass());
52 }
53
54 void NetworkServiceImpl::CreateTCPConnectedSocket(
55     NetAddressPtr remote_address,
56     ScopedDataPipeConsumerHandle send_stream,
57     ScopedDataPipeProducerHandle receive_stream,
58     InterfaceRequest<TCPConnectedSocket> client_socket,
59     const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) {
60   // TODO(brettw) implement this. We need to know what type of socket to use
61   // so we can create the right one (i.e. to pass to TCPSocket::Open) before
62   // doing the connect.
63   callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr());
64 }
65
66 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> socket) {
67   BindToRequest(new UDPSocketImpl(), &socket);
68 }
69
70 }  // namespace mojo