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_( | |
81 new CastCrashReporterClientAndroid(process_type.empty())) { | |
slan
2015/06/10 18:20:54
It's unclear to me why process_type.empty() implie
gunsch
2015/06/10 18:29:05
It's not specific to us, but rather a convention t
| |
79 if (!crash_reporter_client_->GetCrashDumpLocation(&crash_dump_path_)) { | 82 if (!crash_reporter_client_->GetCrashDumpLocation(&crash_dump_path_)) { |
80 LOG(ERROR) << "Could not get crash dump location"; | 83 LOG(ERROR) << "Could not get crash dump location"; |
81 } | 84 } |
82 SetCrashReporterClient(crash_reporter_client_.get()); | 85 SetCrashReporterClient(crash_reporter_client_.get()); |
83 } | 86 } |
84 | 87 |
85 CrashHandler::~CrashHandler() { | 88 CrashHandler::~CrashHandler() { |
86 DCHECK(g_crash_handler); | 89 DCHECK(g_crash_handler); |
87 g_crash_handler = NULL; | 90 g_crash_handler = NULL; |
88 } | 91 } |
89 | 92 |
90 void CrashHandler::Initialize(const std::string& process_type) { | 93 void CrashHandler::Initialize() { |
91 if (process_type.empty()) { | 94 if (process_type_.empty()) { |
92 InitializeUploader(); | 95 InitializeUploader(); |
93 | 96 |
94 // ExceptionHandlers are called on crash in reverse order of | 97 // ExceptionHandlers are called on crash in reverse order of |
95 // instantiation. This ExceptionHandler will attempt to upload crashes | 98 // instantiation. This ExceptionHandler will attempt to upload crashes |
96 // and the log file written out by the main process. | 99 // and the log file written out by the main process. |
97 | 100 |
98 // Dummy MinidumpDescriptor just to start up another ExceptionHandler. | 101 // Dummy MinidumpDescriptor just to start up another ExceptionHandler. |
99 google_breakpad::MinidumpDescriptor dummy(crash_dump_path_.value()); | 102 google_breakpad::MinidumpDescriptor dummy(crash_dump_path_.value()); |
100 crash_uploader_.reset(new google_breakpad::ExceptionHandler( | 103 crash_uploader_.reset(new google_breakpad::ExceptionHandler( |
101 dummy, &HandleCrash, NULL, NULL, true, -1)); | 104 dummy, &HandleCrash, NULL, NULL, true, -1)); |
102 | 105 |
103 breakpad::InitCrashReporter(process_type); | 106 breakpad::InitCrashReporter(process_type_); |
104 | 107 |
105 return; | 108 return; |
106 } | 109 } |
107 | 110 |
108 if (process_type != switches::kZygoteProcess) { | 111 if (process_type_ != switches::kZygoteProcess) { |
109 breakpad::InitNonBrowserCrashReporterForAndroid(process_type); | 112 breakpad::InitNonBrowserCrashReporterForAndroid(process_type_); |
110 } | 113 } |
111 } | 114 } |
112 | 115 |
113 void CrashHandler::InitializeUploader() { | 116 void CrashHandler::InitializeUploader() { |
114 JNIEnv* env = base::android::AttachCurrentThread(); | 117 JNIEnv* env = base::android::AttachCurrentThread(); |
115 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = | 118 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = |
116 base::android::ConvertUTF8ToJavaString(env, | 119 base::android::ConvertUTF8ToJavaString(env, |
117 crash_dump_path_.value()); | 120 crash_dump_path_.value()); |
118 Java_CastCrashHandler_initializeUploader( | 121 Java_CastCrashHandler_initializeUploader( |
119 env, crash_dump_path_java.obj(), UploadCrashToStaging()); | 122 env, crash_dump_path_java.obj(), UploadCrashToStaging()); |
(...skipping 14 matching lines...) Expand all Loading... | |
134 base::android::ConvertUTF8ToJavaString(env, log_file_path_.value()); | 137 base::android::ConvertUTF8ToJavaString(env, log_file_path_.value()); |
135 Java_CastCrashHandler_uploadCrashDumps(env, log_file_path_java.obj()); | 138 Java_CastCrashHandler_uploadCrashDumps(env, log_file_path_java.obj()); |
136 } else { | 139 } else { |
137 VLOG(1) << "Removing crash dumps instead of uploading"; | 140 VLOG(1) << "Removing crash dumps instead of uploading"; |
138 JNIEnv* env = base::android::AttachCurrentThread(); | 141 JNIEnv* env = base::android::AttachCurrentThread(); |
139 Java_CastCrashHandler_removeCrashDumps(env); | 142 Java_CastCrashHandler_removeCrashDumps(env); |
140 } | 143 } |
141 } | 144 } |
142 | 145 |
143 } // namespace chromecast | 146 } // namespace chromecast |
OLD | NEW |