Upstream version 7.36.151.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / app / android / xwalk_main_delegate_android.cc
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 #include "xwalk/runtime/app/android/xwalk_main_delegate_android.h"
6
7 #include <string>
8
9 #include "base/command_line.h"
10 #include "base/cpu.h"
11 #include "base/file_util.h"
12 #include "base/files/file_path.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/base_paths_android.h"
16 #include "base/path_service.h"
17 #include "base/platform_file.h"
18 #include "base/posix/global_descriptors.h"
19 #include "content/public/browser/browser_main_runner.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/base/ui_base_paths.h"
22 #include "ui/base/ui_base_switches.h"
23 #include "xwalk/runtime/common/android/xwalk_globals_android.h"
24 #include "xwalk/runtime/common/xwalk_content_client.h"
25
26 namespace xwalk {
27
28 XWalkMainDelegateAndroid::XWalkMainDelegateAndroid() {
29 }
30
31 XWalkMainDelegateAndroid::~XWalkMainDelegateAndroid() {
32 }
33
34 bool XWalkMainDelegateAndroid::BasicStartupComplete(int* exit_code) {
35   content_client_.reset(new XWalkContentClient);
36   content::SetContentClient(content_client_.get());
37   return false;
38 }
39
40 void XWalkMainDelegateAndroid::PreSandboxStartup() {
41 #if defined(ARCH_CPU_ARM_FAMILY)
42   // Create an instance of the CPU class to parse /proc/cpuinfo and cache
43   // cpu_brand info for ARM platform.
44   base::CPU cpu_info;
45 #endif
46   InitResourceBundle();
47 }
48
49 int XWalkMainDelegateAndroid::RunProcess(
50     const std::string& process_type,
51     const content::MainFunctionParams& main_function_params) {
52   if (process_type.empty()) {
53     browser_runner_.reset(content::BrowserMainRunner::Create());
54     int exit_code = browser_runner_->Initialize(main_function_params);
55     DCHECK_LT(exit_code, 0);
56
57     return 0;
58   }
59   return -1;
60 }
61
62 void XWalkMainDelegateAndroid::InitResourceBundle() {
63   base::FilePath pak_file;
64   base::FilePath pak_dir;
65   bool got_path = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir);
66   DCHECK(got_path);
67   pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks"));
68   pak_file = pak_dir.Append(FILE_PATH_LITERAL(kXWalkPakFilePath));
69   ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
70 }
71
72 }  // namespace xwalk