Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 1 | // Copyright (c) 2013 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 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 5 | #ifndef DEBUGD_SRC_CRASH_SENDER_TOOL_H_ |
| 6 | #define DEBUGD_SRC_CRASH_SENDER_TOOL_H_ |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 7 | |
Ian Barkley-Yeung | 7b7b035 | 2019-04-23 12:52:04 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <tuple> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include <base/files/file_path.h> |
| 13 | #include <base/files/scoped_file.h> |
Ben Chan | 657bed8 | 2014-09-02 20:40:51 -0700 | [diff] [blame] | 14 | #include <base/macros.h> |
Ian Barkley-Yeung | 7b7b035 | 2019-04-23 12:52:04 -0700 | [diff] [blame] | 15 | #include <brillo/errors/error.h> |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 16 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 17 | #include "debugd/src/subprocess_tool.h" |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 18 | |
Ian Barkley-Yeung | c68cfc3 | 2019-07-15 16:43:57 -0700 | [diff] [blame] | 19 | namespace brillo { |
| 20 | namespace dbus_utils { |
| 21 | class ExportedPropertyBase; |
| 22 | } // namespace dbus_utils |
| 23 | } // namespace brillo |
| 24 | |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 25 | namespace debugd { |
| 26 | |
| 27 | class CrashSenderTool : public SubprocessTool { |
| 28 | public: |
Ian Barkley-Yeung | 7b7b035 | 2019-04-23 12:52:04 -0700 | [diff] [blame] | 29 | static constexpr char kErrorBadFileName[] = |
| 30 | "org.chromium.debugd.error.BadFileName"; |
| 31 | |
Ben Chan | 78f8953 | 2014-08-29 09:35:09 -0700 | [diff] [blame] | 32 | CrashSenderTool() = default; |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 33 | CrashSenderTool(const CrashSenderTool&) = delete; |
| 34 | CrashSenderTool& operator=(const CrashSenderTool&) = delete; |
| 35 | |
Ben Chan | 78f8953 | 2014-08-29 09:35:09 -0700 | [diff] [blame] | 36 | ~CrashSenderTool() override = default; |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 37 | |
Ian Barkley-Yeung | 7b7b035 | 2019-04-23 12:52:04 -0700 | [diff] [blame] | 38 | // Run crash_sender to upload any crashes currently on the system. |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 39 | void UploadCrashes(); |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 40 | |
Ian Barkley-Yeung | 7b7b035 | 2019-04-23 12:52:04 -0700 | [diff] [blame] | 41 | // Run crash_sender to upload the crash given in the files in |in_files|. |
| 42 | bool UploadSingleCrash( |
| 43 | const std::vector<std::tuple<std::string, base::ScopedFD>>& in_files, |
| 44 | brillo::ErrorPtr* error); |
| 45 | |
Ian Barkley-Yeung | c68cfc3 | 2019-07-15 16:43:57 -0700 | [diff] [blame] | 46 | // Called when the CrashSenderTestMode dbus property is changed. |
| 47 | void OnTestModeChanged( |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 48 | const brillo::dbus_utils::ExportedPropertyBase* test_mode_property); |
Ian Barkley-Yeung | c68cfc3 | 2019-07-15 16:43:57 -0700 | [diff] [blame] | 49 | |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 50 | private: |
Ian Barkley-Yeung | 7b7b035 | 2019-04-23 12:52:04 -0700 | [diff] [blame] | 51 | int next_crash_directory_id_ = 1; |
| 52 | |
Ian Barkley-Yeung | c68cfc3 | 2019-07-15 16:43:57 -0700 | [diff] [blame] | 53 | // If true, pass the "--test_mode" flag to crash_sender. This is bound to the |
| 54 | // "CrashSenderTestMode" dbus property, so tast tests (and anyone else) can |
| 55 | // change it easily. |
| 56 | bool test_mode_ = false; |
| 57 | |
Ian Barkley-Yeung | 7b7b035 | 2019-04-23 12:52:04 -0700 | [diff] [blame] | 58 | void RunCrashSender(bool ignore_hold_off_time, |
| 59 | const base::FilePath& crash_directory); |
Mike Frysinger | c087152 | 2013-09-16 14:07:27 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace debugd |
| 63 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 64 | #endif // DEBUGD_SRC_CRASH_SENDER_TOOL_H_ |