1 // Copyright 2015 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/shell/content_handler_connection.h"
7 #include "mojo/shell/application_manager.h"
12 ContentHandlerConnection::ContentHandlerConnection(
13 ApplicationInstance
* originator
,
14 ApplicationManager
* manager
,
15 const GURL
& content_handler_url
,
16 const GURL
& requestor_url
,
17 const std::string
& qualifier
,
18 const CapabilityFilter
& filter
,
21 content_handler_url_(content_handler_url
),
22 content_handler_qualifier_(qualifier
),
23 connection_closed_(false),
25 ServiceProviderPtr services
;
26 mojo::URLRequestPtr
request(mojo::URLRequest::New());
27 request
->url
= mojo::String::From(content_handler_url
.spec());
28 manager
->ConnectToApplication(
29 originator
, request
.Pass(), qualifier
, requestor_url
, GetProxy(&services
),
30 nullptr, filter
, base::Closure(), EmptyConnectCallback());
32 content_handler_
.Bind(
33 InterfacePtrInfo
<ContentHandler
>(pipe
.handle0
.Pass(), 0u));
34 services
->ConnectToService(ContentHandler::Name_
, pipe
.handle1
.Pass());
35 content_handler_
.set_connection_error_handler(
36 [this]() { CloseConnection(); });
39 void ContentHandlerConnection::CloseConnection() {
40 if (connection_closed_
)
42 connection_closed_
= true;
43 manager_
->OnContentHandlerConnectionClosed(this);
47 ContentHandlerConnection::~ContentHandlerConnection() {
48 // If this DCHECK fails then something has tried to delete this object without
49 // calling CloseConnection.
50 DCHECK(connection_closed_
);