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"
7 #if !defined(OS_CHROMEOS)
8 #include "chrome/browser/storage_monitor/storage_monitor_linux.h"
9 #include "content/public/browser/browser_thread.h"
12 #if defined(USE_LINUX_BREAKPAD)
15 #include "base/command_line.h"
16 #include "base/linux_util.h"
17 #include "base/prefs/pref_service.h"
18 #include "chrome/app/breakpad_linux.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/env_vars.h"
21 #include "chrome/common/pref_names.h"
23 #if defined(OS_CHROMEOS)
24 #include "chrome/browser/chromeos/settings/cros_settings.h"
25 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
26 #include "chrome/common/chrome_version_info.h"
27 #include "chromeos/chromeos_switches.h"
30 #endif // defined(USE_LINUX_BREAKPAD)
34 #if defined(USE_LINUX_BREAKPAD)
35 #if !defined(OS_CHROMEOS)
36 void GetLinuxDistroCallback() {
37 base::GetLinuxDistro(); // Initialize base::linux_distro if needed.
41 bool IsCrashReportingEnabled(const PrefService
* local_state
) {
42 // Check whether we should initialize the crash reporter. It may be disabled
43 // through configuration policy or user preference. It must be disabled for
44 // Guest mode on Chrome OS in Stable channel.
45 // Also allow crash reporting to be enabled with a command-line flag if the
46 // crash service is under control of the user. It is used by QA
47 // testing infrastructure to switch on generation of crash reports.
48 bool use_switch
= true;
50 // Convert #define to a variable so that we can use if() rather than
51 // #if below and so at least compile-test the Chrome code in
53 #if defined(GOOGLE_CHROME_BUILD)
54 bool is_chrome_build
= true;
56 bool is_chrome_build
= false;
59 // Check these settings in Chrome builds only, to reduce the chance
60 // that we accidentally upload crash dumps from Chromium builds.
61 bool breakpad_enabled
= false;
62 if (is_chrome_build
) {
63 #if defined(OS_CHROMEOS)
64 bool is_guest_session
= CommandLine::ForCurrentProcess()->HasSwitch(
65 chromeos::switches::kGuestSession
);
66 bool is_stable_channel
=
67 chrome::VersionInfo::GetChannel() ==
68 chrome::VersionInfo::CHANNEL_STABLE
;
69 // TODO(pastarmovj): Consider the TrustedGet here.
70 bool reporting_enabled
;
71 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref
,
74 !(is_guest_session
&& is_stable_channel
) && reporting_enabled
;
76 const PrefService::Preference
* metrics_reporting_enabled
=
77 local_state
->FindPreference(prefs::kMetricsReportingEnabled
);
78 CHECK(metrics_reporting_enabled
);
79 breakpad_enabled
= local_state
->GetBoolean(prefs::kMetricsReportingEnabled
);
80 use_switch
= metrics_reporting_enabled
->IsUserModifiable();
81 #endif // defined(OS_CHROMEOS)
85 // Linux Breakpad interferes with the debug stack traces produced
86 // by EnableInProcessStackDumping(), used in browser_tests, so we
87 // do not allow CHROME_HEADLESS=1 to enable Breakpad in Chromium
88 // because the buildbots have CHROME_HEADLESS set. However, we
89 // allow CHROME_HEADLESS to enable Breakpad in Chrome for
90 // compatibility with Breakpad/Chrome tests that may rely on this.
91 // TODO(mseaborn): Change tests to use --enable-crash-reporter-for-testing
93 if (is_chrome_build
&& !breakpad_enabled
)
94 breakpad_enabled
= getenv(env_vars::kHeadless
) != NULL
;
95 if (!breakpad_enabled
)
96 breakpad_enabled
= CommandLine::ForCurrentProcess()->HasSwitch(
97 switches::kEnableCrashReporterForTesting
);
100 return breakpad_enabled
;
102 #endif // defined(USE_LINUX_BREAKPAD)
106 ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux(
107 const content::MainFunctionParams
& parameters
)
108 : ChromeBrowserMainPartsPosix(parameters
) {
111 ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() {
114 void ChromeBrowserMainPartsLinux::PreProfileInit() {
115 #if defined(USE_LINUX_BREAKPAD)
116 #if !defined(OS_CHROMEOS)
117 // Needs to be called after we have chrome::DIR_USER_DATA and
118 // g_browser_process. This happens in PreCreateThreads.
119 content::BrowserThread::PostTask(content::BrowserThread::FILE,
121 base::Bind(&GetLinuxDistroCallback
));
124 if (IsCrashReportingEnabled(local_state()))
128 #if !defined(OS_CHROMEOS)
129 const base::FilePath
kDefaultMtabPath("/etc/mtab");
130 storage_monitor_
.reset(new chrome::StorageMonitorLinux(kDefaultMtabPath
));
133 ChromeBrowserMainPartsPosix::PreProfileInit();
136 void ChromeBrowserMainPartsLinux::PostProfileInit() {
137 #if !defined(OS_CHROMEOS)
138 storage_monitor_
->Init();
141 ChromeBrowserMainPartsPosix::PostProfileInit();
144 void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() {
145 #if !defined(OS_CHROMEOS)
146 // Delete it now. Otherwise the FILE thread would be gone when we try to
147 // release it in the dtor and Valgrind would report a leak on almost every
148 // single browser_test.
149 storage_monitor_
.reset();
152 ChromeBrowserMainPartsPosix::PostMainMessageLoopRun();