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_SHELL_DYNAMIC_APPLICATION_LOADER_H_ | 5 #ifndef MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ |
6 #define MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ | 6 #define MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "mojo/application_manager/application_loader.h" | 13 #include "mojo/application_manager/application_loader.h" |
14 #include "mojo/public/cpp/system/core.h" | 14 #include "mojo/public/cpp/system/core.h" |
15 #include "mojo/services/public/interfaces/network/network_service.mojom.h" | 15 #include "mojo/services/public/interfaces/network/network_service.mojom.h" |
16 #include "mojo/shell/dynamic_service_runner.h" | 16 #include "mojo/shell/dynamic_service_runner.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace shell { | 20 namespace shell { |
21 | 21 |
22 class Context; | 22 class Context; |
23 class DynamicServiceRunnerFactory; | 23 class DynamicServiceRunnerFactory; |
24 class DynamicServiceRunner; | 24 class DynamicServiceRunner; |
25 | 25 |
| 26 namespace { |
| 27 class Loader; |
| 28 |
| 29 class LoaderDelegate { |
| 30 public: |
| 31 virtual void LoaderComplete(Loader* loader) = 0; |
| 32 virtual scoped_ptr<DynamicServiceRunner> CreateRunner() = 0; |
| 33 virtual void CreateURLLoader(InterfaceRequest<URLLoader> loader_request) = 0; |
| 34 virtual const GURL& GetContentHandlerURL(const std::string& mime_type) = 0; |
| 35 virtual base::SequencedWorkerPool* GetBlockingPool() = 0; |
| 36 virtual ~LoaderDelegate() { |
| 37 } |
| 38 }; |
| 39 |
| 40 } // namespace |
| 41 |
26 // An implementation of ApplicationLoader that retrieves a dynamic library | 42 // An implementation of ApplicationLoader that retrieves a dynamic library |
27 // containing the implementation of the service and loads/runs it (via a | 43 // containing the implementation of the service and loads/runs it (via a |
28 // DynamicServiceRunner). | 44 // DynamicServiceRunner). |
29 class DynamicApplicationLoader : public ApplicationLoader { | 45 class DynamicApplicationLoader : public ApplicationLoader, |
| 46 public LoaderDelegate { |
30 public: | 47 public: |
31 DynamicApplicationLoader( | 48 DynamicApplicationLoader( |
32 Context* context, | 49 Context* context, |
33 scoped_ptr<DynamicServiceRunnerFactory> runner_factory); | 50 scoped_ptr<DynamicServiceRunnerFactory> runner_factory); |
34 virtual ~DynamicApplicationLoader(); | 51 virtual ~DynamicApplicationLoader(); |
35 | 52 |
36 void RegisterContentHandler(const std::string& mime_type, | 53 void RegisterContentHandler(const std::string& mime_type, |
37 const GURL& content_handler_url); | 54 const GURL& content_handler_url); |
38 | 55 |
39 // ApplicationLoader methods: | 56 // ApplicationLoader methods: |
40 virtual void Load(ApplicationManager* manager, | 57 virtual void Load(ApplicationManager* manager, |
41 const GURL& url, | 58 const GURL& url, |
42 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE; | 59 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE; |
43 virtual void OnApplicationError(ApplicationManager* manager, | 60 virtual void OnApplicationError(ApplicationManager* manager, |
44 const GURL& url) OVERRIDE; | 61 const GURL& url) OVERRIDE; |
45 | 62 |
46 private: | 63 private: |
47 typedef std::map<std::string, GURL> MimeTypeToURLMap; | 64 typedef std::map<std::string, GURL> MimeTypeToURLMap; |
48 | 65 |
49 void LoadLocalService(const GURL& resolved_url, | 66 // LoaderDelegate methods: |
50 scoped_refptr<LoadCallbacks> callbacks); | 67 virtual void LoaderComplete(Loader* loader) OVERRIDE; |
51 void LoadNetworkService(const GURL& resolved_url, | 68 virtual scoped_ptr<DynamicServiceRunner> CreateRunner() OVERRIDE; |
52 scoped_refptr<LoadCallbacks> callbacks); | 69 virtual void CreateURLLoader( |
53 void OnLoadNetworkServiceComplete(scoped_refptr<LoadCallbacks> callbacks, | 70 InterfaceRequest<URLLoader> loader_request) OVERRIDE; |
54 URLResponsePtr url_response); | 71 virtual const GURL& GetContentHandlerURL( |
55 void RunLibrary(const base::FilePath& response_file, | 72 const std::string& mime_type) OVERRIDE; |
56 scoped_refptr<LoadCallbacks> callbacks, | 73 virtual base::SequencedWorkerPool* GetBlockingPool() OVERRIDE; |
57 bool delete_file_after, | |
58 bool response_path_exists); | |
59 void OnRunLibraryComplete(DynamicServiceRunner* runner, | |
60 const base::FilePath& temp_file); | |
61 | 74 |
62 Context* const context_; | 75 Context* const context_; |
63 scoped_ptr<DynamicServiceRunnerFactory> runner_factory_; | 76 scoped_ptr<DynamicServiceRunnerFactory> runner_factory_; |
64 ScopedVector<DynamicServiceRunner> runners_; | |
65 NetworkServicePtr network_service_; | 77 NetworkServicePtr network_service_; |
66 URLLoaderPtr url_loader_; | |
67 MimeTypeToURLMap mime_type_to_url_; | 78 MimeTypeToURLMap mime_type_to_url_; |
68 base::WeakPtrFactory<DynamicApplicationLoader> weak_ptr_factory_; | 79 ScopedVector<Loader> loaders_; |
69 | 80 |
70 DISALLOW_COPY_AND_ASSIGN(DynamicApplicationLoader); | 81 DISALLOW_COPY_AND_ASSIGN(DynamicApplicationLoader); |
71 }; | 82 }; |
72 | 83 |
73 } // namespace shell | 84 } // namespace shell |
74 } // namespace mojo | 85 } // namespace mojo |
75 | 86 |
76 #endif // MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ | 87 #endif // MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ |
OLD | NEW |