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/time.h" | |
kmixter1
2010/11/18 02:58:19
abc order
| |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "crash-reporter/system_logging.h" | 10 #include "crash-reporter/system_logging.h" |
10 | 11 |
11 static const char kUncleanShutdownFile[] = | 12 static const char kUncleanShutdownFile[] = |
12 "/var/lib/crash_reporter/pending_clean_shutdown"; | 13 "/var/lib/crash_reporter/pending_clean_shutdown"; |
13 | 14 |
15 // Files created by power manager used for crash reporting | |
kmixter1
2010/11/18 02:58:19
Periods at end of comments please.
| |
16 #define TRACE_PATH "/var/lib/power_manager" | |
17 static const char kPowerdTracePath[] = TRACE_PATH; | |
18 // File with timestamp of last suspend | |
19 static const char kPowerdSuspendFile[] = TRACE_PATH "/powerd_suspending"; | |
kmixter1
2010/11/18 02:58:19
Just make this be the filename, make kPowerdTraceP
kmixter1
2010/11/18 02:58:19
I suggest making this be the filename, make kPower
| |
20 // File with timestamp of last resume | |
21 static const char kPowerdResumeFile[] = TRACE_PATH "/powerd_resuming"; | |
22 // Presence of this file indicates that the battery is critically low | |
23 static const char kPowerdLowBatteryFile[] = TRACE_PATH "/powerd_low_battery"; | |
24 | |
25 bool UncleanShutdownCollector::ReadModificationTime(const char *file_string) | |
26 { | |
27 FilePath file_path(file_string); | |
28 file_util::FileInfo file_info; | |
29 base::Time::Exploded timestamp; | |
30 // Initialize timestamp fields to prevent warnings during print | |
31 timestamp.hour = -1; | |
32 timestamp.minute = -1; | |
33 timestamp.second = -1; | |
34 // Log the file modification time if it exists | |
35 if (file_util::PathExists(file_path)) { | |
36 if (!GetFileInfo(file_path, &file_info)) | |
37 return false; | |
38 file_info.last_modified.LocalExplode(×tamp); | |
39 logger_->LogInfo("File %s modified at %02d:%02d:%02d", file_string, | |
40 timestamp.hour, timestamp.minute, timestamp.second); | |
41 return true; | |
42 } | |
43 return false; | |
44 } | |
45 | |
14 UncleanShutdownCollector::UncleanShutdownCollector() | 46 UncleanShutdownCollector::UncleanShutdownCollector() |
15 : unclean_shutdown_file_(kUncleanShutdownFile) { | 47 : unclean_shutdown_file_(kUncleanShutdownFile) { |
16 } | 48 } |
17 | 49 |
18 UncleanShutdownCollector::~UncleanShutdownCollector() { | 50 UncleanShutdownCollector::~UncleanShutdownCollector() { |
19 } | 51 } |
20 | 52 |
21 bool UncleanShutdownCollector::Enable() { | 53 bool UncleanShutdownCollector::Enable() { |
22 FilePath file_path(unclean_shutdown_file_); | 54 FilePath file_path(unclean_shutdown_file_); |
23 file_util::CreateDirectory(file_path.DirName()); | 55 file_util::CreateDirectory(file_path.DirName()); |
(...skipping 14 matching lines...) Expand all Loading... | |
38 } | 70 } |
39 | 71 |
40 bool UncleanShutdownCollector::Collect() { | 72 bool UncleanShutdownCollector::Collect() { |
41 FilePath unclean_file_path(unclean_shutdown_file_); | 73 FilePath unclean_file_path(unclean_shutdown_file_); |
42 if (!file_util::PathExists(unclean_file_path)) { | 74 if (!file_util::PathExists(unclean_file_path)) { |
43 return false; | 75 return false; |
44 } | 76 } |
45 logger_->LogWarning("Last shutdown was not clean"); | 77 logger_->LogWarning("Last shutdown was not clean"); |
46 DeleteUncleanShutdownFile(); | 78 DeleteUncleanShutdownFile(); |
47 | 79 |
80 // Check for failed suspend | |
81 logger_->LogInfo("Checking for Power Daemon files"); | |
82 ReadModificationTime(kPowerdSuspendFile); | |
kmixter1
2010/11/18 02:58:19
I really would like to see the logic of figuring o
| |
83 ReadModificationTime(kPowerdResumeFile); | |
84 ReadModificationTime(kPowerdLowBatteryFile); | |
85 file_util::Delete(FilePath(kPowerdSuspendFile), false); | |
86 file_util::Delete(FilePath(kPowerdResumeFile), false); | |
87 file_util::Delete(FilePath(kPowerdLowBatteryFile), false); | |
48 if (is_feedback_allowed_function_()) { | 88 if (is_feedback_allowed_function_()) { |
49 count_crash_function_(); | 89 count_crash_function_(); |
50 } | 90 } |
51 return true; | 91 return true; |
52 } | 92 } |
53 | 93 |
54 bool UncleanShutdownCollector::Disable() { | 94 bool UncleanShutdownCollector::Disable() { |
55 logger_->LogInfo("Clean shutdown signalled"); | 95 logger_->LogInfo("Clean shutdown signalled"); |
96 file_util::Delete(FilePath(kPowerdSuspendFile), false); | |
97 file_util::Delete(FilePath(kPowerdResumeFile), false); | |
98 file_util::Delete(FilePath(kPowerdLowBatteryFile), false); | |
56 return DeleteUncleanShutdownFile(); | 99 return DeleteUncleanShutdownFile(); |
57 } | 100 } |
OLD | NEW |