| OLD | NEW |
| (Empty) |
| 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 <utility> | |
| 8 | |
| 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 "net/base/mime_util.h" | |
| 15 | |
| 16 namespace mojo { | |
| 17 | |
| 18 NetworkServiceImpl::NetworkServiceImpl( | |
| 19 scoped_ptr<mojo::MessageLoopRef> app_refcount, | |
| 20 InterfaceRequest<NetworkService> request) | |
| 21 : app_refcount_(std::move(app_refcount)), | |
| 22 binding_(this, std::move(request)) {} | |
| 23 | |
| 24 NetworkServiceImpl::~NetworkServiceImpl() { | |
| 25 } | |
| 26 | |
| 27 void NetworkServiceImpl::CreateTCPBoundSocket( | |
| 28 NetAddressPtr local_address, | |
| 29 InterfaceRequest<TCPBoundSocket> bound_socket, | |
| 30 const CreateTCPBoundSocketCallback& callback) { | |
| 31 scoped_ptr<TCPBoundSocketImpl> bound( | |
| 32 new TCPBoundSocketImpl(app_refcount_->Clone(), std::move(bound_socket))); | |
| 33 int net_error = bound->Bind(std::move(local_address)); | |
| 34 if (net_error != net::OK) { | |
| 35 callback.Run(MakeNetworkError(net_error), NetAddressPtr()); | |
| 36 return; | |
| 37 } | |
| 38 ignore_result(bound.release()); // Strongly owned by the message pipe. | |
| 39 NetAddressPtr resulting_local_address(bound->GetLocalAddress()); | |
| 40 callback.Run(MakeNetworkError(net::OK), std::move(resulting_local_address)); | |
| 41 } | |
| 42 | |
| 43 void NetworkServiceImpl::CreateTCPConnectedSocket( | |
| 44 NetAddressPtr remote_address, | |
| 45 ScopedDataPipeConsumerHandle send_stream, | |
| 46 ScopedDataPipeProducerHandle receive_stream, | |
| 47 InterfaceRequest<TCPConnectedSocket> client_socket, | |
| 48 const CreateTCPConnectedSocketCallback& callback) { | |
| 49 // TODO(brettw) implement this. We need to know what type of socket to use | |
| 50 // so we can create the right one (i.e. to pass to TCPSocket::Open) before | |
| 51 // doing the connect. | |
| 52 callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr()); | |
| 53 } | |
| 54 | |
| 55 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) { | |
| 56 // The lifetime of this UDPSocketImpl is bound to that of the underlying pipe. | |
| 57 new UDPSocketImpl(std::move(request), app_refcount_->Clone()); | |
| 58 } | |
| 59 | |
| 60 void NetworkServiceImpl::CreateHttpServer( | |
| 61 NetAddressPtr local_address, | |
| 62 HttpServerDelegatePtr delegate, | |
| 63 const CreateHttpServerCallback& callback) { | |
| 64 HttpServerImpl::Create(std::move(local_address), std::move(delegate), | |
| 65 app_refcount_->Clone(), callback); | |
| 66 } | |
| 67 | |
| 68 void NetworkServiceImpl::GetMimeTypeFromFile( | |
| 69 const mojo::String& file_path, | |
| 70 const GetMimeTypeFromFileCallback& callback) { | |
| 71 std::string mime; | |
| 72 net::GetMimeTypeFromFile( | |
| 73 base::FilePath::FromUTF8Unsafe(file_path.To<std::string>()), &mime); | |
| 74 callback.Run(mime); | |
| 75 } | |
| 76 | |
| 77 } // namespace mojo | |
| OLD | NEW |