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

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

Issue 337533002: Introduce internal::ServiceRegistry to prepare for ServiceProvider split. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review concerns Created 6 years, 6 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 | Annotate | Revision Log
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 #ifndef MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_ 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
6 #define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_ 6 #define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "mojo/public/cpp/application/lib/service_registry.h"
12 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace internal { 16 namespace internal {
16 17
17 template <class ServiceImpl, typename Context> 18 template <class ServiceImpl, typename Context>
18 class ServiceConnector; 19 class ServiceConnector;
19 20
20 // Specialization of ServiceConnection. 21 // Specialization of ServiceConnection.
21 // ServiceImpl: Subclass of InterfaceImpl<...>. 22 // ServiceImpl: Subclass of InterfaceImpl<...>.
(...skipping 12 matching lines...) Expand all
34 private: 35 private:
35 friend class ServiceConnector<ServiceImpl, Context>; 36 friend class ServiceConnector<ServiceImpl, Context>;
36 37
37 // Called shortly after this class is instantiated. 38 // Called shortly after this class is instantiated.
38 void set_service_connector( 39 void set_service_connector(
39 ServiceConnector<ServiceImpl, Context>* connector) { 40 ServiceConnector<ServiceImpl, Context>* connector) {
40 service_connector_ = connector; 41 service_connector_ = connector;
41 } 42 }
42 43
43 ServiceConnector<ServiceImpl, Context>* service_connector_; 44 ServiceConnector<ServiceImpl, Context>* service_connector_;
45
46 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnection);
44 }; 47 };
45 48
46 template <typename ServiceImpl, typename Context> 49 template <typename ServiceImpl, typename Context>
47 struct ServiceConstructor { 50 struct ServiceConstructor {
48 static ServiceConnection<ServiceImpl, Context>* New(Context* context) { 51 static ServiceConnection<ServiceImpl, Context>* New(Context* context) {
49 return new ServiceConnection<ServiceImpl, Context>(context); 52 return new ServiceConnection<ServiceImpl, Context>(context);
50 } 53 }
51 }; 54 };
52 55
53 template <typename ServiceImpl> 56 template <typename ServiceImpl>
54 struct ServiceConstructor<ServiceImpl, void> { 57 struct ServiceConstructor<ServiceImpl, void> {
55 public: 58 public:
56 static ServiceConnection<ServiceImpl, void>* New(void* context) { 59 static ServiceConnection<ServiceImpl, void>* New(void* context) {
57 return new ServiceConnection<ServiceImpl, void>(); 60 return new ServiceConnection<ServiceImpl, void>();
58 } 61 }
59 }; 62 };
60 63
61 class ServiceConnectorBase { 64 class ServiceConnectorBase {
62 public: 65 public:
63 class Owner : public ServiceProvider { 66 ServiceConnectorBase(const std::string& name);
64 public:
65 Owner();
66 Owner(ScopedMessagePipeHandle service_provider_handle);
67 virtual ~Owner();
68 virtual void AddServiceConnector(
69 internal::ServiceConnectorBase* service_connector) = 0;
70 virtual void RemoveServiceConnector(
71 internal::ServiceConnectorBase* service_connector) = 0;
72
73 protected:
74 void set_service_connector_owner(ServiceConnectorBase* service_connector,
75 Owner* owner) {
76 service_connector->owner_ = owner;
77 }
78 ServiceProviderPtr service_provider_;
79 };
80 ServiceConnectorBase(const std::string& name) : name_(name), owner_(NULL) {}
81 virtual ~ServiceConnectorBase(); 67 virtual ~ServiceConnectorBase();
82 virtual void ConnectToService(const std::string& url, 68 virtual void ConnectToService(const std::string& url,
83 const std::string& name, 69 const std::string& name,
84 ScopedMessagePipeHandle client_handle) = 0; 70 ScopedMessagePipeHandle client_handle) = 0;
85 std::string name() const { return name_; } 71 std::string name() const { return name_; }
72 void set_registry(ServiceRegistry* registry) { registry_ = registry; }
86 73
87 protected: 74 protected:
88 std::string name_; 75 std::string name_;
89 Owner* owner_; 76 ServiceRegistry* registry_;
77
78 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorBase);
90 }; 79 };
91 80
92 template <class ServiceImpl, typename Context=void> 81 template <class ServiceImpl, typename Context=void>
93 class ServiceConnector : public internal::ServiceConnectorBase { 82 class ServiceConnector : public internal::ServiceConnectorBase {
94 public: 83 public:
95 ServiceConnector(const std::string& name, Context* context = NULL) 84 ServiceConnector(const std::string& name, Context* context = NULL)
96 : ServiceConnectorBase(name), context_(context) {} 85 : ServiceConnectorBase(name), context_(context) {}
97 86
98 virtual ~ServiceConnector() { 87 virtual ~ServiceConnector() {
99 ConnectionList doomed; 88 ConnectionList doomed;
(...skipping 27 matching lines...) Expand all
127 } 116 }
128 } 117 }
129 } 118 }
130 119
131 Context* context() const { return context_; } 120 Context* context() const { return context_; }
132 121
133 private: 122 private:
134 typedef std::vector<ServiceImpl*> ConnectionList; 123 typedef std::vector<ServiceImpl*> ConnectionList;
135 ConnectionList connections_; 124 ConnectionList connections_;
136 Context* context_; 125 Context* context_;
126
127 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnector);
137 }; 128 };
138 129
139 } // namespace internal 130 } // namespace internal
140 } // namespace mojo 131 } // namespace mojo
141 132
142 #endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_ 133 #endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698