[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / chrome_browser_main_android.cc
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.
4
5 #include "chrome/browser/chrome_browser_main_android.h"
6
7 #include <memory>
8
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"
32
33 ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
34     bool is_integration_test,
35     StartupData* startup_data)
36     : ChromeBrowserMainParts(is_integration_test, startup_data) {}
37
38 ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
39 }
40
41 int ChromeBrowserMainPartsAndroid::PreCreateThreads() {
42   TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreCreateThreads");
43
44   int result_code = ChromeBrowserMainParts::PreCreateThreads();
45
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>());
51
52   return result_code;
53 }
54
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.
59
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();
63
64   ChromeBrowserMainParts::PostProfileInit(profile, is_initial_profile);
65
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
69   // anything.
70   android::InitClipboardAndroidFromLocalState(g_browser_process->local_state());
71
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);
75
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
79   // installed in time.
80   webauthn::authenticator::RegisterForCloudMessages();
81 }
82
83 int ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
84   TRACE_EVENT0("startup",
85                "ChromeBrowserMainPartsAndroid::PreEarlyInitialization");
86   content::Compositor::Initialize();
87
88   CHECK(base::CurrentThread::IsSet());
89
90   return ChromeBrowserMainParts::PreEarlyInitialization();
91 }
92
93 void ChromeBrowserMainPartsAndroid::PostBrowserStart() {
94   ChromeBrowserMainParts::PostBrowserStart();
95
96   base::ThreadPool::PostDelayedTask(
97       FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
98       base::BindOnce(&ReportSeccompSupport), base::Minutes(1));
99
100   RegisterChromeJavaMojoInterfaces();
101 }
102
103 void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {
104   NOTREACHED();
105 }