Steve Fung | 6c34c25 | 2015-08-20 00:27:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 16 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 17 | #ifndef CRASH_REPORTER_UNCLEAN_SHUTDOWN_COLLECTOR_H_ |
| 18 | #define CRASH_REPORTER_UNCLEAN_SHUTDOWN_COLLECTOR_H_ |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 22 | #include <base/files/file_path.h> |
Ben Chan | 895fa5d | 2014-09-02 20:58:20 -0700 | [diff] [blame] | 23 | #include <base/macros.h> |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 24 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 25 | |
Steve Fung | 129bea5 | 2015-07-23 13:11:15 -0700 | [diff] [blame] | 26 | #include "crash_collector.h" |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 27 | |
| 28 | // Unclean shutdown collector. |
| 29 | class UncleanShutdownCollector : public CrashCollector { |
| 30 | public: |
| 31 | UncleanShutdownCollector(); |
Ben Chan | efec0b3 | 2014-08-12 08:52:11 -0700 | [diff] [blame] | 32 | ~UncleanShutdownCollector() override; |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 33 | |
| 34 | // Enable collection - signal that a boot has started. |
| 35 | bool Enable(); |
| 36 | |
| 37 | // Collect if there is was an unclean shutdown. Returns true if |
| 38 | // there was, false otherwise. |
| 39 | bool Collect(); |
| 40 | |
| 41 | // Disable collection - signal that the system has been shutdown cleanly. |
| 42 | bool Disable(); |
| 43 | |
| 44 | private: |
| 45 | friend class UncleanShutdownCollectorTest; |
| 46 | FRIEND_TEST(UncleanShutdownCollectorTest, EnableCannotWrite); |
Simon Que | 3f7ed5d | 2010-11-30 17:10:54 -0800 | [diff] [blame] | 47 | FRIEND_TEST(UncleanShutdownCollectorTest, CollectDeadBatterySuspended); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 48 | |
Simon Que | 3f7ed5d | 2010-11-30 17:10:54 -0800 | [diff] [blame] | 49 | bool DeleteUncleanShutdownFiles(); |
| 50 | |
| 51 | // Check for unclean shutdown due to battery running out by analyzing powerd |
| 52 | // trace files. |
| 53 | bool DeadBatteryCausedUncleanShutdown(); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 54 | |
| 55 | const char *unclean_shutdown_file_; |
Simon Que | 9f90aca | 2013-02-19 17:19:52 -0800 | [diff] [blame] | 56 | base::FilePath powerd_trace_path_; |
| 57 | base::FilePath powerd_suspended_file_; |
Ben Chan | 895fa5d | 2014-09-02 20:58:20 -0700 | [diff] [blame] | 58 | |
| 59 | DISALLOW_COPY_AND_ASSIGN(UncleanShutdownCollector); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 62 | #endif // CRASH_REPORTER_UNCLEAN_SHUTDOWN_COLLECTOR_H_ |