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"
7 #include "base/command_line.h"
8 #include "base/path_service.h"
9 #include "base/trace_event/trace_event.h"
10 #include "chrome/browser/android/chrome_media_client_android.h"
11 #include "chrome/browser/android/seccomp_support_detector.h"
12 #include "chrome/browser/google/google_search_counter_android.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "components/crash/app/breakpad_linux.h"
17 #include "components/crash/browser/crash_dump_manager_android.h"
18 #include "components/signin/core/browser/signin_manager.h"
19 #include "content/public/browser/android/compositor.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/common/main_function_params.h"
22 #include "media/base/android/media_client_android.h"
23 #include "net/android/network_change_notifier_factory_android.h"
24 #include "net/base/network_change_notifier.h"
25 #include "ui/base/ui_base_paths.h"
27 ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
28 const content::MainFunctionParams
& parameters
)
29 : ChromeBrowserMainParts(parameters
) {
32 ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
35 int ChromeBrowserMainPartsAndroid::PreCreateThreads() {
36 TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreCreateThreads")
38 // The CrashDumpManager must be initialized before any child process is
39 // created (as they need to access it during creation). Such processes
40 // are created on the PROCESS_LAUNCHER thread, and so the manager is
41 // initialized before that thread is created.
42 #if defined(GOOGLE_CHROME_BUILD)
43 // TODO(jcivelli): we should not initialize the crash-reporter when it was not
44 // enabled. Right now if it is disabled we still generate the minidumps but we
45 // do not upload them.
46 bool breakpad_enabled
= true;
48 bool breakpad_enabled
= false;
51 // Allow Breakpad to be enabled in Chromium builds for testing purposes.
52 if (!breakpad_enabled
)
53 breakpad_enabled
= base::CommandLine::ForCurrentProcess()->HasSwitch(
54 switches::kEnableCrashReporterForTesting
);
56 if (breakpad_enabled
) {
57 base::FilePath crash_dump_dir
;
58 PathService::Get(chrome::DIR_CRASH_DUMPS
, &crash_dump_dir
);
59 crash_dump_manager_
.reset(new breakpad::CrashDumpManager(crash_dump_dir
));
62 return ChromeBrowserMainParts::PreCreateThreads();
65 void ChromeBrowserMainPartsAndroid::PostProfileInit() {
66 Profile
* main_profile
= profile();
67 search_counter_
.reset(new GoogleSearchCounterAndroid(main_profile
));
69 ChromeBrowserMainParts::PostProfileInit();
72 void ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
73 TRACE_EVENT0("startup",
74 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization")
75 net::NetworkChangeNotifier::SetFactory(
76 new net::NetworkChangeNotifierFactoryAndroid());
78 content::Compositor::Initialize();
80 // Chrome on Android does not use default MessageLoop. It has its own
81 // Android specific MessageLoop.
82 DCHECK(!main_message_loop_
.get());
84 // Create and start the MessageLoop.
85 // This is a critical point in the startup process.
87 TRACE_EVENT0("startup",
88 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:CreateUiMsgLoop");
89 main_message_loop_
.reset(new base::MessageLoopForUI
);
93 TRACE_EVENT0("startup",
94 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:StartUiMsgLoop");
95 base::MessageLoopForUI::current()->Start();
98 ChromeBrowserMainParts::PreEarlyInitialization();
101 void ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun() {
102 media::SetMediaClientAndroid(new ChromeMediaClientAndroid
);
104 ChromeBrowserMainParts::PreMainMessageLoopRun();
107 void ChromeBrowserMainPartsAndroid::PostBrowserStart() {
108 ChromeBrowserMainParts::PostBrowserStart();
110 content::BrowserThread::GetBlockingPool()->PostDelayedTask(FROM_HERE
,
111 base::Bind(&SeccompSupportDetector::StartDetection
),
112 base::TimeDelta::FromMinutes(1));
115 void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {