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_SERVICE_LOADER_H_ | 5 #ifndef MOJO_SHELL_DYNAMIC_SERVICE_LOADER_H_ |
6 #define MOJO_SHELL_DYNAMIC_SERVICE_LOADER_H_ | 6 #define MOJO_SHELL_DYNAMIC_SERVICE_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/weak_ptr.h" | |
12 #include "mojo/public/cpp/system/core.h" | 11 #include "mojo/public/cpp/system/core.h" |
13 #include "mojo/service_manager/service_loader.h" | 12 #include "mojo/service_manager/service_loader.h" |
14 #include "mojo/services/public/interfaces/network/network_service.mojom.h" | 13 #include "mojo/services/public/interfaces/network/network_service.mojom.h" |
15 #include "mojo/shell/dynamic_service_runner.h" | 14 #include "mojo/shell/dynamic_service_runner.h" |
16 #include "mojo/shell/keep_alive.h" | 15 #include "mojo/shell/keep_alive.h" |
17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
18 | 17 |
19 namespace mojo { | 18 namespace mojo { |
20 namespace shell { | 19 namespace shell { |
21 | 20 |
22 class Context; | 21 class Context; |
23 class DynamicServiceRunnerFactory; | 22 class DynamicServiceRunnerFactory; |
24 | 23 |
25 // An implementation of ServiceLoader that retrieves a dynamic library | 24 // An implementation of ServiceLoader that retrieves a dynamic library |
26 // containing the implementation of the service and loads/runs it (via a | 25 // containing the implementation of the service and loads/runs it (via a |
27 // DynamicServiceRunner). | 26 // DynamicServiceRunner). |
28 class DynamicServiceLoader : public ServiceLoader { | 27 class DynamicServiceLoader : public ServiceLoader { |
29 public: | 28 public: |
30 DynamicServiceLoader(Context* context, | 29 DynamicServiceLoader(Context* context, |
31 scoped_ptr<DynamicServiceRunnerFactory> runner_factory); | 30 scoped_ptr<DynamicServiceRunnerFactory> runner_factory); |
32 virtual ~DynamicServiceLoader(); | 31 virtual ~DynamicServiceLoader(); |
33 | 32 |
34 void RegisterContentHandler(const std::string& mime_type, | |
35 const GURL& content_handler_url); | |
36 | |
37 // ServiceLoader methods: | 33 // ServiceLoader methods: |
38 virtual void Load(ServiceManager* manager, | 34 virtual void LoadService(ServiceManager* manager, |
39 const GURL& url, | 35 const GURL& url, |
40 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE; | 36 ScopedMessagePipeHandle service_handle) OVERRIDE; |
41 virtual void OnServiceError(ServiceManager* manager, const GURL& url) | 37 virtual void OnServiceError(ServiceManager* manager, const GURL& url) |
42 OVERRIDE; | 38 OVERRIDE; |
43 | 39 |
44 private: | 40 private: |
45 typedef std::map<std::string, GURL> MimeTypeToURLMap; | |
46 | |
47 void LoadLocalService(const GURL& resolved_url, | |
48 scoped_refptr<LoadCallbacks> callbacks); | |
49 void LoadNetworkService(const GURL& resolved_url, | |
50 scoped_refptr<LoadCallbacks> callbacks); | |
51 void OnLoadNetworkServiceComplete(scoped_refptr<LoadCallbacks> callbacks, | |
52 URLResponsePtr url_response); | |
53 void RunLibrary(const base::FilePath& response_file, | |
54 scoped_refptr<LoadCallbacks> callbacks, | |
55 bool delete_file_after, | |
56 bool response_path_exists); | |
57 | |
58 Context* const context_; | 41 Context* const context_; |
59 scoped_ptr<DynamicServiceRunnerFactory> runner_factory_; | 42 scoped_ptr<DynamicServiceRunnerFactory> runner_factory_; |
60 NetworkServicePtr network_service_; | 43 NetworkServicePtr network_service_; |
61 URLLoaderPtr url_loader_; | |
62 MimeTypeToURLMap mime_type_to_url_; | |
63 base::WeakPtrFactory<DynamicServiceLoader> weak_ptr_factory_; | |
64 | 44 |
65 DISALLOW_COPY_AND_ASSIGN(DynamicServiceLoader); | 45 DISALLOW_COPY_AND_ASSIGN(DynamicServiceLoader); |
66 }; | 46 }; |
67 | 47 |
68 } // namespace shell | 48 } // namespace shell |
69 } // namespace mojo | 49 } // namespace mojo |
70 | 50 |
71 #endif // MOJO_SHELL_DYNAMIC_SERVICE_LOADER_H_ | 51 #endif // MOJO_SHELL_DYNAMIC_SERVICE_LOADER_H_ |
OLD | NEW |