Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 } | 46 } |
| 47 | 47 |
| 48 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { | 48 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { |
| 49 return url; | 49 return url; |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 class ApplicationManager::LoadCallbacksImpl | 53 class ApplicationManager::LoadCallbacksImpl |
| 54 : public ApplicationLoader::LoadCallbacks { | 54 : public ApplicationLoader::LoadCallbacks { |
| 55 public: | 55 public: |
| 56 LoadCallbacksImpl(base::WeakPtr<ApplicationManager> manager, | 56 LoadCallbacksImpl(base::WeakPtr<ApplicationManager> manager) |
| 57 const GURL& requested_url, | 57 : manager_(manager) {} |
|
DaveMoore
2014/11/18 17:00:45
The changes simplified the code in application_man
| |
| 58 const GURL& resolved_url, | |
| 59 const GURL& requestor_url, | |
| 60 ServiceProviderPtr service_provider) | |
| 61 : manager_(manager), | |
| 62 requested_url_(requested_url), | |
| 63 resolved_url_(resolved_url), | |
| 64 requestor_url_(requestor_url), | |
| 65 service_provider_(service_provider.Pass()) {} | |
| 66 | 58 |
| 67 private: | 59 private: |
| 68 ~LoadCallbacksImpl() override {} | 60 ~LoadCallbacksImpl() override {} |
| 69 | 61 |
| 70 // LoadCallbacks implementation | |
| 71 ScopedMessagePipeHandle RegisterApplication() override { | |
| 72 ScopedMessagePipeHandle shell_handle; | |
| 73 if (manager_) { | |
| 74 manager_->RegisterLoadedApplication(requested_url_, | |
| 75 resolved_url_, | |
| 76 requestor_url_, | |
| 77 service_provider_.Pass(), | |
| 78 &shell_handle); | |
| 79 } | |
| 80 return shell_handle.Pass(); | |
| 81 } | |
| 82 | |
| 83 void LoadWithContentHandler(const GURL& content_handler_url, | 62 void LoadWithContentHandler(const GURL& content_handler_url, |
| 63 ScopedMessagePipeHandle shell_handle, | |
| 84 URLResponsePtr url_response) override { | 64 URLResponsePtr url_response) override { |
| 85 if (manager_) { | 65 if (manager_) { |
| 86 manager_->LoadWithContentHandler(requested_url_, | 66 manager_->LoadWithContentHandler(content_handler_url, shell_handle.Pass(), |
| 87 resolved_url_, | 67 url_response.Pass()); |
| 88 requestor_url_, | |
| 89 content_handler_url, | |
| 90 url_response.Pass(), | |
| 91 service_provider_.Pass()); | |
| 92 } | 68 } |
| 93 } | 69 } |
| 94 | 70 |
| 95 base::WeakPtr<ApplicationManager> manager_; | 71 base::WeakPtr<ApplicationManager> manager_; |
| 96 GURL requested_url_; | |
| 97 GURL resolved_url_; | |
| 98 GURL requestor_url_; | |
| 99 ServiceProviderPtr service_provider_; | |
| 100 }; | 72 }; |
| 101 | 73 |
| 102 class ApplicationManager::ShellImpl : public Shell, public ErrorHandler { | 74 class ApplicationManager::ShellImpl : public Shell, public ErrorHandler { |
| 103 public: | 75 public: |
| 104 ShellImpl(ScopedMessagePipeHandle handle, | 76 ShellImpl(ScopedMessagePipeHandle handle, |
| 105 ApplicationManager* manager, | 77 ApplicationManager* manager, |
| 106 const GURL& requested_url, | 78 const GURL& requested_url, |
| 107 const GURL& url) | 79 const GURL& url) |
| 108 : ShellImpl(manager, requested_url, url) { | 80 : ShellImpl(manager, requested_url, url) { |
| 109 binding_.Bind(handle.Pass()); | 81 binding_.Bind(handle.Pass()); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, | 215 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, |
| 244 service_provider.Pass(), loader); | 216 service_provider.Pass(), loader); |
| 245 return; | 217 return; |
| 246 } | 218 } |
| 247 | 219 |
| 248 LOG(WARNING) << "Could not find loader to load application: " | 220 LOG(WARNING) << "Could not find loader to load application: " |
| 249 << requested_url.spec(); | 221 << requested_url.spec(); |
| 250 } | 222 } |
| 251 | 223 |
| 252 void ApplicationManager::ConnectToApplicationImpl( | 224 void ApplicationManager::ConnectToApplicationImpl( |
| 253 const GURL& requested_url, const GURL& resolved_url, | 225 const GURL& requested_url, |
| 254 const GURL& requestor_url, ServiceProviderPtr service_provider, | 226 const GURL& resolved_url, |
| 227 const GURL& requestor_url, | |
| 228 ServiceProviderPtr service_provider, | |
| 255 ApplicationLoader* loader) { | 229 ApplicationLoader* loader) { |
| 230 ShellImpl* shell = nullptr; | |
| 256 URLToShellImplMap::const_iterator shell_it = | 231 URLToShellImplMap::const_iterator shell_it = |
| 257 url_to_shell_impl_.find(resolved_url); | 232 url_to_shell_impl_.find(resolved_url); |
| 258 if (shell_it != url_to_shell_impl_.end()) { | 233 if (shell_it != url_to_shell_impl_.end()) { |
| 259 ConnectToClient(shell_it->second, resolved_url, requestor_url, | 234 shell = shell_it->second; |
| 260 service_provider.Pass()); | 235 } else { |
| 261 return; | 236 MessagePipe pipe; |
| 237 shell = | |
| 238 new ShellImpl(pipe.handle0.Pass(), this, requested_url, resolved_url); | |
|
Aaron Boodman
2014/11/19 01:47:24
Argh, I just realized we can't make this simplific
qsr
2014/11/19 13:42:37
I guess you mean it has to be treated identically
Aaron Boodman
2014/11/19 15:58:15
Yes.
qsr
2014/11/19 16:37:21
Only for content handled app. For usual app, we ha
Aaron Boodman
2014/11/20 00:59:01
OK, I don't follow exactly why this changes whethe
| |
| 239 url_to_shell_impl_[resolved_url] = shell; | |
| 240 shell->client()->Initialize(GetArgsForURL(requested_url)); | |
| 241 | |
| 242 scoped_refptr<LoadCallbacksImpl> callbacks( | |
| 243 new LoadCallbacksImpl(weak_ptr_factory_.GetWeakPtr())); | |
| 244 loader->Load(this, resolved_url, pipe.handle1.Pass(), callbacks); | |
| 262 } | 245 } |
| 263 | 246 ConnectToClient(shell, resolved_url, requestor_url, service_provider.Pass()); |
| 264 scoped_refptr<LoadCallbacksImpl> callbacks( | |
| 265 new LoadCallbacksImpl(weak_ptr_factory_.GetWeakPtr(), | |
| 266 requested_url, | |
| 267 resolved_url, | |
| 268 requestor_url, | |
| 269 service_provider.Pass())); | |
| 270 loader->Load(this, resolved_url, callbacks); | |
| 271 } | 247 } |
| 272 | 248 |
| 273 void ApplicationManager::ConnectToClient(ShellImpl* shell_impl, | 249 void ApplicationManager::ConnectToClient(ShellImpl* shell_impl, |
| 274 const GURL& url, | 250 const GURL& url, |
| 275 const GURL& requestor_url, | 251 const GURL& requestor_url, |
| 276 ServiceProviderPtr service_provider) { | 252 ServiceProviderPtr service_provider) { |
| 277 if (interceptor_) { | 253 if (interceptor_) { |
| 278 shell_impl->ConnectToClient( | 254 shell_impl->ConnectToClient( |
| 279 requestor_url, | 255 requestor_url, |
| 280 interceptor_->OnConnectToClient(url, service_provider.Pass())); | 256 interceptor_->OnConnectToClient(url, service_provider.Pass())); |
| 281 } else { | 257 } else { |
| 282 shell_impl->ConnectToClient(requestor_url, service_provider.Pass()); | 258 shell_impl->ConnectToClient(requestor_url, service_provider.Pass()); |
| 283 } | 259 } |
| 284 } | 260 } |
| 285 | 261 |
| 286 void ApplicationManager::RegisterExternalApplication( | 262 void ApplicationManager::RegisterExternalApplication( |
| 287 const GURL& url, | 263 const GURL& url, |
| 288 ScopedMessagePipeHandle shell_handle) { | 264 ScopedMessagePipeHandle shell_handle) { |
| 289 ShellImpl* shell_impl = new ShellImpl(shell_handle.Pass(), this, url, url); | 265 ShellImpl* shell_impl = new ShellImpl(shell_handle.Pass(), this, url, url); |
| 290 url_to_shell_impl_[url] = shell_impl; | 266 url_to_shell_impl_[url] = shell_impl; |
| 291 | 267 |
| 292 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); | 268 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); |
| 293 Array<String> args; | 269 Array<String> args; |
| 294 if (args_it != url_to_args_.end()) | 270 if (args_it != url_to_args_.end()) |
| 295 args = Array<String>::From(args_it->second); | 271 args = Array<String>::From(args_it->second); |
| 296 shell_impl->client()->Initialize(args.Pass()); | 272 shell_impl->client()->Initialize(args.Pass()); |
| 297 } | 273 } |
| 298 | 274 |
| 299 void ApplicationManager::RegisterLoadedApplication( | |
| 300 const GURL& requested_url, | |
| 301 const GURL& resolved_url, | |
| 302 const GURL& requestor_url, | |
| 303 ServiceProviderPtr service_provider, | |
| 304 ScopedMessagePipeHandle* shell_handle) { | |
| 305 ShellImpl* shell_impl = NULL; | |
| 306 URLToShellImplMap::iterator iter = url_to_shell_impl_.find(resolved_url); | |
| 307 if (iter != url_to_shell_impl_.end()) { | |
| 308 // This can happen because services are loaded asynchronously. So if we get | |
| 309 // two requests for the same service close to each other, we might get here | |
| 310 // and find that we already have it. | |
| 311 shell_impl = iter->second; | |
| 312 } else { | |
| 313 MessagePipe pipe; | |
| 314 shell_impl = | |
| 315 new ShellImpl(pipe.handle1.Pass(), this, requested_url, resolved_url); | |
| 316 url_to_shell_impl_[resolved_url] = shell_impl; | |
| 317 *shell_handle = pipe.handle0.Pass(); | |
| 318 shell_impl->client()->Initialize(GetArgsForURL(requested_url)); | |
| 319 } | |
| 320 | |
| 321 ConnectToClient(shell_impl, resolved_url, requestor_url, | |
| 322 service_provider.Pass()); | |
| 323 } | |
| 324 | |
| 325 void ApplicationManager::LoadWithContentHandler( | 275 void ApplicationManager::LoadWithContentHandler( |
| 326 const GURL& requested_url, | |
| 327 const GURL& resolved_url, | |
| 328 const GURL& requestor_url, | |
| 329 const GURL& content_handler_url, | 276 const GURL& content_handler_url, |
| 330 URLResponsePtr url_response, | 277 ScopedMessagePipeHandle shell_handle, |
| 331 ServiceProviderPtr service_provider) { | 278 URLResponsePtr url_response) { |
| 332 ContentHandlerConnection* connection = NULL; | 279 ContentHandlerConnection* connection = NULL; |
| 333 URLToContentHandlerMap::iterator iter = | 280 URLToContentHandlerMap::iterator iter = |
| 334 url_to_content_handler_.find(content_handler_url); | 281 url_to_content_handler_.find(content_handler_url); |
| 335 if (iter != url_to_content_handler_.end()) { | 282 if (iter != url_to_content_handler_.end()) { |
| 336 connection = iter->second; | 283 connection = iter->second; |
| 337 } else { | 284 } else { |
| 338 connection = new ContentHandlerConnection(this, content_handler_url); | 285 connection = new ContentHandlerConnection(this, content_handler_url); |
| 339 url_to_content_handler_[content_handler_url] = connection; | 286 url_to_content_handler_[content_handler_url] = connection; |
| 340 } | 287 } |
| 341 | 288 |
| 342 ShellPtr shell_proxy; | 289 connection->content_handler()->StartApplication( |
| 343 ShellImpl* shell_impl = | 290 MakeProxy<Shell>(shell_handle.Pass()), url_response.Pass()); |
| 344 new ShellImpl(&shell_proxy, this, requested_url, resolved_url); | |
| 345 content_shell_impls_.insert(shell_impl); | |
| 346 shell_impl->client()->Initialize(GetArgsForURL(requested_url)); | |
| 347 | |
| 348 connection->content_handler()->StartApplication(shell_proxy.Pass(), | |
| 349 url_response.Pass()); | |
| 350 ConnectToClient( | |
| 351 shell_impl, resolved_url, requestor_url, service_provider.Pass()); | |
| 352 } | 291 } |
| 353 | 292 |
| 354 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, | 293 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, |
| 355 const GURL& url) { | 294 const GURL& url) { |
| 356 URLToLoaderMap::iterator it = url_to_loader_.find(url); | 295 URLToLoaderMap::iterator it = url_to_loader_.find(url); |
| 357 if (it != url_to_loader_.end()) | 296 if (it != url_to_loader_.end()) |
| 358 delete it->second; | 297 delete it->second; |
| 359 url_to_loader_[url] = loader.release(); | 298 url_to_loader_[url] = loader.release(); |
| 360 } | 299 } |
| 361 | 300 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 return pipe.handle0.Pass(); | 374 return pipe.handle0.Pass(); |
| 436 } | 375 } |
| 437 | 376 |
| 438 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { | 377 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { |
| 439 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); | 378 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); |
| 440 if (args_it != url_to_args_.end()) | 379 if (args_it != url_to_args_.end()) |
| 441 return Array<String>::From(args_it->second); | 380 return Array<String>::From(args_it->second); |
| 442 return Array<String>(); | 381 return Array<String>(); |
| 443 } | 382 } |
| 444 } // namespace mojo | 383 } // namespace mojo |
| OLD | NEW |