OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/app/android/chrome_main_delegate_android.h" | 5 #include "chrome/app/android/chrome_main_delegate_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "chrome/browser/android/chrome_jni_registrar.h" | |
10 #include "chrome/browser/android/chrome_startup_flags.h" | 9 #include "chrome/browser/android/chrome_startup_flags.h" |
11 #include "chrome/browser/android/uma_utils.h" | 10 #include "chrome/browser/android/uma_utils.h" |
12 #include "components/startup_metric_utils/startup_metric_utils.h" | 11 #include "components/startup_metric_utils/startup_metric_utils.h" |
13 #include "content/public/browser/browser_main_runner.h" | 12 #include "content/public/browser/browser_main_runner.h" |
14 | 13 |
15 // ChromeMainDelegateAndroid is created when the library is loaded. It is always | 14 // ChromeMainDelegateAndroid is created when the library is loaded. It is always |
16 // done in the process's main Java thread. But for non browser process, e.g. | 15 // done in the process's main Java thread. But for non browser process, e.g. |
17 // renderer process, it is not the native Chrome's main thread. | 16 // renderer process, it is not the native Chrome's main thread. |
18 ChromeMainDelegateAndroid::ChromeMainDelegateAndroid() { | 17 ChromeMainDelegateAndroid::ChromeMainDelegateAndroid() { |
19 } | 18 } |
20 | 19 |
21 ChromeMainDelegateAndroid::~ChromeMainDelegateAndroid() { | 20 ChromeMainDelegateAndroid::~ChromeMainDelegateAndroid() { |
22 } | 21 } |
23 | 22 |
24 void ChromeMainDelegateAndroid::SandboxInitialized( | 23 void ChromeMainDelegateAndroid::SandboxInitialized( |
25 const std::string& process_type) { | 24 const std::string& process_type) { |
26 ChromeMainDelegate::SandboxInitialized(process_type); | 25 ChromeMainDelegate::SandboxInitialized(process_type); |
27 } | 26 } |
28 | 27 |
29 int ChromeMainDelegateAndroid::RunProcess( | 28 int ChromeMainDelegateAndroid::RunProcess( |
30 const std::string& process_type, | 29 const std::string& process_type, |
31 const content::MainFunctionParams& main_function_params) { | 30 const content::MainFunctionParams& main_function_params) { |
32 TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess") | 31 TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess") |
33 if (process_type.empty()) { | 32 if (process_type.empty()) { |
34 JNIEnv* env = base::android::AttachCurrentThread(); | |
35 RegisterApplicationNativeMethods(env); | |
36 | |
37 // Because the browser process can be started asynchronously as a series of | 33 // Because the browser process can be started asynchronously as a series of |
38 // UI thread tasks a second request to start it can come in while the | 34 // UI thread tasks a second request to start it can come in while the |
39 // first request is still being processed. Chrome must keep the same | 35 // first request is still being processed. Chrome must keep the same |
40 // browser runner for the second request. | 36 // browser runner for the second request. |
41 // Also only record the start time the first time round, since this is the | 37 // Also only record the start time the first time round, since this is the |
42 // start time of the application, and will be same for all requests. | 38 // start time of the application, and will be same for all requests. |
43 if (!browser_runner_.get()) { | 39 if (!browser_runner_.get()) { |
44 base::Time startTime = chrome::android::GetMainEntryPointTime(); | 40 base::Time startTime = chrome::android::GetMainEntryPointTime(); |
45 startup_metric_utils::RecordSavedMainEntryPointTime(startTime); | 41 startup_metric_utils::RecordSavedMainEntryPointTime(startTime); |
46 browser_runner_.reset(content::BrowserMainRunner::Create()); | 42 browser_runner_.reset(content::BrowserMainRunner::Create()); |
47 } | 43 } |
48 return browser_runner_->Initialize(main_function_params); | 44 return browser_runner_->Initialize(main_function_params); |
49 } | 45 } |
50 | 46 |
51 return ChromeMainDelegate::RunProcess(process_type, main_function_params); | 47 return ChromeMainDelegate::RunProcess(process_type, main_function_params); |
52 } | 48 } |
53 | 49 |
54 bool ChromeMainDelegateAndroid::BasicStartupComplete(int* exit_code) { | 50 bool ChromeMainDelegateAndroid::BasicStartupComplete(int* exit_code) { |
55 SetChromeSpecificCommandLineFlags(); | 51 SetChromeSpecificCommandLineFlags(); |
56 return ChromeMainDelegate::BasicStartupComplete(exit_code); | 52 return ChromeMainDelegate::BasicStartupComplete(exit_code); |
57 } | 53 } |
58 | |
59 bool ChromeMainDelegateAndroid::RegisterApplicationNativeMethods(JNIEnv* env) { | |
60 return chrome::android::RegisterJni(env); | |
61 } | |
OLD | NEW |