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

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

Issue 845593003: Pass ServiceProvider and ServiceProvider& params in Connect (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
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 #include "mojo/application_manager/application_manager.h" 5 #include "mojo/application_manager/application_manager.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 ApplicationManager* manager, 64 ApplicationManager* manager,
65 const GURL& requested_url, 65 const GURL& requested_url,
66 const GURL& url) 66 const GURL& url)
67 : ShellImpl(manager, requested_url, url) { 67 : ShellImpl(manager, requested_url, url) {
68 binding_.Bind(ptr); 68 binding_.Bind(ptr);
69 } 69 }
70 70
71 ~ShellImpl() override {} 71 ~ShellImpl() override {}
72 72
73 void ConnectToClient(const GURL& requestor_url, 73 void ConnectToClient(const GURL& requestor_url,
74 ServiceProviderPtr service_provider) { 74 InterfaceRequest<ServiceProvider> services,
75 client()->AcceptConnection(String::From(requestor_url), 75 ServiceProviderPtr exported_services) {
76 service_provider.Pass()); 76 client()->AcceptConnection(String::From(requestor_url), services.Pass(),
77 exported_services.Pass());
77 } 78 }
78 79
79 Application* client() { return binding_.client(); } 80 Application* client() { return binding_.client(); }
80 const GURL& url() const { return url_; } 81 const GURL& url() const { return url_; }
81 const GURL& requested_url() const { return requested_url_; } 82 const GURL& requested_url() const { return requested_url_; }
82 83
83 private: 84 private:
84 ShellImpl(ApplicationManager* manager, 85 ShellImpl(ApplicationManager* manager,
85 const GURL& requested_url, 86 const GURL& requested_url,
86 const GURL& url) 87 const GURL& url)
87 : manager_(manager), 88 : manager_(manager),
88 requested_url_(requested_url), 89 requested_url_(requested_url),
89 url_(url), 90 url_(url),
90 binding_(this) { 91 binding_(this) {
91 binding_.set_error_handler(this); 92 binding_.set_error_handler(this);
92 } 93 }
93 94
94 // Shell implementation: 95 // Shell implementation:
95 void ConnectToApplication( 96 void ConnectToApplication(const String& app_url,
96 const String& app_url, 97 InterfaceRequest<ServiceProvider> services,
97 InterfaceRequest<ServiceProvider> in_service_provider) override { 98 ServiceProviderPtr exported_services) override {
98 ServiceProviderPtr out_service_provider;
99 out_service_provider.Bind(in_service_provider.PassMessagePipe());
100 GURL app_gurl(app_url); 99 GURL app_gurl(app_url);
101 if (!app_gurl.is_valid()) { 100 if (!app_gurl.is_valid()) {
102 LOG(ERROR) << "Error: invalid URL: " << app_url; 101 LOG(ERROR) << "Error: invalid URL: " << app_url;
103 return; 102 return;
104 } 103 }
105 manager_->ConnectToApplication(app_gurl, url_, out_service_provider.Pass()); 104 manager_->ConnectToApplication(app_gurl, url_, services.Pass(),
105 exported_services.Pass());
106 } 106 }
107 107
108 // ErrorHandler implementation: 108 // ErrorHandler implementation:
109 void OnConnectionError() override { manager_->OnShellImplError(this); } 109 void OnConnectionError() override { manager_->OnShellImplError(this); }
110 110
111 ApplicationManager* const manager_; 111 ApplicationManager* const manager_;
112 const GURL requested_url_; 112 const GURL requested_url_;
113 const GURL url_; 113 const GURL url_;
114 Binding<Shell> binding_; 114 Binding<Shell> binding_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(ShellImpl); 116 DISALLOW_COPY_AND_ASSIGN(ShellImpl);
117 }; 117 };
118 118
119 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { 119 class ApplicationManager::ContentHandlerConnection : public ErrorHandler {
120 public: 120 public:
121 ContentHandlerConnection(ApplicationManager* manager, 121 ContentHandlerConnection(ApplicationManager* manager,
122 const GURL& content_handler_url) 122 const GURL& content_handler_url)
123 : manager_(manager), content_handler_url_(content_handler_url) { 123 : manager_(manager), content_handler_url_(content_handler_url) {
124 ServiceProviderPtr service_provider; 124 ServiceProviderPtr services;
125 StubServiceProvider* service_provider_impl = 125 manager->ConnectToApplication(content_handler_url, GURL(),
126 BindToProxy(new StubServiceProvider, &service_provider); 126 GetProxy(&services), ServiceProviderPtr());
127 manager->ConnectToApplication( 127 mojo::ConnectToService(services.get(), &content_handler_);
128 content_handler_url, GURL(), service_provider.Pass());
129 mojo::ConnectToService(service_provider_impl->client(), &content_handler_);
130 content_handler_.set_error_handler(this); 128 content_handler_.set_error_handler(this);
131 } 129 }
132 130
133 ContentHandler* content_handler() { return content_handler_.get(); } 131 ContentHandler* content_handler() { return content_handler_.get(); }
134 132
135 GURL content_handler_url() { return content_handler_url_; } 133 GURL content_handler_url() { return content_handler_url_; }
136 134
137 private: 135 private:
138 // ErrorHandler implementation: 136 // ErrorHandler implementation:
139 void OnConnectionError() override { manager_->OnContentHandlerError(this); } 137 void OnConnectionError() override { manager_->OnContentHandlerError(this); }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 STLDeleteValues(&scheme_to_loader_); 172 STLDeleteValues(&scheme_to_loader_);
175 } 173 }
176 174
177 void ApplicationManager::TerminateShellConnections() { 175 void ApplicationManager::TerminateShellConnections() {
178 STLDeleteValues(&url_to_shell_impl_); 176 STLDeleteValues(&url_to_shell_impl_);
179 } 177 }
180 178
181 void ApplicationManager::ConnectToApplication( 179 void ApplicationManager::ConnectToApplication(
182 const GURL& requested_url, 180 const GURL& requested_url,
183 const GURL& requestor_url, 181 const GURL& requestor_url,
184 ServiceProviderPtr service_provider) { 182 InterfaceRequest<ServiceProvider> services,
183 ServiceProviderPtr exported_services) {
185 DCHECK(requested_url.is_valid()); 184 DCHECK(requested_url.is_valid());
186 ApplicationLoader* loader = GetLoaderForURL(requested_url, 185 ApplicationLoader* loader = GetLoaderForURL(requested_url,
187 DONT_INCLUDE_DEFAULT_LOADER); 186 DONT_INCLUDE_DEFAULT_LOADER);
188 if (loader) { 187 if (loader) {
189 ConnectToApplicationImpl(requested_url, requested_url, requestor_url, 188 ConnectToApplicationImpl(requested_url, requested_url, requestor_url,
190 service_provider.Pass(), loader); 189 services.Pass(), exported_services.Pass(), loader);
191 return; 190 return;
192 } 191 }
193 192
194 GURL resolved_url = delegate_->ResolveURL(requested_url); 193 GURL resolved_url = delegate_->ResolveURL(requested_url);
195 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER); 194 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER);
196 if (loader) { 195 if (loader) {
197 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, 196 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url,
198 service_provider.Pass(), loader); 197 services.Pass(), exported_services.Pass(), loader);
199 return; 198 return;
200 } 199 }
201 200
202 LOG(WARNING) << "Could not find loader to load application: " 201 LOG(WARNING) << "Could not find loader to load application: "
203 << requested_url.spec(); 202 << requested_url.spec();
204 } 203 }
205 204
206 void ApplicationManager::ConnectToApplicationImpl( 205 void ApplicationManager::ConnectToApplicationImpl(
207 const GURL& requested_url, 206 const GURL& requested_url,
208 const GURL& resolved_url, 207 const GURL& resolved_url,
209 const GURL& requestor_url, 208 const GURL& requestor_url,
210 ServiceProviderPtr service_provider, 209 InterfaceRequest<ServiceProvider> services,
210 ServiceProviderPtr exported_services,
211 ApplicationLoader* loader) { 211 ApplicationLoader* loader) {
212 ShellImpl* shell = nullptr; 212 ShellImpl* shell = nullptr;
213 URLToShellImplMap::const_iterator shell_it = 213 URLToShellImplMap::const_iterator shell_it =
214 url_to_shell_impl_.find(resolved_url); 214 url_to_shell_impl_.find(resolved_url);
215 if (shell_it != url_to_shell_impl_.end()) { 215 if (shell_it != url_to_shell_impl_.end()) {
216 shell = shell_it->second; 216 shell = shell_it->second;
217 } else { 217 } else {
218 MessagePipe pipe; 218 MessagePipe pipe;
219 shell = 219 shell =
220 new ShellImpl(pipe.handle0.Pass(), this, requested_url, resolved_url); 220 new ShellImpl(pipe.handle0.Pass(), this, requested_url, resolved_url);
221 url_to_shell_impl_[resolved_url] = shell; 221 url_to_shell_impl_[resolved_url] = shell;
222 shell->client()->Initialize(GetArgsForURL(requested_url)); 222 shell->client()->Initialize(GetArgsForURL(requested_url));
223 223
224 loader->Load(this, resolved_url, pipe.handle1.Pass(), 224 loader->Load(this, resolved_url, pipe.handle1.Pass(),
225 base::Bind(&ApplicationManager::LoadWithContentHandler, 225 base::Bind(&ApplicationManager::LoadWithContentHandler,
226 weak_ptr_factory_.GetWeakPtr())); 226 weak_ptr_factory_.GetWeakPtr()));
227 } 227 }
228 ConnectToClient(shell, resolved_url, requestor_url, service_provider.Pass()); 228 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(),
229 exported_services.Pass());
229 } 230 }
230 231
231 void ApplicationManager::ConnectToClient(ShellImpl* shell_impl, 232 void ApplicationManager::ConnectToClient(
232 const GURL& url, 233 ShellImpl* shell_impl,
233 const GURL& requestor_url, 234 const GURL& url,
234 ServiceProviderPtr service_provider) { 235 const GURL& requestor_url,
235 shell_impl->ConnectToClient(requestor_url, service_provider.Pass()); 236 InterfaceRequest<ServiceProvider> services,
237 ServiceProviderPtr exported_services) {
238 shell_impl->ConnectToClient(requestor_url, services.Pass(),
239 exported_services.Pass());
236 } 240 }
237 241
238 void ApplicationManager::RegisterExternalApplication( 242 void ApplicationManager::RegisterExternalApplication(
239 const GURL& url, 243 const GURL& url,
240 ScopedMessagePipeHandle shell_handle) { 244 ScopedMessagePipeHandle shell_handle) {
241 ShellImpl* shell_impl = new ShellImpl(shell_handle.Pass(), this, url, url); 245 ShellImpl* shell_impl = new ShellImpl(shell_handle.Pass(), this, url, url);
242 url_to_shell_impl_[url] = shell_impl; 246 url_to_shell_impl_[url] = shell_impl;
243 shell_impl->client()->Initialize(GetArgsForURL(url)); 247 shell_impl->client()->Initialize(GetArgsForURL(url));
244 } 248 }
245 249
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 auto it = 322 auto it =
319 url_to_content_handler_.find(content_handler->content_handler_url()); 323 url_to_content_handler_.find(content_handler->content_handler_url());
320 DCHECK(it != url_to_content_handler_.end()); 324 DCHECK(it != url_to_content_handler_.end());
321 delete it->second; 325 delete it->second;
322 url_to_content_handler_.erase(it); 326 url_to_content_handler_.erase(it);
323 } 327 }
324 328
325 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( 329 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName(
326 const GURL& application_url, 330 const GURL& application_url,
327 const std::string& interface_name) { 331 const std::string& interface_name) {
328 StubServiceProvider* stub_sp = new StubServiceProvider; 332 ServiceProviderPtr services;
329 ServiceProviderPtr spp; 333 ConnectToApplication(application_url, GURL(), GetProxy(&services),
330 BindToProxy(stub_sp, &spp); 334 ServiceProviderPtr());
331 ConnectToApplication(application_url, GURL(), spp.Pass());
332 MessagePipe pipe; 335 MessagePipe pipe;
333 stub_sp->GetRemoteServiceProvider()->ConnectToService(interface_name, 336 services->ConnectToService(interface_name, pipe.handle1.Pass());
334 pipe.handle1.Pass());
335 return pipe.handle0.Pass(); 337 return pipe.handle0.Pass();
336 } 338 }
337 339
338 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { 340 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) {
339 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); 341 URLToArgsMap::const_iterator args_it = url_to_args_.find(url);
340 if (args_it != url_to_args_.end()) 342 if (args_it != url_to_args_.end())
341 return Array<String>::From(args_it->second); 343 return Array<String>::From(args_it->second);
342 return Array<String>(); 344 return Array<String>();
343 } 345 }
344 } // namespace mojo 346 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698