Delete unused downloads page asset.
[chromium-blink-merge.git] / chromecast / app / android / crash_handler.cc
blob8a2dc7ac657a65ab30ac2b2aaf52c16a008b495f
1 // Copyright 2014 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 "chromecast/app/android/crash_handler.h"
7 #include <jni.h>
8 #include <stdlib.h>
9 #include <string>
11 #include "base/android/jni_android.h"
12 #include "base/android/jni_string.h"
13 #include "base/files/file_path.h"
14 #include "base/logging.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "breakpad/src/client/linux/handler/exception_handler.h"
17 #include "breakpad/src/client/linux/handler/minidump_descriptor.h"
18 #include "chromecast/app/android/cast_crash_reporter_client_android.h"
19 #include "chromecast/base/version.h"
20 #include "components/crash/app/breakpad_linux.h"
21 #include "components/crash/app/crash_reporter_client.h"
22 #include "content/public/common/content_switches.h"
23 #include "jni/CastCrashHandler_jni.h"
25 namespace {
27 chromecast::CrashHandler* g_crash_handler = NULL;
29 // Debug builds: always to crash-staging
30 // Release builds: only to crash-staging for local/invalid build numbers
31 bool UploadCrashToStaging() {
32 #if CAST_IS_DEBUG_BUILD()
33 return true;
34 #else
35 int build_number;
36 if (base::StringToInt(CAST_BUILD_INCREMENTAL, &build_number))
37 return build_number == 0;
38 return true;
39 #endif
42 } // namespace
44 namespace chromecast {
46 // static
47 void CrashHandler::Initialize(const std::string& process_type,
48 const base::FilePath& log_file_path) {
49 DCHECK(!g_crash_handler);
50 g_crash_handler = new CrashHandler(process_type, log_file_path);
51 g_crash_handler->Initialize();
54 // static
55 bool CrashHandler::GetCrashDumpLocation(base::FilePath* crash_dir) {
56 DCHECK(g_crash_handler);
57 return g_crash_handler->crash_reporter_client_->GetCrashDumpLocation(
58 crash_dir);
61 // static
62 bool CrashHandler::RegisterCastCrashJni(JNIEnv* env) {
63 return RegisterNativesImpl(env);
66 CrashHandler::CrashHandler(const std::string& process_type,
67 const base::FilePath& log_file_path)
68 : log_file_path_(log_file_path),
69 process_type_(process_type),
70 crash_reporter_client_(new CastCrashReporterClientAndroid(process_type)) {
71 if (!crash_reporter_client_->GetCrashDumpLocation(&crash_dump_path_)) {
72 LOG(ERROR) << "Could not get crash dump location";
74 SetCrashReporterClient(crash_reporter_client_.get());
77 CrashHandler::~CrashHandler() {
78 DCHECK(g_crash_handler);
79 g_crash_handler = NULL;
82 void CrashHandler::Initialize() {
83 if (process_type_.empty()) {
84 InitializeUploader();
85 breakpad::InitCrashReporter(process_type_);
86 return;
89 if (process_type_ != switches::kZygoteProcess) {
90 breakpad::InitNonBrowserCrashReporterForAndroid(process_type_);
94 void CrashHandler::InitializeUploader() {
95 JNIEnv* env = base::android::AttachCurrentThread();
96 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java =
97 base::android::ConvertUTF8ToJavaString(env, crash_dump_path_.value());
98 Java_CastCrashHandler_initializeUploader(
99 env,
100 base::android::GetApplicationContext(),
101 crash_dump_path_java.obj(),
102 UploadCrashToStaging());
105 } // namespace chromecast