Add ICU message format support
[chromium-blink-merge.git] / mojo / services / network / network_service_impl.cc
blob1b77db3fca2318b2e6b465acaa02d1a52daa2709
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"
15 #include "net/base/mime_util.h"
17 namespace mojo {
19 NetworkServiceImpl::NetworkServiceImpl(
20 ApplicationConnection* connection,
21 NetworkContext* context,
22 scoped_ptr<mojo::AppRefCount> app_refcount,
23 InterfaceRequest<NetworkService> request)
24 : context_(context),
25 app_refcount_(app_refcount.Pass()),
26 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()),
27 binding_(this, request.Pass()) {
30 NetworkServiceImpl::~NetworkServiceImpl() {
33 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
34 new CookieStoreImpl(context_, origin_, app_refcount_->Clone(), store.Pass());
37 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
38 new WebSocketImpl(context_, app_refcount_->Clone(), socket.Pass());
41 void NetworkServiceImpl::CreateTCPBoundSocket(
42 NetAddressPtr local_address,
43 InterfaceRequest<TCPBoundSocket> bound_socket,
44 const CreateTCPBoundSocketCallback& callback) {
45 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl(
46 app_refcount_->Clone(), bound_socket.Pass()));
47 int net_error = bound->Bind(local_address.Pass());
48 if (net_error != net::OK) {
49 callback.Run(MakeNetworkError(net_error), NetAddressPtr());
50 return;
52 ignore_result(bound.release()); // Strongly owned by the message pipe.
53 NetAddressPtr resulting_local_address(bound->GetLocalAddress());
54 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass());
57 void NetworkServiceImpl::CreateTCPConnectedSocket(
58 NetAddressPtr remote_address,
59 ScopedDataPipeConsumerHandle send_stream,
60 ScopedDataPipeProducerHandle receive_stream,
61 InterfaceRequest<TCPConnectedSocket> client_socket,
62 const CreateTCPConnectedSocketCallback& callback) {
63 // TODO(brettw) implement this. We need to know what type of socket to use
64 // so we can create the right one (i.e. to pass to TCPSocket::Open) before
65 // doing the connect.
66 callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr());
69 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) {
70 // The lifetime of this UDPSocketImpl is bound to that of the underlying pipe.
71 new UDPSocketImpl(request.Pass(), app_refcount_->Clone());
74 void NetworkServiceImpl::CreateHttpServer(
75 NetAddressPtr local_address,
76 HttpServerDelegatePtr delegate,
77 const CreateHttpServerCallback& callback) {
78 HttpServerImpl::Create(local_address.Pass(), delegate.Pass(),
79 app_refcount_->Clone(), callback);
82 void NetworkServiceImpl::GetMimeTypeFromFile(
83 const mojo::String& file_path,
84 const GetMimeTypeFromFileCallback& callback) {
85 std::string mime;
86 net::GetMimeTypeFromFile(
87 base::FilePath::FromUTF8Unsafe(file_path.To<std::string>()), &mime);
88 callback.Run(mime);
91 } // namespace mojo