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

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

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

Powered by Google App Engine
This is Rietveld 408576698