OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "crash-reporter/unclean_shutdown_collector.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" |
| 9 #include "crash-reporter/system_logging.h" |
| 10 |
| 11 static const char kUncleanShutdownFile[] = |
| 12 "/var/lib/crash_reporter/pending_clean_shutdown"; |
| 13 |
| 14 UncleanShutdownCollector::UncleanShutdownCollector() |
| 15 : unclean_shutdown_file_(kUncleanShutdownFile) { |
| 16 } |
| 17 |
| 18 UncleanShutdownCollector::~UncleanShutdownCollector() { |
| 19 } |
| 20 |
| 21 bool UncleanShutdownCollector::Enable() { |
| 22 FilePath file_path(unclean_shutdown_file_); |
| 23 file_util::CreateDirectory(file_path.DirName()); |
| 24 if (file_util::WriteFile(file_path, "", 0) != 0) { |
| 25 logger_->LogError("Unable to create shutdown check file"); |
| 26 return false; |
| 27 } |
| 28 return true; |
| 29 } |
| 30 |
| 31 bool UncleanShutdownCollector::DeleteUncleanShutdownFile() { |
| 32 if (!file_util::Delete(FilePath(unclean_shutdown_file_), false)) { |
| 33 logger_->LogError("Failed to delete unclean shutdown file %s", |
| 34 unclean_shutdown_file_); |
| 35 return false; |
| 36 } |
| 37 return true; |
| 38 } |
| 39 |
| 40 bool UncleanShutdownCollector::Collect() { |
| 41 FilePath unclean_file_path(unclean_shutdown_file_); |
| 42 if (!file_util::PathExists(unclean_file_path)) { |
| 43 return false; |
| 44 } |
| 45 logger_->LogWarning("Last shutdown was not clean"); |
| 46 DeleteUncleanShutdownFile(); |
| 47 |
| 48 if (is_feedback_allowed_function_()) { |
| 49 count_crash_function_(); |
| 50 } |
| 51 return true; |
| 52 } |
| 53 |
| 54 bool UncleanShutdownCollector::Disable() { |
| 55 logger_->LogInfo("Clean shutdown signalled"); |
| 56 return DeleteUncleanShutdownFile(); |
| 57 } |
OLD | NEW |