Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: mojo/services/network/network_service_impl.cc

Issue 1139673003: Make Mandoline shut down cleanly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/services/network/network_service_impl.h" 5 #include "mojo/services/network/network_service_impl.h"
6 6
7 #include "mojo/application/public/cpp/application_connection.h" 7 #include "mojo/application/public/cpp/application_connection.h"
8 #include "mojo/services/network/cookie_store_impl.h" 8 #include "mojo/services/network/cookie_store_impl.h"
9 #include "mojo/services/network/http_server_impl.h" 9 #include "mojo/services/network/http_server_impl.h"
10 #include "mojo/services/network/net_adapters.h" 10 #include "mojo/services/network/net_adapters.h"
11 #include "mojo/services/network/tcp_bound_socket_impl.h" 11 #include "mojo/services/network/tcp_bound_socket_impl.h"
12 #include "mojo/services/network/udp_socket_impl.h" 12 #include "mojo/services/network/udp_socket_impl.h"
13 #include "mojo/services/network/url_loader_impl.h" 13 #include "mojo/services/network/url_loader_impl.h"
14 #include "mojo/services/network/web_socket_impl.h" 14 #include "mojo/services/network/web_socket_impl.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 17
18 NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection, 18 NetworkServiceImpl::NetworkServiceImpl(
19 NetworkContext* context) 19 ApplicationConnection* connection,
20 NetworkContext* context,
21 scoped_ptr<mojo::AppRefCount> app_refcount)
20 : context_(context), 22 : context_(context),
23 app_refcount_(app_refcount.Pass()),
21 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) { 24 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) {
22 } 25 }
23 26
24 NetworkServiceImpl::~NetworkServiceImpl() { 27 NetworkServiceImpl::~NetworkServiceImpl() {
25 } 28 }
26 29
27 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) { 30 void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) {
28 // TODO(darin): Plumb origin_. Use for CORS. 31 // TODO(darin): Plumb origin_. Use for CORS.
29 // The loader will delete itself when the pipe is closed, unless a request is 32 // The loader will delete itself when the pipe is closed, unless a request is
30 // in progress. In which case, the loader will delete itself when the request 33 // in progress. In which case, the loader will delete itself when the request
31 // is finished. 34 // is finished.
32 new URLLoaderImpl(context_, loader.Pass()); 35 new URLLoaderImpl(context_, loader.Pass(), app_refcount_->Clone());
33 } 36 }
34 37
35 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) { 38 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
36 BindToRequest(new CookieStoreImpl(context_, origin_), &store); 39 BindToRequest(new CookieStoreImpl(context_, origin_, app_refcount_->Clone()),
40 &store);
37 } 41 }
38 42
39 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) { 43 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
40 BindToRequest(new WebSocketImpl(context_), &socket); 44 BindToRequest(new WebSocketImpl(context_, app_refcount_->Clone()), &socket);
41 } 45 }
42 46
43 void NetworkServiceImpl::CreateTCPBoundSocket( 47 void NetworkServiceImpl::CreateTCPBoundSocket(
44 NetAddressPtr local_address, 48 NetAddressPtr local_address,
45 InterfaceRequest<TCPBoundSocket> bound_socket, 49 InterfaceRequest<TCPBoundSocket> bound_socket,
46 const CreateTCPBoundSocketCallback& callback) { 50 const CreateTCPBoundSocketCallback& callback) {
47 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl); 51 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl(
52 app_refcount_->Clone()));
48 int net_error = bound->Bind(local_address.Pass()); 53 int net_error = bound->Bind(local_address.Pass());
49 if (net_error != net::OK) { 54 if (net_error != net::OK) {
50 callback.Run(MakeNetworkError(net_error), NetAddressPtr()); 55 callback.Run(MakeNetworkError(net_error), NetAddressPtr());
51 return; 56 return;
52 } 57 }
53 NetAddressPtr resulting_local_address(bound->GetLocalAddress()); 58 NetAddressPtr resulting_local_address(bound->GetLocalAddress());
54 BindToRequest(bound.release(), &bound_socket); 59 BindToRequest(bound.release(), &bound_socket);
55 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass()); 60 callback.Run(MakeNetworkError(net::OK), resulting_local_address.Pass());
56 } 61 }
57 62
58 void NetworkServiceImpl::CreateTCPConnectedSocket( 63 void NetworkServiceImpl::CreateTCPConnectedSocket(
59 NetAddressPtr remote_address, 64 NetAddressPtr remote_address,
60 ScopedDataPipeConsumerHandle send_stream, 65 ScopedDataPipeConsumerHandle send_stream,
61 ScopedDataPipeProducerHandle receive_stream, 66 ScopedDataPipeProducerHandle receive_stream,
62 InterfaceRequest<TCPConnectedSocket> client_socket, 67 InterfaceRequest<TCPConnectedSocket> client_socket,
63 const CreateTCPConnectedSocketCallback& callback) { 68 const CreateTCPConnectedSocketCallback& callback) {
64 // TODO(brettw) implement this. We need to know what type of socket to use 69 // TODO(brettw) implement this. We need to know what type of socket to use
65 // so we can create the right one (i.e. to pass to TCPSocket::Open) before 70 // so we can create the right one (i.e. to pass to TCPSocket::Open) before
66 // doing the connect. 71 // doing the connect.
67 callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr()); 72 callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), NetAddressPtr());
68 } 73 }
69 74
70 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) { 75 void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) {
71 // The lifetime of this UDPSocketImpl is bound to that of the underlying pipe. 76 // The lifetime of this UDPSocketImpl is bound to that of the underlying pipe.
72 new UDPSocketImpl(request.Pass()); 77 new UDPSocketImpl(request.Pass(), app_refcount_->Clone());
73 } 78 }
74 79
75 void NetworkServiceImpl::CreateHttpServer( 80 void NetworkServiceImpl::CreateHttpServer(
76 NetAddressPtr local_address, 81 NetAddressPtr local_address,
77 HttpServerDelegatePtr delegate, 82 HttpServerDelegatePtr delegate,
78 const CreateHttpServerCallback& callback) { 83 const CreateHttpServerCallback& callback) {
79 HttpServerImpl::Create(local_address.Pass(), delegate.Pass(), callback); 84 HttpServerImpl::Create(local_address.Pass(), delegate.Pass(),
85 app_refcount_->Clone(), callback);
80 } 86 }
81 87
82 } // namespace mojo 88 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/network/network_service_impl.h ('k') | mojo/services/network/tcp_bound_socket_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698