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