Skip to content

Commit

Permalink
Add application state to crash reports. (#181)
Browse files Browse the repository at this point in the history
Add application state to crash reports by using the existing crash handler extension.

b/261773222

Co-authored-by: Brian Ting <brianting@google.com>
  • Loading branch information
briantting and briantting authored Apr 27, 2023
1 parent a37d1fe commit f60be99
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cobalt/browser/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,28 @@ void AddCrashHandlerAnnotations() {
}
}

void AddCrashHandlerApplicationState(base::ApplicationState state) {
auto crash_handler_extension =
static_cast<const CobaltExtensionCrashHandlerApi*>(
SbSystemGetExtension(kCobaltExtensionCrashHandlerName));
if (!crash_handler_extension) {
DLOG(INFO) << "No crash handler extension, not sending application state.";
return;
}

std::string application_state = std::string(GetApplicationStateString(state));
application_state.push_back('\0');

if (crash_handler_extension->version > 1) {
if (crash_handler_extension->SetString("application_state",
application_state.c_str())) {
DLOG(INFO) << "Sent application state to crash handler.";
return;
}
}
DLOG(ERROR) << "Could not send application state to crash handler.";
}

} // namespace

// Helper stub to disable histogram tracking in StatisticsRecorder
Expand Down Expand Up @@ -1207,6 +1229,7 @@ void Application::OnApplicationEvent(SbEventType event_type,
case kSbEventTypeStop:
LOG(INFO) << "Got quit event.";
if (watchdog) watchdog->UpdateState(base::kApplicationStateStopped);
AddCrashHandlerApplicationState(base::kApplicationStateStopped);
Quit();
LOG(INFO) << "Finished quitting.";
break;
Expand Down Expand Up @@ -1325,6 +1348,7 @@ void Application::OnApplicationEvent(SbEventType event_type,
return;
}
if (watchdog) watchdog->UpdateState(browser_module_->GetApplicationState());
AddCrashHandlerApplicationState(browser_module_->GetApplicationState());
}

void Application::OnWindowSizeChangedEvent(const base::Event* event) {
Expand Down

0 comments on commit f60be99

Please sign in to comment.