blob: 024fdb1893e44f8806055282a839cd52a189f4e1 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chrome_browser_main_android.h"
#include "base/bind.h"
#include "base/message_loop/message_loop_current.h"
#include "base/path_service.h"
#include "base/task/post_task.h"
#include "base/trace_event/trace_event.h"
#include "chrome/browser/android/mojo/chrome_interface_registrar_android.h"
#include "chrome/browser/android/preferences/clipboard_android.h"
#include "chrome/browser/android/seccomp_support_detector.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/crash/content/browser/child_exit_observer_android.h"
#include "components/crash/content/browser/child_process_crash_observer_android.h"
#include "components/metrics/stability_metrics_helper.h"
#include "content/public/browser/android/compositor.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/main_function_params.h"
#include "net/base/network_change_notifier.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/resource_bundle_android.h"
#include "ui/base/ui_base_paths.h"
ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
const content::MainFunctionParams& parameters,
StartupData* startup_data)
: ChromeBrowserMainParts(parameters, startup_data) {}
ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
}
int ChromeBrowserMainPartsAndroid::PreCreateThreads() {
TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreCreateThreads")
int result_code = ChromeBrowserMainParts::PreCreateThreads();
// The ChildExitObserver needs to be created before any child process is
// created because it needs to be notified during process creation.
crash_reporter::ChildExitObserver::Create();
crash_reporter::ChildExitObserver::GetInstance()->RegisterClient(
std::make_unique<crash_reporter::ChildProcessCrashObserver>());
return result_code;
}
void ChromeBrowserMainPartsAndroid::PostProfileInit() {
ChromeBrowserMainParts::PostProfileInit();
// Idempotent. Needs to be called once on startup. If
// InitializeClipboardAndroidFromLocalState() is called multiple times (e.g.,
// once per profile load), that's okay; the additional calls don't change
// anything.
android::InitClipboardAndroidFromLocalState(g_browser_process->local_state());
// Start watching the preferences that need to be backed up backup using
// Android backup, so that we create a new backup if they change.
backup_watcher_.reset(new android::ChromeBackupWatcher(profile()));
}
int ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
TRACE_EVENT0("startup",
"ChromeBrowserMainPartsAndroid::PreEarlyInitialization")
content::Compositor::Initialize();
CHECK(base::MessageLoopCurrent::IsSet());
return ChromeBrowserMainParts::PreEarlyInitialization();
}
void ChromeBrowserMainPartsAndroid::PostEarlyInitialization() {
profile_manager_android_.reset(new ProfileManagerAndroid());
g_browser_process->profile_manager()->AddObserver(
profile_manager_android_.get());
ChromeBrowserMainParts::PostEarlyInitialization();
}
void ChromeBrowserMainPartsAndroid::PostBrowserStart() {
ChromeBrowserMainParts::PostBrowserStart();
base::PostDelayedTask(
FROM_HERE,
{base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&ReportSeccompSupport), base::TimeDelta::FromMinutes(1));
RegisterChromeJavaMojoInterfaces();
}
void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {
NOTREACHED();
}