Commit 980ad399 authored by Joshua Peraza's avatar Joshua Peraza Committed by Commit Bot

Prepare for Crashpad on Android

This CL includes several minor changes to components/crash/ in
preparation for enabling Crashpad on Android.

- Use std::string instead of char* in GetProductNameAndVersion.
- Set LD_LIBRARY_PATH when building handler args for component builds.
- Update Android handler executable to libcrashpad_handler.so.
- Don't set a url parameter on Android to avoid Crashpad attempting to
  upload reports, which it doesn't yet support.
- Initialize CrashHandlerHost on the first call to GetDeathSignalSocket
  because CrashHandlerHost may be created before it can post tasks to
  the IO thread.

Bug: crashpad:30
Change-Id: I80efa0cf87cb4081773eaa516b1d6eb90fb6f5e8
Reviewed-on: https://chromium-review.googlesource.com/1056320
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558408}
parent 149d9339
......@@ -93,9 +93,9 @@ void CrashReporterClient::GetProductNameAndVersion(const char** product_name,
const char** version) {
}
void CrashReporterClient::GetProductNameAndVersion(const char** product_name,
const char** version,
const char** channel) {}
void CrashReporterClient::GetProductNameAndVersion(std::string* product_name,
std::string* version,
std::string* channel) {}
base::FilePath CrashReporterClient::GetReporterLogFilename() {
return base::FilePath();
......
......@@ -98,9 +98,9 @@ class CrashReporterClient {
// Linux-ish breakpad clients have transitioned to crashpad.
virtual void GetProductNameAndVersion(const char** product_name,
const char** version);
virtual void GetProductNameAndVersion(const char** product_name,
const char** version,
const char** channel);
virtual void GetProductNameAndVersion(std::string* product_name,
std::string* version,
std::string* channel);
virtual base::FilePath GetReporterLogFilename();
......
......@@ -11,6 +11,7 @@
#include <algorithm>
#include "base/environment.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
......@@ -124,6 +125,26 @@ class SandboxedHandler {
namespace crash_reporter {
namespace internal {
bool SetLdLibraryPath(const base::FilePath& lib_path) {
#if defined(OS_ANDROID) && defined(COMPONENT_BUILD)
std::string library_path(lib_path.value());
static constexpr char kLibraryPathVar[] = "LD_LIBRARY_PATH";
std::unique_ptr<base::Environment> env(base::Environment::Create());
std::string old_path;
if (env->GetVar(kLibraryPathVar, &old_path)) {
library_path.push_back(':');
library_path.append(old_path);
}
if (!env->SetVar(kLibraryPathVar, library_path)) {
return false;
}
#endif
return true;
}
bool BuildHandlerArgs(base::FilePath* handler_path,
base::FilePath* database_path,
base::FilePath* metrics_path,
......@@ -139,25 +160,40 @@ bool BuildHandlerArgs(base::FilePath* handler_path,
DCHECK(false);
return false;
}
#if defined(OS_ANDROID)
// There is not any normal way to package native executables in an Android
// APK. The Crashpad handler is packaged like a loadable module, which
// Android's APK installer expects to be named like a shared library, but it
// is in fact a standalone executable.
*handler_path = exe_dir.Append("libcrashpad_handler.so");
#else
*handler_path = exe_dir.Append("crashpad_handler");
#endif
static bool env_setup = SetLdLibraryPath(exe_dir);
if (!env_setup) {
return false;
}
CrashReporterClient* crash_reporter_client = GetCrashReporterClient();
crash_reporter_client->GetCrashDumpLocation(database_path);
crash_reporter_client->GetCrashMetricsLocation(metrics_path);
#if defined(GOOGLE_CHROME_BUILD) && defined(OFFICIAL_BUILD)
// TODO(jperaza): Set URL for Android when Crashpad takes over report upload.
#if defined(GOOGLE_CHROME_BUILD) && defined(OFFICIAL_BUILD) && \
!defined(OS_ANDROID)
*url = "https://clients2.google.com/cr/report";
#else
*url = std::string();
#endif
const char* product_name;
const char* product_version;
const char* channel;
std::string product_name;
std::string product_version;
std::string channel;
crash_reporter_client->GetProductNameAndVersion(&product_name,
&product_version, &channel);
(*process_annotations)["prod"] = std::string(product_name);
(*process_annotations)["ver"] = std::string(product_version);
(*process_annotations)["prod"] = product_name;
(*process_annotations)["ver"] = product_version;
#if defined(GOOGLE_CHROME_BUILD)
// Empty means stable.
......@@ -165,9 +201,8 @@ bool BuildHandlerArgs(base::FilePath* handler_path,
#else
const bool allow_empty_channel = false;
#endif
std::string channel_string(channel);
if (allow_empty_channel || !channel_string.empty()) {
(*process_annotations)["channel"] = channel_string;
if (allow_empty_channel || !channel.empty()) {
(*process_annotations)["channel"] = channel;
}
#if defined(OS_ANDROID)
......
......@@ -516,6 +516,15 @@ CrashHandlerHost* CrashHandlerHost::Get() {
return instance;
}
int CrashHandlerHost::GetDeathSignalSocket() {
static bool initialized = BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&CrashHandlerHost::Init, base::Unretained(this)));
DCHECK(initialized);
return process_socket_.get();
}
CrashHandlerHost::~CrashHandlerHost() = default;
CrashHandlerHost::CrashHandlerHost()
......@@ -538,10 +547,6 @@ CrashHandlerHost::CrashHandlerHost()
static const int on = 1;
CHECK_EQ(0, setsockopt(browser_socket_.get(), SOL_SOCKET, SO_PASSCRED, &on,
sizeof(on)));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&CrashHandlerHost::Init, base::Unretained(this)));
}
void CrashHandlerHost::Init() {
......
......@@ -139,7 +139,7 @@ class CrashHandlerHost : public base::MessagePumpForIO::FdWatcher,
// Get the file descriptor which processes should be given in order to signal
// crashes to the browser.
int GetDeathSignalSocket() const { return process_socket_.get(); }
int GetDeathSignalSocket();
protected:
~CrashHandlerHost() override;
......
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