[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 | |||||
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 7 | #include <memory> |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 8 | #include <string> |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 9 | #include <utility> |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 10 | |
Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame] | 11 | #include "base/bind.h" |
cfroussios | 6b340f81 | 2017-07-06 15:05:10 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
Gabriel Charette | 5ff87ce | 2017-05-16 18:03:45 | [diff] [blame] | 13 | #include "base/single_thread_task_runner.h" |
Gabriel Charette | 05503913 | 2020-02-26 23:02:06 | [diff] [blame] | 14 | #include "base/task/thread_pool.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 15 | #include "build/build_config.h" |
[email protected] | 9742508 | 2013-07-16 03:10:07 | [diff] [blame] | 16 | #include "chrome/browser/browser_process.h" |
thestig | d2efdad | 2015-09-02 18:03:09 | [diff] [blame] | 17 | #include "chrome/grit/chromium_strings.h" |
Rohit Rao | 92f84b6a | 2020-03-25 14:57:50 | [diff] [blame] | 18 | #include "components/crash/core/app/breakpad_linux.h" |
19 | #include "components/crash/core/app/crashpad.h" | ||||
[email protected] | d6147bd | 2014-06-11 01:58:19 | [diff] [blame] | 20 | #include "components/metrics/metrics_service.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 21 | #include "content/public/browser/browser_task_traits.h" |
rkc | 4107704 | 2015-11-06 07:20:58 | [diff] [blame] | 22 | #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
Giovanni Ortuño Urquidi | 3e60c042 | 2018-09-25 00:08:28 | [diff] [blame] | 23 | #include "device/bluetooth/dbus/bluez_dbus_thread_manager.h" |
thestig | d2efdad | 2015-09-02 18:03:09 | [diff] [blame] | 24 | #include "media/audio/audio_manager.h" |
25 | #include "ui/base/l10n/l10n_util.h" | ||||
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 26 | |
Ian Barkley-Yeung | 04bbedf0 | 2020-02-19 21:14:18 | [diff] [blame] | 27 | #if defined(OS_CHROMEOS) |
28 | #include "chrome/installer/util/google_update_settings.h" | ||||
29 | #else | ||||
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 30 | #include "base/command_line.h" |
[email protected] | a153f552 | 2014-05-24 12:57:09 | [diff] [blame] | 31 | #include "base/linux_util.h" |
cfroussios | 6b340f81 | 2017-07-06 15:05:10 | [diff] [blame] | 32 | #include "chrome/common/chrome_paths_internal.h" |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 33 | #include "chrome/common/chrome_switches.h" |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 34 | #include "components/os_crypt/key_storage_config_linux.h" |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 35 | #include "components/os_crypt/os_crypt.h" |
[email protected] | 9742508 | 2013-07-16 03:10:07 | [diff] [blame] | 36 | #include "content/public/browser/browser_thread.h" |
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 37 | #endif |
38 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 39 | ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( |
Ran Ji | a96d43d4 | 2018-05-02 17:14:53 | [diff] [blame] | 40 | const content::MainFunctionParams& parameters, |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 41 | StartupData* startup_data) |
42 | : ChromeBrowserMainPartsPosix(parameters, startup_data) {} | ||||
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 43 | |
[email protected] | ab714ec7b | 2012-04-12 23:20:23 | [diff] [blame] | 44 | ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() { |
45 | } | ||||
46 | |||||
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 47 | void ChromeBrowserMainPartsLinux::PreProfileInit() { |
[email protected] | 143633ce2 | 2012-12-10 22:53:27 | [diff] [blame] | 48 | #if !defined(OS_CHROMEOS) |
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 49 | // Needs to be called after we have chrome::DIR_USER_DATA and |
50 | // g_browser_process. This happens in PreCreateThreads. | ||||
[email protected] | a153f552 | 2014-05-24 12:57:09 | [diff] [blame] | 51 | // base::GetLinuxDistro() will initialize its value if needed. |
Gabriel Charette | 05503913 | 2020-02-26 23:02:06 | [diff] [blame] | 52 | base::ThreadPool::PostTask( |
53 | FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, | ||||
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 54 | base::BindOnce(base::IgnoreResult(&base::GetLinuxDistro))); |
[email protected] | cbf0d1d | 2012-08-15 20:54:06 | [diff] [blame] | 55 | #endif |
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 56 | |
thestig | d2efdad | 2015-09-02 18:03:09 | [diff] [blame] | 57 | media::AudioManager::SetGlobalAppName( |
58 | l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME)); | ||||
59 | |||||
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 60 | #if !defined(OS_CHROMEOS) |
Clark DuVall | 1c6f0e1 | 2018-07-06 17:31:34 | [diff] [blame] | 61 | // Set up crypt config. This should be kept in sync with the OSCrypt parts of |
62 | // SystemNetworkContextManager::OnNetworkServiceCreated. | ||||
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 63 | std::unique_ptr<os_crypt::Config> config(new os_crypt::Config()); |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 64 | // Forward to os_crypt the flag to use a specific password store. |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 65 | config->store = |
66 | parsed_command_line().GetSwitchValueASCII(switches::kPasswordStore); | ||||
cfroussios | 2e6729a4 | 2016-07-26 09:18:12 | [diff] [blame] | 67 | // Forward the product name |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 68 | config->product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); |
Christos Froussios | 70cc95b | 2017-12-14 21:13:23 | [diff] [blame] | 69 | // OSCrypt may target keyring, which requires calls from the main thread. |
Gabriel Charette | b2bbd48 | 2020-05-27 01:24:21 | [diff] [blame] | 70 | config->main_thread_runner = content::GetUIThreadTaskRunner({}); |
cfroussios | 6b340f81 | 2017-07-06 15:05:10 | [diff] [blame] | 71 | // OSCrypt can be disabled in a special settings file. |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 72 | config->should_use_preference = |
73 | parsed_command_line().HasSwitch(switches::kEnableEncryptionSelection); | ||||
74 | chrome::GetDefaultUserDataDirectory(&config->user_data_path); | ||||
75 | OSCrypt::SetConfig(std::move(config)); | ||||
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 76 | #endif |
77 | |||||
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 78 | ChromeBrowserMainPartsPosix::PreProfileInit(); |
79 | } | ||||
[email protected] | 1b8529f | 2012-07-17 18:56:14 | [diff] [blame] | 80 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 81 | void ChromeBrowserMainPartsLinux::PostProfileInit() { |
82 | ChromeBrowserMainPartsPosix::PostProfileInit(); | ||||
83 | |||||
Ian Barkley-Yeung | 04bbedf0 | 2020-02-19 21:14:18 | [diff] [blame] | 84 | 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] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 101 | } |
rkc | 4107704 | 2015-11-06 07:20:58 | [diff] [blame] | 102 | |
103 | void ChromeBrowserMainPartsLinux::PostMainMessageLoopStart() { | ||||
104 | #if !defined(OS_CHROMEOS) | ||||
Steven Bennetts | fe68b0d | 2019-04-17 14:51:41 | [diff] [blame] | 105 | bluez::BluezDBusManager::Initialize(nullptr /* system_bus */); |
rkc | 4107704 | 2015-11-06 07:20:58 | [diff] [blame] | 106 | #endif |
107 | |||||
108 | ChromeBrowserMainPartsPosix::PostMainMessageLoopStart(); | ||||
109 | } | ||||
110 | |||||
111 | void ChromeBrowserMainPartsLinux::PostDestroyThreads() { | ||||
112 | #if !defined(OS_CHROMEOS) | ||||
113 | bluez::BluezDBusManager::Shutdown(); | ||||
Giovanni Ortuño Urquidi | 3e60c042 | 2018-09-25 00:08:28 | [diff] [blame] | 114 | bluez::BluezDBusThreadManager::Shutdown(); |
rkc | 4107704 | 2015-11-06 07:20:58 | [diff] [blame] | 115 | #endif |
116 | |||||
117 | ChromeBrowserMainPartsPosix::PostDestroyThreads(); | ||||
118 | } |