OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/crash/android/crash_handler.h" | 5 #include "chromecast/crash/android/crash_handler.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 namespace chromecast { | 54 namespace chromecast { |
55 | 55 |
56 // static | 56 // static |
57 void CrashHandler::Initialize(const std::string& process_type, | 57 void CrashHandler::Initialize(const std::string& process_type, |
58 const base::FilePath& log_file_path) { | 58 const base::FilePath& log_file_path) { |
59 DCHECK(!g_crash_handler); | 59 DCHECK(!g_crash_handler); |
60 g_crash_handler = new CrashHandler(log_file_path); | 60 g_crash_handler = new CrashHandler(process_type, log_file_path); |
61 g_crash_handler->Initialize(process_type); | 61 g_crash_handler->Initialize(); |
62 } | 62 } |
63 | 63 |
64 // static | 64 // static |
65 bool CrashHandler::GetCrashDumpLocation(base::FilePath* crash_dir) { | 65 bool CrashHandler::GetCrashDumpLocation(base::FilePath* crash_dir) { |
66 DCHECK(g_crash_handler); | 66 DCHECK(g_crash_handler); |
67 return g_crash_handler->crash_reporter_client_-> | 67 return g_crash_handler->crash_reporter_client_-> |
68 GetCrashDumpLocation(crash_dir); | 68 GetCrashDumpLocation(crash_dir); |
69 } | 69 } |
70 | 70 |
71 // static | 71 // static |
72 bool CrashHandler::RegisterCastCrashJni(JNIEnv* env) { | 72 bool CrashHandler::RegisterCastCrashJni(JNIEnv* env) { |
73 return RegisterNativesImpl(env); | 73 return RegisterNativesImpl(env); |
74 } | 74 } |
75 | 75 |
76 CrashHandler::CrashHandler(const base::FilePath& log_file_path) | 76 CrashHandler::CrashHandler(const std::string& process_type, |
| 77 const base::FilePath& log_file_path) |
77 : log_file_path_(log_file_path), | 78 : log_file_path_(log_file_path), |
78 crash_reporter_client_(new CastCrashReporterClientAndroid) { | 79 process_type_(process_type), |
| 80 crash_reporter_client_(new CastCrashReporterClientAndroid(process_type)) { |
79 if (!crash_reporter_client_->GetCrashDumpLocation(&crash_dump_path_)) { | 81 if (!crash_reporter_client_->GetCrashDumpLocation(&crash_dump_path_)) { |
80 LOG(ERROR) << "Could not get crash dump location"; | 82 LOG(ERROR) << "Could not get crash dump location"; |
81 } | 83 } |
82 SetCrashReporterClient(crash_reporter_client_.get()); | 84 SetCrashReporterClient(crash_reporter_client_.get()); |
83 } | 85 } |
84 | 86 |
85 CrashHandler::~CrashHandler() { | 87 CrashHandler::~CrashHandler() { |
86 DCHECK(g_crash_handler); | 88 DCHECK(g_crash_handler); |
87 g_crash_handler = NULL; | 89 g_crash_handler = NULL; |
88 } | 90 } |
89 | 91 |
90 void CrashHandler::Initialize(const std::string& process_type) { | 92 void CrashHandler::Initialize() { |
91 if (process_type.empty()) { | 93 if (process_type_.empty()) { |
92 InitializeUploader(); | 94 InitializeUploader(); |
93 | 95 |
94 // ExceptionHandlers are called on crash in reverse order of | 96 // ExceptionHandlers are called on crash in reverse order of |
95 // instantiation. This ExceptionHandler will attempt to upload crashes | 97 // instantiation. This ExceptionHandler will attempt to upload crashes |
96 // and the log file written out by the main process. | 98 // and the log file written out by the main process. |
97 | 99 |
98 // Dummy MinidumpDescriptor just to start up another ExceptionHandler. | 100 // Dummy MinidumpDescriptor just to start up another ExceptionHandler. |
99 google_breakpad::MinidumpDescriptor dummy(crash_dump_path_.value()); | 101 google_breakpad::MinidumpDescriptor dummy(crash_dump_path_.value()); |
100 crash_uploader_.reset(new google_breakpad::ExceptionHandler( | 102 crash_uploader_.reset(new google_breakpad::ExceptionHandler( |
101 dummy, &HandleCrash, NULL, NULL, true, -1)); | 103 dummy, &HandleCrash, NULL, NULL, true, -1)); |
102 | 104 |
103 breakpad::InitCrashReporter(process_type); | 105 breakpad::InitCrashReporter(process_type_); |
104 | 106 |
105 return; | 107 return; |
106 } | 108 } |
107 | 109 |
108 if (process_type != switches::kZygoteProcess) { | 110 if (process_type_ != switches::kZygoteProcess) { |
109 breakpad::InitNonBrowserCrashReporterForAndroid(process_type); | 111 breakpad::InitNonBrowserCrashReporterForAndroid(process_type_); |
110 } | 112 } |
111 } | 113 } |
112 | 114 |
113 void CrashHandler::InitializeUploader() { | 115 void CrashHandler::InitializeUploader() { |
114 JNIEnv* env = base::android::AttachCurrentThread(); | 116 JNIEnv* env = base::android::AttachCurrentThread(); |
115 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = | 117 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = |
116 base::android::ConvertUTF8ToJavaString(env, | 118 base::android::ConvertUTF8ToJavaString(env, |
117 crash_dump_path_.value()); | 119 crash_dump_path_.value()); |
118 Java_CastCrashHandler_initializeUploader( | 120 Java_CastCrashHandler_initializeUploader( |
119 env, crash_dump_path_java.obj(), UploadCrashToStaging()); | 121 env, crash_dump_path_java.obj(), UploadCrashToStaging()); |
(...skipping 14 matching lines...) Expand all Loading... |
134 base::android::ConvertUTF8ToJavaString(env, log_file_path_.value()); | 136 base::android::ConvertUTF8ToJavaString(env, log_file_path_.value()); |
135 Java_CastCrashHandler_uploadCrashDumps(env, log_file_path_java.obj()); | 137 Java_CastCrashHandler_uploadCrashDumps(env, log_file_path_java.obj()); |
136 } else { | 138 } else { |
137 VLOG(1) << "Removing crash dumps instead of uploading"; | 139 VLOG(1) << "Removing crash dumps instead of uploading"; |
138 JNIEnv* env = base::android::AttachCurrentThread(); | 140 JNIEnv* env = base::android::AttachCurrentThread(); |
139 Java_CastCrashHandler_removeCrashDumps(env); | 141 Java_CastCrashHandler_removeCrashDumps(env); |
140 } | 142 } |
141 } | 143 } |
142 | 144 |
143 } // namespace chromecast | 145 } // namespace chromecast |
OLD | NEW |