Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crash-reporter/unclean_shutdown_collector.h" | 5 #include "crash-reporter/unclean_shutdown_collector.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "crash-reporter/system_logging.h" | 9 #include "crash-reporter/system_logging.h" |
| 10 | 10 |
| 11 static const char kUncleanShutdownFile[] = | 11 static const char kUncleanShutdownFile[] = |
| 12 "/var/lib/crash_reporter/pending_clean_shutdown"; | 12 "/var/lib/crash_reporter/pending_clean_shutdown"; |
| 13 | 13 |
| 14 // Files created by power manager used for crash reporting. | |
| 15 static const char kPowerdTracePath[] = "/var/lib/power_manager"; | |
| 16 // File with timestamp of last suspend. | |
| 17 static const char kPowerdSuspended[] = "powerd_suspended"; | |
| 18 // Presence of this file indicates that the battery is critically low. | |
| 19 static const char kPowerdLowBattery[] = "powerd_low_battery"; | |
| 20 | |
| 14 UncleanShutdownCollector::UncleanShutdownCollector() | 21 UncleanShutdownCollector::UncleanShutdownCollector() |
| 15 : unclean_shutdown_file_(kUncleanShutdownFile) { | 22 : unclean_shutdown_file_(kUncleanShutdownFile), |
| 23 powerd_trace_path_(kPowerdTracePath), | |
| 24 powerd_suspend_file_(powerd_trace_path_.Append(kPowerdSuspended)), | |
| 25 powerd_low_battery_file_(powerd_trace_path_.Append(kPowerdLowBattery)) { | |
| 16 } | 26 } |
| 17 | 27 |
| 18 UncleanShutdownCollector::~UncleanShutdownCollector() { | 28 UncleanShutdownCollector::~UncleanShutdownCollector() { |
| 19 } | 29 } |
| 20 | 30 |
| 21 bool UncleanShutdownCollector::Enable() { | 31 bool UncleanShutdownCollector::Enable() { |
| 22 FilePath file_path(unclean_shutdown_file_); | 32 FilePath file_path(unclean_shutdown_file_); |
| 23 file_util::CreateDirectory(file_path.DirName()); | 33 file_util::CreateDirectory(file_path.DirName()); |
| 24 if (file_util::WriteFile(file_path, "", 0) != 0) { | 34 if (file_util::WriteFile(file_path, "", 0) != 0) { |
| 25 logger_->LogError("Unable to create shutdown check file"); | 35 logger_->LogError("Unable to create shutdown check file"); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 38 } | 48 } |
| 39 | 49 |
| 40 bool UncleanShutdownCollector::Collect() { | 50 bool UncleanShutdownCollector::Collect() { |
| 41 FilePath unclean_file_path(unclean_shutdown_file_); | 51 FilePath unclean_file_path(unclean_shutdown_file_); |
| 42 if (!file_util::PathExists(unclean_file_path)) { | 52 if (!file_util::PathExists(unclean_file_path)) { |
| 43 return false; | 53 return false; |
| 44 } | 54 } |
| 45 logger_->LogWarning("Last shutdown was not clean"); | 55 logger_->LogWarning("Last shutdown was not clean"); |
| 46 DeleteUncleanShutdownFile(); | 56 DeleteUncleanShutdownFile(); |
| 47 | 57 |
| 58 CheckForDeadBatteryUncleanShutdown(); | |
| 59 file_util::Delete(powerd_suspend_file_, false); | |
|
kmixter1
2010/11/19 23:43:27
Still would be nice to factor this out. How about
| |
| 60 file_util::Delete(powerd_low_battery_file_, false); | |
| 61 | |
| 48 if (is_feedback_allowed_function_()) { | 62 if (is_feedback_allowed_function_()) { |
| 49 count_crash_function_(); | 63 count_crash_function_(); |
| 50 } | 64 } |
| 51 return true; | 65 return true; |
| 52 } | 66 } |
| 53 | 67 |
| 54 bool UncleanShutdownCollector::Disable() { | 68 bool UncleanShutdownCollector::Disable() { |
| 55 logger_->LogInfo("Clean shutdown signalled"); | 69 logger_->LogInfo("Clean shutdown signalled"); |
| 70 file_util::Delete(powerd_suspend_file_, false); | |
| 71 file_util::Delete(powerd_low_battery_file_, false); | |
| 56 return DeleteUncleanShutdownFile(); | 72 return DeleteUncleanShutdownFile(); |
| 57 } | 73 } |
| 74 | |
| 75 bool UncleanShutdownCollector::CheckForDeadBatteryUncleanShutdown() | |
| 76 { | |
| 77 // Check for case of battery running out while suspended. | |
| 78 if (file_util::PathExists(powerd_suspend_file_)) { | |
| 79 logger_->LogInfo("Unclean shutdown occurred while suspended. The battery " | |
| 80 "probably ran out."); | |
| 81 return true; | |
| 82 } | |
| 83 // Check for case of battery running out after resuming from a low-battery | |
| 84 // suspend. | |
| 85 if (file_util::PathExists(powerd_low_battery_file_)) { | |
| 86 logger_->LogInfo("Unclean shutdown occurred while resumed after battery " | |
|
kmixter1
2010/11/19 23:43:27
how about "while running with critically low batte
| |
| 87 "was critically low. The battery probably ran out."); | |
| 88 return true; | |
| 89 } | |
| 90 return false; | |
| 91 } | |
| OLD | NEW |