Commit aa564b7d authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

AppShell: Enable crash reporting on Linux

Upload crashes to the crash server (official build only) using the
product name "AppShell_Linux".

Bug: 818065
Change-Id: I6ad23001323bbc7858ab5b45763868bccfa90a7e
Reviewed-on: https://chromium-review.googlesource.com/957968
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542618}
parent c825cfb1
...@@ -205,9 +205,17 @@ source_set("app_shell_lib") { ...@@ -205,9 +205,17 @@ source_set("app_shell_lib") {
if (is_desktop_linux) { if (is_desktop_linux) {
sources += [ sources += [
"app/shell_crash_reporter_client.cc",
"app/shell_crash_reporter_client.h",
"browser/api/file_system/shell_file_system_delegate.cc", "browser/api/file_system/shell_file_system_delegate.cc",
"browser/api/file_system/shell_file_system_delegate.h", "browser/api/file_system/shell_file_system_delegate.h",
] ]
deps += [
"//components/crash/content/app",
"//components/crash/core/common",
"//components/upload_list",
"//components/version_info:generate_version_info",
]
} }
if (is_chromeos) { if (is_chromeos) {
......
include_rules = [ include_rules = [
"+extensions/shell", "+extensions/shell",
"+chromeos", "+chromeos",
"+components/crash",
"+components/nacl", "+components/nacl",
"+components/upload_list",
"+content/public/app", "+content/public/app",
"+content/public/browser", "+content/public/browser",
"+content/public/utility", "+content/public/utility",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/shell/app/shell_crash_reporter_client.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "components/crash/core/common/crash_keys.h"
#include "components/upload_list/crash_upload_list.h"
#include "components/version_info/version_info_values.h"
#include "content/public/common/content_switches.h"
#include "extensions/shell/common/switches.h"
namespace extensions {
ShellCrashReporterClient::ShellCrashReporterClient() = default;
ShellCrashReporterClient::~ShellCrashReporterClient() = default;
void ShellCrashReporterClient::SetCrashReporterClientIdFromGUID(
const std::string& client_guid) {
crash_keys::SetMetricsClientIdFromGUID(client_guid);
}
void ShellCrashReporterClient::GetProductNameAndVersion(
const char** product_name,
const char** version) {
DCHECK(product_name);
DCHECK(version);
*product_name = "AppShell_Linux";
*version = PRODUCT_VERSION;
}
base::FilePath ShellCrashReporterClient::GetReporterLogFilename() {
return base::FilePath(CrashUploadList::kReporterLogFilename);
}
bool ShellCrashReporterClient::GetCrashDumpLocation(base::FilePath* crash_dir) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCrashDumpsDir)) {
return false;
}
base::FilePath crash_directory =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kCrashDumpsDir);
if (crash_directory.empty())
return false;
if (!base::PathExists(crash_directory) &&
!base::CreateDirectory(crash_directory)) {
return false;
}
*crash_dir = std::move(crash_directory);
return true;
}
bool ShellCrashReporterClient::IsRunningUnattended() {
return false;
}
bool ShellCrashReporterClient::GetCollectStatsConsent() {
#if defined(GOOGLE_CHROME_BUILD)
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableReporting);
#else
return false;
#endif
}
bool ShellCrashReporterClient::EnableBreakpadForProcess(
const std::string& process_type) {
return process_type == ::switches::kRendererProcess ||
process_type == ::switches::kPpapiPluginProcess ||
process_type == ::switches::kZygoteProcess ||
process_type == ::switches::kGpuProcess ||
process_type == ::switches::kUtilityProcess;
}
} // namespace extensions
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_SHELL_APP_SHELL_CRASH_REPORTER_CLIENT_H_
#define EXTENSIONS_SHELL_APP_SHELL_CRASH_REPORTER_CLIENT_H_
#include "base/macros.h"
#include "components/crash/content/app/crash_reporter_client.h"
namespace extensions {
class ShellCrashReporterClient : public crash_reporter::CrashReporterClient {
public:
ShellCrashReporterClient();
~ShellCrashReporterClient() override;
// crash_reporter::CrashReporterClient:
void SetCrashReporterClientIdFromGUID(
const std::string& client_guid) override;
void GetProductNameAndVersion(const char** product_name,
const char** version) override;
base::FilePath GetReporterLogFilename() override;
bool GetCrashDumpLocation(base::FilePath* crash_dir) override;
bool IsRunningUnattended() override;
bool GetCollectStatsConsent() override;
bool EnableBreakpadForProcess(const std::string& process_type) override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellCrashReporterClient);
};
} // namespace extensions
#endif // EXTENSIONS_SHELL_APP_SHELL_CRASH_REPORTER_CLIENT_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/no_destructor.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/nacl/common/buildflags.h" #include "components/nacl/common/buildflags.h"
...@@ -48,8 +49,21 @@ ...@@ -48,8 +49,21 @@
#include "base/base_paths_mac.h" #include "base/base_paths_mac.h"
#endif #endif
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "components/crash/content/app/breakpad_linux.h"
#include "components/crash/content/app/crash_reporter_client.h"
#include "extensions/shell/app/shell_crash_reporter_client.h"
#endif
namespace { namespace {
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
extensions::ShellCrashReporterClient* GetCrashReporterClient() {
static base::NoDestructor<extensions::ShellCrashReporterClient> instance;
return instance.get();
}
#endif
// Returns the same directory that the browser context will later be // Returns the same directory that the browser context will later be
// initialized with. // initialized with.
base::FilePath GetDataPath() { base::FilePath GetDataPath() {
...@@ -153,6 +167,13 @@ void ShellMainDelegate::PreSandboxStartup() { ...@@ -153,6 +167,13 @@ void ShellMainDelegate::PreSandboxStartup() {
std::string process_type = std::string process_type =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessType); switches::kProcessType);
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
crash_reporter::SetCrashReporterClient(GetCrashReporterClient());
// Reporting for sub-processes will be initialized in ZygoteForked.
if (process_type != switches::kZygoteProcess)
breakpad::InitCrashReporter(process_type);
#endif
if (ProcessNeedsResourceBundle(process_type)) if (ProcessNeedsResourceBundle(process_type))
InitializeResourceBundle(); InitializeResourceBundle();
} }
...@@ -181,6 +202,15 @@ void ShellMainDelegate::ZygoteStarting( ...@@ -181,6 +202,15 @@ void ShellMainDelegate::ZygoteStarting(
} }
#endif // OS_POSIX && !OS_MACOSX && !OS_ANDROID #endif // OS_POSIX && !OS_MACOSX && !OS_ANDROID
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
void ShellMainDelegate::ZygoteForked() {
std::string process_type =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessType);
breakpad::InitCrashReporter(process_type);
}
#endif
content::ContentClient* ShellMainDelegate::CreateContentClient() { content::ContentClient* ShellMainDelegate::CreateContentClient() {
return new ShellContentClient(); return new ShellContentClient();
} }
......
...@@ -36,6 +36,9 @@ class ShellMainDelegate : public content::ContentMainDelegate { ...@@ -36,6 +36,9 @@ class ShellMainDelegate : public content::ContentMainDelegate {
void ZygoteStarting(std::vector<std::unique_ptr<content::ZygoteForkDelegate>>* void ZygoteStarting(std::vector<std::unique_ptr<content::ZygoteForkDelegate>>*
delegates) override; delegates) override;
#endif #endif
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
void ZygoteForked() override;
#endif
protected: protected:
// The created object is owned by this object. // The created object is owned by this object.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace extensions { namespace extensions {
namespace switches { namespace switches {
#if defined(OS_CHROMEOS)
// Allow roaming in the cellular network. // Allow roaming in the cellular network.
const char kAppShellAllowRoaming[] = "app-shell-allow-roaming"; const char kAppShellAllowRoaming[] = "app-shell-allow-roaming";
...@@ -15,6 +16,7 @@ const char kAppShellHostWindowSize[] = "app-shell-host-window-size"; ...@@ -15,6 +16,7 @@ const char kAppShellHostWindowSize[] = "app-shell-host-window-size";
// SSID of the preferred WiFi network. // SSID of the preferred WiFi network.
const char kAppShellPreferredNetwork[] = "app-shell-preferred-network"; const char kAppShellPreferredNetwork[] = "app-shell-preferred-network";
#endif
// Refresh token for identity API calls for the current user. Used for testing. // Refresh token for identity API calls for the current user. Used for testing.
const char kAppShellRefreshToken[] = "app-shell-refresh-token"; const char kAppShellRefreshToken[] = "app-shell-refresh-token";
...@@ -22,5 +24,13 @@ const char kAppShellRefreshToken[] = "app-shell-refresh-token"; ...@@ -22,5 +24,13 @@ const char kAppShellRefreshToken[] = "app-shell-refresh-token";
// User email address of the current user. // User email address of the current user.
const char kAppShellUser[] = "app-shell-user"; const char kAppShellUser[] = "app-shell-user";
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The directory breakpad should store minidumps in.
const char kCrashDumpsDir[] = "crash-dumps-dir";
// Enables metrics and crash reporting.
const char kEnableReporting[] = "enable-reporting";
#endif
} // namespace switches } // namespace switches
} // namespace extensions } // namespace extensions
...@@ -5,16 +5,24 @@ ...@@ -5,16 +5,24 @@
#ifndef EXTENSIONS_SHELL_COMMON_SWITCHES_H_ #ifndef EXTENSIONS_SHELL_COMMON_SWITCHES_H_
#define EXTENSIONS_SHELL_COMMON_SWITCHES_H_ #define EXTENSIONS_SHELL_COMMON_SWITCHES_H_
#include "build/build_config.h"
namespace extensions { namespace extensions {
namespace switches { namespace switches {
// All switches in alphabetical order. The switches should be documented // All switches in alphabetical order. The switches should be documented
// alongside the definition of their values in the .cc file. // alongside the definition of their values in the .cc file.
#if defined(OS_CHROMEOS)
extern const char kAppShellAllowRoaming[]; extern const char kAppShellAllowRoaming[];
extern const char kAppShellHostWindowSize[]; extern const char kAppShellHostWindowSize[];
extern const char kAppShellPreferredNetwork[]; extern const char kAppShellPreferredNetwork[];
#endif
extern const char kAppShellRefreshToken[]; extern const char kAppShellRefreshToken[];
extern const char kAppShellUser[]; extern const char kAppShellUser[];
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
extern const char kCrashDumpsDir[];
extern const char kEnableReporting[];
#endif
} // namespace switches } // namespace switches
} // namespace extensions } // namespace extensions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment