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 MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_ | 5 #ifndef MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_ |
6 #define MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_ | 6 #define MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_ |
7 | 7 |
| 8 #include "base/memory/ref_counted.h" |
8 #include "mojo/public/cpp/system/core.h" | 9 #include "mojo/public/cpp/system/core.h" |
9 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
10 #include "mojo/service_manager/service_manager_export.h" | 11 #include "mojo/service_manager/service_manager_export.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 namespace mojo { | 14 namespace mojo { |
14 | 15 |
15 class ServiceManager; | 16 class ServiceManager; |
16 | 17 |
17 // Interface to allowing loading behavior to be established for schemes, | 18 // Interface to allowing loading behavior to be established for schemes, |
18 // specific urls or as the default. | 19 // specific urls or as the default. |
19 // A ServiceLoader is responsible to using whatever mechanism is appropriate | 20 // A ServiceLoader is responsible to using whatever mechanism is appropriate |
20 // to load the application at url. | 21 // to load the application at url. |
21 // TODO(davemoore): change name to ApplicationLoader. | 22 // TODO(davemoore): change name to ApplicationLoader. |
22 // The handle to the shell is passed to that application so it can bind it to | 23 // The handle to the shell is passed to that application so it can bind it to |
23 // a Shell instance. This will give the Application a way to connect to other | 24 // a Shell instance. This will give the Application a way to connect to other |
24 // apps and services. | 25 // apps and services. |
25 class MOJO_SERVICE_MANAGER_EXPORT ServiceLoader { | 26 class MOJO_SERVICE_MANAGER_EXPORT ServiceLoader { |
26 public: | 27 public: |
| 28 class LoadServiceCallbacks : public base::RefCounted<LoadServiceCallbacks> { |
| 29 public: |
| 30 // Register the requested application with ServiceManager. If the returned |
| 31 // handle is valid, it should be used to implement the mojo::Application |
| 32 // interface. |
| 33 virtual ScopedMessagePipeHandle RegisterApplication() = 0; |
| 34 |
| 35 // Load the requested application with a content handler. |
| 36 virtual void LoadWithContentHandler( |
| 37 const GURL& content_handler_url, |
| 38 ScopedDataPipeConsumerHandle content) = 0; |
| 39 protected: |
| 40 friend base::RefCounted<LoadServiceCallbacks>; |
| 41 virtual ~LoadServiceCallbacks() {} |
| 42 }; |
| 43 |
| 44 // Implements RegisterApplication() by returning a handle that was specified |
| 45 // at construction time. LoadWithContentHandler() is not supported. |
| 46 class SimpleLoadServiceCallbacks : public LoadServiceCallbacks { |
| 47 public: |
| 48 SimpleLoadServiceCallbacks(ScopedMessagePipeHandle shell_handle); |
| 49 virtual ScopedMessagePipeHandle RegisterApplication() OVERRIDE; |
| 50 virtual void LoadWithContentHandler( |
| 51 const GURL& content_handler_url, |
| 52 ScopedDataPipeConsumerHandle content) OVERRIDE; |
| 53 private: |
| 54 ScopedMessagePipeHandle shell_handle_; |
| 55 virtual ~SimpleLoadServiceCallbacks(); |
| 56 }; |
| 57 |
27 virtual ~ServiceLoader() {} | 58 virtual ~ServiceLoader() {} |
28 virtual void LoadService(ServiceManager* manager, | 59 |
| 60 // Load the application named |url|. Applications can be loaded two ways: |
| 61 // |
| 62 // 1. |url| can refer directly to a Mojo application. In this case, call |
| 63 // callbacks->RegisterApplication(). The returned handle should be used to |
| 64 // implement the mojo.Application interface. Note that the returned handle |
| 65 // can be invalid in the case where the application has already been |
| 66 // loaded. |
| 67 // |
| 68 // 2. |url| can refer to some content that can be handled by some other Mojo |
| 69 // application. In this case, call callbacks->LoadWithContentHandler() and |
| 70 // specify the URL of the application that should handle the content. |
| 71 // The specified application must implement the mojo.ContentHandler |
| 72 // interface. |
| 73 virtual void LoadService(ServiceManager* service_manager, |
29 const GURL& url, | 74 const GURL& url, |
30 ScopedMessagePipeHandle shell_handle) = 0; | 75 scoped_refptr<LoadServiceCallbacks> callbacks) = 0; |
| 76 |
31 virtual void OnServiceError(ServiceManager* manager, const GURL& url) = 0; | 77 virtual void OnServiceError(ServiceManager* manager, const GURL& url) = 0; |
32 | 78 |
33 protected: | 79 protected: |
34 ServiceLoader() {} | 80 ServiceLoader() {} |
35 }; | 81 }; |
36 | 82 |
37 } // namespace mojo | 83 } // namespace mojo |
38 | 84 |
39 #endif // MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_ | 85 #endif // MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_ |
OLD | NEW |