Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: unclean_shutdown_collector.cc

Issue 6517001: crash-reporter: Use standard logging and new libchromeos Process code (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crash-reporter.git@master
Patch Set: More comments Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test_helpers.h ('k') | unclean_shutdown_collector_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 9
11 static const char kUncleanShutdownFile[] = 10 static const char kUncleanShutdownFile[] =
12 "/var/lib/crash_reporter/pending_clean_shutdown"; 11 "/var/lib/crash_reporter/pending_clean_shutdown";
13 12
14 // Files created by power manager used for crash reporting. 13 // Files created by power manager used for crash reporting.
15 static const char kPowerdTracePath[] = "/var/lib/power_manager"; 14 static const char kPowerdTracePath[] = "/var/lib/power_manager";
16 // Presence of this file indicates that the system was suspended 15 // Presence of this file indicates that the system was suspended
17 static const char kPowerdSuspended[] = "powerd_suspended"; 16 static const char kPowerdSuspended[] = "powerd_suspended";
18 // Presence of this file indicates that the battery was critically low. 17 // Presence of this file indicates that the battery was critically low.
19 static const char kPowerdLowBattery[] = "powerd_low_battery"; 18 static const char kPowerdLowBattery[] = "powerd_low_battery";
20 19
21 UncleanShutdownCollector::UncleanShutdownCollector() 20 UncleanShutdownCollector::UncleanShutdownCollector()
22 : unclean_shutdown_file_(kUncleanShutdownFile), 21 : unclean_shutdown_file_(kUncleanShutdownFile),
23 powerd_trace_path_(kPowerdTracePath), 22 powerd_trace_path_(kPowerdTracePath),
24 powerd_suspended_file_(powerd_trace_path_.Append(kPowerdSuspended)), 23 powerd_suspended_file_(powerd_trace_path_.Append(kPowerdSuspended)),
25 powerd_low_battery_file_(powerd_trace_path_.Append(kPowerdLowBattery)) { 24 powerd_low_battery_file_(powerd_trace_path_.Append(kPowerdLowBattery)) {
26 } 25 }
27 26
28 UncleanShutdownCollector::~UncleanShutdownCollector() { 27 UncleanShutdownCollector::~UncleanShutdownCollector() {
29 } 28 }
30 29
31 bool UncleanShutdownCollector::Enable() { 30 bool UncleanShutdownCollector::Enable() {
32 FilePath file_path(unclean_shutdown_file_); 31 FilePath file_path(unclean_shutdown_file_);
33 file_util::CreateDirectory(file_path.DirName()); 32 file_util::CreateDirectory(file_path.DirName());
34 if (file_util::WriteFile(file_path, "", 0) != 0) { 33 if (file_util::WriteFile(file_path, "", 0) != 0) {
35 logger_->LogError("Unable to create shutdown check file"); 34 LOG(ERROR) << "Unable to create shutdown check file";
36 return false; 35 return false;
37 } 36 }
38 return true; 37 return true;
39 } 38 }
40 39
41 bool UncleanShutdownCollector::DeleteUncleanShutdownFiles() { 40 bool UncleanShutdownCollector::DeleteUncleanShutdownFiles() {
42 if (!file_util::Delete(FilePath(unclean_shutdown_file_), false)) { 41 if (!file_util::Delete(FilePath(unclean_shutdown_file_), false)) {
43 logger_->LogError("Failed to delete unclean shutdown file %s", 42 LOG(ERROR) << "Failed to delete unclean shutdown file "
44 unclean_shutdown_file_); 43 << unclean_shutdown_file_;
45 return false; 44 return false;
46 } 45 }
47 // Delete power manager trace files if they exist. 46 // Delete power manager trace files if they exist.
48 file_util::Delete(powerd_suspended_file_, false); 47 file_util::Delete(powerd_suspended_file_, false);
49 file_util::Delete(powerd_low_battery_file_, false); 48 file_util::Delete(powerd_low_battery_file_, false);
50 return true; 49 return true;
51 } 50 }
52 51
53 bool UncleanShutdownCollector::Collect() { 52 bool UncleanShutdownCollector::Collect() {
54 FilePath unclean_file_path(unclean_shutdown_file_); 53 FilePath unclean_file_path(unclean_shutdown_file_);
55 if (!file_util::PathExists(unclean_file_path)) { 54 if (!file_util::PathExists(unclean_file_path)) {
56 return false; 55 return false;
57 } 56 }
58 logger_->LogWarning("Last shutdown was not clean"); 57 LOG(WARNING) << "Last shutdown was not clean";
59 if (DeadBatteryCausedUncleanShutdown()) { 58 if (DeadBatteryCausedUncleanShutdown()) {
60 DeleteUncleanShutdownFiles(); 59 DeleteUncleanShutdownFiles();
61 return false; 60 return false;
62 } 61 }
63 DeleteUncleanShutdownFiles(); 62 DeleteUncleanShutdownFiles();
64 63
65 if (is_feedback_allowed_function_()) { 64 if (is_feedback_allowed_function_()) {
66 count_crash_function_(); 65 count_crash_function_();
67 } 66 }
68 return true; 67 return true;
69 } 68 }
70 69
71 bool UncleanShutdownCollector::Disable() { 70 bool UncleanShutdownCollector::Disable() {
72 logger_->LogInfo("Clean shutdown signalled"); 71 LOG(INFO) << "Clean shutdown signalled";
73 return DeleteUncleanShutdownFiles(); 72 return DeleteUncleanShutdownFiles();
74 } 73 }
75 74
76 bool UncleanShutdownCollector::DeadBatteryCausedUncleanShutdown() 75 bool UncleanShutdownCollector::DeadBatteryCausedUncleanShutdown()
77 { 76 {
78 // Check for case of battery running out while suspended. 77 // Check for case of battery running out while suspended.
79 if (file_util::PathExists(powerd_suspended_file_)) { 78 if (file_util::PathExists(powerd_suspended_file_)) {
80 logger_->LogInfo("Unclean shutdown occurred while suspended. Not counting " 79 LOG(INFO) << "Unclean shutdown occurred while suspended. Not counting "
81 "toward unclean shutdown statistic."); 80 << "toward unclean shutdown statistic.";
82 return true; 81 return true;
83 } 82 }
84 // Check for case of battery running out after resuming from a low-battery 83 // Check for case of battery running out after resuming from a low-battery
85 // suspend. 84 // suspend.
86 if (file_util::PathExists(powerd_low_battery_file_)) { 85 if (file_util::PathExists(powerd_low_battery_file_)) {
87 logger_->LogInfo("Unclean shutdown occurred while running with battery " 86 LOG(INFO) << "Unclean shutdown occurred while running with battery "
88 "critically low. Not counting toward unclean shutdown " 87 << "critically low. Not counting toward unclean shutdown "
89 "statistic."); 88 << "statistic.";
90 return true; 89 return true;
91 } 90 }
92 return false; 91 return false;
93 } 92 }
OLDNEW
« no previous file with comments | « test_helpers.h ('k') | unclean_shutdown_collector_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698