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