base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / mojo / services / network / network_service_impl.cc
blob6f2f5502d645d78dbf466e2e3558922814fe6d0f
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 #include "mojo/services/network/network_service_impl.h"
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"
15 namespace mojo {
17 NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection,
18 NetworkContext* context)
19 : context_(context),
20 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) {
23 NetworkServiceImpl::~NetworkServiceImpl() {
26 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) {
27 // TODO(darin): Plumb origin_. Use for CORS.
28 BindToRequest(new URLLoaderImpl(context_), &loader);
31 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
32 BindToRequest(new CookieStoreImpl(context_, origin_), &store);
35 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
36 BindToRequest(new WebSocketImpl(context_), &socket);
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;
49 NetAddressPtr resulting_local_address(bound->GetLocalAddress());
50 BindToRequest(bound.release(), &bound_socket);
51 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass());
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());
66 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> socket) {
67 BindToRequest(new UDPSocketImpl(), &socket);
70 } // namespace mojo