1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_browser_main_android.h"
9 #include "base/functional/bind.h"
10 #include "base/path_service.h"
11 #include "base/task/current_thread.h"
12 #include "base/task/thread_pool.h"
13 #include "base/trace_event/trace_event.h"
14 #include "chrome/browser/android/chrome_backup_watcher.h"
15 #include "chrome/browser/android/mojo/chrome_interface_registrar_android.h"
16 #include "chrome/browser/android/preferences/clipboard_android.h"
17 #include "chrome/browser/android/seccomp_support_detector.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/data_saver/data_saver.h"
20 #include "chrome/browser/webauthn/android/cable_module_android.h"
21 #include "components/crash/content/browser/child_exit_observer_android.h"
22 #include "components/crash/content/browser/child_process_crash_observer_android.h"
23 #include "components/metrics/stability_metrics_helper.h"
24 #include "content/public/browser/android/compositor.h"
25 #include "content/public/browser/browser_thread.h"
26 #include "content/public/common/main_function_params.h"
27 #include "device/fido/features.h"
28 #include "net/base/network_change_notifier.h"
29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/resource/resource_bundle_android.h"
31 #include "ui/base/ui_base_paths.h"
33 ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
34 bool is_integration_test,
35 StartupData* startup_data)
36 : ChromeBrowserMainParts(is_integration_test, startup_data) {}
38 ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
41 int ChromeBrowserMainPartsAndroid::PreCreateThreads() {
42 TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreCreateThreads");
44 int result_code = ChromeBrowserMainParts::PreCreateThreads();
46 // The ChildExitObserver needs to be created before any child process is
47 // created because it needs to be notified during process creation.
48 child_exit_observer_ = std::make_unique<crash_reporter::ChildExitObserver>();
49 child_exit_observer_->RegisterClient(
50 std::make_unique<crash_reporter::ChildProcessCrashObserver>());
55 void ChromeBrowserMainPartsAndroid::PostProfileInit(Profile* profile,
56 bool is_initial_profile) {
57 DCHECK(is_initial_profile); // No multiprofile on Android, only the initial
58 // call should happen.
60 // Get the OS Data Saver setting. This will be needed later on, so we want to
61 // fetch this setting as soon as possible to avoid blocking on it.
62 data_saver::FetchDataSaverOSSettingAsynchronously();
64 ChromeBrowserMainParts::PostProfileInit(profile, is_initial_profile);
66 // Idempotent. Needs to be called once on startup. If
67 // InitializeClipboardAndroidFromLocalState() is called multiple times (e.g.,
68 // once per profile load), that's okay; the additional calls don't change
70 android::InitClipboardAndroidFromLocalState(g_browser_process->local_state());
72 // Start watching the preferences that need to be backed up backup using
73 // Android backup, so that we create a new backup if they change.
74 backup_watcher_ = std::make_unique<android::ChromeBackupWatcher>(profile);
76 // The GCM driver can be used at this point because the primary profile has
77 // been created. Register non-profile-specific things that use GCM so that no
78 // messages can be processed (and dropped) because the handler wasn't
80 webauthn::authenticator::RegisterForCloudMessages();
83 int ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
84 TRACE_EVENT0("startup",
85 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization");
86 content::Compositor::Initialize();
88 CHECK(base::CurrentThread::IsSet());
90 return ChromeBrowserMainParts::PreEarlyInitialization();
93 void ChromeBrowserMainPartsAndroid::PostBrowserStart() {
94 ChromeBrowserMainParts::PostBrowserStart();
96 base::ThreadPool::PostDelayedTask(
97 FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
98 base::BindOnce(&ReportSeccompSupport), base::Minutes(1));
100 RegisterChromeJavaMojoInterfaces();
103 void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {