| OLD | NEW |
| 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 #ifndef MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ | 5 #ifndef MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ |
| 6 #define MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ | 6 #define MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 explicit TestAPI(ServiceManager* manager) : manager_(manager) {} | 33 explicit TestAPI(ServiceManager* manager) : manager_(manager) {} |
| 34 // Returns true if the shared instance has been created. | 34 // Returns true if the shared instance has been created. |
| 35 static bool HasCreatedInstance(); | 35 static bool HasCreatedInstance(); |
| 36 // Returns true if there is a ServiceFactory for this URL. | 36 // Returns true if there is a ServiceFactory for this URL. |
| 37 bool HasFactoryForURL(const GURL& url) const; | 37 bool HasFactoryForURL(const GURL& url) const; |
| 38 | 38 |
| 39 ServiceManager* manager_; | 39 ServiceManager* manager_; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // Interface class for debugging only. |
| 43 class Interceptor { |
| 44 public: |
| 45 virtual ~Interceptor() {} |
| 46 // Called when ServiceManager::Connect is called. |
| 47 virtual ScopedMessagePipeHandle OnConnectToClient( |
| 48 const GURL& url, ScopedMessagePipeHandle handle) = 0; |
| 49 }; |
| 50 |
| 42 ServiceManager(); | 51 ServiceManager(); |
| 43 ~ServiceManager(); | 52 ~ServiceManager(); |
| 44 | 53 |
| 45 // Returns a shared instance, creating it if necessary. | 54 // Returns a shared instance, creating it if necessary. |
| 46 static ServiceManager* GetInstance(); | 55 static ServiceManager* GetInstance(); |
| 47 | 56 |
| 48 // Loads a service if necessary and establishes a new client connection. | 57 // Loads a service if necessary and establishes a new client connection. |
| 49 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); | 58 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); |
| 50 | 59 |
| 51 // Sets the default Loader to be used if not overridden by | 60 // Sets the default Loader to be used if not overridden by |
| 52 // SetLoaderForURL() or SetLoaderForScheme(). | 61 // SetLoaderForURL() or SetLoaderForScheme(). |
| 53 // Does not take ownership of |loader|. | 62 // Does not take ownership of |loader|. |
| 54 void set_default_loader(ServiceLoader* loader) { default_loader_ = loader; } | 63 void set_default_loader(ServiceLoader* loader) { default_loader_ = loader; } |
| 55 // Sets a Loader to be used for a specific url. | 64 // Sets a Loader to be used for a specific url. |
| 56 // Does not take ownership of |loader|. | 65 // Does not take ownership of |loader|. |
| 57 void SetLoaderForURL(ServiceLoader* loader, const GURL& url); | 66 void SetLoaderForURL(ServiceLoader* loader, const GURL& url); |
| 58 // Sets a Loader to be used for a specific url scheme. | 67 // Sets a Loader to be used for a specific url scheme. |
| 59 // Does not take ownership of |loader|. | 68 // Does not take ownership of |loader|. |
| 60 void SetLoaderForScheme(ServiceLoader* loader, const std::string& scheme); | 69 void SetLoaderForScheme(ServiceLoader* loader, const std::string& scheme); |
| 70 // Allows to interpose a debugger to service connections. |
| 71 void SetInterceptor(Interceptor* interceptor); |
| 61 | 72 |
| 62 private: | 73 private: |
| 63 class ServiceFactory; | 74 class ServiceFactory; |
| 64 typedef std::map<std::string, ServiceLoader*> SchemeToLoaderMap; | 75 typedef std::map<std::string, ServiceLoader*> SchemeToLoaderMap; |
| 65 typedef std::map<GURL, ServiceLoader*> URLToLoaderMap; | 76 typedef std::map<GURL, ServiceLoader*> URLToLoaderMap; |
| 66 typedef std::map<GURL, ServiceFactory*> URLToServiceFactoryMap; | 77 typedef std::map<GURL, ServiceFactory*> URLToServiceFactoryMap; |
| 67 | 78 |
| 68 // Returns the Loader to use for a url (using default if not overridden.) | 79 // Returns the Loader to use for a url (using default if not overridden.) |
| 69 // The preference is to use a loader that's been specified for an url first, | 80 // The preference is to use a loader that's been specified for an url first, |
| 70 // then one that's been specified for a scheme, then the default. | 81 // then one that's been specified for a scheme, then the default. |
| 71 ServiceLoader* GetLoaderForURL(const GURL& url); | 82 ServiceLoader* GetLoaderForURL(const GURL& url); |
| 72 | 83 |
| 73 // Removes a ServiceFactory when it no longer has any connections. | 84 // Removes a ServiceFactory when it no longer has any connections. |
| 74 void OnServiceFactoryError(ServiceFactory* service_factory); | 85 void OnServiceFactoryError(ServiceFactory* service_factory); |
| 75 | 86 |
| 76 // Loader management. | 87 // Loader management. |
| 77 URLToLoaderMap url_to_loader_; | 88 URLToLoaderMap url_to_loader_; |
| 78 SchemeToLoaderMap scheme_to_loader_; | 89 SchemeToLoaderMap scheme_to_loader_; |
| 79 ServiceLoader* default_loader_; | 90 ServiceLoader* default_loader_; |
| 91 Interceptor* interceptor_; |
| 80 | 92 |
| 81 URLToServiceFactoryMap url_to_service_factory_; | 93 URLToServiceFactoryMap url_to_service_factory_; |
| 82 DISALLOW_COPY_AND_ASSIGN(ServiceManager); | 94 DISALLOW_COPY_AND_ASSIGN(ServiceManager); |
| 83 }; | 95 }; |
| 84 | 96 |
| 85 } // namespace mojo | 97 } // namespace mojo |
| 86 | 98 |
| 87 #endif // MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ | 99 #endif // MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ |
| OLD | NEW |