blob: f6ce26c76930b77b45ab05a9421fa95241b11e8e [file] [log] [blame]
[email protected]81ce2c42012-03-24 01:43:261// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]b48c9182011-10-26 18:03:302// 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_linux.h"
6
Christos Froussios494196d2017-07-14 10:10:047#include <memory>
cfroussios3ea4c692016-07-18 19:15:148#include <string>
Christos Froussios494196d2017-07-14 10:10:049#include <utility>
cfroussios3ea4c692016-07-18 19:15:1410
Sebastien Marchandf1349f52019-01-25 03:16:4111#include "base/bind.h"
cfroussios6b340f812017-07-06 15:05:1012#include "base/files/file_path.h"
Gabriel Charette5ff87ce2017-05-16 18:03:4513#include "base/single_thread_task_runner.h"
Gabriel Charette055039132020-02-26 23:02:0614#include "base/task/thread_pool.h"
avie4d7b6f2015-12-26 00:59:1815#include "build/build_config.h"
[email protected]97425082013-07-16 03:10:0716#include "chrome/browser/browser_process.h"
thestigd2efdad2015-09-02 18:03:0917#include "chrome/grit/chromium_strings.h"
Rohit Rao92f84b6a2020-03-25 14:57:5018#include "components/crash/core/app/breakpad_linux.h"
19#include "components/crash/core/app/crashpad.h"
[email protected]d6147bd2014-06-11 01:58:1920#include "components/metrics/metrics_service.h"
Eric Seckler8652dcd52018-09-20 10:42:2821#include "content/public/browser/browser_task_traits.h"
rkc41077042015-11-06 07:20:5822#include "device/bluetooth/dbus/bluez_dbus_manager.h"
Giovanni Ortuño Urquidi3e60c0422018-09-25 00:08:2823#include "device/bluetooth/dbus/bluez_dbus_thread_manager.h"
thestigd2efdad2015-09-02 18:03:0924#include "media/audio/audio_manager.h"
25#include "ui/base/l10n/l10n_util.h"
[email protected]a5e8c6d42012-04-09 20:22:0126
Ian Barkley-Yeung04bbedf02020-02-19 21:14:1827#if defined(OS_CHROMEOS)
28#include "chrome/installer/util/google_update_settings.h"
29#else
cfroussios3ea4c692016-07-18 19:15:1430#include "base/command_line.h"
[email protected]a153f5522014-05-24 12:57:0931#include "base/linux_util.h"
cfroussios6b340f812017-07-06 15:05:1032#include "chrome/common/chrome_paths_internal.h"
cfroussios3ea4c692016-07-18 19:15:1433#include "chrome/common/chrome_switches.h"
Christos Froussios494196d2017-07-14 10:10:0434#include "components/os_crypt/key_storage_config_linux.h"
cfroussios3ea4c692016-07-18 19:15:1435#include "components/os_crypt/os_crypt.h"
[email protected]97425082013-07-16 03:10:0736#include "content/public/browser/browser_thread.h"
[email protected]a5e8c6d42012-04-09 20:22:0137#endif
38
[email protected]b48c9182011-10-26 18:03:3039ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux(
Ran Jia96d43d42018-05-02 17:14:5340 const content::MainFunctionParams& parameters,
Xi Han85079c22019-04-18 21:43:0541 StartupData* startup_data)
42 : ChromeBrowserMainPartsPosix(parameters, startup_data) {}
[email protected]a5e8c6d42012-04-09 20:22:0143
[email protected]ab714ec7b2012-04-12 23:20:2344ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() {
45}
46
[email protected]a5e8c6d42012-04-09 20:22:0147void ChromeBrowserMainPartsLinux::PreProfileInit() {
[email protected]143633ce22012-12-10 22:53:2748#if !defined(OS_CHROMEOS)
[email protected]a5e8c6d42012-04-09 20:22:0149 // Needs to be called after we have chrome::DIR_USER_DATA and
50 // g_browser_process. This happens in PreCreateThreads.
[email protected]a153f5522014-05-24 12:57:0951 // base::GetLinuxDistro() will initialize its value if needed.
Gabriel Charette055039132020-02-26 23:02:0652 base::ThreadPool::PostTask(
53 FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
tzik29ea5c72017-04-20 02:16:5154 base::BindOnce(base::IgnoreResult(&base::GetLinuxDistro)));
[email protected]cbf0d1d2012-08-15 20:54:0655#endif
[email protected]a5e8c6d42012-04-09 20:22:0156
thestigd2efdad2015-09-02 18:03:0957 media::AudioManager::SetGlobalAppName(
58 l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME));
59
cfroussios3ea4c692016-07-18 19:15:1460#if !defined(OS_CHROMEOS)
Clark DuVall1c6f0e12018-07-06 17:31:3461 // Set up crypt config. This should be kept in sync with the OSCrypt parts of
62 // SystemNetworkContextManager::OnNetworkServiceCreated.
Christos Froussios494196d2017-07-14 10:10:0463 std::unique_ptr<os_crypt::Config> config(new os_crypt::Config());
cfroussios3ea4c692016-07-18 19:15:1464 // Forward to os_crypt the flag to use a specific password store.
Christos Froussios494196d2017-07-14 10:10:0465 config->store =
66 parsed_command_line().GetSwitchValueASCII(switches::kPasswordStore);
cfroussios2e6729a42016-07-26 09:18:1267 // Forward the product name
Christos Froussios494196d2017-07-14 10:10:0468 config->product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
Christos Froussios70cc95b2017-12-14 21:13:2369 // OSCrypt may target keyring, which requires calls from the main thread.
Gabriel Charetteb2bbd482020-05-27 01:24:2170 config->main_thread_runner = content::GetUIThreadTaskRunner({});
cfroussios6b340f812017-07-06 15:05:1071 // OSCrypt can be disabled in a special settings file.
Christos Froussios494196d2017-07-14 10:10:0472 config->should_use_preference =
73 parsed_command_line().HasSwitch(switches::kEnableEncryptionSelection);
74 chrome::GetDefaultUserDataDirectory(&config->user_data_path);
75 OSCrypt::SetConfig(std::move(config));
cfroussios3ea4c692016-07-18 19:15:1476#endif
77
[email protected]a5e8c6d42012-04-09 20:22:0178 ChromeBrowserMainPartsPosix::PreProfileInit();
79}
[email protected]1b8529f2012-07-17 18:56:1480
[email protected]e8b6ca02013-07-10 18:00:5181void ChromeBrowserMainPartsLinux::PostProfileInit() {
82 ChromeBrowserMainPartsPosix::PostProfileInit();
83
Ian Barkley-Yeung04bbedf02020-02-19 21:14:1884 bool breakpad_registered;
85 if (crash_reporter::IsCrashpadEnabled()) {
86 // If we're using crashpad, there's no breakpad and crashpad is always
87 // registered as a crash handler. Since setting |breakpad_registered| to
88 // true all the time isn't useful, we overload the meaning of the breakpad
89 // registration metric to mean "is crash reporting enabled", since that's
90 // what breakpad registration effectively meant in the days before crashpad.
91#if defined(OS_CHROMEOS)
92 breakpad_registered = GoogleUpdateSettings::GetCollectStatsConsent();
93#else
94 breakpad_registered = crash_reporter::GetUploadsEnabled();
95#endif
96 } else {
97 breakpad_registered = breakpad::IsCrashReporterEnabled();
98 }
99 g_browser_process->metrics_service()->RecordBreakpadRegistration(
100 breakpad_registered);
[email protected]e8b6ca02013-07-10 18:00:51101}
rkc41077042015-11-06 07:20:58102
103void ChromeBrowserMainPartsLinux::PostMainMessageLoopStart() {
104#if !defined(OS_CHROMEOS)
Steven Bennettsfe68b0d2019-04-17 14:51:41105 bluez::BluezDBusManager::Initialize(nullptr /* system_bus */);
rkc41077042015-11-06 07:20:58106#endif
107
108 ChromeBrowserMainPartsPosix::PostMainMessageLoopStart();
109}
110
111void ChromeBrowserMainPartsLinux::PostDestroyThreads() {
112#if !defined(OS_CHROMEOS)
113 bluez::BluezDBusManager::Shutdown();
Giovanni Ortuño Urquidi3e60c0422018-09-25 00:08:28114 bluez::BluezDBusThreadManager::Shutdown();
rkc41077042015-11-06 07:20:58115#endif
116
117 ChromeBrowserMainPartsPosix::PostDestroyThreads();
118}