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

Side by Side Diff: mojo/public/cpp/application/lib/service_connector_registry.h

Issue 1984463002: More cleanup: Get rid of ServiceConnectorRegistry. (Closed) Base URL: https://github.com/domokit/mojo.git@work791_app_conn_devo_4
Patch Set: Created 4 years, 7 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 2015 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_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_
6 #define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11
12 #include "mojo/public/cpp/system/message_pipe.h"
13
14 namespace mojo {
15
16 struct ConnectionContext;
17 class ServiceConnector;
18
19 namespace internal {
20
21 // ServiceConnectorRegistry maintains a default ServiceConnector as well as at
22 // most one ServiceConnector per interface name. When ConnectToService() is
23 // invoked the ServiceConnector registered by name is given the request.
24 class ServiceConnectorRegistry {
25 public:
26 ServiceConnectorRegistry();
27 ~ServiceConnectorRegistry();
28
29 // Returns true if non ServiceConnectors have been registered by name.
30 bool empty() const { return name_to_service_connector_.empty(); }
31
32 // Sets a ServiceConnector by name. This deletes any existing ServiceConnector
33 // of the same name.
34 void SetServiceConnectorForName(
35 std::unique_ptr<ServiceConnector> service_connector,
36 const std::string& interface_name);
37 void RemoveServiceConnectorForName(const std::string& interface_name);
38
39 // ConnectToService returns true if this registery has an entry for
40 // |interface_name|. In that case, the |client_handle| is passed along
41 // to the |ServiceConnector|. Otherwise, this function returns false and
42 // |client_handle| is untouched.
43 bool ConnectToService(const ConnectionContext& connection_context,
44 const std::string& interface_name,
45 ScopedMessagePipeHandle* client_handle);
46
47 private:
48 using NameToServiceConnectorMap =
49 std::map<std::string, std::unique_ptr<ServiceConnector>>;
50
51 NameToServiceConnectorMap name_to_service_connector_;
52
53 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorRegistry);
54 };
55
56 } // namespace internal
57 } // namespace mojo
58
59 #endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/BUILD.gn ('k') | mojo/public/cpp/application/lib/service_connector_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698