Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / services / network / network_service_impl.cc
blob661f7e0cf6f910523c69c04cf840e0633c2e89a6
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/application/public/cpp/application_connection.h"
8 #include "mojo/services/network/cookie_store_impl.h"
9 #include "mojo/services/network/http_server_impl.h"
10 #include "mojo/services/network/net_adapters.h"
11 #include "mojo/services/network/tcp_bound_socket_impl.h"
12 #include "mojo/services/network/udp_socket_impl.h"
13 #include "mojo/services/network/url_loader_impl.h"
14 #include "mojo/services/network/web_socket_impl.h"
16 namespace mojo {
18 NetworkServiceImpl::NetworkServiceImpl(
19 ApplicationConnection* connection,
20 NetworkContext* context,
21 scoped_ptr<mojo::AppRefCount> app_refcount,
22 InterfaceRequest<NetworkService> request)
23 : context_(context),
24 app_refcount_(app_refcount.Pass()),
25 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()),
26 binding_(this, request.Pass()) {
29 NetworkServiceImpl::~NetworkServiceImpl() {
32 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
33 new CookieStoreImpl(context_, origin_, app_refcount_->Clone(), store.Pass());
36 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
37 new WebSocketImpl(context_, app_refcount_->Clone(), socket.Pass());
40 void NetworkServiceImpl::CreateTCPBoundSocket(
41 NetAddressPtr local_address,
42 InterfaceRequest<TCPBoundSocket> bound_socket,
43 const CreateTCPBoundSocketCallback& callback) {
44 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl(
45 app_refcount_->Clone(), bound_socket.Pass()));
46 int net_error = bound->Bind(local_address.Pass());
47 if (net_error != net::OK) {
48 callback.Run(MakeNetworkError(net_error), NetAddressPtr());
49 return;
51 ignore_result(bound.release()); // Strongly owned by the message pipe.
52 NetAddressPtr resulting_local_address(bound->GetLocalAddress());
53 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass());
56 void NetworkServiceImpl::CreateTCPConnectedSocket(
57 NetAddressPtr remote_address,
58 ScopedDataPipeConsumerHandle send_stream,
59 ScopedDataPipeProducerHandle receive_stream,
60 InterfaceRequest<TCPConnectedSocket> client_socket,
61 const CreateTCPConnectedSocketCallback& callback) {
62 // TODO(brettw) implement this. We need to know what type of socket to use
63 // so we can create the right one (i.e. to pass to TCPSocket::Open) before
64 // doing the connect.
65 callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr());
68 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) {
69 // The lifetime of this UDPSocketImpl is bound to that of the underlying pipe.
70 new UDPSocketImpl(request.Pass(), app_refcount_->Clone());
73 void NetworkServiceImpl::CreateHttpServer(
74 NetAddressPtr local_address,
75 HttpServerDelegatePtr delegate,
76 const CreateHttpServerCallback& callback) {
77 HttpServerImpl::Create(local_address.Pass(), delegate.Pass(),
78 app_refcount_->Clone(), callback);
81 } // namespace mojo