diff --git a/cobalt/browser/application.cc b/cobalt/browser/application.cc index fe4c0984a20f..d12a563e6748 100644 --- a/cobalt/browser/application.cc +++ b/cobalt/browser/application.cc @@ -589,6 +589,28 @@ void AddCrashHandlerAnnotations() { } } +void AddCrashHandlerApplicationState(base::ApplicationState state) { + auto crash_handler_extension = + static_cast( + 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 @@ -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; @@ -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) {