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

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

Issue 1578473002: Pass application ids via AcceptConnection & ConnectToApplication callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 11 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/shell/public/cpp/lib/service_registry.h" 5 #include "mojo/shell/public/cpp/lib/service_registry.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "mojo/shell/public/cpp/application_connection.h" 13 #include "mojo/shell/public/cpp/application_connection.h"
14 #include "mojo/shell/public/cpp/service_connector.h" 14 #include "mojo/shell/public/cpp/service_connector.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace internal { 17 namespace internal {
18 18
19 ServiceRegistry::ServiceRegistry( 19 ServiceRegistry::ServiceRegistry(
20 const std::string& connection_url, 20 const std::string& connection_url,
21 const std::string& remote_url, 21 const std::string& remote_url,
22 uint32_t remote_id,
22 ServiceProviderPtr remote_services, 23 ServiceProviderPtr remote_services,
23 InterfaceRequest<ServiceProvider> local_services, 24 InterfaceRequest<ServiceProvider> local_services,
24 const std::set<std::string>& allowed_interfaces) 25 const std::set<std::string>& allowed_interfaces)
25 : connection_url_(connection_url), 26 : connection_url_(connection_url),
26 remote_url_(remote_url), 27 remote_url_(remote_url),
27 local_binding_(this), 28 local_binding_(this),
28 remote_service_provider_(std::move(remote_services)), 29 remote_service_provider_(std::move(remote_services)),
29 allowed_interfaces_(allowed_interfaces), 30 allowed_interfaces_(allowed_interfaces),
30 allow_all_interfaces_(allowed_interfaces_.size() == 1 && 31 allow_all_interfaces_(allowed_interfaces_.size() == 1 &&
31 allowed_interfaces_.count("*") == 1), 32 allowed_interfaces_.count("*") == 1),
33 remote_id_(remote_id),
32 content_handler_id_(0u), 34 content_handler_id_(0u),
33 is_content_handler_id_valid_(false), 35 remote_ids_valid_(false),
34 weak_factory_(this) { 36 weak_factory_(this) {
35 if (local_services.is_pending()) 37 if (local_services.is_pending())
36 local_binding_.Bind(std::move(local_services)); 38 local_binding_.Bind(std::move(local_services));
37 } 39 }
38 40
39 ServiceRegistry::ServiceRegistry() 41 ServiceRegistry::ServiceRegistry()
40 : local_binding_(this), 42 : local_binding_(this),
41 allow_all_interfaces_(true), 43 allow_all_interfaces_(true),
42 weak_factory_(this) { 44 weak_factory_(this) {
43 } 45 }
44 46
45 ServiceRegistry::~ServiceRegistry() { 47 ServiceRegistry::~ServiceRegistry() {
46 } 48 }
47 49
48 Shell::ConnectToApplicationCallback 50 Shell::ConnectToApplicationCallback
49 ServiceRegistry::GetConnectToApplicationCallback() { 51 ServiceRegistry::GetConnectToApplicationCallback() {
50 return base::Bind(&ServiceRegistry::OnGotContentHandlerID, 52 return base::Bind(&ServiceRegistry::OnGotRemoteIDs,
51 weak_factory_.GetWeakPtr()); 53 weak_factory_.GetWeakPtr());
52 } 54 }
53 55
54 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) { 56 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) {
55 service_connector_registry_.set_service_connector(connector); 57 service_connector_registry_.set_service_connector(connector);
56 } 58 }
57 59
58 bool ServiceRegistry::SetServiceConnectorForName( 60 bool ServiceRegistry::SetServiceConnectorForName(
59 ServiceConnector* service_connector, 61 ServiceConnector* service_connector,
60 const std::string& interface_name) { 62 const std::string& interface_name) {
(...skipping 11 matching lines...) Expand all
72 74
73 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() { 75 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() {
74 return this; 76 return this;
75 } 77 }
76 78
77 void ServiceRegistry::SetRemoteServiceProviderConnectionErrorHandler( 79 void ServiceRegistry::SetRemoteServiceProviderConnectionErrorHandler(
78 const Closure& handler) { 80 const Closure& handler) {
79 remote_service_provider_.set_connection_error_handler(handler); 81 remote_service_provider_.set_connection_error_handler(handler);
80 } 82 }
81 83
82 bool ServiceRegistry::GetContentHandlerID(uint32_t* content_handler_id) { 84 bool ServiceRegistry::GetRemoteApplicationID(uint32_t* remote_id) const {
83 if (!is_content_handler_id_valid_) 85 if (!remote_ids_valid_)
86 return false;
87
88 *remote_id = remote_id_;
89 return true;
90 }
91
92 bool ServiceRegistry::GetRemoteContentHandlerID(
93 uint32_t* content_handler_id) const {
94 if (!remote_ids_valid_)
84 return false; 95 return false;
85 96
86 *content_handler_id = content_handler_id_; 97 *content_handler_id = content_handler_id_;
87 return true; 98 return true;
88 } 99 }
89 100
90 void ServiceRegistry::AddContentHandlerIDCallback(const Closure& callback) { 101 void ServiceRegistry::AddRemoteIDCallback(const Closure& callback) {
91 if (is_content_handler_id_valid_) { 102 if (remote_ids_valid_) {
92 callback.Run(); 103 callback.Run();
93 return; 104 return;
94 } 105 }
95 content_handler_id_callbacks_.push_back(callback); 106 remote_id_callbacks_.push_back(callback);
96 } 107 }
97 108
98 base::WeakPtr<ApplicationConnection> ServiceRegistry::GetWeakPtr() { 109 base::WeakPtr<ApplicationConnection> ServiceRegistry::GetWeakPtr() {
99 return weak_factory_.GetWeakPtr(); 110 return weak_factory_.GetWeakPtr();
100 } 111 }
101 112
102 void ServiceRegistry::RemoveServiceConnectorForName( 113 void ServiceRegistry::RemoveServiceConnectorForName(
103 const std::string& interface_name) { 114 const std::string& interface_name) {
104 service_connector_registry_.RemoveServiceConnectorForName(interface_name); 115 service_connector_registry_.RemoveServiceConnectorForName(interface_name);
105 if (service_connector_registry_.empty()) 116 if (service_connector_registry_.empty())
106 remote_service_provider_.reset(); 117 remote_service_provider_.reset();
107 } 118 }
108 119
109 const std::string& ServiceRegistry::GetConnectionURL() { 120 const std::string& ServiceRegistry::GetConnectionURL() {
110 return connection_url_; 121 return connection_url_;
111 } 122 }
112 123
113 const std::string& ServiceRegistry::GetRemoteApplicationURL() { 124 const std::string& ServiceRegistry::GetRemoteApplicationURL() {
114 return remote_url_; 125 return remote_url_;
115 } 126 }
116 127
117 ServiceProvider* ServiceRegistry::GetServiceProvider() { 128 ServiceProvider* ServiceRegistry::GetServiceProvider() {
118 return remote_service_provider_.get(); 129 return remote_service_provider_.get();
119 } 130 }
120 131
121 void ServiceRegistry::OnGotContentHandlerID(uint32_t content_handler_id) { 132 void ServiceRegistry::OnGotRemoteIDs(uint32_t target_application_id,
122 DCHECK(!is_content_handler_id_valid_); 133 uint32_t content_handler_id) {
123 is_content_handler_id_valid_ = true; 134 DCHECK(!remote_ids_valid_);
135 remote_ids_valid_ = true;
136
137 remote_id_ = target_application_id;
124 content_handler_id_ = content_handler_id; 138 content_handler_id_ = content_handler_id;
125 std::vector<Closure> callbacks; 139 std::vector<Closure> callbacks;
126 callbacks.swap(content_handler_id_callbacks_); 140 callbacks.swap(remote_id_callbacks_);
127 for (auto callback : callbacks) 141 for (auto callback : callbacks)
128 callback.Run(); 142 callback.Run();
129 } 143 }
130 144
131 void ServiceRegistry::ConnectToService(const mojo::String& service_name, 145 void ServiceRegistry::ConnectToService(const mojo::String& service_name,
132 ScopedMessagePipeHandle client_handle) { 146 ScopedMessagePipeHandle client_handle) {
133 service_connector_registry_.ConnectToService(this, service_name, 147 service_connector_registry_.ConnectToService(this, service_name,
134 std::move(client_handle)); 148 std::move(client_handle));
135 } 149 }
136 150
137 } // namespace internal 151 } // namespace internal
138 } // namespace mojo 152 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/service_registry.h ('k') | mojo/shell/public/interfaces/application.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698