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
3 // found in the LICENSE file.
5 #ifndef MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_
6 #define MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "mojo/application_manager/application_loader.h"
13 #include "mojo/public/cpp/system/core.h"
14 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
15 #include "mojo/shell/dynamic_service_runner.h"
16 #include "mojo/shell/keep_alive.h"
23 class DynamicServiceRunnerFactory;
25 // An implementation of ApplicationLoader that retrieves a dynamic library
26 // containing the implementation of the service and loads/runs it (via a
27 // DynamicServiceRunner).
28 class DynamicApplicationLoader : public ApplicationLoader {
30 DynamicApplicationLoader(
32 scoped_ptr<DynamicServiceRunnerFactory> runner_factory);
33 virtual ~DynamicApplicationLoader();
35 void RegisterContentHandler(const std::string& mime_type,
36 const GURL& content_handler_url);
38 // ApplicationLoader methods:
39 virtual void Load(ApplicationManager* manager,
41 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE;
42 virtual void OnServiceError(ApplicationManager* manager,
43 const GURL& url) OVERRIDE;
46 typedef std::map<std::string, GURL> MimeTypeToURLMap;
48 void LoadLocalService(const GURL& resolved_url,
49 scoped_refptr<LoadCallbacks> callbacks);
50 void LoadNetworkService(const GURL& resolved_url,
51 scoped_refptr<LoadCallbacks> callbacks);
52 void OnLoadNetworkServiceComplete(scoped_refptr<LoadCallbacks> callbacks,
53 URLResponsePtr url_response);
54 void RunLibrary(const base::FilePath& response_file,
55 scoped_refptr<LoadCallbacks> callbacks,
56 bool delete_file_after,
57 bool response_path_exists);
59 Context* const context_;
60 scoped_ptr<DynamicServiceRunnerFactory> runner_factory_;
61 NetworkServicePtr network_service_;
62 URLLoaderPtr url_loader_;
63 MimeTypeToURLMap mime_type_to_url_;
64 base::WeakPtrFactory<DynamicApplicationLoader> weak_ptr_factory_;
66 DISALLOW_COPY_AND_ASSIGN(DynamicApplicationLoader);
72 #endif // MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_