Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / mojo / shell / dynamic_application_loader.h
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.
4
5 #ifndef MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_
6 #define MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_
7
8 #include <map>
9
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"
17 #include "url/gurl.h"
18
19 namespace mojo {
20 namespace shell {
21
22 class Context;
23 class DynamicServiceRunnerFactory;
24
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 {
29  public:
30   DynamicApplicationLoader(
31       Context* context,
32       scoped_ptr<DynamicServiceRunnerFactory> runner_factory);
33   virtual ~DynamicApplicationLoader();
34
35   void RegisterContentHandler(const std::string& mime_type,
36                               const GURL& content_handler_url);
37
38   // ApplicationLoader methods:
39   virtual void Load(ApplicationManager* manager,
40                     const GURL& url,
41                     scoped_refptr<LoadCallbacks> callbacks) OVERRIDE;
42   virtual void OnServiceError(ApplicationManager* manager,
43                               const GURL& url) OVERRIDE;
44
45  private:
46   typedef std::map<std::string, GURL> MimeTypeToURLMap;
47
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);
58
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_;
65
66   DISALLOW_COPY_AND_ASSIGN(DynamicApplicationLoader);
67 };
68
69 }  // namespace shell
70 }  // namespace mojo
71
72 #endif  // MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_