| 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_SHELL_SERVICE_CONNECTOR_H_ | 5 #ifndef MOJO_SHELL_SERVICE_CONNECTOR_H_ |
| 6 #define MOJO_SHELL_SERVICE_CONNECTOR_H_ | 6 #define MOJO_SHELL_SERVICE_CONNECTOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // specific url. | 21 // specific url. |
| 22 class Loader { | 22 class Loader { |
| 23 public: | 23 public: |
| 24 virtual ~Loader(); | 24 virtual ~Loader(); |
| 25 virtual void Load(const GURL& url, | 25 virtual void Load(const GURL& url, |
| 26 ScopedMessagePipeHandle service_handle) = 0; | 26 ScopedMessagePipeHandle service_handle) = 0; |
| 27 protected: | 27 protected: |
| 28 Loader(); | 28 Loader(); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 // API for testing. |
| 32 class TestAPI { |
| 33 private: |
| 34 friend class ServiceConnectorTest; |
| 35 explicit TestAPI(ServiceConnector* connector) : connector_(connector) {} |
| 36 // Returns true if there is a ServiceFactory for this URL. |
| 37 bool HasFactoryForURL(const GURL& url) const; |
| 38 |
| 39 ServiceConnector* connector_; |
| 40 }; |
| 41 |
| 31 ServiceConnector(); | 42 ServiceConnector(); |
| 32 ~ServiceConnector(); | 43 ~ServiceConnector(); |
| 33 | 44 |
| 34 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). | 45 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). |
| 35 // Does not take ownership of |loader|. | 46 // Does not take ownership of |loader|. |
| 36 void set_default_loader(Loader* loader) { default_loader_ = loader; } | 47 void set_default_loader(Loader* loader) { default_loader_ = loader; } |
| 37 // Sets a Loader to be used for a specific url. | 48 // Sets a Loader to be used for a specific url. |
| 38 // Does not take ownership of |loader|. | 49 // Does not take ownership of |loader|. |
| 39 void SetLoaderForURL(Loader* loader, const GURL& gurl); | 50 void SetLoaderForURL(Loader* loader, const GURL& gurl); |
| 40 // Returns the Loader to use for a url (using default if not overridden.) | 51 // Returns the Loader to use for a url (using default if not overridden.) |
| 41 Loader* GetLoaderForURL(const GURL& gurl); | 52 Loader* GetLoaderForURL(const GURL& gurl); |
| 42 // Loads a service if necessary and establishes a new client connection. | 53 // Loads a service if necessary and establishes a new client connection. |
| 43 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); | 54 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); |
| 44 | |
| 45 private: | 55 private: |
| 46 class ServiceFactory; | 56 class ServiceFactory; |
| 47 | 57 |
| 58 // Removes a ServiceFactory when it no longer has any connections. |
| 59 void RemoveServiceFactory(ServiceFactory* service_factory); |
| 60 |
| 48 Loader* default_loader_; | 61 Loader* default_loader_; |
| 49 typedef std::map<GURL, ServiceFactory*> ServiceFactoryMap; | 62 typedef std::map<GURL, ServiceFactory*> ServiceFactoryMap; |
| 50 ServiceFactoryMap url_to_service_factory_; | 63 ServiceFactoryMap url_to_service_factory_; |
| 51 typedef std::map<GURL, Loader*> LoaderMap; | 64 typedef std::map<GURL, Loader*> LoaderMap; |
| 52 LoaderMap url_to_loader_; | 65 LoaderMap url_to_loader_; |
| 53 DISALLOW_COPY_AND_ASSIGN(ServiceConnector); | 66 DISALLOW_COPY_AND_ASSIGN(ServiceConnector); |
| 54 }; | 67 }; |
| 55 | 68 |
| 56 } // namespace shell | 69 } // namespace shell |
| 57 } // namespace mojo | 70 } // namespace mojo |
| 58 | 71 |
| 59 #endif // MOJO_SHELL_SERVICE_CONNECTOR_H_ | 72 #endif // MOJO_SHELL_SERVICE_CONNECTOR_H_ |
| OLD | NEW |