Chromium Code Reviews| Index: unclean_shutdown_collector.cc |
| diff --git a/unclean_shutdown_collector.cc b/unclean_shutdown_collector.cc |
| index bb2dd7a862ee50597868cf5ecfbf8cab6caa2dbe..ab8172bfdefc9830aadecd2beffa21a83ca48d6b 100644 |
| --- a/unclean_shutdown_collector.cc |
| +++ b/unclean_shutdown_collector.cc |
| @@ -11,6 +11,15 @@ |
| static const char kUncleanShutdownFile[] = |
| "/var/lib/crash_reporter/pending_clean_shutdown"; |
| +// Files created by power manager used for crash reporting. |
| +static const FilePath kPowerdTracePath = FilePath("/var/lib/power_manager"); |
|
tfarina
2010/11/19 15:35:43
Please, don't do this.
See http://groups.google.co
tfarina
2010/11/19 15:35:43
Can you use FILE_PATH_LITERAL instead?
kmixter1
2010/11/19 20:02:02
Fair enough, I retract my statement about doing th
|
| +// File with timestamp of last suspend. |
| +static const char kPowerdSuspendFile[] = "powerd_suspending"; |
| +// File with timestamp of last resume. |
| +static const char kPowerdResumeFile[] = "powerd_resuming"; |
| +// Presence of this file indicates that the battery is critically low. |
| +static const char kPowerdLowBatteryFile[] = "powerd_low_battery"; |
| + |
| UncleanShutdownCollector::UncleanShutdownCollector() |
| : unclean_shutdown_file_(kUncleanShutdownFile) { |
| } |
| @@ -45,6 +54,9 @@ bool UncleanShutdownCollector::Collect() { |
| logger_->LogWarning("Last shutdown was not clean"); |
| DeleteUncleanShutdownFile(); |
| + // Check for unclean shutdown due to battery running out. |
|
tfarina
2010/11/19 15:35:43
This comment is good. I'd add it in the header fil
kmixter1
2010/11/19 20:02:02
I'd name the function to indicate this: CheckForDe
|
| + CheckPowerdFiles(); |
| + |
| if (is_feedback_allowed_function_()) { |
| count_crash_function_(); |
| } |
| @@ -53,5 +65,69 @@ bool UncleanShutdownCollector::Collect() { |
| bool UncleanShutdownCollector::Disable() { |
| logger_->LogInfo("Clean shutdown signalled"); |
| + file_util::Delete(kPowerdTracePath.Append(kPowerdSuspendFile), false); |
| + file_util::Delete(kPowerdTracePath.Append(kPowerdResumeFile), false); |
| + file_util::Delete(kPowerdTracePath.Append(kPowerdLowBatteryFile), false); |
| return DeleteUncleanShutdownFile(); |
| } |
| + |
| +bool UncleanShutdownCollector::ReadModificationTime(const FilePath &file_path, |
| + base::Time *mod_time) |
| +{ |
|
tfarina
2010/11/19 15:35:43
the { should be in the end of the previous line.
|
| + file_util::FileInfo file_info; |
|
tfarina
2010/11/19 15:35:43
Please, move this inside the first if, close where
|
| + base::Time::Exploded timestamp; |
|
tfarina
2010/11/19 15:35:43
Please, move this inside the if too.
|
| + // Initialize timestamp fields to prevent warnings during print. |
| + timestamp.hour = -1; |
| + timestamp.minute = -1; |
| + timestamp.second = -1; |
| + // Log the file modification time if it exists. |
| + if (file_util::PathExists(file_path)) { |
|
tfarina
2010/11/19 15:35:43
You can return early. I think it's better.
if (!f
|
| + if (!GetFileInfo(file_path, &file_info)) |
| + return false; |
| + file_info.last_modified.LocalExplode(×tamp); |
| + logger_->LogInfo("%s modified at %02d:%02d:%02d", file_path.value().c_str(), |
| + timestamp.hour, timestamp.minute, timestamp.second); |
| + // Return the timestamp. |
| + if (mod_time != NULL) |
| + *mod_time = base::Time::FromLocalExploded(timestamp); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +bool UncleanShutdownCollector::CheckPowerdFiles() |
| +{ |
|
tfarina
2010/11/19 15:35:43
the { should be on the previous line.
|
| + logger_->LogInfo("Checking for Power Daemon files"); |
|
kmixter1
2010/11/19 20:02:02
This seems pretty chatty as we already emit a few
|
| + |
| + base::Time suspend_time, resume_time, low_battery_time; |
| + bool was_suspended = ReadModificationTime(kPowerdTracePath. |
| + Append(kPowerdSuspendFile), &suspend_time); |
|
tfarina
2010/11/19 15:35:43
wrong indentation. Indent 4 spaces. Better, if pos
|
| + bool was_resumed = ReadModificationTime(kPowerdTracePath. |
|
kmixter1
2010/11/19 20:02:02
I would move these down to where they're actually
|
| + Append(kPowerdResumeFile), &resume_time); |
| + bool running_on_low_battery = ReadModificationTime(kPowerdTracePath. |
| + Append(kPowerdLowBatteryFile), &low_battery_time); |
| + bool battery_ran_out = false; |
| + |
| + if (was_suspended) { |
|
kmixter1
2010/11/19 20:02:02
Once the Delete calls are factored out you can mak
|
| + // Check for case of battery running out while suspended. |
| + if (!was_resumed || (was_resumed && resume_time < suspend_time)) { |
| + logger_->LogInfo("Unclean shutdown occurred while suspended. The battery " |
| + "probably ran out."); |
| + battery_ran_out = true; |
| + // Check for case of battery running out after resuming from a low-battery |
| + // suspend. |
| + } else if (was_suspended && was_resumed && resume_time > suspend_time && |
|
kmixter1
2010/11/19 20:02:02
I think the whole first line of this is redundant.
|
| + running_on_low_battery && low_battery_time <= suspend_time) { |
| + |
|
tfarina
2010/11/19 15:35:43
remove this blank line.
|
| + logger_->LogInfo("Unclean shutdown occurred while resumed after battery " |
| + "was critically low. The battery probably ran out."); |
| + battery_ran_out = true; |
| + } |
| + } |
| + |
| + file_util::Delete(kPowerdTracePath.Append(kPowerdSuspendFile), false); |
|
kmixter1
2010/11/19 20:02:02
Please separate this out into a function with a na
|
| + file_util::Delete(kPowerdTracePath.Append(kPowerdResumeFile), false); |
| + file_util::Delete(kPowerdTracePath.Append(kPowerdLowBatteryFile), false); |
| + |
| + return battery_ran_out; |
| +} |