blob: 411e2a1a2562ddf41bcdc3d36e723c63f09154fe [file] [log] [blame]
Mike Frysingerc0871522013-09-16 14:07:27 -04001// 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 Vakulenko262be3f2014-07-30 15:25:50 -07005#ifndef DEBUGD_SRC_CRASH_SENDER_TOOL_H_
6#define DEBUGD_SRC_CRASH_SENDER_TOOL_H_
Mike Frysingerc0871522013-09-16 14:07:27 -04007
Ian Barkley-Yeung7b7b0352019-04-23 12:52:04 -07008#include <string>
9#include <tuple>
10#include <vector>
11
12#include <base/files/file_path.h>
13#include <base/files/scoped_file.h>
Ben Chan657bed82014-09-02 20:40:51 -070014#include <base/macros.h>
Ian Barkley-Yeung7b7b0352019-04-23 12:52:04 -070015#include <brillo/errors/error.h>
Mike Frysingerc0871522013-09-16 14:07:27 -040016
Alex Vakulenko262be3f2014-07-30 15:25:50 -070017#include "debugd/src/subprocess_tool.h"
Mike Frysingerc0871522013-09-16 14:07:27 -040018
Ian Barkley-Yeungc68cfc32019-07-15 16:43:57 -070019namespace brillo {
20namespace dbus_utils {
21class ExportedPropertyBase;
22} // namespace dbus_utils
23} // namespace brillo
24
Mike Frysingerc0871522013-09-16 14:07:27 -040025namespace debugd {
26
27class CrashSenderTool : public SubprocessTool {
28 public:
Ian Barkley-Yeung7b7b0352019-04-23 12:52:04 -070029 static constexpr char kErrorBadFileName[] =
30 "org.chromium.debugd.error.BadFileName";
31
Ben Chan78f89532014-08-29 09:35:09 -070032 CrashSenderTool() = default;
Qijiang Fan6bc59e12020-11-11 02:51:06 +090033 CrashSenderTool(const CrashSenderTool&) = delete;
34 CrashSenderTool& operator=(const CrashSenderTool&) = delete;
35
Ben Chan78f89532014-08-29 09:35:09 -070036 ~CrashSenderTool() override = default;
Mike Frysingerc0871522013-09-16 14:07:27 -040037
Ian Barkley-Yeung7b7b0352019-04-23 12:52:04 -070038 // Run crash_sender to upload any crashes currently on the system.
Eric Carusoc93a15c2017-04-24 16:15:12 -070039 void UploadCrashes();
Mike Frysingerc0871522013-09-16 14:07:27 -040040
Ian Barkley-Yeung7b7b0352019-04-23 12:52:04 -070041 // 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-Yeungc68cfc32019-07-15 16:43:57 -070046 // Called when the CrashSenderTestMode dbus property is changed.
47 void OnTestModeChanged(
Tom Hughesd6c2d392020-08-24 18:12:11 -070048 const brillo::dbus_utils::ExportedPropertyBase* test_mode_property);
Ian Barkley-Yeungc68cfc32019-07-15 16:43:57 -070049
Mike Frysingerc0871522013-09-16 14:07:27 -040050 private:
Ian Barkley-Yeung7b7b0352019-04-23 12:52:04 -070051 int next_crash_directory_id_ = 1;
52
Ian Barkley-Yeungc68cfc32019-07-15 16:43:57 -070053 // 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-Yeung7b7b0352019-04-23 12:52:04 -070058 void RunCrashSender(bool ignore_hold_off_time,
59 const base::FilePath& crash_directory);
Mike Frysingerc0871522013-09-16 14:07:27 -040060};
61
62} // namespace debugd
63
Alex Vakulenko262be3f2014-07-30 15:25:50 -070064#endif // DEBUGD_SRC_CRASH_SENDER_TOOL_H_