diff options
author | jam <jam@chromium.org> | 2015-05-19 10:35:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-19 17:36:19 +0000 |
commit | e152cdb102e5e495dd3aa124a512ea750b47c04c (patch) | |
tree | 94ccb226918b370a3524711fcb2b8c071c8d0bd2 /mojo/services | |
parent | 5849cfec2bbfc5e16a3c033c15e73d09a1b6af4f (diff) | |
download | chromium_src-e152cdb102e5e495dd3aa124a512ea750b47c04c.zip chromium_src-e152cdb102e5e495dd3aa124a512ea750b47c04c.tar.gz chromium_src-e152cdb102e5e495dd3aa124a512ea750b47c04c.tar.bz2 |
Making Mandoline apps notice when all the objects they vended are gone so that it can terminate.
With this change, closing the window shuts down Mandoline cleanly.
This is split off https://codereview.chromium.org/1139673003
BUG=484234
Review URL: https://codereview.chromium.org/1131933009
Cr-Commit-Position: refs/heads/master@{#330550}
Diffstat (limited to 'mojo/services')
21 files changed, 105 insertions, 36 deletions
diff --git a/mojo/services/network/cookie_store_impl.cc b/mojo/services/network/cookie_store_impl.cc index 033d7a4..05963aa 100644 --- a/mojo/services/network/cookie_store_impl.cc +++ b/mojo/services/network/cookie_store_impl.cc @@ -24,10 +24,13 @@ void AdaptSetCookieCallback(const Callback<void(bool)>& callback, } // namespace -CookieStoreImpl::CookieStoreImpl(NetworkContext* context, - const GURL& origin) +CookieStoreImpl::CookieStoreImpl( + NetworkContext* context, + const GURL& origin, + scoped_ptr<mojo::AppRefCount> app_refcount) : context_(context), - origin_(origin) { + origin_(origin), + app_refcount_(app_refcount.Pass()) { } CookieStoreImpl::~CookieStoreImpl() { diff --git a/mojo/services/network/cookie_store_impl.h b/mojo/services/network/cookie_store_impl.h index e3e9711..ee02ce9 100644 --- a/mojo/services/network/cookie_store_impl.h +++ b/mojo/services/network/cookie_store_impl.h @@ -5,6 +5,7 @@ #ifndef MOJO_SERVICES_NETWORK_COOKIE_STORE_IMPL_H_ #define MOJO_SERVICES_NETWORK_COOKIE_STORE_IMPL_H_ +#include "mojo/application/app_lifetime_helper.h" #include "mojo/services/network/public/interfaces/cookie_store.mojom.h" #include "url/gurl.h" @@ -13,7 +14,9 @@ class NetworkContext; class CookieStoreImpl : public InterfaceImpl<CookieStore> { public: - CookieStoreImpl(NetworkContext* context, const GURL& origin); + CookieStoreImpl(NetworkContext* context, + const GURL& origin, + scoped_ptr<mojo::AppRefCount> app_refcount); ~CookieStoreImpl() override; private: @@ -25,6 +28,7 @@ class CookieStoreImpl : public InterfaceImpl<CookieStore> { NetworkContext* context_; GURL origin_; + scoped_ptr<mojo::AppRefCount> app_refcount_; DISALLOW_COPY_AND_ASSIGN(CookieStoreImpl); }; diff --git a/mojo/services/network/http_server_impl.cc b/mojo/services/network/http_server_impl.cc index 599b3df..761c312 100644 --- a/mojo/services/network/http_server_impl.cc +++ b/mojo/services/network/http_server_impl.cc @@ -25,8 +25,10 @@ const int kBackLog = 10; void HttpServerImpl::Create( NetAddressPtr local_address, HttpServerDelegatePtr delegate, + scoped_ptr<mojo::AppRefCount> app_refcount, const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { - HttpServerImpl* http_server = new HttpServerImpl(delegate.Pass()); + HttpServerImpl* http_server = new HttpServerImpl( + delegate.Pass(), app_refcount.Pass()); int net_error = http_server->Start(local_address.Pass()); if (net_error != net::OK) { @@ -37,8 +39,10 @@ void HttpServerImpl::Create( callback.Run(MakeNetworkError(net::OK), http_server->GetLocalAddress()); } -HttpServerImpl::HttpServerImpl(HttpServerDelegatePtr delegate) - : delegate_(delegate.Pass()) { +HttpServerImpl::HttpServerImpl( + HttpServerDelegatePtr delegate, + scoped_ptr<mojo::AppRefCount> app_refcount) + : delegate_(delegate.Pass()), app_refcount_(app_refcount.Pass()) { DCHECK(delegate_); delegate_.set_error_handler(this); } diff --git a/mojo/services/network/http_server_impl.h b/mojo/services/network/http_server_impl.h index 01e26cc..bb43ce1 100644 --- a/mojo/services/network/http_server_impl.h +++ b/mojo/services/network/http_server_impl.h @@ -10,6 +10,7 @@ #include "base/macros.h" #include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/services/network/public/interfaces/http_server.mojom.h" #include "mojo/services/network/public/interfaces/net_address.mojom.h" #include "net/server/http_server.h" @@ -29,6 +30,7 @@ class HttpServerImpl : public net::HttpServer::Delegate, static void Create( NetAddressPtr local_address, HttpServerDelegatePtr delegate, + scoped_ptr<mojo::AppRefCount> app_refcount, const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback); net::HttpServer* server() { return server_.get(); } @@ -38,7 +40,8 @@ class HttpServerImpl : public net::HttpServer::Delegate, // |delegate|'s underlying pipe. The object will self-destruct when it is // notified that |delegate|'s pipe is closed. Deleting the object directly // before that is okay, too. - explicit HttpServerImpl(HttpServerDelegatePtr delegate); + HttpServerImpl(HttpServerDelegatePtr delegate, + scoped_ptr<mojo::AppRefCount> app_refcount); ~HttpServerImpl() override; int Start(NetAddressPtr local_address); @@ -57,6 +60,7 @@ class HttpServerImpl : public net::HttpServer::Delegate, void OnConnectionError() override; HttpServerDelegatePtr delegate_; + scoped_ptr<mojo::AppRefCount> app_refcount_; scoped_ptr<net::HttpServer> server_; std::map<int, linked_ptr<HttpConnectionImpl>> connections_; diff --git a/mojo/services/network/network_service_delegate.cc b/mojo/services/network/network_service_delegate.cc index 4884314..c6f4af5 100644 --- a/mojo/services/network/network_service_delegate.cc +++ b/mojo/services/network/network_service_delegate.cc @@ -40,5 +40,9 @@ void NetworkServiceDelegate::Create( mojo::ApplicationConnection* connection, mojo::InterfaceRequest<mojo::NetworkService> request) { mojo::BindToRequest( - new mojo::NetworkServiceImpl(connection, context_.get()), &request); + new mojo::NetworkServiceImpl( + connection, + context_.get(), + app_lifetime_helper_.CreateAppRefCount()), + &request); } diff --git a/mojo/services/network/network_service_delegate.h b/mojo/services/network/network_service_delegate.h index 570f595..4deb421 100644 --- a/mojo/services/network/network_service_delegate.h +++ b/mojo/services/network/network_service_delegate.h @@ -32,6 +32,7 @@ class NetworkServiceDelegate private: scoped_ptr<mojo::NetworkContext> context_; + mojo::AppLifetimeHelper app_lifetime_helper_; }; #endif // MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_ diff --git a/mojo/services/network/network_service_impl.cc b/mojo/services/network/network_service_impl.cc index 20c2558..fe44530 100644 --- a/mojo/services/network/network_service_impl.cc +++ b/mojo/services/network/network_service_impl.cc @@ -15,9 +15,12 @@ namespace mojo { -NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection, - NetworkContext* context) +NetworkServiceImpl::NetworkServiceImpl( + ApplicationConnection* connection, + NetworkContext* context, + scoped_ptr<mojo::AppRefCount> app_refcount) : context_(context), + app_refcount_(app_refcount.Pass()), origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()) { } @@ -29,22 +32,24 @@ void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) { // The loader will delete itself when the pipe is closed, unless a request is // in progress. In which case, the loader will delete itself when the request // is finished. - new URLLoaderImpl(context_, loader.Pass()); + new URLLoaderImpl(context_, loader.Pass(), app_refcount_->Clone()); } void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) { - BindToRequest(new CookieStoreImpl(context_, origin_), &store); + BindToRequest(new CookieStoreImpl(context_, origin_, app_refcount_->Clone()), + &store); } void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) { - BindToRequest(new WebSocketImpl(context_), &socket); + BindToRequest(new WebSocketImpl(context_, app_refcount_->Clone()), &socket); } void NetworkServiceImpl::CreateTCPBoundSocket( NetAddressPtr local_address, InterfaceRequest<TCPBoundSocket> bound_socket, const CreateTCPBoundSocketCallback& callback) { - scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl); + scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl( + app_refcount_->Clone())); int net_error = bound->Bind(local_address.Pass()); if (net_error != net::OK) { callback.Run(MakeNetworkError(net_error), NetAddressPtr()); @@ -69,14 +74,15 @@ void NetworkServiceImpl::CreateTCPConnectedSocket( void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) { // The lifetime of this UDPSocketImpl is bound to that of the underlying pipe. - new UDPSocketImpl(request.Pass()); + new UDPSocketImpl(request.Pass(), app_refcount_->Clone()); } void NetworkServiceImpl::CreateHttpServer( NetAddressPtr local_address, HttpServerDelegatePtr delegate, const CreateHttpServerCallback& callback) { - HttpServerImpl::Create(local_address.Pass(), delegate.Pass(), callback); + HttpServerImpl::Create(local_address.Pass(), delegate.Pass(), + app_refcount_->Clone(), callback); } } // namespace mojo diff --git a/mojo/services/network/network_service_impl.h b/mojo/services/network/network_service_impl.h index 0c2e325..ebecff1 100644 --- a/mojo/services/network/network_service_impl.h +++ b/mojo/services/network/network_service_impl.h @@ -6,6 +6,7 @@ #define MOJO_SERVICES_NETWORK_NETWORK_SERVICE_IMPL_H_ #include "base/compiler_specific.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/services/network/public/interfaces/network_service.mojom.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" #include "url/gurl.h" @@ -17,7 +18,8 @@ class NetworkContext; class NetworkServiceImpl : public InterfaceImpl<NetworkService> { public: NetworkServiceImpl(ApplicationConnection* connection, - NetworkContext* context); + NetworkContext* context, + scoped_ptr<mojo::AppRefCount> app_refcount); ~NetworkServiceImpl() override; // NetworkService methods: @@ -41,6 +43,7 @@ class NetworkServiceImpl : public InterfaceImpl<NetworkService> { private: NetworkContext* context_; + scoped_ptr<mojo::AppRefCount> app_refcount_; GURL origin_; }; diff --git a/mojo/services/network/tcp_bound_socket_impl.cc b/mojo/services/network/tcp_bound_socket_impl.cc index b776304..5cf6828 100644 --- a/mojo/services/network/tcp_bound_socket_impl.cc +++ b/mojo/services/network/tcp_bound_socket_impl.cc @@ -12,7 +12,9 @@ namespace mojo { -TCPBoundSocketImpl::TCPBoundSocketImpl() { +TCPBoundSocketImpl::TCPBoundSocketImpl( + scoped_ptr<mojo::AppRefCount> app_refcount) + : app_refcount_(app_refcount.Pass()) { } TCPBoundSocketImpl::~TCPBoundSocketImpl() { @@ -63,7 +65,9 @@ void TCPBoundSocketImpl::StartListening( } // The server socket object takes ownership of the socket. - BindToRequest(new TCPServerSocketImpl(socket_.Pass()), &server); + BindToRequest( + new TCPServerSocketImpl(socket_.Pass(), app_refcount_->Clone()), + &server); callback.Run(MakeNetworkError(net::OK)); } @@ -106,7 +110,8 @@ void TCPBoundSocketImpl::OnConnected(int result) { if (result == net::OK) { new TCPConnectedSocketImpl( socket_.Pass(), pending_connect_send_stream_.Pass(), - pending_connect_receive_stream_.Pass(), pending_connect_socket_.Pass()); + pending_connect_receive_stream_.Pass(), pending_connect_socket_.Pass(), + app_refcount_->Clone()); } else { pending_connect_send_stream_.reset(); pending_connect_receive_stream_.reset(); diff --git a/mojo/services/network/tcp_bound_socket_impl.h b/mojo/services/network/tcp_bound_socket_impl.h index e5e1b6c2..b6609c5 100644 --- a/mojo/services/network/tcp_bound_socket_impl.h +++ b/mojo/services/network/tcp_bound_socket_impl.h @@ -6,6 +6,7 @@ #define MOJO_SERVICES_NETWORK_TCP_BOUND_SOCKET_H_ #include "base/memory/scoped_ptr.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/services/network/public/interfaces/tcp_bound_socket.mojom.h" #include "net/socket/tcp_socket.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" @@ -14,7 +15,7 @@ namespace mojo { class TCPBoundSocketImpl : public InterfaceImpl<TCPBoundSocket> { public: - TCPBoundSocketImpl(); + explicit TCPBoundSocketImpl(scoped_ptr<mojo::AppRefCount> app_refcount); ~TCPBoundSocketImpl() override; // Does the actual binding. Returns a net error code. On net::OK, the bound @@ -45,6 +46,7 @@ class TCPBoundSocketImpl : public InterfaceImpl<TCPBoundSocket> { ScopedDataPipeProducerHandle pending_connect_receive_stream_; InterfaceRequest<TCPConnectedSocket> pending_connect_socket_; Callback<void(NetworkErrorPtr)> pending_connect_callback_; + scoped_ptr<mojo::AppRefCount> app_refcount_; }; } // namespace mojo diff --git a/mojo/services/network/tcp_connected_socket_impl.cc b/mojo/services/network/tcp_connected_socket_impl.cc index bc8c98b..8241a18 100644 --- a/mojo/services/network/tcp_connected_socket_impl.cc +++ b/mojo/services/network/tcp_connected_socket_impl.cc @@ -14,11 +14,13 @@ TCPConnectedSocketImpl::TCPConnectedSocketImpl( scoped_ptr<net::TCPSocket> socket, ScopedDataPipeConsumerHandle send_stream, ScopedDataPipeProducerHandle receive_stream, - InterfaceRequest<TCPConnectedSocket> request) + InterfaceRequest<TCPConnectedSocket> request, + scoped_ptr<mojo::AppRefCount> app_refcount) : socket_(socket.Pass()), send_stream_(send_stream.Pass()), receive_stream_(receive_stream.Pass()), binding_(this, request.Pass()), + app_refcount_(app_refcount.Pass()), weak_ptr_factory_(this) { // Queue up async communication. binding_.set_error_handler(this); diff --git a/mojo/services/network/tcp_connected_socket_impl.h b/mojo/services/network/tcp_connected_socket_impl.h index 6e71499..7e8fa45 100644 --- a/mojo/services/network/tcp_connected_socket_impl.h +++ b/mojo/services/network/tcp_connected_socket_impl.h @@ -7,6 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/common/handle_watcher.h" #include "mojo/services/network/public/interfaces/tcp_connected_socket.mojom.h" #include "net/socket/tcp_socket.h" @@ -22,7 +23,8 @@ class TCPConnectedSocketImpl : public TCPConnectedSocket, public ErrorHandler { TCPConnectedSocketImpl(scoped_ptr<net::TCPSocket> socket, ScopedDataPipeConsumerHandle send_stream, ScopedDataPipeProducerHandle receive_stream, - InterfaceRequest<TCPConnectedSocket> request); + InterfaceRequest<TCPConnectedSocket> request, + scoped_ptr<mojo::AppRefCount> app_refcount); ~TCPConnectedSocketImpl() override; private: @@ -68,6 +70,8 @@ class TCPConnectedSocketImpl : public TCPConnectedSocket, public ErrorHandler { // To bind to the message pipe. Binding<TCPConnectedSocket> binding_; + scoped_ptr<mojo::AppRefCount> app_refcount_; + base::WeakPtrFactory<TCPConnectedSocketImpl> weak_ptr_factory_; }; diff --git a/mojo/services/network/tcp_server_socket_impl.cc b/mojo/services/network/tcp_server_socket_impl.cc index 96ec1e3..dce7ecb 100644 --- a/mojo/services/network/tcp_server_socket_impl.cc +++ b/mojo/services/network/tcp_server_socket_impl.cc @@ -11,8 +11,10 @@ namespace mojo { -TCPServerSocketImpl::TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket) - : socket_(socket.Pass()) { +TCPServerSocketImpl::TCPServerSocketImpl( + scoped_ptr<net::TCPSocket> socket, + scoped_ptr<mojo::AppRefCount> app_refcount) + : socket_(socket.Pass()), app_refcount_(app_refcount.Pass()) { } TCPServerSocketImpl::~TCPServerSocketImpl() { @@ -57,7 +59,8 @@ void TCPServerSocketImpl::OnAcceptCompleted(int result) { } else { new TCPConnectedSocketImpl( accepted_socket_.Pass(), pending_send_stream_.Pass(), - pending_receive_stream_.Pass(), pending_client_socket_.Pass()); + pending_receive_stream_.Pass(), pending_client_socket_.Pass(), + app_refcount_->Clone()); pending_callback_.Run(MakeNetworkError(net::OK), NetAddress::From(accepted_address_)); } diff --git a/mojo/services/network/tcp_server_socket_impl.h b/mojo/services/network/tcp_server_socket_impl.h index 0039f8d..f45e2cb 100644 --- a/mojo/services/network/tcp_server_socket_impl.h +++ b/mojo/services/network/tcp_server_socket_impl.h @@ -6,6 +6,7 @@ #define MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ #include "base/memory/scoped_ptr.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/services/network/public/interfaces/tcp_server_socket.mojom.h" #include "net/base/ip_endpoint.h" #include "net/socket/tcp_socket.h" @@ -18,7 +19,8 @@ class TCPServerSocketImpl : public InterfaceImpl<TCPServerSocket> { typedef Callback<void(NetworkErrorPtr, NetAddressPtr)> AcceptCallback; // Passed ownership of a socket already in listening mode. - explicit TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket); + TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket, + scoped_ptr<mojo::AppRefCount> app_refcount); ~TCPServerSocketImpl() override; // TCPServerSocket. @@ -43,6 +45,8 @@ class TCPServerSocketImpl : public InterfaceImpl<TCPServerSocket> { // These are written to by net::TCPSocket when Accept is completed. scoped_ptr<net::TCPSocket> accepted_socket_; net::IPEndPoint accepted_address_; + + scoped_ptr<mojo::AppRefCount> app_refcount_; }; } // namespace mojo diff --git a/mojo/services/network/udp_socket_impl.cc b/mojo/services/network/udp_socket_impl.cc index cc11da7..83b480f 100644 --- a/mojo/services/network/udp_socket_impl.cc +++ b/mojo/services/network/udp_socket_impl.cc @@ -34,7 +34,8 @@ UDPSocketImpl::PendingSendRequest::PendingSendRequest() {} UDPSocketImpl::PendingSendRequest::~PendingSendRequest() {} -UDPSocketImpl::UDPSocketImpl(InterfaceRequest<UDPSocket> request) +UDPSocketImpl::UDPSocketImpl(InterfaceRequest<UDPSocket> request, + scoped_ptr<mojo::AppRefCount> app_refcount) : binding_(this, request.Pass()), socket_(net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), @@ -43,7 +44,8 @@ UDPSocketImpl::UDPSocketImpl(InterfaceRequest<UDPSocket> request) state_(NOT_BOUND_OR_CONNECTED), allow_address_reuse_(false), remaining_recv_slots_(0), - max_pending_send_requests_(kDefaultMaxPendingSendRequests) { + max_pending_send_requests_(kDefaultMaxPendingSendRequests), + app_refcount_(app_refcount.Pass()) { } UDPSocketImpl::~UDPSocketImpl() { diff --git a/mojo/services/network/udp_socket_impl.h b/mojo/services/network/udp_socket_impl.h index c2070bf..2c5a36a 100644 --- a/mojo/services/network/udp_socket_impl.h +++ b/mojo/services/network/udp_socket_impl.h @@ -9,6 +9,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/services/network/public/interfaces/udp_socket.mojom.h" #include "net/base/ip_endpoint.h" #include "net/udp/udp_socket.h" @@ -26,7 +27,8 @@ class UDPSocketImpl : public UDPSocket { public: // The lifetime of a new UDPSocketImpl is bound to the connection associated // with |request|. - explicit UDPSocketImpl(InterfaceRequest<UDPSocket> request); + UDPSocketImpl(InterfaceRequest<UDPSocket> request, + scoped_ptr<mojo::AppRefCount> app_refcount); ~UDPSocketImpl() override; // UDPSocket implementation. @@ -119,6 +121,8 @@ class UDPSocketImpl : public UDPSocket { // The maximum size of the |pending_send_requests_| queue. size_t max_pending_send_requests_; + scoped_ptr<mojo::AppRefCount> app_refcount_; + DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); }; diff --git a/mojo/services/network/url_loader_impl.cc b/mojo/services/network/url_loader_impl.cc index 464eda9..e2e88a1 100644 --- a/mojo/services/network/url_loader_impl.cc +++ b/mojo/services/network/url_loader_impl.cc @@ -96,12 +96,14 @@ class UploadDataPipeElementReader : public net::UploadElementReader { } // namespace URLLoaderImpl::URLLoaderImpl(NetworkContext* context, - InterfaceRequest<URLLoader> request) + InterfaceRequest<URLLoader> request, + scoped_ptr<mojo::AppRefCount> app_refcount) : context_(context), response_body_buffer_size_(0), auto_follow_redirects_(true), connected_(true), binding_(this, request.Pass()), + app_refcount_(app_refcount.Pass()), weak_ptr_factory_(this) { binding_.set_error_handler(this); context_->RegisterURLLoader(this); diff --git a/mojo/services/network/url_loader_impl.h b/mojo/services/network/url_loader_impl.h index 421b717..c4aa451 100644 --- a/mojo/services/network/url_loader_impl.h +++ b/mojo/services/network/url_loader_impl.h @@ -7,6 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/common/handle_watcher.h" #include "mojo/services/network/public/interfaces/url_loader.mojom.h" #include "net/base/net_errors.h" @@ -24,7 +25,9 @@ class URLLoaderImpl : public URLLoader, public ErrorHandler, public net::URLRequest::Delegate { public: - URLLoaderImpl(NetworkContext* context, InterfaceRequest<URLLoader> request); + URLLoaderImpl(NetworkContext* context, + InterfaceRequest<URLLoader> request, + scoped_ptr<mojo::AppRefCount> app_refcount); ~URLLoaderImpl() override; // Called when the associated NetworkContext is going away. @@ -68,6 +71,7 @@ class URLLoaderImpl : public URLLoader, bool auto_follow_redirects_; bool connected_; Binding<URLLoader> binding_; + scoped_ptr<mojo::AppRefCount> app_refcount_; base::WeakPtrFactory<URLLoaderImpl> weak_ptr_factory_; }; diff --git a/mojo/services/network/url_loader_impl_apptest.cc b/mojo/services/network/url_loader_impl_apptest.cc index 583fd3d..1c4ec27 100644 --- a/mojo/services/network/url_loader_impl_apptest.cc +++ b/mojo/services/network/url_loader_impl_apptest.cc @@ -114,7 +114,9 @@ class UrlLoaderImplTest : public test::ApplicationTestBase { url_request_context->Init(); network_context_.reset(new NetworkContext(url_request_context.Pass())); MessagePipe pipe; - new URLLoaderImpl(network_context_.get(), GetProxy(&url_loader_proxy_)); + new URLLoaderImpl(network_context_.get(), + GetProxy(&url_loader_proxy_), + make_scoped_ptr<mojo::AppRefCount>(nullptr)); EXPECT_TRUE(IsUrlLoaderValid()); } diff --git a/mojo/services/network/web_socket_impl.cc b/mojo/services/network/web_socket_impl.cc index 0513be6..f69f6dd 100644 --- a/mojo/services/network/web_socket_impl.cc +++ b/mojo/services/network/web_socket_impl.cc @@ -177,7 +177,10 @@ void WebSocketEventHandler::DidWriteToReceiveStream( } // namespace mojo -WebSocketImpl::WebSocketImpl(NetworkContext* context) : context_(context) { +WebSocketImpl::WebSocketImpl( + NetworkContext* context, + scoped_ptr<mojo::AppRefCount> app_refcount) + : context_(context), app_refcount_(app_refcount.Pass()) { } WebSocketImpl::~WebSocketImpl() { diff --git a/mojo/services/network/web_socket_impl.h b/mojo/services/network/web_socket_impl.h index bb41104..b1fee40 100644 --- a/mojo/services/network/web_socket_impl.h +++ b/mojo/services/network/web_socket_impl.h @@ -6,6 +6,7 @@ #define MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_ #include "base/memory/scoped_ptr.h" +#include "mojo/application/app_lifetime_helper.h" #include "mojo/services/network/public/interfaces/web_socket.mojom.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" @@ -21,7 +22,8 @@ class WebSocketReadQueue; // implementation. class WebSocketImpl : public InterfaceImpl<WebSocket> { public: - explicit WebSocketImpl(NetworkContext* context); + WebSocketImpl(NetworkContext* context, + scoped_ptr<mojo::AppRefCount> app_refcount); ~WebSocketImpl() override; private: @@ -46,6 +48,7 @@ class WebSocketImpl : public InterfaceImpl<WebSocket> { ScopedDataPipeConsumerHandle send_stream_; scoped_ptr<WebSocketReadQueue> read_queue_; NetworkContext* context_; + scoped_ptr<mojo::AppRefCount> app_refcount_; }; } // namespace mojo |