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
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_browser_main_android.h"
8 #include "base/message_loop/message_loop_current.h"
9 #include "base/path_service.h"
10 #include "base/task/post_task.h"
11 #include "base/task/thread_pool.h"
12 #include "base/trace_event/trace_event.h"
13 #include "chrome/browser/android/mojo/chrome_interface_registrar_android.h"
14 #include "chrome/browser/android/preferences/clipboard_android.h"
15 #include "chrome/browser/android/seccomp_support_detector.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "components/crash/content/browser/child_exit_observer_android.h"
19 #include "components/crash/content/browser/child_process_crash_observer_android.h"
20 #include "components/metrics/stability_metrics_helper.h"
21 #include "content/public/browser/android/compositor.h"
22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/common/main_function_params.h"
24 #include "net/base/network_change_notifier.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/base/resource/resource_bundle_android.h"
27 #include "ui/base/ui_base_paths.h"
29 ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
30 const content::MainFunctionParams& parameters,
31 StartupData* startup_data)
32 : ChromeBrowserMainParts(parameters, startup_data) {}
34 ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
37 int ChromeBrowserMainPartsAndroid::PreCreateThreads() {
38 TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreCreateThreads")
40 int result_code = ChromeBrowserMainParts::PreCreateThreads();
42 // The ChildExitObserver needs to be created before any child process is
43 // created because it needs to be notified during process creation.
44 crash_reporter::ChildExitObserver::Create();
45 crash_reporter::ChildExitObserver::GetInstance()->RegisterClient(
46 std::make_unique<crash_reporter::ChildProcessCrashObserver>());
51 void ChromeBrowserMainPartsAndroid::PostProfileInit() {
52 ChromeBrowserMainParts::PostProfileInit();
54 // Idempotent. Needs to be called once on startup. If
55 // InitializeClipboardAndroidFromLocalState() is called multiple times (e.g.,
56 // once per profile load), that's okay; the additional calls don't change
58 android::InitClipboardAndroidFromLocalState(g_browser_process->local_state());
60 // Start watching the preferences that need to be backed up backup using
61 // Android backup, so that we create a new backup if they change.
62 backup_watcher_.reset(new android::ChromeBackupWatcher(profile()));
65 int ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
66 TRACE_EVENT0("startup",
67 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization")
68 content::Compositor::Initialize();
70 CHECK(base::MessageLoopCurrent::IsSet());
72 return ChromeBrowserMainParts::PreEarlyInitialization();
75 void ChromeBrowserMainPartsAndroid::PostEarlyInitialization() {
76 profile_manager_android_.reset(new ProfileManagerAndroid());
77 g_browser_process->profile_manager()->AddObserver(
78 profile_manager_android_.get());
79 ChromeBrowserMainParts::PostEarlyInitialization();
82 void ChromeBrowserMainPartsAndroid::PostBrowserStart() {
83 ChromeBrowserMainParts::PostBrowserStart();
85 base::ThreadPool::PostDelayedTask(
86 FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
87 base::BindOnce(&ReportSeccompSupport), base::TimeDelta::FromMinutes(1));
89 RegisterChromeJavaMojoInterfaces();
92 void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {