blob: 5bc9968697f8735df30f65033e51cfe540a0db11 [file] [log] [blame]
Steve Fung6c34c252015-08-20 00:27:30 -07001/*
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 Mixter03403162010-08-18 15:23:16 -070016
Ben Chan7e776902014-06-18 13:19:51 -070017#ifndef CRASH_REPORTER_UNCLEAN_SHUTDOWN_COLLECTOR_H_
18#define CRASH_REPORTER_UNCLEAN_SHUTDOWN_COLLECTOR_H_
Ken Mixter03403162010-08-18 15:23:16 -070019
20#include <string>
21
Ben Chan7e776902014-06-18 13:19:51 -070022#include <base/files/file_path.h>
Ben Chan895fa5d2014-09-02 20:58:20 -070023#include <base/macros.h>
Ben Chan7e776902014-06-18 13:19:51 -070024#include <gtest/gtest_prod.h> // for FRIEND_TEST
25
Steve Fung129bea52015-07-23 13:11:15 -070026#include "crash_collector.h"
Ken Mixter03403162010-08-18 15:23:16 -070027
28// Unclean shutdown collector.
29class UncleanShutdownCollector : public CrashCollector {
30 public:
31 UncleanShutdownCollector();
Ben Chanefec0b32014-08-12 08:52:11 -070032 ~UncleanShutdownCollector() override;
Ken Mixter03403162010-08-18 15:23:16 -070033
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 Que3f7ed5d2010-11-30 17:10:54 -080047 FRIEND_TEST(UncleanShutdownCollectorTest, CollectDeadBatterySuspended);
Ken Mixter03403162010-08-18 15:23:16 -070048
Simon Que3f7ed5d2010-11-30 17:10:54 -080049 bool DeleteUncleanShutdownFiles();
50
51 // Check for unclean shutdown due to battery running out by analyzing powerd
52 // trace files.
53 bool DeadBatteryCausedUncleanShutdown();
Ken Mixter03403162010-08-18 15:23:16 -070054
55 const char *unclean_shutdown_file_;
Simon Que9f90aca2013-02-19 17:19:52 -080056 base::FilePath powerd_trace_path_;
57 base::FilePath powerd_suspended_file_;
Ben Chan895fa5d2014-09-02 20:58:20 -070058
59 DISALLOW_COPY_AND_ASSIGN(UncleanShutdownCollector);
Ken Mixter03403162010-08-18 15:23:16 -070060};
61
Ben Chan7e776902014-06-18 13:19:51 -070062#endif // CRASH_REPORTER_UNCLEAN_SHUTDOWN_COLLECTOR_H_