blob: be63d8b34aa01bb6e04159f448757c0c02e8d1d7 [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
[email protected]dd357e12014-08-22 01:28:507#include <fontconfig/fontconfig.h>
8
Christos Froussios494196d2017-07-14 10:10:049#include <memory>
cfroussios3ea4c692016-07-18 19:15:1410#include <string>
Christos Froussios494196d2017-07-14 10:10:0411#include <utility>
cfroussios3ea4c692016-07-18 19:15:1412
cfroussios6b340f812017-07-06 15:05:1013#include "base/files/file_path.h"
Gabriel Charette5ff87ce2017-05-16 18:03:4514#include "base/single_thread_task_runner.h"
fdorayf78be9742017-02-07 16:15:1715#include "base/task_scheduler/post_task.h"
avie4d7b6f2015-12-26 00:59:1816#include "build/build_config.h"
[email protected]97425082013-07-16 03:10:0717#include "chrome/browser/browser_process.h"
thestigd2efdad2015-09-02 18:03:0918#include "chrome/grit/chromium_strings.h"
sdefresne8ba0b88c2015-09-18 10:33:1319#include "components/crash/content/app/breakpad_linux.h"
[email protected]d6147bd2014-06-11 01:58:1920#include "components/metrics/metrics_service.h"
rkc41077042015-11-06 07:20:5821#include "device/bluetooth/dbus/bluez_dbus_manager.h"
22#include "device/bluetooth/dbus/dbus_thread_manager_linux.h"
thestigd2efdad2015-09-02 18:03:0923#include "media/audio/audio_manager.h"
24#include "ui/base/l10n/l10n_util.h"
[email protected]a5e8c6d42012-04-09 20:22:0125
[email protected]6664958a2013-11-07 08:35:2926#if !defined(OS_CHROMEOS)
cfroussios3ea4c692016-07-18 19:15:1427#include "base/command_line.h"
[email protected]a153f5522014-05-24 12:57:0928#include "base/linux_util.h"
cfroussios6b340f812017-07-06 15:05:1029#include "chrome/common/chrome_paths_internal.h"
cfroussios3ea4c692016-07-18 19:15:1430#include "chrome/common/chrome_switches.h"
Christos Froussios494196d2017-07-14 10:10:0431#include "components/os_crypt/key_storage_config_linux.h"
cfroussios3ea4c692016-07-18 19:15:1432#include "components/os_crypt/os_crypt.h"
[email protected]97425082013-07-16 03:10:0733#include "content/public/browser/browser_thread.h"
[email protected]a5e8c6d42012-04-09 20:22:0134#endif
35
[email protected]b48c9182011-10-26 18:03:3036ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux(
Ran Jia96d43d42018-05-02 17:14:5337 const content::MainFunctionParams& parameters,
38 std::unique_ptr<ui::DataPack> data_pack)
39 : ChromeBrowserMainPartsPosix(parameters, std::move(data_pack)) {}
[email protected]a5e8c6d42012-04-09 20:22:0140
[email protected]ab714ec7b2012-04-12 23:20:2341ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() {
42}
43
[email protected]dd357e12014-08-22 01:28:5044void ChromeBrowserMainPartsLinux::ToolkitInitialized() {
45 // Explicitly initialize Fontconfig early on to prevent races later due to
46 // implicit initialization in response to threads' first calls to Fontconfig:
47 // http://crbug.com/404311
48 FcInit();
49
50 ChromeBrowserMainPartsPosix::ToolkitInitialized();
51}
52
[email protected]a5e8c6d42012-04-09 20:22:0153void ChromeBrowserMainPartsLinux::PreProfileInit() {
[email protected]143633ce22012-12-10 22:53:2754#if !defined(OS_CHROMEOS)
[email protected]a5e8c6d42012-04-09 20:22:0155 // Needs to be called after we have chrome::DIR_USER_DATA and
56 // g_browser_process. This happens in PreCreateThreads.
[email protected]a153f5522014-05-24 12:57:0957 // base::GetLinuxDistro() will initialize its value if needed.
fdorayf78be9742017-02-07 16:15:1758 base::PostTaskWithTraits(
fdoray4ad14932017-05-03 21:21:1159 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
tzik29ea5c72017-04-20 02:16:5160 base::BindOnce(base::IgnoreResult(&base::GetLinuxDistro)));
[email protected]cbf0d1d2012-08-15 20:54:0661#endif
[email protected]a5e8c6d42012-04-09 20:22:0162
thestigd2efdad2015-09-02 18:03:0963 media::AudioManager::SetGlobalAppName(
64 l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME));
65
cfroussios3ea4c692016-07-18 19:15:1466#if !defined(OS_CHROMEOS)
Christos Froussios494196d2017-07-14 10:10:0467 std::unique_ptr<os_crypt::Config> config(new os_crypt::Config());
cfroussios3ea4c692016-07-18 19:15:1468 // Forward to os_crypt the flag to use a specific password store.
Christos Froussios494196d2017-07-14 10:10:0469 config->store =
70 parsed_command_line().GetSwitchValueASCII(switches::kPasswordStore);
cfroussios2e6729a42016-07-26 09:18:1271 // Forward the product name
Christos Froussios494196d2017-07-14 10:10:0472 config->product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
Christos Froussios70cc95b2017-12-14 21:13:2373 // OSCrypt may target keyring, which requires calls from the main thread.
Christos Froussios494196d2017-07-14 10:10:0474 config->main_thread_runner = content::BrowserThread::GetTaskRunnerForThread(
75 content::BrowserThread::UI);
cfroussios6b340f812017-07-06 15:05:1076 // OSCrypt can be disabled in a special settings file.
Christos Froussios494196d2017-07-14 10:10:0477 config->should_use_preference =
78 parsed_command_line().HasSwitch(switches::kEnableEncryptionSelection);
79 chrome::GetDefaultUserDataDirectory(&config->user_data_path);
80 OSCrypt::SetConfig(std::move(config));
cfroussios3ea4c692016-07-18 19:15:1481#endif
82
[email protected]a5e8c6d42012-04-09 20:22:0183 ChromeBrowserMainPartsPosix::PreProfileInit();
84}
[email protected]1b8529f2012-07-17 18:56:1485
[email protected]e8b6ca02013-07-10 18:00:5186void ChromeBrowserMainPartsLinux::PostProfileInit() {
87 ChromeBrowserMainPartsPosix::PostProfileInit();
88
[email protected]e8b6ca02013-07-10 18:00:5189 g_browser_process->metrics_service()->RecordBreakpadRegistration(
[email protected]0b818f72013-10-22 00:11:0390 breakpad::IsCrashReporterEnabled());
[email protected]e8b6ca02013-07-10 18:00:5191}
rkc41077042015-11-06 07:20:5892
93void ChromeBrowserMainPartsLinux::PostMainMessageLoopStart() {
94#if !defined(OS_CHROMEOS)
95 bluez::DBusThreadManagerLinux::Initialize();
96 bluez::BluezDBusManager::Initialize(
97 bluez::DBusThreadManagerLinux::Get()->GetSystemBus(), false);
98#endif
99
100 ChromeBrowserMainPartsPosix::PostMainMessageLoopStart();
101}
102
103void ChromeBrowserMainPartsLinux::PostDestroyThreads() {
104#if !defined(OS_CHROMEOS)
105 bluez::BluezDBusManager::Shutdown();
106 bluez::DBusThreadManagerLinux::Shutdown();
107#endif
108
109 ChromeBrowserMainPartsPosix::PostDestroyThreads();
110}