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 "base/memory/scoped_ptr.h"
8 #include "mojo/shell/application_manager.h"
9 #include "mojo/shell/connect_to_application_params.h"
10 #include "mojo/shell/identity.h"
15 ContentHandlerConnection::ContentHandlerConnection(
16 ApplicationManager
* manager
,
17 const Identity
& source
,
18 const Identity
& content_handler
,
21 identity_(content_handler
),
22 connection_closed_(false),
24 ServiceProviderPtr services
;
26 scoped_ptr
<ConnectToApplicationParams
> params(new ConnectToApplicationParams
);
27 params
->set_source(source
);
28 params
->SetTarget(identity_
);
29 params
->set_services(GetProxy(&services
));
30 manager
->ConnectToApplication(params
.Pass());
33 content_handler_
.Bind(
34 InterfacePtrInfo
<ContentHandler
>(pipe
.handle0
.Pass(), 0u));
35 services
->ConnectToService(ContentHandler::Name_
, pipe
.handle1
.Pass());
36 content_handler_
.set_connection_error_handler(
37 [this]() { CloseConnection(); });
40 void ContentHandlerConnection::CloseConnection() {
41 if (connection_closed_
)
43 connection_closed_
= true;
44 manager_
->OnContentHandlerConnectionClosed(this);
48 ContentHandlerConnection::~ContentHandlerConnection() {
49 // If this DCHECK fails then something has tried to delete this object without
50 // calling CloseConnection.
51 DCHECK(connection_closed_
);