Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / application_system.h
1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_APPLICATION_BROWSER_APPLICATION_SYSTEM_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_SYSTEM_H_
7
8 #include <map>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "xwalk/extensions/common/xwalk_extension_vector.h"
13
14 class GURL;
15
16 namespace base {
17 class CommandLine;
18 }
19
20 namespace content {
21 class RenderProcessHost;
22 }
23
24 namespace xwalk {
25 class RuntimeContext;
26 }
27
28 namespace xwalk {
29 namespace application {
30
31 class ApplicationService;
32 class ApplicationServiceProvider;
33 class ApplicationStorage;
34
35 // The ApplicationSystem manages the creation and destruction of services which
36 // related to applications' runtime model.
37 // There's one-to-one correspondence between ApplicationSystem and
38 // RuntimeContext.
39 class ApplicationSystem {
40  public:
41   virtual ~ApplicationSystem();
42
43   static scoped_ptr<ApplicationSystem> Create(RuntimeContext* runtime_context);
44
45   // The ApplicationService is created at startup.
46   ApplicationService* application_service() {
47     return application_service_.get();
48   }
49
50   ApplicationStorage* application_storage() {
51     return application_storage_.get();
52   }
53
54   // Parse the command line and process the --install, --uninstall and
55   // --list-apps commands. Returns true when a management command was processed,
56   // so the caller shouldn't load a runtime.
57   //
58   // The parameter `url` contains the current URL Crosswalk is considering to
59   // load.
60   bool HandleApplicationManagementCommands(const base::CommandLine& cmd_line,
61                                            const GURL& url,
62                                            bool& run_default_message_loop);
63
64   // Launches an application based on the given command line, there are
65   // different ways to inform which application should be launched
66   //
67   // (1) app_id from the binary name (used in Tizen);
68   // (2) app_id passed in the command line;
69   // (3) launching a directory that contains an extracted package.
70   //
71   // The parameter `url` contains the current URL Crosswalk is considering to
72   // load, and the output parameter `run_default_message_loop` controls whether
73   // Crosswalk should run the mainloop or not.
74   //
75   // A return value of true indicates that ApplicationSystem handled the command
76   // line, so the caller shouldn't try to load the url by itself.
77   bool LaunchFromCommandLine(const base::CommandLine& cmd_line,
78                              const GURL& url,
79                              bool& run_default_message_loop_);
80
81   void CreateExtensions(content::RenderProcessHost* host,
82                         extensions::XWalkExtensionVector* extensions);
83
84  protected:
85   explicit ApplicationSystem(RuntimeContext* runtime_context);
86
87  private:
88   template <typename T>
89   bool LaunchWithCommandLineParam(const T& param,
90                                   const base::CommandLine& cmd_line);
91   // Note: initialization order matters.
92   xwalk::RuntimeContext* runtime_context_;
93   scoped_ptr<ApplicationStorage> application_storage_;
94   scoped_ptr<ApplicationService> application_service_;
95
96   DISALLOW_COPY_AND_ASSIGN(ApplicationSystem);
97 };
98
99 }  // namespace application
100 }  // namespace xwalk
101
102 #endif  // XWALK_APPLICATION_BROWSER_APPLICATION_SYSTEM_H_