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 ApplicationManager
* manager
,
14 const GURL
& content_handler_url
,
15 const GURL
& requestor_url
,
16 const std::string
& qualifier
)
18 content_handler_url_(content_handler_url
),
19 content_handler_qualifier_(qualifier
),
20 connection_closed_(false) {
21 ServiceProviderPtr services
;
22 mojo::URLRequestPtr
request(mojo::URLRequest::New());
23 request
->url
= mojo::String::From(content_handler_url
.spec());
24 // TODO(beng): Need to figure out how to deal with originator and
25 // CapabilityFilter here.
26 manager
->ConnectToApplication(
27 nullptr, request
.Pass(), qualifier
, requestor_url
, GetProxy(&services
),
28 nullptr, nullptr, base::Closure());
30 content_handler_
.Bind(
31 InterfacePtrInfo
<ContentHandler
>(pipe
.handle0
.Pass(), 0u));
32 services
->ConnectToService(ContentHandler::Name_
, pipe
.handle1
.Pass());
33 content_handler_
.set_connection_error_handler(
34 [this]() { CloseConnection(); });
37 void ContentHandlerConnection::CloseConnection() {
38 if (connection_closed_
)
40 connection_closed_
= true;
41 manager_
->OnContentHandlerConnectionClosed(this);
45 ContentHandlerConnection::~ContentHandlerConnection() {
46 // If this DCHECK fails then something has tried to delete this object without
47 // calling CloseConnection.
48 DCHECK(connection_closed_
);