blob: 2836901fe967a1f89a3fd4c294be6e15a51640ef [file] [log] [blame]
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The generic failure collector collects issues that anomaly_detector catches
// that manifest as a single line logged to a log file.
// The flow looks like this:
// 1. One of the parsers in anomaly_detector flag an issue
// 2. anomaly_detector invokes crash_reporter with an appropriate flag
// 3. crash_reporter invokes a GenericFailureCollector instance
#include <string>
#include <base/macros.h>
#include <base/optional.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
#include "crash-reporter/crash_collector.h"
// Generic failure collector.
class GenericFailureCollector : public CrashCollector {
GenericFailureCollector(const GenericFailureCollector&) = delete;
GenericFailureCollector& operator=(const GenericFailureCollector&) = delete;
~GenericFailureCollector() override;
// Collects generic failure.
bool Collect(const std::string& exec_name) {
return CollectFull(exec_name, exec_name, base::nullopt);
// Collects generic failure with a weight specified.
bool CollectWithWeight(const std::string& exec_name,
base::Optional<int> weight) {
return CollectFull(exec_name, exec_name, weight);
// All the bells and whistles.
// exec_name is the string used for filenames on disk.
// log_key_name is a key used for the exec_name as passed to GetLogContents
// if weight is not nullopt, the "weight" key is set to that value.
bool CollectFull(const std::string& exec_name,
const std::string& log_key_name,
base::Optional<int> weight);
static const char* const kGenericFailure;
static const char* const kSuspendFailure;
static const char* const kServiceFailure;
static const char* const kArcServiceFailure;
std::string failure_report_path_;
std::string exec_name_;
std::string log_key_name_;
base::Optional<int> weight_;
friend class GenericFailureCollectorTest;
friend class ArcGenericFailureCollectorTest;
// Generic failure dump consists only of the signature.
bool LoadGenericFailure(std::string* content, std::string* signature);