Skip to content

Commit

Permalink
Add application state to crash reports. (#181) (#698)
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 <[email protected]>
(cherry picked from commit f60be99)

Co-authored-by: Brian Ting <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and briantting authored Jul 10, 2023
1 parent 7dd1d98 commit cca954c
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 @@ -589,6 +589,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 @@ -1198,6 +1220,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 @@ -1316,6 +1339,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 cca954c

Please sign in to comment.