OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/shell/content_handler_connection.h" | 5 #include "mojo/package_manager/content_handler_connection.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "mojo/shell/application_manager.h" | 8 #include "mojo/shell/application_manager.h" |
9 #include "mojo/shell/connect_to_application_params.h" | 9 #include "mojo/shell/connect_to_application_params.h" |
10 #include "mojo/shell/identity.h" | 10 #include "mojo/shell/identity.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 namespace shell { | 13 namespace package_manager { |
14 | 14 |
15 ContentHandlerConnection::ContentHandlerConnection( | 15 ContentHandlerConnection::ContentHandlerConnection( |
16 ApplicationManager* manager, | 16 shell::ApplicationManager* manager, |
17 const Identity& source, | 17 const shell::Identity& source, |
18 const Identity& content_handler, | 18 const shell::Identity& content_handler, |
19 uint32_t id) | 19 uint32_t id, |
20 : manager_(manager), | 20 const ClosedCallback& connection_closed_callback) |
| 21 : connection_closed_callback_(connection_closed_callback), |
21 identity_(content_handler), | 22 identity_(content_handler), |
22 connection_closed_(false), | 23 connection_closed_(false), |
23 id_(id) { | 24 id_(id) { |
24 ServiceProviderPtr services; | 25 ServiceProviderPtr services; |
25 | 26 |
26 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 27 scoped_ptr<shell::ConnectToApplicationParams> params( |
| 28 new shell::ConnectToApplicationParams); |
27 params->set_source(source); | 29 params->set_source(source); |
28 params->SetTarget(identity_); | 30 params->SetTarget(identity_); |
29 params->set_services(GetProxy(&services)); | 31 params->set_services(GetProxy(&services)); |
30 manager->ConnectToApplication(params.Pass()); | 32 manager->ConnectToApplication(params.Pass()); |
31 | 33 |
32 MessagePipe pipe; | 34 MessagePipe pipe; |
33 content_handler_.Bind( | 35 content_handler_.Bind( |
34 InterfacePtrInfo<ContentHandler>(pipe.handle0.Pass(), 0u)); | 36 InterfacePtrInfo<ContentHandler>(pipe.handle0.Pass(), 0u)); |
35 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass()); | 37 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass()); |
36 content_handler_.set_connection_error_handler( | 38 content_handler_.set_connection_error_handler( |
37 [this]() { CloseConnection(); }); | 39 [this]() { CloseConnection(); }); |
38 } | 40 } |
39 | 41 |
40 void ContentHandlerConnection::CloseConnection() { | 42 void ContentHandlerConnection::CloseConnection() { |
41 if (connection_closed_) | 43 if (connection_closed_) |
42 return; | 44 return; |
43 connection_closed_ = true; | 45 connection_closed_ = true; |
44 manager_->OnContentHandlerConnectionClosed(this); | 46 connection_closed_callback_.Run(this); |
45 delete this; | 47 delete this; |
46 } | 48 } |
47 | 49 |
48 ContentHandlerConnection::~ContentHandlerConnection() { | 50 ContentHandlerConnection::~ContentHandlerConnection() { |
49 // If this DCHECK fails then something has tried to delete this object without | 51 // If this DCHECK fails then something has tried to delete this object without |
50 // calling CloseConnection. | 52 // calling CloseConnection. |
51 DCHECK(connection_closed_); | 53 DCHECK(connection_closed_); |
52 } | 54 } |
53 | 55 |
54 } // namespace shell | 56 } // namespace package_manager |
55 } // namespace mojo | 57 } // namespace mojo |
OLD | NEW |