Remove OS_ANDROID knowledge in ContentMain() wrt running BrowserMain()
The ContentMainDelegate can already control if BrowserMain() is run so it is not needed in ContentMain() and is a complexity that is harder to understand there, hard to find at all, and a layering violation. The ShellMainDelegate already returns 0 on OS_ANDROID now as of https://chromium-review.googlesource.com/c/chromium/src/+/1609676 but ChromeMainDelegate does not. AwMainDelegate already returns 0 for the browser process always. These are the only ContentMainDelegate impls that are used on Android. Change ChromeMainDelegateAndroid to stop running ChromeMainDelegate's RunProcess() since all it does on Android is return -1. Since the BrowserMainRunnerImpl returns -1 on success, have the delegate catch that and return 0 to avoid running BrowserMain() from ContentMain(). Removes the OS_ANDROID branch from ContentMain(). R=jam@chromium.org Bug: 961849 Change-Id: If1d4ad11c274e23973aa6e6974e62b9352c875bd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1612248 Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: John Abd-El-Malek <jam@chromium.org> Reviewed-by: Bo <boliu@chromium.org> Commit-Queue: danakj <danakj@chromium.org> Cr-Commit-Position: refs/heads/master@{#660031}
This commit is contained in:
android_webview/lib
chrome/app
content/app
@ -288,17 +288,18 @@ void AwMainDelegate::PreSandboxStartup() {
|
||||
int AwMainDelegate::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
if (process_type.empty()) {
|
||||
browser_runner_ = content::BrowserMainRunner::Create();
|
||||
int exit_code = browser_runner_->Initialize(main_function_params);
|
||||
DCHECK_LT(exit_code, 0);
|
||||
// Defer to the default main method outside the browser process.
|
||||
if (!process_type.empty())
|
||||
return -1;
|
||||
|
||||
// Return 0 so that we do NOT trigger the default behavior. On Android, the
|
||||
// UI message loop is managed by the Java application.
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
browser_runner_ = content::BrowserMainRunner::Create();
|
||||
int exit_code = browser_runner_->Initialize(main_function_params);
|
||||
// We do not expect Initialize() to ever fail in AndroidWebView. On success
|
||||
// it returns a negative value but we do not want to use that on Android.
|
||||
DCHECK_LT(exit_code, 0);
|
||||
// Return 0 so that we do NOT trigger the default behavior. On Android, the
|
||||
// UI message loop is managed by the Java application.
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AwMainDelegate::ProcessExiting(const std::string& process_type) {
|
||||
|
@ -72,25 +72,32 @@ void ChromeMainDelegateAndroid::SecureDataDirectory() {
|
||||
int ChromeMainDelegateAndroid::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess")
|
||||
if (process_type.empty()) {
|
||||
SecureDataDirectory();
|
||||
TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess");
|
||||
// Defer to the default main method outside the browser process.
|
||||
if (!process_type.empty())
|
||||
return -1;
|
||||
|
||||
// Because the browser process can be started asynchronously as a series of
|
||||
// UI thread tasks a second request to start it can come in while the
|
||||
// first request is still being processed. Chrome must keep the same
|
||||
// browser runner for the second request.
|
||||
// Also only record the start time the first time round, since this is the
|
||||
// start time of the application, and will be same for all requests.
|
||||
if (!browser_runner_.get()) {
|
||||
startup_metric_utils::RecordMainEntryPointTime(
|
||||
chrome::android::GetMainEntryPointTimeTicks());
|
||||
browser_runner_ = content::BrowserMainRunner::Create();
|
||||
}
|
||||
return browser_runner_->Initialize(main_function_params);
|
||||
SecureDataDirectory();
|
||||
|
||||
// Because the browser process can be started asynchronously as a series of
|
||||
// UI thread tasks a second request to start it can come in while the
|
||||
// first request is still being processed. Chrome must keep the same
|
||||
// browser runner for the second request.
|
||||
// Also only record the start time the first time round, since this is the
|
||||
// start time of the application, and will be same for all requests.
|
||||
if (!browser_runner_) {
|
||||
startup_metric_utils::RecordMainEntryPointTime(
|
||||
chrome::android::GetMainEntryPointTimeTicks());
|
||||
browser_runner_ = content::BrowserMainRunner::Create();
|
||||
}
|
||||
|
||||
return ChromeMainDelegate::RunProcess(process_type, main_function_params);
|
||||
int exit_code = browser_runner_->Initialize(main_function_params);
|
||||
// On Android we do not run BrowserMain(), so the above initialization of a
|
||||
// BrowserMainRunner is all we want to occur. Return >= 0 to avoid running
|
||||
// BrowserMain, while preserving any error codes > 0.
|
||||
if (exit_code > 0)
|
||||
return exit_code;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ChromeMainDelegateAndroid::ProcessExiting(
|
||||
|
@ -1044,7 +1044,9 @@ int ChromeMainDelegate::RunProcess(
|
||||
// ANDROID doesn't support "service", so no CloudPrintServiceProcessMain, and
|
||||
// arraysize doesn't support empty array. So we comment out the block for
|
||||
// Android.
|
||||
#if !defined(OS_ANDROID)
|
||||
#if defined(OS_ANDROID)
|
||||
NOTREACHED(); // Android provides a subclass and shares no code here.
|
||||
#else
|
||||
static const MainFunction kMainFunctions[] = {
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && !defined(CHROME_MULTIPLE_DLL_CHILD) && \
|
||||
!defined(OS_CHROMEOS)
|
||||
@ -1070,7 +1072,7 @@ int ChromeMainDelegate::RunProcess(
|
||||
if (process_type == kMainFunctions[i].name)
|
||||
return kMainFunctions[i].function(main_function_params);
|
||||
}
|
||||
#endif
|
||||
#endif // !defined(OS_ANDROID)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -544,17 +544,9 @@ static void RegisterMainThreadFactories() {
|
||||
int RunBrowserProcessMain(const MainFunctionParams& main_function_params,
|
||||
ContentMainDelegate* delegate) {
|
||||
int exit_code = delegate->RunProcess("", main_function_params);
|
||||
#if defined(OS_ANDROID)
|
||||
// In Android's browser process, the negative exit code doesn't mean the
|
||||
// default behavior should be used as the UI message loop is managed by
|
||||
// the Java and the browser process's default behavior is always
|
||||
// overridden.
|
||||
return exit_code;
|
||||
#else
|
||||
if (exit_code >= 0)
|
||||
return exit_code;
|
||||
return BrowserMain(main_function_params);
|
||||
#endif
|
||||
}
|
||||
#endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
|
||||
|
||||
|
Reference in New Issue
Block a user