Skip to content

Commit

Permalink
Adding crash utilities to chromecast/crash.
Browse files Browse the repository at this point in the history
Includes initial commits for writing, managing, and uploading information generated on Linux crashes.

Change-Id: I6ff36ffb54bf9153e5663844b2a428ce7b03773f

BUG= b/20121400

Review URL: https://codereview.chromium.org/1154383006

Cr-Commit-Position: refs/heads/master@{#335727}
  • Loading branch information
slan authored and Commit bot committed Jun 23, 2015
1 parent 8d84d9c commit f48fe87
Show file tree
Hide file tree
Showing 46 changed files with 2,602 additions and 133 deletions.
12 changes: 12 additions & 0 deletions chromecast/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ component("chromecast") {
deps = [
"//chromecast/base",
"//chromecast/base/metrics",
"//chromecast/crash",
"//chromecast/media",
]
}

group("chromecast_unittests") {
testonly = true

deps = [
"//chromecast/app:cast_shell_unittests",
"//chromecast/base:cast_base_unittests",
"//chromecast/crash:cast_crash_unittests",
"//chromecast/media:cast_media_unittests",
]
}
2 changes: 1 addition & 1 deletion chromecast/android/DEPS
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include_rules = [
# Includes for JNI.
"+chromecast/android",
"+chromecast/app/android",
"+chromecast/browser/android",
"+chromecast/crash/android",
"+components/external_video_surface",
]
2 changes: 1 addition & 1 deletion chromecast/android/cast_jni_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "chromecast/android/cast_metrics_helper_android.h"
#include "chromecast/app/android/crash_handler.h"
#include "chromecast/base/cast_sys_info_android.h"
#include "chromecast/base/chromecast_config_android.h"
#include "chromecast/browser/android/cast_window_android.h"
#include "chromecast/browser/android/cast_window_manager.h"
#include "chromecast/crash/android/crash_handler.h"
#include "components/external_video_surface/component_jni_registrar.h"

namespace chromecast {
Expand Down
34 changes: 34 additions & 0 deletions chromecast/app/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2015 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.

import("//testing/test.gni")

component("cast_crash_client") {
sources = [
"android/cast_crash_reporter_client_androic.cc",
"android/cast_crash_reporter_client_android.h",
"linux/cast_crash_reporter_client.cc",
"linux/cast_crash_reporter_client.h",
]

deps = [
"//chromecast/crash",
"//components/crash/app",
"//content/public/common",
]

configs += [ "//chromecast:config" ]
}

test("cast_shell_unittests") {
sources = [
"linux/cast_crash_reporter_client_unittest.cc",
]

deps = [
":cast_crash_client",
"//base/test:run_all_unittests",
"//testing/gtest",
]
}
1 change: 1 addition & 0 deletions chromecast/app/android/DEPS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include_rules = [
"+breakpad",
"+chromecast/android",
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromecast/crash/android/cast_crash_reporter_client_android.h"
#include "chromecast/app/android/cast_crash_reporter_client_android.h"

#include "base/base_paths.h"
#include "base/files/file_path.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMECAST_CRASH_ANDROID_CAST_CRASH_REPORTER_CLIENT_ANDROID_H_
#define CHROMECAST_CRASH_ANDROID_CAST_CRASH_REPORTER_CLIENT_ANDROID_H_
#ifndef CHROMECAST_APP_ANDROID_CAST_CRASH_REPORTER_CLIENT_ANDROID_H_
#define CHROMECAST_APP_ANDROID_CAST_CRASH_REPORTER_CLIENT_ANDROID_H_

#include "base/compiler_specific.h"
#include "components/crash/app/crash_reporter_client.h"
Expand All @@ -23,8 +23,7 @@ class CastCrashReporterClientAndroid
bool GetCrashDumpLocation(base::FilePath* crash_dir) override;
int GetAndroidMinidumpDescriptor() override;
bool GetCollectStatsConsent() override;
bool EnableBreakpadForProcess(
const std::string& process_type) override;
bool EnableBreakpadForProcess(const std::string& process_type) override;
size_t RegisterCrashKeys() override;

private:
Expand All @@ -35,4 +34,4 @@ class CastCrashReporterClientAndroid

} // namespace chromecast

#endif // CHROMECAST_CRASH_ANDROID_CAST_CRASH_REPORTER_CLIENT_ANDROID_H_
#endif // CHROMECAST_APP_ANDROID_CAST_CRASH_REPORTER_CLIENT_ANDROID_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromecast/crash/android/crash_handler.h"
#include "chromecast/app/android/crash_handler.h"

#include <jni.h>
#include <stdlib.h>
Expand All @@ -15,8 +15,8 @@
#include "base/strings/string_number_conversions.h"
#include "breakpad/src/client/linux/handler/exception_handler.h"
#include "breakpad/src/client/linux/handler/minidump_descriptor.h"
#include "chromecast/app/android/cast_crash_reporter_client_android.h"
#include "chromecast/base/version.h"
#include "chromecast/crash/android/cast_crash_reporter_client_android.h"
#include "components/crash/app/breakpad_linux.h"
#include "components/crash/app/crash_reporter_client.h"
#include "content/public/common/content_switches.h"
Expand Down Expand Up @@ -54,8 +54,8 @@ void CrashHandler::Initialize(const std::string& process_type,
// static
bool CrashHandler::GetCrashDumpLocation(base::FilePath* crash_dir) {
DCHECK(g_crash_handler);
return g_crash_handler->crash_reporter_client_->
GetCrashDumpLocation(crash_dir);
return g_crash_handler->crash_reporter_client_->GetCrashDumpLocation(
crash_dir);
}

// static
Expand Down Expand Up @@ -94,11 +94,12 @@ void CrashHandler::Initialize() {
void CrashHandler::InitializeUploader() {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java =
base::android::ConvertUTF8ToJavaString(env,
crash_dump_path_.value());
base::android::ConvertUTF8ToJavaString(env, crash_dump_path_.value());
Java_CastCrashHandler_initializeUploader(
env, base::android::GetApplicationContext(),
crash_dump_path_java.obj(), UploadCrashToStaging());
env,
base::android::GetApplicationContext(),
crash_dump_path_java.obj(),
UploadCrashToStaging());
}

} // namespace chromecast
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMECAST_CRASH_ANDROID_CRASH_HANDLER_H_
#define CHROMECAST_CRASH_ANDROID_CRASH_HANDLER_H_
#ifndef CHROMECAST_APP_ANDROID_CRASH_HANDLER_H_
#define CHROMECAST_APP_ANDROID_CRASH_HANDLER_H_

#include <jni.h>
#include <string>
Expand Down Expand Up @@ -54,4 +54,4 @@ class CrashHandler {

} // namespace chromecast

#endif // CHROMECAST_CRASH_ANDROID_CRASH_HANDLER_H_
#endif // CHROMECAST_APP_ANDROID_CRASH_HANDLER_H_
5 changes: 3 additions & 2 deletions chromecast/app/cast_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
#include "chromecast/browser/cast_content_browser_client.h"
#include "chromecast/common/cast_resource_delegate.h"
#include "chromecast/common/global_descriptors.h"
#include "chromecast/crash/cast_crash_reporter_client.h"
#include "chromecast/renderer/cast_content_renderer_client.h"
#include "components/crash/app/crash_reporter_client.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/public/common/content_switches.h"
#include "ui/base/resource/resource_bundle.h"

#if defined(OS_ANDROID)
#include "chromecast/crash/android/crash_handler.h"
#include "chromecast/app/android/crash_handler.h"
#else
#include "chromecast/app/linux/cast_crash_reporter_client.h"
#endif // defined(OS_ANDROID)

namespace {
Expand Down
77 changes: 77 additions & 0 deletions chromecast/app/linux/cast_crash_reporter_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2014 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 "chromecast/app/linux/cast_crash_reporter_client.h"

#include "base/time/time.h"
#include "chromecast/base/error_codes.h"
#include "chromecast/crash/linux/crash_util.h"
#include "components/crash/app/breakpad_linux.h"
#include "content/public/common/content_switches.h"

namespace chromecast {

namespace {

std::string* g_process_type = nullptr;
uint64_t g_process_start_time_ms = 0u;

} // namespace

// static
void CastCrashReporterClient::InitCrashReporter(
const std::string& process_type) {
DCHECK(!g_process_type);
g_process_start_time_ms =
(base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();

// Save the process type (leaked).
g_process_type = new std::string(process_type);

// Start up breakpad for this process, if applicable.
breakpad::InitCrashReporter(process_type);
}

// static
const char* CastCrashReporterClient::GetProcessType() {
return g_process_type ? g_process_type->c_str() : nullptr;
}

// static
uint64_t CastCrashReporterClient::GetProcessStartTime() {
return g_process_start_time_ms;
}

CastCrashReporterClient::CastCrashReporterClient() {
}
CastCrashReporterClient::~CastCrashReporterClient() {
}

bool CastCrashReporterClient::EnableBreakpadForProcess(
const std::string& process_type) {
return process_type == switches::kRendererProcess ||
process_type == switches::kZygoteProcess ||
process_type == switches::kGpuProcess;
}

bool CastCrashReporterClient::HandleCrashDump(const char* crashdump_filename) {
// Set the initial error code to ERROR_WEB_CONTENT_RENDER_VIEW_GONE to show
// an error message on next cast_shell run. Though the error code is for
// renderer process crash, the actual messages can be used for browser process
// as well.
if (!GetProcessType() || !strcmp(GetProcessType(), ""))
SetInitialErrorCode(ERROR_WEB_CONTENT_RENDER_VIEW_GONE);

// Upload crash dump. If user didn't opt-in crash report, minidump writer
// instantiated within CrashUtil::RequestUploadCrashDump() does nothing.
CrashUtil::RequestUploadCrashDump(crashdump_filename,
GetProcessType() ? GetProcessType() : "",
GetProcessStartTime());

// Always return true to indicate that this crash dump has been processed,
// so that it won't fallback to use chrome's default uploader.
return true;
}

} // namespace chromecast
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMECAST_CRASH_CAST_CRASH_REPORTER_CLIENT_H_
#define CHROMECAST_CRASH_CAST_CRASH_REPORTER_CLIENT_H_
#ifndef CHROMECAST_APP_LINUX_CAST_CRASH_REPORTER_CLIENT_H_
#define CHROMECAST_APP_LINUX_CAST_CRASH_REPORTER_CLIENT_H_

#include <string>

Expand All @@ -20,17 +20,16 @@ class CastCrashReporterClient : public crash_reporter::CrashReporterClient {
~CastCrashReporterClient() override;

// crash_reporter::CrashReporterClient implementation:
bool EnableBreakpadForProcess(
const std::string& process_type) override;
bool EnableBreakpadForProcess(const std::string& process_type) override;
bool HandleCrashDump(const char* crashdump_filename) override;

private:
static char* GetProcessType();
static const char* GetProcessType();
static uint64_t GetProcessStartTime();

DISALLOW_COPY_AND_ASSIGN(CastCrashReporterClient);
};

} // namespace chromecast

#endif // CHROMECAST_CRASH_CAST_CRASH_REPORTER_CLIENT_H_
#endif // CHROMECAST_APP_LINUX_CAST_CRASH_REPORTER_CLIENT_H_
Loading

0 comments on commit f48fe87

Please sign in to comment.