| 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 SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ | 5 #ifndef SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ |
| 6 #define SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ | 6 #define SHELL_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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace mojo { | 29 namespace mojo { |
| 30 | 30 |
| 31 // ApplicationManager requires implementations of NativeRunner and | 31 // ApplicationManager requires implementations of NativeRunner and |
| 32 // NativeRunnerFactory to run native applications. | 32 // NativeRunnerFactory to run native applications. |
| 33 class NativeRunner { | 33 class NativeRunner { |
| 34 public: | 34 public: |
| 35 // Parameter for |Start()| to specify its cleanup behavior. | 35 // Parameter for |Start()| to specify its cleanup behavior. |
| 36 enum CleanupBehavior { DeleteAppPath, DontDeleteAppPath }; | 36 enum CleanupBehavior { DeleteAppPath, DontDeleteAppPath }; |
| 37 |
| 37 virtual ~NativeRunner() {} | 38 virtual ~NativeRunner() {} |
| 38 | 39 |
| 39 // Loads the app in the file at |app_path| and runs it on some other | 40 // Loads the app in the file at |app_path| and runs it on some other |
| 40 // thread/process. If |cleanup_behavior| is |true|, takes ownership of the | 41 // thread/process. If |cleanup_behavior| is |true|, takes ownership of the |
| 41 // file. |app_completed_callback| is posted (to the thread on which |Start()| | 42 // file. |app_completed_callback| is posted (to the thread on which |Start()| |
| 42 // was called) after |MojoMain()| completes. | 43 // was called) after |MojoMain()| completes. |
| 44 // TODO(vtl): |app_path| and |cleanup_behavior| should probably be moved to |
| 45 // the factory's Create(). Rationale: The factory may need information from |
| 46 // the file to decide what kind of NativeRunner to make. |
| 43 virtual void Start(const base::FilePath& app_path, | 47 virtual void Start(const base::FilePath& app_path, |
| 44 CleanupBehavior cleanup_behavior, | 48 CleanupBehavior cleanup_behavior, |
| 45 InterfaceRequest<Application> application_request, | 49 InterfaceRequest<Application> application_request, |
| 46 const base::Closure& app_completed_callback) = 0; | 50 const base::Closure& app_completed_callback) = 0; |
| 47 }; | 51 }; |
| 48 | 52 |
| 49 class NativeRunnerFactory { | 53 class NativeRunnerFactory { |
| 50 public: | 54 public: |
| 55 // Options for running the native app. (This will contain, e.g., information |
| 56 // about the sandbox profile, etc.) |
| 57 struct Options { |
| 58 // Constructs with default options. |
| 59 Options() : force_in_process(false) {} |
| 60 |
| 61 bool force_in_process; |
| 62 }; |
| 63 |
| 51 virtual ~NativeRunnerFactory() {} | 64 virtual ~NativeRunnerFactory() {} |
| 52 virtual scoped_ptr<NativeRunner> Create() = 0; | 65 virtual scoped_ptr<NativeRunner> Create(const Options& options) = 0; |
| 53 }; | 66 }; |
| 54 | 67 |
| 55 class ApplicationManager { | 68 class ApplicationManager { |
| 56 public: | 69 public: |
| 57 class Delegate { | 70 class Delegate { |
| 58 public: | 71 public: |
| 59 virtual ~Delegate(); | 72 virtual ~Delegate(); |
| 60 // Send when the Application holding the handle on the other end of the | 73 // Send when the Application holding the handle on the other end of the |
| 61 // Shell pipe goes away. | 74 // Shell pipe goes away. |
| 62 virtual void OnApplicationError(const GURL& url); | 75 virtual void OnApplicationError(const GURL& url); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 133 } |
| 121 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { | 134 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { |
| 122 blocking_pool_ = blocking_pool; | 135 blocking_pool_ = blocking_pool; |
| 123 } | 136 } |
| 124 void set_disable_cache(bool disable_cache) { disable_cache_ = disable_cache; } | 137 void set_disable_cache(bool disable_cache) { disable_cache_ = disable_cache; } |
| 125 // Sets a Loader to be used for a specific url. | 138 // Sets a Loader to be used for a specific url. |
| 126 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); | 139 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); |
| 127 // Sets a Loader to be used for a specific url scheme. | 140 // Sets a Loader to be used for a specific url scheme. |
| 128 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, | 141 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, |
| 129 const std::string& scheme); | 142 const std::string& scheme); |
| 130 // These strings will be passed to the Initialize() method when an | 143 // These strings will be passed to the Initialize() method when an Application |
| 131 // Application is instantiated. | 144 // is instantiated. |
| 145 // TODO(vtl): Maybe we should store/compare resolved URLs, like |
| 146 // SetNativeOptionsForURL() below? |
| 132 void SetArgsForURL(const std::vector<std::string>& args, const GURL& url); | 147 void SetArgsForURL(const std::vector<std::string>& args, const GURL& url); |
| 148 // These options will be used in running any native application at |url|. |
| 149 // (|url| will be mapped and resolved, and any application whose resolved URL |
| 150 // matches it will have |options| applied.) |
| 151 // TODO(vtl): This may not do what's desired if the resolved URL results in an |
| 152 // HTTP redirect. Really, we want options to be identified with a particular |
| 153 // implementation, maybe via a signed manifest or something like that. |
| 154 void SetNativeOptionsForURL(const NativeRunnerFactory::Options& options, |
| 155 const GURL& url); |
| 133 | 156 |
| 134 // Destroys all Shell-ends of connections established with Applications. | 157 // Destroys all Shell-ends of connections established with Applications. |
| 135 // Applications connected by this ApplicationManager will observe pipe errors | 158 // Applications connected by this ApplicationManager will observe pipe errors |
| 136 // and have a chance to shutdown. | 159 // and have a chance to shutdown. |
| 137 void TerminateShellConnections(); | 160 void TerminateShellConnections(); |
| 138 | 161 |
| 139 // Removes a ShellImpl when it encounters an error. | 162 // Removes a ShellImpl when it encounters an error. |
| 140 void OnShellImplError(ShellImpl* shell_impl); | 163 void OnShellImplError(ShellImpl* shell_impl); |
| 141 | 164 |
| 142 private: | 165 private: |
| 143 class ContentHandlerConnection; | 166 class ContentHandlerConnection; |
| 144 | 167 |
| 145 typedef std::map<std::string, ApplicationLoader*> SchemeToLoaderMap; | 168 typedef std::map<std::string, ApplicationLoader*> SchemeToLoaderMap; |
| 146 typedef std::map<GURL, ApplicationLoader*> URLToLoaderMap; | 169 typedef std::map<GURL, ApplicationLoader*> URLToLoaderMap; |
| 147 typedef std::map<GURL, ShellImpl*> URLToShellImplMap; | 170 typedef std::map<GURL, ShellImpl*> URLToShellImplMap; |
| 148 typedef std::map<GURL, ContentHandlerConnection*> URLToContentHandlerMap; | 171 typedef std::map<GURL, ContentHandlerConnection*> URLToContentHandlerMap; |
| 149 typedef std::map<GURL, std::vector<std::string>> URLToArgsMap; | 172 typedef std::map<GURL, std::vector<std::string>> URLToArgsMap; |
| 150 typedef std::map<std::string, GURL> MimeTypeToURLMap; | 173 typedef std::map<std::string, GURL> MimeTypeToURLMap; |
| 174 typedef std::map<GURL, NativeRunnerFactory::Options> URLToNativeOptionsMap; |
| 151 | 175 |
| 152 bool ConnectToRunningApplication(const GURL& resolved_url, | 176 bool ConnectToRunningApplication(const GURL& resolved_url, |
| 153 const GURL& requestor_url, | 177 const GURL& requestor_url, |
| 154 InterfaceRequest<ServiceProvider>* services, | 178 InterfaceRequest<ServiceProvider>* services, |
| 155 ServiceProviderPtr* exposed_services); | 179 ServiceProviderPtr* exposed_services); |
| 156 | 180 |
| 157 bool ConnectToApplicationWithLoader( | 181 bool ConnectToApplicationWithLoader( |
| 158 const GURL& requested_url, | 182 const GURL& requested_url, |
| 159 const GURL& resolved_url, | 183 const GURL& resolved_url, |
| 160 const GURL& requestor_url, | 184 const GURL& requestor_url, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 182 ServiceProviderPtr exposed_services); | 206 ServiceProviderPtr exposed_services); |
| 183 | 207 |
| 184 void HandleFetchCallback(const GURL& requested_url, | 208 void HandleFetchCallback(const GURL& requested_url, |
| 185 const GURL& requestor_url, | 209 const GURL& requestor_url, |
| 186 InterfaceRequest<ServiceProvider> services, | 210 InterfaceRequest<ServiceProvider> services, |
| 187 ServiceProviderPtr exposed_services, | 211 ServiceProviderPtr exposed_services, |
| 188 NativeRunner::CleanupBehavior cleanup_behavior, | 212 NativeRunner::CleanupBehavior cleanup_behavior, |
| 189 scoped_ptr<Fetcher> fetcher); | 213 scoped_ptr<Fetcher> fetcher); |
| 190 | 214 |
| 191 void RunNativeApplication(InterfaceRequest<Application> application_request, | 215 void RunNativeApplication(InterfaceRequest<Application> application_request, |
| 216 const NativeRunnerFactory::Options& options, |
| 192 NativeRunner::CleanupBehavior cleanup_behavior, | 217 NativeRunner::CleanupBehavior cleanup_behavior, |
| 193 scoped_ptr<Fetcher> fetcher, | 218 scoped_ptr<Fetcher> fetcher, |
| 194 const base::FilePath& file_path, | 219 const base::FilePath& file_path, |
| 195 bool path_exists); | 220 bool path_exists); |
| 196 | 221 |
| 197 void LoadWithContentHandler(const GURL& content_handler_url, | 222 void LoadWithContentHandler(const GURL& content_handler_url, |
| 198 InterfaceRequest<Application> application_request, | 223 InterfaceRequest<Application> application_request, |
| 199 URLResponsePtr url_response); | 224 URLResponsePtr url_response); |
| 200 | 225 |
| 201 // Return the appropriate loader for |url|. This can return NULL if there is | 226 // Return the appropriate loader for |url|. This can return NULL if there is |
| 202 // no loader configured for the URL. | 227 // no loader configured for the URL. |
| 203 ApplicationLoader* GetLoaderForURL(const GURL& url); | 228 ApplicationLoader* GetLoaderForURL(const GURL& url); |
| 204 | 229 |
| 205 // Removes a ContentHandler when it encounters an error. | 230 // Removes a ContentHandler when it encounters an error. |
| 206 void OnContentHandlerError(ContentHandlerConnection* content_handler); | 231 void OnContentHandlerError(ContentHandlerConnection* content_handler); |
| 207 | 232 |
| 208 // Returns the arguments for the given url. | 233 // Returns the arguments for the given url. |
| 209 Array<String> GetArgsForURL(const GURL& url); | 234 Array<String> GetArgsForURL(const GURL& url); |
| 210 | 235 |
| 211 void CleanupRunner(NativeRunner* runner); | 236 void CleanupRunner(NativeRunner* runner); |
| 212 | 237 |
| 213 Delegate* delegate_; | 238 Delegate* const delegate_; |
| 214 // Loader management. | 239 // Loader management. |
| 215 // Loaders are chosen in the order they are listed here. | 240 // Loaders are chosen in the order they are listed here. |
| 216 URLToLoaderMap url_to_loader_; | 241 URLToLoaderMap url_to_loader_; |
| 217 SchemeToLoaderMap scheme_to_loader_; | 242 SchemeToLoaderMap scheme_to_loader_; |
| 218 scoped_ptr<ApplicationLoader> default_loader_; | 243 scoped_ptr<ApplicationLoader> default_loader_; |
| 219 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | 244 scoped_ptr<NativeRunnerFactory> native_runner_factory_; |
| 220 | 245 |
| 221 URLToShellImplMap url_to_shell_impl_; | 246 URLToShellImplMap url_to_shell_impl_; |
| 222 URLToContentHandlerMap url_to_content_handler_; | 247 URLToContentHandlerMap url_to_content_handler_; |
| 223 URLToArgsMap url_to_args_; | 248 URLToArgsMap url_to_args_; |
| 249 // Note: The keys are URLs after mapping and resolving. |
| 250 URLToNativeOptionsMap url_to_native_options_; |
| 224 | 251 |
| 225 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 252 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
| 226 | 253 |
| 227 base::SequencedWorkerPool* blocking_pool_; | 254 base::SequencedWorkerPool* blocking_pool_; |
| 228 NetworkServicePtr network_service_; | 255 NetworkServicePtr network_service_; |
| 229 MimeTypeToURLMap mime_type_to_url_; | 256 MimeTypeToURLMap mime_type_to_url_; |
| 230 ScopedVector<NativeRunner> native_runners_; | 257 ScopedVector<NativeRunner> native_runners_; |
| 231 bool disable_cache_; | 258 bool disable_cache_; |
| 232 | 259 |
| 233 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 260 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
| 234 }; | 261 }; |
| 235 | 262 |
| 236 } // namespace mojo | 263 } // namespace mojo |
| 237 | 264 |
| 238 #endif // SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ | 265 #endif // SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ |
| OLD | NEW |