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

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

Issue 298003008: Shell / ShellClient -> ServiceProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | 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_SHELL_LIB_SERVICE_CONNECTOR_H_ 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
6 #define MOJO_PUBLIC_CPP_SHELL_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/bindings/allocation_scope.h" 12 #include "mojo/public/cpp/bindings/allocation_scope.h"
13 #include "mojo/public/interfaces/shell/shell.mojom.h" 13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace internal { 16 namespace internal {
17 17
18 template <class ServiceImpl, typename Context> 18 template <class ServiceImpl, typename Context>
19 class ServiceConnector; 19 class ServiceConnector;
20 20
21 // Specialization of ServiceConnection. 21 // Specialization of ServiceConnection.
22 // ServiceImpl: Subclass of InterfaceImpl<...>. 22 // ServiceImpl: Subclass of InterfaceImpl<...>.
23 // Context: Type of shared context. 23 // Context: Type of shared context.
(...skipping 30 matching lines...) Expand all
54 template <typename ServiceImpl> 54 template <typename ServiceImpl>
55 struct ServiceConstructor<ServiceImpl, void> { 55 struct ServiceConstructor<ServiceImpl, void> {
56 public: 56 public:
57 static ServiceConnection<ServiceImpl, void>* New(void* context) { 57 static ServiceConnection<ServiceImpl, void>* New(void* context) {
58 return new ServiceConnection<ServiceImpl, void>(); 58 return new ServiceConnection<ServiceImpl, void>();
59 } 59 }
60 }; 60 };
61 61
62 class ServiceConnectorBase { 62 class ServiceConnectorBase {
63 public: 63 public:
64 class Owner : public ShellClient { 64 class Owner : public ServiceProvider {
65 public: 65 public:
66 Owner(ScopedMessagePipeHandle shell_handle); 66 Owner(ScopedMessagePipeHandle service_provider_handle);
67 virtual ~Owner(); 67 virtual ~Owner();
68 Shell* shell() { return shell_.get(); } 68 ServiceProvider* service_provider() { return service_provider_.get(); }
69 virtual void AddServiceConnector( 69 virtual void AddServiceConnector(
70 internal::ServiceConnectorBase* service_connector) = 0; 70 internal::ServiceConnectorBase* service_connector) = 0;
71 virtual void RemoveServiceConnector( 71 virtual void RemoveServiceConnector(
72 internal::ServiceConnectorBase* service_connector) = 0; 72 internal::ServiceConnectorBase* service_connector) = 0;
73 73
74 protected: 74 protected:
75 void set_service_connector_owner(ServiceConnectorBase* service_connector, 75 void set_service_connector_owner(ServiceConnectorBase* service_connector,
76 Owner* owner) { 76 Owner* owner) {
77 service_connector->owner_ = owner; 77 service_connector->owner_ = owner;
78 } 78 }
79 ShellPtr shell_; 79 ServiceProviderPtr service_provider_;
80 }; 80 };
81 ServiceConnectorBase() : owner_(NULL) {} 81 ServiceConnectorBase() : owner_(NULL) {}
82 virtual ~ServiceConnectorBase(); 82 virtual ~ServiceConnectorBase();
83 Shell* shell() { return owner_->shell(); } 83 ServiceProvider* service_provider() { return owner_->service_provider(); }
84 virtual void AcceptConnection(const std::string& url, 84 virtual void ConnectToService(const std::string& url,
85 ScopedMessagePipeHandle client_handle) = 0; 85 ScopedMessagePipeHandle client_handle) = 0;
86 86
87 protected: 87 protected:
88 Owner* owner_; 88 Owner* owner_;
89 }; 89 };
90 90
91 template <class ServiceImpl, typename Context=void> 91 template <class ServiceImpl, typename Context=void>
92 class ServiceConnector : public internal::ServiceConnectorBase { 92 class ServiceConnector : public internal::ServiceConnectorBase {
93 public: 93 public:
94 ServiceConnector(Context* context = NULL) : context_(context) {} 94 ServiceConnector(Context* context = NULL) : context_(context) {}
95 95
96 virtual ~ServiceConnector() { 96 virtual ~ServiceConnector() {
97 ConnectionList doomed; 97 ConnectionList doomed;
98 doomed.swap(connections_); 98 doomed.swap(connections_);
99 for (typename ConnectionList::iterator it = doomed.begin(); 99 for (typename ConnectionList::iterator it = doomed.begin();
100 it != doomed.end(); ++it) { 100 it != doomed.end(); ++it) {
101 delete *it; 101 delete *it;
102 } 102 }
103 assert(connections_.empty()); // No one should have added more! 103 assert(connections_.empty()); // No one should have added more!
104 } 104 }
105 105
106 virtual void AcceptConnection(const std::string& url, 106 virtual void ConnectToService(const std::string& url,
107 ScopedMessagePipeHandle handle) MOJO_OVERRIDE { 107 ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
108 ServiceConnection<ServiceImpl, Context>* impl = 108 ServiceConnection<ServiceImpl, Context>* impl =
109 ServiceConstructor<ServiceImpl, Context>::New(context_); 109 ServiceConstructor<ServiceImpl, Context>::New(context_);
110 impl->set_service_connector(this); 110 impl->set_service_connector(this);
111 BindToPipe(impl, handle.Pass()); 111 BindToPipe(impl, handle.Pass());
112 112
113 connections_.push_back(impl); 113 connections_.push_back(impl);
114 } 114 }
115 115
116 void RemoveConnection(ServiceImpl* impl) { 116 void RemoveConnection(ServiceImpl* impl) {
(...skipping 14 matching lines...) Expand all
131 131
132 private: 132 private:
133 typedef std::vector<ServiceImpl*> ConnectionList; 133 typedef std::vector<ServiceImpl*> ConnectionList;
134 ConnectionList connections_; 134 ConnectionList connections_;
135 Context* context_; 135 Context* context_;
136 }; 136 };
137 137
138 } // namespace internal 138 } // namespace internal
139 } // namespace mojo 139 } // namespace mojo
140 140
141 #endif // MOJO_PUBLIC_CPP_SHELL_LIB_SERVICE_CONNECTOR_H_ 141 #endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/lib/application.cc ('k') | mojo/public/cpp/application/lib/service_connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698