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_linux.h"
11 #include "base/bind.h"
12 #include "base/files/file_path.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/task/thread_pool.h"
15 #include "build/build_config.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/grit/chromium_strings.h"
18 #include "components/crash/core/app/breakpad_linux.h"
19 #include "components/crash/core/app/crashpad.h"
20 #include "components/metrics/metrics_service.h"
21 #include "content/public/browser/browser_task_traits.h"
22 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
23 #include "device/bluetooth/dbus/bluez_dbus_thread_manager.h"
24 #include "media/audio/audio_manager.h"
25 #include "ui/base/l10n/l10n_util.h"
27 #if defined(OS_CHROMEOS)
28 #include "chrome/installer/util/google_update_settings.h"
30 #include "base/command_line.h"
31 #include "base/linux_util.h"
32 #include "chrome/common/chrome_paths_internal.h"
33 #include "chrome/common/chrome_switches.h"
34 #include "components/os_crypt/key_storage_config_linux.h"
35 #include "components/os_crypt/os_crypt.h"
36 #include "content/public/browser/browser_thread.h"
39 ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux(
40 const content::MainFunctionParams& parameters,
41 StartupData* startup_data)
42 : ChromeBrowserMainPartsPosix(parameters, startup_data) {}
44 ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() {
47 void ChromeBrowserMainPartsLinux::PreProfileInit() {
48 #if !defined(OS_CHROMEOS)
49 // Needs to be called after we have chrome::DIR_USER_DATA and
50 // g_browser_process. This happens in PreCreateThreads.
51 // base::GetLinuxDistro() will initialize its value if needed.
52 base::ThreadPool::PostTask(
53 FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
54 base::BindOnce(base::IgnoreResult(&base::GetLinuxDistro)));
57 media::AudioManager::SetGlobalAppName(
58 l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME));
60 #if !defined(OS_CHROMEOS)
61 // Set up crypt config. This should be kept in sync with the OSCrypt parts of
62 // SystemNetworkContextManager::OnNetworkServiceCreated.
63 std::unique_ptr<os_crypt::Config> config(new os_crypt::Config());
64 // Forward to os_crypt the flag to use a specific password store.
66 parsed_command_line().GetSwitchValueASCII(switches::kPasswordStore);
67 // Forward the product name
68 config->product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
69 // OSCrypt may target keyring, which requires calls from the main thread.
70 config->main_thread_runner = content::GetUIThreadTaskRunner({});
71 // OSCrypt can be disabled in a special settings file.
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));
78 ChromeBrowserMainPartsPosix::PreProfileInit();
81 void ChromeBrowserMainPartsLinux::PostProfileInit() {
82 ChromeBrowserMainPartsPosix::PostProfileInit();
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();
94 breakpad_registered = crash_reporter::GetUploadsEnabled();
97 breakpad_registered = breakpad::IsCrashReporterEnabled();
99 g_browser_process->metrics_service()->RecordBreakpadRegistration(
100 breakpad_registered);
103 void ChromeBrowserMainPartsLinux::PostMainMessageLoopStart() {
104 #if !defined(OS_CHROMEOS)
105 bluez::BluezDBusManager::Initialize(nullptr /* system_bus */);
108 ChromeBrowserMainPartsPosix::PostMainMessageLoopStart();
111 void ChromeBrowserMainPartsLinux::PostDestroyThreads() {
112 #if !defined(OS_CHROMEOS)
113 bluez::BluezDBusManager::Shutdown();
114 bluez::BluezDBusThreadManager::Shutdown();
117 ChromeBrowserMainPartsPosix::PostDestroyThreads();