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" |
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 "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 13 #include "mojo/public/interfaces/shell/shell.mojom.h" |
14 #include "mojo/service_manager/service_loader.h" | 14 #include "mojo/service_manager/service_loader.h" |
15 #include "mojo/service_manager/service_manager_export.h" | 15 #include "mojo/service_manager/service_manager_export.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace mojo { | 18 namespace mojo { |
19 | 19 |
20 class MOJO_SERVICE_MANAGER_EXPORT ServiceManager { | 20 class MOJO_SERVICE_MANAGER_EXPORT ServiceManager { |
21 public: | 21 public: |
22 // API for testing. | 22 // API for testing. |
23 class MOJO_SERVICE_MANAGER_EXPORT TestAPI { | 23 class MOJO_SERVICE_MANAGER_EXPORT TestAPI { |
24 public: | 24 public: |
25 explicit TestAPI(ServiceManager* manager); | 25 explicit TestAPI(ServiceManager* manager); |
26 ~TestAPI(); | 26 ~TestAPI(); |
27 | 27 |
28 // Returns a handle to a unique ServiceProvider instance. | 28 // Returns a handle to a unique shell instance. |
29 ScopedMessagePipeHandle GetServiceProviderHandle(); | 29 ScopedMessagePipeHandle GetShellHandle(); |
30 | 30 |
31 // Returns true if the shared instance has been created. | 31 // Returns true if the shared instance has been created. |
32 static bool HasCreatedInstance(); | 32 static bool HasCreatedInstance(); |
33 // Returns true if there is a ServiceFactory for this URL. | 33 // Returns true if there is a ServiceFactory for this URL. |
34 bool HasFactoryForURL(const GURL& url) const; | 34 bool HasFactoryForURL(const GURL& url) const; |
35 | 35 |
36 private: | 36 private: |
37 class TestServiceProviderConnection; | 37 class TestShellConnection; |
38 | 38 |
39 ServiceManager* manager_; | 39 ServiceManager* manager_; |
40 scoped_ptr<TestServiceProviderConnection> service_provider_; | 40 scoped_ptr<TestShellConnection> shell_; |
41 | 41 |
42 DISALLOW_COPY_AND_ASSIGN(TestAPI); | 42 DISALLOW_COPY_AND_ASSIGN(TestAPI); |
43 }; | 43 }; |
44 | 44 |
45 // Interface class for debugging only. | 45 // Interface class for debugging only. |
46 class Interceptor { | 46 class Interceptor { |
47 public: | 47 public: |
48 virtual ~Interceptor() {} | 48 virtual ~Interceptor() {} |
49 // Called when ServiceManager::Connect is called. | 49 // Called when ServiceManager::Connect is called. |
50 virtual ScopedMessagePipeHandle OnConnectToClient( | 50 virtual ScopedMessagePipeHandle OnConnectToClient( |
51 const GURL& url, ScopedMessagePipeHandle handle) = 0; | 51 const GURL& url, ScopedMessagePipeHandle handle) = 0; |
52 }; | 52 }; |
53 | 53 |
54 ServiceManager(); | 54 ServiceManager(); |
55 ~ServiceManager(); | 55 ~ServiceManager(); |
56 | 56 |
57 // Returns a shared instance, creating it if necessary. | 57 // Returns a shared instance, creating it if necessary. |
58 static ServiceManager* GetInstance(); | 58 static ServiceManager* GetInstance(); |
59 | 59 |
60 // Loads a service if necessary and establishes a new client connection. | 60 // Loads a service if necessary and establishes a new client connection. |
61 void ConnectToService(const GURL& url, ScopedMessagePipeHandle client_handle); | 61 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); |
62 | 62 |
63 // Sets the default Loader to be used if not overridden by SetLoaderForURL() | 63 // Sets the default Loader to be used if not overridden by SetLoaderForURL() |
64 // or SetLoaderForScheme(). | 64 // or SetLoaderForScheme(). |
65 void set_default_loader(scoped_ptr<ServiceLoader> loader) { | 65 void set_default_loader(scoped_ptr<ServiceLoader> loader) { |
66 default_loader_ = loader.Pass(); | 66 default_loader_ = loader.Pass(); |
67 } | 67 } |
68 // Sets a Loader to be used for a specific url. | 68 // Sets a Loader to be used for a specific url. |
69 void SetLoaderForURL(scoped_ptr<ServiceLoader> loader, const GURL& url); | 69 void SetLoaderForURL(scoped_ptr<ServiceLoader> loader, const GURL& url); |
70 // Sets a Loader to be used for a specific url scheme. | 70 // Sets a Loader to be used for a specific url scheme. |
71 void SetLoaderForScheme(scoped_ptr<ServiceLoader> loader, | 71 void SetLoaderForScheme(scoped_ptr<ServiceLoader> loader, |
(...skipping 21 matching lines...) Expand all Loading... |
93 scoped_ptr<ServiceLoader> default_loader_; | 93 scoped_ptr<ServiceLoader> default_loader_; |
94 Interceptor* interceptor_; | 94 Interceptor* interceptor_; |
95 | 95 |
96 URLToServiceFactoryMap url_to_service_factory_; | 96 URLToServiceFactoryMap url_to_service_factory_; |
97 DISALLOW_COPY_AND_ASSIGN(ServiceManager); | 97 DISALLOW_COPY_AND_ASSIGN(ServiceManager); |
98 }; | 98 }; |
99 | 99 |
100 } // namespace mojo | 100 } // namespace mojo |
101 | 101 |
102 #endif // MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ | 102 #endif // MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_ |
OLD | NEW |