File: chrome_browser_main_linux.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (140 lines) | stat: -rw-r--r-- 5,312 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chrome_browser_main_linux.h"

#include <memory>
#include <string>
#include <utility>

#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/branded_strings.h"
#include "components/password_manager/core/browser/password_manager_switches.h"
#include "content/public/browser/browser_thread.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/bluez_dbus_thread_manager.h"
#include "ui/base/l10n/l10n_util.h"

#if BUILDFLAG(IS_LINUX)
#include "ui/ozone/public/ozone_platform.h"
#endif

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/installer/util/google_update_settings.h"
#include "components/metrics/call_stacks/stack_sampling_recorder.h"
#endif

#if BUILDFLAG(USE_DBUS) && !BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/dbus_memory_pressure_evaluator_linux.h"
#endif

#if !BUILDFLAG(IS_CHROMEOS)
#include "base/linux_util.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#include "components/os_crypt/sync/key_storage_config_linux.h"
#include "components/os_crypt/sync/os_crypt.h"
#endif

ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux(
    bool is_integration_test,
    StartupData* startup_data)
    : ChromeBrowserMainPartsPosix(is_integration_test, startup_data) {}

ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() = default;

void ChromeBrowserMainPartsLinux::PostCreateMainMessageLoop() {
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
#if BUILDFLAG(IS_CHROMEOS)
  if (command_line->HasSwitch(metrics::kRecordStackSamplingDataSwitch)) {
    stack_sampling_recorder_ =
        base::MakeRefCounted<metrics::StackSamplingRecorder>();
    stack_sampling_recorder_->Start();
  }
  // Don't initialize DBus here. Bluetooth DBusManager initialization depends on
  // FeatureList, and is done elsewhere.
#endif  // BUILDFLAG(IS_CHROMEOS)

#if !BUILDFLAG(IS_CHROMEOS)
  bluez::BluezDBusManager::Initialize(nullptr /* system_bus */);

  // Set up crypt config. This needs to be done before anything starts the
  // network service, as the raw encryption key needs to be shared with the
  // network service for encrypted cookie storage.
  // Chrome OS does not need a crypt config as its user data directories are
  // already encrypted and none of the true encryption backends used by desktop
  // Linux are available on Chrome OS anyway.
  std::unique_ptr<os_crypt::Config> config =
      std::make_unique<os_crypt::Config>();
  // Forward to os_crypt the flag to use a specific password store.
  config->store =
      command_line->GetSwitchValueASCII(password_manager::kPasswordStore);
  // Forward the product name
  config->product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
  // OSCrypt can be disabled in a special settings file.
  config->should_use_preference =
      base::CommandLine::ForCurrentProcess()->HasSwitch(
          password_manager::kEnableEncryptionSelection);
  chrome::GetDefaultUserDataDirectory(&config->user_data_path);
  OSCrypt::SetConfig(std::move(config));
#endif  // !BUILDFLAG(IS_CHROMEOS)

  ChromeBrowserMainPartsPosix::PostCreateMainMessageLoop();
}

#if BUILDFLAG(IS_LINUX)
void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() {
  ChromeBrowserMainPartsPosix::PostMainMessageLoopRun();
  ui::OzonePlatform::GetInstance()->PostMainMessageLoopRun();
}
#endif

void ChromeBrowserMainPartsLinux::PreProfileInit() {
#if !BUILDFLAG(IS_CHROMEOS)
  // Needs to be called after we have chrome::DIR_USER_DATA and
  // g_browser_process.  This happens in PreCreateThreads.
  // base::GetLinuxDistro() will initialize its value if needed.
  base::ThreadPool::PostTask(
      FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
      base::BindOnce(base::IgnoreResult(&base::GetLinuxDistro)));
#endif

  ChromeBrowserMainPartsPosix::PreProfileInit();
}

#if BUILDFLAG(USE_DBUS) && !BUILDFLAG(IS_CHROMEOS)
void ChromeBrowserMainPartsLinux::PostBrowserStart() {
  // static_cast is safe because this is the only implementation of
  // MemoryPressureMonitor.
  auto* monitor =
      static_cast<memory_pressure::MultiSourceMemoryPressureMonitor*>(
          base::MemoryPressureMonitor::Get());
  if (monitor &&
      base::FeatureList::IsEnabled(features::kLinuxLowMemoryMonitor)) {
    monitor->SetSystemEvaluator(
        std::make_unique<DbusMemoryPressureEvaluatorLinux>(
            monitor->CreateVoter()));
  }
  ChromeBrowserMainPartsPosix::PostBrowserStart();
}
#endif  // BUILDFLAG(USE_DBUS) && !BUILDFLAG(IS_CHROMEOS)

void ChromeBrowserMainPartsLinux::PostDestroyThreads() {
#if BUILDFLAG(IS_CHROMEOS)
  // No-op; per PostBrowserStart() comment, this is done elsewhere.
#else
  bluez::BluezDBusManager::Shutdown();
  bluez::BluezDBusThreadManager::Shutdown();
#endif  // BUILDFLAG(IS_CHROMEOS)

  ChromeBrowserMainPartsPosix::PostDestroyThreads();
}