1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_ASH_COMPONENTS_DBUS_ANOMALY_DETECTOR_ANOMALY_DETECTOR_CLIENT_H_
#define CHROMEOS_ASH_COMPONENTS_DBUS_ANOMALY_DETECTOR_ANOMALY_DETECTOR_CLIENT_H_
#include "base/component_export.h"
#include "base/observer_list_types.h"
#include "chromeos/ash/components/dbus/anomaly_detector/anomaly_detector.pb.h"
#include "chromeos/dbus/common/dbus_client.h"
namespace ash {
// AnomalyDetectorClient is used to communicate with anomaly_detector.
// Currently this just amounts to listening to signals it sends.
class COMPONENT_EXPORT(ASH_DBUS_ANOMALY_DETECTOR) AnomalyDetectorClient
: public chromeos::DBusClient {
public:
class Observer : public base::CheckedObserver {
public:
// OnGuestFileCorruption is signaled by anomaly_detector when it detects
// that a VM has encountered filesystem corruption.
virtual void OnGuestFileCorruption(
const anomaly_detector::GuestFileCorruptionSignal& signal) = 0;
};
AnomalyDetectorClient(const AnomalyDetectorClient&) = delete;
AnomalyDetectorClient& operator=(const AnomalyDetectorClient&) = delete;
~AnomalyDetectorClient() override;
// Adds an observer.
virtual void AddObserver(Observer* observer) = 0;
// Removes an observer if added.
virtual void RemoveObserver(Observer* observer) = 0;
// IsGuestFileCorruptionSignalConnected must return true before starting a VM,
// or we will be unable to detect if it's filesystem is corrupt.
virtual bool IsGuestFileCorruptionSignalConnected() = 0;
// Creates and initializes the global instance. |bus| must not be null.
static void Initialize(dbus::Bus* bus);
// Creates and initializes a fake global instance if not already created.
static void InitializeFake();
// Destroys the global instance if it has been initialized.
static void Shutdown();
// Returns the global instance if initialized. May return null.
static AnomalyDetectorClient* Get();
protected:
// Initialize() should be used instead.
AnomalyDetectorClient();
};
} // namespace ash
#endif // CHROMEOS_ASH_COMPONENTS_DBUS_ANOMALY_DETECTOR_ANOMALY_DETECTOR_CLIENT_H_
|