Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: mojo/application/public/cpp/lib/service_registry.cc

Issue 1254383016: ApplicationConnection lifetime management changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/application/public/cpp/lib/service_registry.h" 5 #include "mojo/application/public/cpp/lib/service_registry.h"
6 6
7 #include "base/logging.h"
7 #include "mojo/application/public/cpp/application_connection.h" 8 #include "mojo/application/public/cpp/application_connection.h"
8 #include "mojo/application/public/cpp/application_impl.h"
9 #include "mojo/application/public/cpp/service_connector.h" 9 #include "mojo/application/public/cpp/service_connector.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace internal { 12 namespace internal {
13 13
14 ServiceRegistry::ServiceRegistry( 14 ServiceRegistry::ServiceRegistry(
15 ApplicationImpl* application_impl,
16 const std::string& connection_url, 15 const std::string& connection_url,
17 const std::string& remote_url, 16 const std::string& remote_url,
18 ServiceProviderPtr remote_services, 17 ServiceProviderPtr remote_services,
19 InterfaceRequest<ServiceProvider> local_services, 18 InterfaceRequest<ServiceProvider> local_services,
20 const std::set<std::string>& allowed_interfaces) 19 const std::set<std::string>& allowed_interfaces)
21 : application_impl_(application_impl), 20 : connection_url_(connection_url),
22 connection_url_(connection_url),
23 remote_url_(remote_url), 21 remote_url_(remote_url),
24 local_binding_(this), 22 local_binding_(this),
25 remote_service_provider_(remote_services.Pass()), 23 remote_service_provider_(remote_services.Pass()),
26 allowed_interfaces_(allowed_interfaces), 24 allowed_interfaces_(allowed_interfaces),
27 allow_all_interfaces_(allowed_interfaces_.size() == 1 && 25 allow_all_interfaces_(allowed_interfaces_.size() == 1 &&
28 allowed_interfaces_.count("*") == 1) { 26 allowed_interfaces_.count("*") == 1),
27 weak_factory_(this) {
29 if (local_services.is_pending()) 28 if (local_services.is_pending())
30 local_binding_.Bind(local_services.Pass()); 29 local_binding_.Bind(local_services.Pass());
31 } 30 }
32 31
33 ServiceRegistry::ServiceRegistry() 32 ServiceRegistry::ServiceRegistry()
34 : application_impl_(nullptr), 33 : local_binding_(this),
35 local_binding_(this), 34 allow_all_interfaces_(true),
36 allow_all_interfaces_(true) { 35 weak_factory_(this) {
36 }
37
38 ServiceRegistry::~ServiceRegistry() {
37 } 39 }
38 40
39 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) { 41 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) {
40 service_connector_registry_.set_service_connector(connector); 42 service_connector_registry_.set_service_connector(connector);
41 } 43 }
42 44
43 bool ServiceRegistry::SetServiceConnectorForName( 45 bool ServiceRegistry::SetServiceConnectorForName(
44 ServiceConnector* service_connector, 46 ServiceConnector* service_connector,
45 const std::string& interface_name) { 47 const std::string& interface_name) {
46 if (allow_all_interfaces_ || 48 if (allow_all_interfaces_ ||
47 allowed_interfaces_.count(interface_name)) { 49 allowed_interfaces_.count(interface_name)) {
48 service_connector_registry_.SetServiceConnectorForName(service_connector, 50 service_connector_registry_.SetServiceConnectorForName(service_connector,
49 interface_name); 51 interface_name);
50 return true; 52 return true;
51 } 53 }
52 DVLOG(2) << "CapabilityFilter prevented connection to interface: " << 54 DVLOG(2) << "CapabilityFilter prevented connection to interface: " <<
53 interface_name; 55 interface_name;
54 return false; 56 return false;
55 } 57 }
56 58
57 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() { 59 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() {
58 return this; 60 return this;
59 } 61 }
60 62
61 void ServiceRegistry::SetRemoteServiceProviderConnectionErrorHandler( 63 void ServiceRegistry::SetRemoteServiceProviderConnectionErrorHandler(
62 const Closure& handler) { 64 const Closure& handler) {
63 remote_service_provider_.set_connection_error_handler(handler); 65 remote_service_provider_.set_connection_error_handler(handler);
64 } 66 }
65 67
68 base::WeakPtr<ApplicationConnection> ServiceRegistry::GetWeakPtr() {
69 return weak_factory_.GetWeakPtr();
70 }
71
66 void ServiceRegistry::RemoveServiceConnectorForName( 72 void ServiceRegistry::RemoveServiceConnectorForName(
67 const std::string& interface_name) { 73 const std::string& interface_name) {
68 service_connector_registry_.RemoveServiceConnectorForName(interface_name); 74 service_connector_registry_.RemoveServiceConnectorForName(interface_name);
69 if (service_connector_registry_.empty()) 75 if (service_connector_registry_.empty())
70 remote_service_provider_.reset(); 76 remote_service_provider_.reset();
71 } 77 }
72 78
73 const std::string& ServiceRegistry::GetConnectionURL() { 79 const std::string& ServiceRegistry::GetConnectionURL() {
74 return connection_url_; 80 return connection_url_;
75 } 81 }
76 82
77 const std::string& ServiceRegistry::GetRemoteApplicationURL() { 83 const std::string& ServiceRegistry::GetRemoteApplicationURL() {
78 return remote_url_; 84 return remote_url_;
79 } 85 }
80 86
81 ServiceProvider* ServiceRegistry::GetServiceProvider() { 87 ServiceProvider* ServiceRegistry::GetServiceProvider() {
82 return remote_service_provider_.get(); 88 return remote_service_provider_.get();
83 } 89 }
84 90
85 ServiceRegistry::~ServiceRegistry() {
86 }
87
88 void ServiceRegistry::OnCloseConnection() {
89 if (application_impl_)
90 application_impl_->CloseConnection(this);
91 }
92
93 void ServiceRegistry::ConnectToService(const mojo::String& service_name, 91 void ServiceRegistry::ConnectToService(const mojo::String& service_name,
94 ScopedMessagePipeHandle client_handle) { 92 ScopedMessagePipeHandle client_handle) {
95 service_connector_registry_.ConnectToService(this, service_name, 93 service_connector_registry_.ConnectToService(this, service_name,
96 client_handle.Pass()); 94 client_handle.Pass());
97 } 95 }
98 96
99 } // namespace internal 97 } // namespace internal
100 } // namespace mojo 98 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/application/public/cpp/lib/service_registry.h ('k') | mojo/application/public/cpp/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698