| 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 #ifndef MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ | 5 #ifndef MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ |
| 6 #define MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ | 6 #define MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "mojo/application_manager/application_loader.h" | 14 #include "mojo/application_manager/application_loader.h" |
| 15 #include "mojo/application_manager/application_manager_export.h" | 15 #include "mojo/application_manager/application_manager_export.h" |
| 16 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 16 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 namespace mojo { | 19 namespace mojo { |
| 20 | 20 |
| 21 class MOJO_APPLICATION_MANAGER_EXPORT ApplicationManager { | 21 class MOJO_APPLICATION_MANAGER_EXPORT ApplicationManager { |
| 22 public: | 22 public: |
| 23 class Delegate { |
| 24 public: |
| 25 virtual void OnServiceError(const GURL& url) = 0; |
| 26 }; |
| 27 |
| 23 // API for testing. | 28 // API for testing. |
| 24 class MOJO_APPLICATION_MANAGER_EXPORT TestAPI { | 29 class MOJO_APPLICATION_MANAGER_EXPORT TestAPI { |
| 25 public: | 30 public: |
| 26 explicit TestAPI(ApplicationManager* manager); | 31 explicit TestAPI(ApplicationManager* manager); |
| 27 ~TestAPI(); | 32 ~TestAPI(); |
| 28 | 33 |
| 29 // Returns true if the shared instance has been created. | 34 // Returns true if the shared instance has been created. |
| 30 static bool HasCreatedInstance(); | 35 static bool HasCreatedInstance(); |
| 31 // Returns true if there is a ShellImpl for this URL. | 36 // Returns true if there is a ShellImpl for this URL. |
| 32 bool HasFactoryForURL(const GURL& url) const; | 37 bool HasFactoryForURL(const GURL& url) const; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 63 InterfacePtr<Interface>* ptr) { | 68 InterfacePtr<Interface>* ptr) { |
| 64 ScopedMessagePipeHandle service_handle = | 69 ScopedMessagePipeHandle service_handle = |
| 65 ConnectToServiceByName(application_url, Interface::Name_); | 70 ConnectToServiceByName(application_url, Interface::Name_); |
| 66 ptr->Bind(service_handle.Pass()); | 71 ptr->Bind(service_handle.Pass()); |
| 67 } | 72 } |
| 68 | 73 |
| 69 ScopedMessagePipeHandle ConnectToServiceByName( | 74 ScopedMessagePipeHandle ConnectToServiceByName( |
| 70 const GURL& application_url, | 75 const GURL& application_url, |
| 71 const std::string& interface_name); | 76 const std::string& interface_name); |
| 72 | 77 |
| 78 void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
| 79 |
| 73 // Sets the default Loader to be used if not overridden by SetLoaderForURL() | 80 // Sets the default Loader to be used if not overridden by SetLoaderForURL() |
| 74 // or SetLoaderForScheme(). | 81 // or SetLoaderForScheme(). |
| 75 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { | 82 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { |
| 76 default_loader_ = loader.Pass(); | 83 default_loader_ = loader.Pass(); |
| 77 } | 84 } |
| 78 // Sets a Loader to be used for a specific url. | 85 // Sets a Loader to be used for a specific url. |
| 79 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); | 86 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); |
| 80 // Sets a Loader to be used for a specific url scheme. | 87 // Sets a Loader to be used for a specific url scheme. |
| 81 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, | 88 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, |
| 82 const std::string& scheme); | 89 const std::string& scheme); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 ServiceProviderPtr service_provider); | 122 ServiceProviderPtr service_provider); |
| 116 | 123 |
| 117 // Returns the Loader to use for a url (using default if not overridden.) | 124 // Returns the Loader to use for a url (using default if not overridden.) |
| 118 // The preference is to use a loader that's been specified for an url first, | 125 // The preference is to use a loader that's been specified for an url first, |
| 119 // then one that's been specified for a scheme, then the default. | 126 // then one that's been specified for a scheme, then the default. |
| 120 ApplicationLoader* GetLoaderForURL(const GURL& url); | 127 ApplicationLoader* GetLoaderForURL(const GURL& url); |
| 121 | 128 |
| 122 // Removes a ShellImpl when it encounters an error. | 129 // Removes a ShellImpl when it encounters an error. |
| 123 void OnShellImplError(ShellImpl* shell_impl); | 130 void OnShellImplError(ShellImpl* shell_impl); |
| 124 | 131 |
| 132 Delegate* delegate_; |
| 125 // Loader management. | 133 // Loader management. |
| 126 URLToLoaderMap url_to_loader_; | 134 URLToLoaderMap url_to_loader_; |
| 127 SchemeToLoaderMap scheme_to_loader_; | 135 SchemeToLoaderMap scheme_to_loader_; |
| 128 scoped_ptr<ApplicationLoader> default_loader_; | 136 scoped_ptr<ApplicationLoader> default_loader_; |
| 129 Interceptor* interceptor_; | 137 Interceptor* interceptor_; |
| 130 | 138 |
| 131 URLToShellImplMap url_to_shell_impl_; | 139 URLToShellImplMap url_to_shell_impl_; |
| 132 URLToContentHandlerMap url_to_content_handler_; | 140 URLToContentHandlerMap url_to_content_handler_; |
| 133 | 141 |
| 134 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 142 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
| 135 | 143 |
| 136 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 144 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
| 137 }; | 145 }; |
| 138 | 146 |
| 139 } // namespace mojo | 147 } // namespace mojo |
| 140 | 148 |
| 141 #endif // MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ | 149 #endif // MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ |
| OLD | NEW |