Change to single process model
[platform/framework/web/crosswalk-tizen.git] / runtime / browser / runtime_process.cc
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #include <ewk_chromium.h>
18
19 #include <Elementary.h>
20
21 #include "common/command_line.h"
22 #include "common/logger.h"
23 #include "common/profiler.h"
24 #include "runtime/browser/runtime.h"
25 #include "runtime/browser/prelauncher.h"
26 #include "runtime/browser/preload_manager.h"
27
28 bool g_prelaunch = false;
29
30 int real_main(int argc, char* argv[]) {
31   STEP_PROFILE_START("Start -> Launch Completed");
32   STEP_PROFILE_START("Start -> OnCreate");
33   // Parse commandline.
34   common::CommandLine::Init(argc, argv);
35
36   // Default behavior, run as runtime.
37   LOGGER(INFO) << "Runtime process has been created.";
38   if (!g_prelaunch) {
39     ewk_init();
40     char* chromium_arg_options[] = {
41       argv[0],
42       const_cast<char*>("--no-sandbox"),
43       const_cast<char*>("--enable-file-cookies"),
44       const_cast<char*>("--allow-file-access-from-files"),
45       const_cast<char*>("--allow-universal-access-from-files"),
46       const_cast<char*>("--single-process")
47     };
48     const int chromium_arg_cnt =
49         sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
50     ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
51   }
52
53   int ret = 0;
54   // Runtime's destructor should be called before ewk_shutdown()
55   {
56     runtime::Runtime runtime;
57     ret = runtime.Exec(argc, argv);
58   }
59   ewk_shutdown();
60   exit(ret);
61
62   return EXIT_SUCCESS;
63 }
64
65 int main(int argc, char* argv[]) {
66   if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
67     elm_init(argc, argv);
68     auto preload = [argv](void) {
69       g_prelaunch = true;
70       ewk_init();
71       char* chromium_arg_options[] = {
72         argv[0],
73         const_cast<char*>("--no-sandbox"),
74         const_cast<char*>("--enable-file-cookies"),
75         const_cast<char*>("--allow-file-access-from-files"),
76         const_cast<char*>("--allow-universal-access-from-files"),
77         const_cast<char*>("--single-process")
78       };
79       const int chromium_arg_cnt =
80           sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
81       ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
82       runtime::PreloadManager::GetInstance()->CreateCacheComponet();
83     };
84     auto did_launch = [](const std::string& app_path) {
85     };
86     auto prelaunch = runtime::PreLauncher::Prelaunch;
87     return prelaunch(argc, argv, preload, did_launch, real_main);
88   } else {
89     return real_main(argc, argv);
90   }
91 }