Chromium Code Reviews| Index: unclean_shutdown_collector.cc |
| diff --git a/unclean_shutdown_collector.cc b/unclean_shutdown_collector.cc |
| index bb2dd7a862ee50597868cf5ecfbf8cab6caa2dbe..fcac84586b9eb652fdacdd8dbd3cb552f90eac1b 100644 |
| --- a/unclean_shutdown_collector.cc |
| +++ b/unclean_shutdown_collector.cc |
| @@ -11,8 +11,18 @@ |
| static const char kUncleanShutdownFile[] = |
| "/var/lib/crash_reporter/pending_clean_shutdown"; |
| +// Files created by power manager used for crash reporting. |
| +static const char kPowerdTracePath[] = "/var/lib/power_manager"; |
| +// File with timestamp of last suspend. |
| +static const char kPowerdSuspended[] = "powerd_suspended"; |
| +// Presence of this file indicates that the battery is critically low. |
| +static const char kPowerdLowBattery[] = "powerd_low_battery"; |
| + |
| UncleanShutdownCollector::UncleanShutdownCollector() |
| - : unclean_shutdown_file_(kUncleanShutdownFile) { |
| + : unclean_shutdown_file_(kUncleanShutdownFile), |
| + powerd_trace_path_(kPowerdTracePath), |
| + powerd_suspend_file_(powerd_trace_path_.Append(kPowerdSuspended)), |
| + powerd_low_battery_file_(powerd_trace_path_.Append(kPowerdLowBattery)) { |
| } |
| UncleanShutdownCollector::~UncleanShutdownCollector() { |
| @@ -45,6 +55,10 @@ bool UncleanShutdownCollector::Collect() { |
| logger_->LogWarning("Last shutdown was not clean"); |
| DeleteUncleanShutdownFile(); |
| + CheckForDeadBatteryUncleanShutdown(); |
| + file_util::Delete(powerd_suspend_file_, false); |
|
kmixter1
2010/11/19 23:43:27
Still would be nice to factor this out. How about
|
| + file_util::Delete(powerd_low_battery_file_, false); |
| + |
| if (is_feedback_allowed_function_()) { |
| count_crash_function_(); |
| } |
| @@ -53,5 +67,25 @@ bool UncleanShutdownCollector::Collect() { |
| bool UncleanShutdownCollector::Disable() { |
| logger_->LogInfo("Clean shutdown signalled"); |
| + file_util::Delete(powerd_suspend_file_, false); |
| + file_util::Delete(powerd_low_battery_file_, false); |
| return DeleteUncleanShutdownFile(); |
| } |
| + |
| +bool UncleanShutdownCollector::CheckForDeadBatteryUncleanShutdown() |
| +{ |
| + // Check for case of battery running out while suspended. |
| + if (file_util::PathExists(powerd_suspend_file_)) { |
| + logger_->LogInfo("Unclean shutdown occurred while suspended. The battery " |
| + "probably ran out."); |
| + return true; |
| + } |
| + // Check for case of battery running out after resuming from a low-battery |
| + // suspend. |
| + if (file_util::PathExists(powerd_low_battery_file_)) { |
| + logger_->LogInfo("Unclean shutdown occurred while resumed after battery " |
|
kmixter1
2010/11/19 23:43:27
how about "while running with critically low batte
|
| + "was critically low. The battery probably ran out."); |
| + return true; |
| + } |
| + return false; |
| +} |