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

Side by Side Diff: mojo/service_manager/service_manager.cc

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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include <stdio.h> 5 #include <stdio.h>
6 6
7 #include "mojo/service_manager/service_manager.h" 7 #include "mojo/service_manager/service_manager.h"
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 11 matching lines...) Expand all
22 class ServiceManager::ServiceFactory : public InterfaceImpl<ServiceProvider> { 22 class ServiceManager::ServiceFactory : public InterfaceImpl<ServiceProvider> {
23 public: 23 public:
24 ServiceFactory(ServiceManager* manager, const GURL& url) 24 ServiceFactory(ServiceManager* manager, const GURL& url)
25 : manager_(manager), 25 : manager_(manager),
26 url_(url) { 26 url_(url) {
27 } 27 }
28 28
29 virtual ~ServiceFactory() { 29 virtual ~ServiceFactory() {
30 } 30 }
31 31
32 void ConnectToClient(ScopedMessagePipeHandle handle) { 32 void ConnectToClient(const std::string& name,
33 ScopedMessagePipeHandle handle) {
33 if (handle.is_valid()) 34 if (handle.is_valid())
34 client()->ConnectToService(url_.spec(), handle.Pass()); 35 client()->ConnectToService(url_.spec(), name, handle.Pass());
35 } 36 }
36 37
37 // ServiceProvider implementation: 38 // ServiceProvider implementation:
38 virtual void ConnectToService(const String& url, 39 virtual void ConnectToService(const String& url,
40 const String& name,
39 ScopedMessagePipeHandle client_pipe) OVERRIDE { 41 ScopedMessagePipeHandle client_pipe) OVERRIDE {
40 manager_->ConnectToService(GURL(url), client_pipe.Pass()); 42 manager_->ConnectToService(GURL(url), name, client_pipe.Pass());
41 } 43 }
42 44
43 const GURL& url() const { return url_; } 45 const GURL& url() const { return url_; }
44 46
45 private: 47 private:
46 virtual void OnConnectionError() OVERRIDE { 48 virtual void OnConnectionError() OVERRIDE {
47 manager_->OnServiceFactoryError(this); 49 manager_->OnServiceFactoryError(this);
48 } 50 }
49 51
50 ServiceManager* const manager_; 52 ServiceManager* const manager_;
51 const GURL url_; 53 const GURL url_;
52 54
53 DISALLOW_COPY_AND_ASSIGN(ServiceFactory); 55 DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
54 }; 56 };
55 57
56 class ServiceManager::TestAPI::TestServiceProviderConnection 58 class ServiceManager::TestAPI::TestServiceProviderConnection
57 : public InterfaceImpl<ServiceProvider> { 59 : public InterfaceImpl<ServiceProvider> {
58 public: 60 public:
59 explicit TestServiceProviderConnection(ServiceManager* manager) 61 explicit TestServiceProviderConnection(ServiceManager* manager)
60 : manager_(manager) {} 62 : manager_(manager) {}
61 virtual ~TestServiceProviderConnection() {} 63 virtual ~TestServiceProviderConnection() {}
62 64
63 virtual void OnConnectionError() OVERRIDE { 65 virtual void OnConnectionError() OVERRIDE {
64 // TODO(darin): How should we handle this error? 66 // TODO(darin): How should we handle this error?
65 } 67 }
66 68
67 // ServiceProvider: 69 // ServiceProvider:
68 virtual void ConnectToService(const String& url, 70 virtual void ConnectToService(const String& url,
71 const String& name,
69 ScopedMessagePipeHandle client_pipe) OVERRIDE { 72 ScopedMessagePipeHandle client_pipe) OVERRIDE {
70 manager_->ConnectToService(GURL(url), client_pipe.Pass()); 73 manager_->ConnectToService(GURL(url), name, client_pipe.Pass());
71 } 74 }
72 75
73 private: 76 private:
74 ServiceManager* manager_; 77 ServiceManager* manager_;
75 78
76 DISALLOW_COPY_AND_ASSIGN(TestServiceProviderConnection); 79 DISALLOW_COPY_AND_ASSIGN(TestServiceProviderConnection);
77 }; 80 };
78 81
79 // static 82 // static
80 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) { 83 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 115
113 // static 116 // static
114 ServiceManager* ServiceManager::GetInstance() { 117 ServiceManager* ServiceManager::GetInstance() {
115 static base::LazyInstance<ServiceManager> instance = 118 static base::LazyInstance<ServiceManager> instance =
116 LAZY_INSTANCE_INITIALIZER; 119 LAZY_INSTANCE_INITIALIZER;
117 has_created_instance = true; 120 has_created_instance = true;
118 return &instance.Get(); 121 return &instance.Get();
119 } 122 }
120 123
121 void ServiceManager::ConnectToService(const GURL& url, 124 void ServiceManager::ConnectToService(const GURL& url,
125 const std::string& name,
122 ScopedMessagePipeHandle client_handle) { 126 ScopedMessagePipeHandle client_handle) {
123 URLToServiceFactoryMap::const_iterator service_it = 127 URLToServiceFactoryMap::const_iterator service_it =
124 url_to_service_factory_.find(url); 128 url_to_service_factory_.find(url);
125 ServiceFactory* service_factory; 129 ServiceFactory* service_factory;
126 if (service_it != url_to_service_factory_.end()) { 130 if (service_it != url_to_service_factory_.end()) {
127 service_factory = service_it->second; 131 service_factory = service_it->second;
128 } else { 132 } else {
129 MessagePipe pipe; 133 MessagePipe pipe;
130 GetLoaderForURL(url)->LoadService(this, url, pipe.handle0.Pass()); 134 GetLoaderForURL(url)->LoadService(this, url, pipe.handle0.Pass());
131 135
132 service_factory = 136 service_factory =
133 BindToPipe(new ServiceFactory(this, url), pipe.handle1.Pass()); 137 BindToPipe(new ServiceFactory(this, url), pipe.handle1.Pass());
134 138
135 url_to_service_factory_[url] = service_factory; 139 url_to_service_factory_[url] = service_factory;
136 } 140 }
137 if (interceptor_) { 141 if (interceptor_) {
138 service_factory->ConnectToClient( 142 service_factory->ConnectToClient(
139 interceptor_->OnConnectToClient(url, client_handle.Pass())); 143 name, interceptor_->OnConnectToClient(url, client_handle.Pass()));
140 } else { 144 } else {
141 service_factory->ConnectToClient(client_handle.Pass()); 145 service_factory->ConnectToClient(name, client_handle.Pass());
142 } 146 }
143 } 147 }
144 148
145 void ServiceManager::SetLoaderForURL(scoped_ptr<ServiceLoader> loader, 149 void ServiceManager::SetLoaderForURL(scoped_ptr<ServiceLoader> loader,
146 const GURL& url) { 150 const GURL& url) {
147 URLToLoaderMap::iterator it = url_to_loader_.find(url); 151 URLToLoaderMap::iterator it = url_to_loader_.find(url);
148 if (it != url_to_loader_.end()) 152 if (it != url_to_loader_.end())
149 delete it->second; 153 delete it->second;
150 url_to_loader_[url] = loader.release(); 154 url_to_loader_[url] = loader.release();
151 } 155 }
(...skipping 26 matching lines...) Expand all
178 // Called from ~ServiceFactory, so we do not need to call Destroy here. 182 // Called from ~ServiceFactory, so we do not need to call Destroy here.
179 const GURL url = service_factory->url(); 183 const GURL url = service_factory->url();
180 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); 184 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
181 DCHECK(it != url_to_service_factory_.end()); 185 DCHECK(it != url_to_service_factory_.end());
182 delete it->second; 186 delete it->second;
183 url_to_service_factory_.erase(it); 187 url_to_service_factory_.erase(it);
184 GetLoaderForURL(url)->OnServiceError(this, url); 188 GetLoaderForURL(url)->OnServiceError(this, url);
185 } 189 }
186 190
187 } // namespace mojo 191 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/service_manager.h ('k') | mojo/service_manager/service_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698