[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 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_linux.h" | ||||
6 | |||||
[email protected] | dd357e1 | 2014-08-22 01:28:50 | [diff] [blame] | 7 | #include <fontconfig/fontconfig.h> |
8 | |||||
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 9 | #include <memory> |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 10 | #include <string> |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 11 | #include <utility> |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 12 | |
cfroussios | 6b340f81 | 2017-07-06 15:05:10 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
Gabriel Charette | 5ff87ce | 2017-05-16 18:03:45 | [diff] [blame] | 14 | #include "base/single_thread_task_runner.h" |
fdoray | f78be974 | 2017-02-07 16:15:17 | [diff] [blame] | 15 | #include "base/task_scheduler/post_task.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | 9742508 | 2013-07-16 03:10:07 | [diff] [blame] | 17 | #include "chrome/browser/browser_process.h" |
thestig | d2efdad | 2015-09-02 18:03:09 | [diff] [blame] | 18 | #include "chrome/grit/chromium_strings.h" |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 19 | #include "components/crash/content/app/breakpad_linux.h" |
[email protected] | d6147bd | 2014-06-11 01:58:19 | [diff] [blame] | 20 | #include "components/metrics/metrics_service.h" |
rkc | 4107704 | 2015-11-06 07:20:58 | [diff] [blame] | 21 | #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
22 | #include "device/bluetooth/dbus/dbus_thread_manager_linux.h" | ||||
thestig | d2efdad | 2015-09-02 18:03:09 | [diff] [blame] | 23 | #include "media/audio/audio_manager.h" |
24 | #include "ui/base/l10n/l10n_util.h" | ||||
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 25 | |
[email protected] | 6664958a | 2013-11-07 08:35:29 | [diff] [blame] | 26 | #if !defined(OS_CHROMEOS) |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 27 | #include "base/command_line.h" |
[email protected] | a153f552 | 2014-05-24 12:57:09 | [diff] [blame] | 28 | #include "base/linux_util.h" |
cfroussios | 6b340f81 | 2017-07-06 15:05:10 | [diff] [blame] | 29 | #include "chrome/common/chrome_paths_internal.h" |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 30 | #include "chrome/common/chrome_switches.h" |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 31 | #include "components/os_crypt/key_storage_config_linux.h" |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 32 | #include "components/os_crypt/os_crypt.h" |
[email protected] | 9742508 | 2013-07-16 03:10:07 | [diff] [blame] | 33 | #include "content/public/browser/browser_thread.h" |
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 34 | #endif |
35 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 36 | ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( |
Ran Ji | a96d43d4 | 2018-05-02 17:14:53 | [diff] [blame^] | 37 | const content::MainFunctionParams& parameters, |
38 | std::unique_ptr<ui::DataPack> data_pack) | ||||
39 | : ChromeBrowserMainPartsPosix(parameters, std::move(data_pack)) {} | ||||
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 40 | |
[email protected] | ab714ec7b | 2012-04-12 23:20:23 | [diff] [blame] | 41 | ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() { |
42 | } | ||||
43 | |||||
[email protected] | dd357e1 | 2014-08-22 01:28:50 | [diff] [blame] | 44 | void 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] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 53 | void ChromeBrowserMainPartsLinux::PreProfileInit() { |
[email protected] | 143633ce2 | 2012-12-10 22:53:27 | [diff] [blame] | 54 | #if !defined(OS_CHROMEOS) |
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 55 | // Needs to be called after we have chrome::DIR_USER_DATA and |
56 | // g_browser_process. This happens in PreCreateThreads. | ||||
[email protected] | a153f552 | 2014-05-24 12:57:09 | [diff] [blame] | 57 | // base::GetLinuxDistro() will initialize its value if needed. |
fdoray | f78be974 | 2017-02-07 16:15:17 | [diff] [blame] | 58 | base::PostTaskWithTraits( |
fdoray | 4ad1493 | 2017-05-03 21:21:11 | [diff] [blame] | 59 | FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 60 | base::BindOnce(base::IgnoreResult(&base::GetLinuxDistro))); |
[email protected] | cbf0d1d | 2012-08-15 20:54:06 | [diff] [blame] | 61 | #endif |
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 62 | |
thestig | d2efdad | 2015-09-02 18:03:09 | [diff] [blame] | 63 | media::AudioManager::SetGlobalAppName( |
64 | l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME)); | ||||
65 | |||||
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 66 | #if !defined(OS_CHROMEOS) |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 67 | std::unique_ptr<os_crypt::Config> config(new os_crypt::Config()); |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 68 | // Forward to os_crypt the flag to use a specific password store. |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 69 | config->store = |
70 | parsed_command_line().GetSwitchValueASCII(switches::kPasswordStore); | ||||
cfroussios | 2e6729a4 | 2016-07-26 09:18:12 | [diff] [blame] | 71 | // Forward the product name |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 72 | config->product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); |
Christos Froussios | 70cc95b | 2017-12-14 21:13:23 | [diff] [blame] | 73 | // OSCrypt may target keyring, which requires calls from the main thread. |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 74 | config->main_thread_runner = content::BrowserThread::GetTaskRunnerForThread( |
75 | content::BrowserThread::UI); | ||||
cfroussios | 6b340f81 | 2017-07-06 15:05:10 | [diff] [blame] | 76 | // OSCrypt can be disabled in a special settings file. |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 77 | config->should_use_preference = |
78 | parsed_command_line().HasSwitch(switches::kEnableEncryptionSelection); | ||||
79 | chrome::GetDefaultUserDataDirectory(&config->user_data_path); | ||||
80 | OSCrypt::SetConfig(std::move(config)); | ||||
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 81 | #endif |
82 | |||||
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 83 | ChromeBrowserMainPartsPosix::PreProfileInit(); |
84 | } | ||||
[email protected] | 1b8529f | 2012-07-17 18:56:14 | [diff] [blame] | 85 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 86 | void ChromeBrowserMainPartsLinux::PostProfileInit() { |
87 | ChromeBrowserMainPartsPosix::PostProfileInit(); | ||||
88 | |||||
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 89 | g_browser_process->metrics_service()->RecordBreakpadRegistration( |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 90 | breakpad::IsCrashReporterEnabled()); |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 91 | } |
rkc | 4107704 | 2015-11-06 07:20:58 | [diff] [blame] | 92 | |
93 | void 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 | |||||
103 | void ChromeBrowserMainPartsLinux::PostDestroyThreads() { | ||||
104 | #if !defined(OS_CHROMEOS) | ||||
105 | bluez::BluezDBusManager::Shutdown(); | ||||
106 | bluez::DBusThreadManagerLinux::Shutdown(); | ||||
107 | #endif | ||||
108 | |||||
109 | ChromeBrowserMainPartsPosix::PostDestroyThreads(); | ||||
110 | } |