cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / mojo / services / network / network_service_impl.cc
blob011afde89cceaa79fe0fd9780b3f8bc554ccbe61
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/services/network/http_server_impl.h"
8 #include "mojo/services/network/net_adapters.h"
9 #include "mojo/services/network/tcp_bound_socket_impl.h"
10 #include "mojo/services/network/udp_socket_impl.h"
11 #include "mojo/services/network/url_loader_impl.h"
12 #include "net/base/mime_util.h"
14 namespace mojo {
16 NetworkServiceImpl::NetworkServiceImpl(
17 scoped_ptr<mojo::AppRefCount> app_refcount,
18 InterfaceRequest<NetworkService> request)
19 : app_refcount_(app_refcount.Pass()),
20 binding_(this, request.Pass()) {
23 NetworkServiceImpl::~NetworkServiceImpl() {
26 void NetworkServiceImpl::CreateTCPBoundSocket(
27 NetAddressPtr local_address,
28 InterfaceRequest<TCPBoundSocket> bound_socket,
29 const CreateTCPBoundSocketCallback& callback) {
30 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl(
31 app_refcount_->Clone(), bound_socket.Pass()));
32 int net_error = bound->Bind(local_address.Pass());
33 if (net_error != net::OK) {
34 callback.Run(MakeNetworkError(net_error), NetAddressPtr());
35 return;
37 ignore_result(bound.release()); // Strongly owned by the message pipe.
38 NetAddressPtr resulting_local_address(bound->GetLocalAddress());
39 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass());
42 void NetworkServiceImpl::CreateTCPConnectedSocket(
43 NetAddressPtr remote_address,
44 ScopedDataPipeConsumerHandle send_stream,
45 ScopedDataPipeProducerHandle receive_stream,
46 InterfaceRequest<TCPConnectedSocket> client_socket,
47 const CreateTCPConnectedSocketCallback& callback) {
48 // TODO(brettw) implement this. We need to know what type of socket to use
49 // so we can create the right one (i.e. to pass to TCPSocket::Open) before
50 // doing the connect.
51 callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr());
54 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) {
55 // The lifetime of this UDPSocketImpl is bound to that of the underlying pipe.
56 new UDPSocketImpl(request.Pass(), app_refcount_->Clone());
59 void NetworkServiceImpl::CreateHttpServer(
60 NetAddressPtr local_address,
61 HttpServerDelegatePtr delegate,
62 const CreateHttpServerCallback& callback) {
63 HttpServerImpl::Create(local_address.Pass(), delegate.Pass(),
64 app_refcount_->Clone(), callback);
67 void NetworkServiceImpl::GetMimeTypeFromFile(
68 const mojo::String& file_path,
69 const GetMimeTypeFromFileCallback& callback) {
70 std::string mime;
71 net::GetMimeTypeFromFile(
72 base::FilePath::FromUTF8Unsafe(file_path.To<std::string>()), &mime);
73 callback.Run(mime);
76 } // namespace mojo