OLD | NEW |
| (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 #ifndef MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_REGISTRY_H_ | |
6 #define MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_REGISTRY_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <set> | |
11 #include <string> | |
12 | |
13 #include "mojo/application/public/cpp/application_connection.h" | |
14 #include "mojo/application/public/cpp/lib/service_connector_registry.h" | |
15 #include "mojo/application/public/interfaces/service_provider.mojom.h" | |
16 #include "mojo/application/public/interfaces/shell.mojom.h" | |
17 #include "mojo/public/cpp/bindings/binding.h" | |
18 | |
19 namespace mojo { | |
20 namespace internal { | |
21 | |
22 // A ServiceRegistry represents each half of a connection between two | |
23 // applications, allowing customization of which services are published to the | |
24 // other. | |
25 class ServiceRegistry : public ServiceProvider, public ApplicationConnection { | |
26 public: | |
27 ServiceRegistry(); | |
28 // |allowed_interfaces| are the set of interfaces that the shell has allowed | |
29 // an application to expose to another application. If this set contains only | |
30 // the string value "*" all interfaces may be exposed. | |
31 ServiceRegistry(const std::string& connection_url, | |
32 const std::string& remote_url, | |
33 ServiceProviderPtr remote_services, | |
34 InterfaceRequest<ServiceProvider> local_services, | |
35 const std::set<std::string>& allowed_interfaces); | |
36 ~ServiceRegistry() override; | |
37 | |
38 Shell::ConnectToApplicationCallback GetConnectToApplicationCallback(); | |
39 | |
40 // ApplicationConnection overrides. | |
41 void SetServiceConnector(ServiceConnector* service_connector) override; | |
42 bool SetServiceConnectorForName(ServiceConnector* service_connector, | |
43 const std::string& interface_name) override; | |
44 const std::string& GetConnectionURL() override; | |
45 const std::string& GetRemoteApplicationURL() override; | |
46 ServiceProvider* GetServiceProvider() override; | |
47 ServiceProvider* GetLocalServiceProvider() override; | |
48 void SetRemoteServiceProviderConnectionErrorHandler( | |
49 const Closure& handler) override; | |
50 bool GetContentHandlerID(uint32_t* target_id) override; | |
51 void AddContentHandlerIDCallback(const Closure& callback) override; | |
52 base::WeakPtr<ApplicationConnection> GetWeakPtr() override; | |
53 | |
54 void RemoveServiceConnectorForName(const std::string& interface_name); | |
55 | |
56 private: | |
57 void OnGotContentHandlerID(uint32_t content_handler_id); | |
58 | |
59 // ServiceProvider method. | |
60 void ConnectToService(const mojo::String& service_name, | |
61 ScopedMessagePipeHandle client_handle) override; | |
62 | |
63 const std::string connection_url_; | |
64 const std::string remote_url_; | |
65 Binding<ServiceProvider> local_binding_; | |
66 ServiceProviderPtr remote_service_provider_; | |
67 ServiceConnectorRegistry service_connector_registry_; | |
68 const std::set<std::string> allowed_interfaces_; | |
69 const bool allow_all_interfaces_; | |
70 // The id of the content_handler is only available once the callback from | |
71 // establishing the connection is made. | |
72 uint32_t content_handler_id_; | |
73 bool is_content_handler_id_valid_; | |
74 std::vector<Closure> content_handler_id_callbacks_; | |
75 base::WeakPtrFactory<ServiceRegistry> weak_factory_; | |
76 | |
77 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceRegistry); | |
78 }; | |
79 | |
80 } // namespace internal | |
81 } // namespace mojo | |
82 | |
83 #endif // MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_REGISTRY_H_ | |
OLD | NEW |