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

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

Issue 304273004: Add name to services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get chrome to build 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>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 virtual void RemoveServiceConnector( 70 virtual void RemoveServiceConnector(
71 internal::ServiceConnectorBase* service_connector) = 0; 71 internal::ServiceConnectorBase* service_connector) = 0;
72 72
73 protected: 73 protected:
74 void set_service_connector_owner(ServiceConnectorBase* service_connector, 74 void set_service_connector_owner(ServiceConnectorBase* service_connector,
75 Owner* owner) { 75 Owner* owner) {
76 service_connector->owner_ = owner; 76 service_connector->owner_ = owner;
77 } 77 }
78 ServiceProviderPtr service_provider_; 78 ServiceProviderPtr service_provider_;
79 }; 79 };
80 ServiceConnectorBase() : owner_(NULL) {} 80 ServiceConnectorBase(const std::string& name) : name_(name), owner_(NULL) {}
81 virtual ~ServiceConnectorBase(); 81 virtual ~ServiceConnectorBase();
82 virtual void ConnectToService(const std::string& url, 82 virtual void ConnectToService(const std::string& url,
83 const std::string& name,
83 ScopedMessagePipeHandle client_handle) = 0; 84 ScopedMessagePipeHandle client_handle) = 0;
85 std::string name() const { return name_; }
84 86
85 protected: 87 protected:
88 std::string name_;
86 Owner* owner_; 89 Owner* owner_;
87 }; 90 };
88 91
89 template <class ServiceImpl, typename Context=void> 92 template <class ServiceImpl, typename Context=void>
90 class ServiceConnector : public internal::ServiceConnectorBase { 93 class ServiceConnector : public internal::ServiceConnectorBase {
91 public: 94 public:
92 ServiceConnector(Context* context = NULL) : context_(context) {} 95 ServiceConnector(const std::string& name, Context* context = NULL)
96 : ServiceConnectorBase(name), context_(context) {}
93 97
94 virtual ~ServiceConnector() { 98 virtual ~ServiceConnector() {
95 ConnectionList doomed; 99 ConnectionList doomed;
96 doomed.swap(connections_); 100 doomed.swap(connections_);
97 for (typename ConnectionList::iterator it = doomed.begin(); 101 for (typename ConnectionList::iterator it = doomed.begin();
98 it != doomed.end(); ++it) { 102 it != doomed.end(); ++it) {
99 delete *it; 103 delete *it;
100 } 104 }
101 assert(connections_.empty()); // No one should have added more! 105 assert(connections_.empty()); // No one should have added more!
102 } 106 }
103 107
104 virtual void ConnectToService(const std::string& url, 108 virtual void ConnectToService(const std::string& url,
109 const std::string& name,
105 ScopedMessagePipeHandle handle) MOJO_OVERRIDE { 110 ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
106 ServiceConnection<ServiceImpl, Context>* impl = 111 ServiceConnection<ServiceImpl, Context>* impl =
107 ServiceConstructor<ServiceImpl, Context>::New(context_); 112 ServiceConstructor<ServiceImpl, Context>::New(context_);
108 impl->set_service_connector(this); 113 impl->set_service_connector(this);
109 BindToPipe(impl, handle.Pass()); 114 BindToPipe(impl, handle.Pass());
110 115
111 connections_.push_back(impl); 116 connections_.push_back(impl);
112 } 117 }
113 118
114 void RemoveConnection(ServiceImpl* impl) { 119 void RemoveConnection(ServiceImpl* impl) {
(...skipping 15 matching lines...) Expand all
130 private: 135 private:
131 typedef std::vector<ServiceImpl*> ConnectionList; 136 typedef std::vector<ServiceImpl*> ConnectionList;
132 ConnectionList connections_; 137 ConnectionList connections_;
133 Context* context_; 138 Context* context_;
134 }; 139 };
135 140
136 } // namespace internal 141 } // namespace internal
137 } // namespace mojo 142 } // namespace mojo
138 143
139 #endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_ 144 #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/bindings/lib/no_interface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698