File: rmad_client.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (159 lines) | stat: -rw-r--r-- 6,027 bytes parent folder | download | duplicates (7)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright 2021 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_RMAD_RMAD_CLIENT_H_
#define CHROMEOS_ASH_COMPONENTS_DBUS_RMAD_RMAD_CLIENT_H_

#include <string>

#include "base/component_export.h"
#include "base/functional/callback_forward.h"
#include "base/observer_list_types.h"
#include "chromeos/ash/components/dbus/rmad/rmad.pb.h"
#include "chromeos/dbus/common/dbus_callback.h"

namespace dbus {
class Bus;
}

namespace ash {

// RmadClient is responsible for receiving D-bus signals from the RmaDaemon
// service. The RmaDaemon is the underlying service that informs us whenever
// a shimless RMA is in progress and manages its state.
// Shimless RMA implements repair finalization for devices without the use of
// the USB shim. See go/cros-shimless-rma for details.
class COMPONENT_EXPORT(RMAD) RmadClient {
 public:
  // Interface for observing signals from rmad.
  class Observer : public base::CheckedObserver {
   public:
    // Called when an error occurs outside of state transitions.
    // e.g. while calibrating devices.
    virtual void Error(rmad::RmadErrorCode error) {}

    // Called when calibration progress is updated.
    virtual void CalibrationProgress(
        const rmad::CalibrationComponentStatus& component_status) {}

    // Called when overall calibration progress is updated.
    virtual void CalibrationOverallProgress(
        rmad::CalibrationOverallStatus status) {}

    // Called when provisioning progress is updated.
    virtual void ProvisioningProgress(const rmad::ProvisionStatus& status) {}

    // Called when hardware write protection state changes.
    virtual void HardwareWriteProtectionState(bool enabled) {}

    // Called when power cable is plugged in or removed.
    virtual void PowerCableState(bool plugged_in) {}

    // Called when an external disk is plugged in or removed.
    virtual void ExternalDiskState(bool detected) {}

    // Called when hardware verification completes.
    virtual void HardwareVerificationResult(
        const rmad::HardwareVerificationResult& result) {}

    // Called when finalization progress is updated.
    virtual void FinalizationProgress(const rmad::FinalizeStatus& status) {}

    // Called when overall calibration progress is updated.
    virtual void RoFirmwareUpdateProgress(rmad::UpdateRoFirmwareStatus status) {
    }
  };

  // Creates and initializes a global instance. |bus| must not be null.
  static void Initialize(dbus::Bus* bus);

  // Destroys the global instance.
  static void Shutdown();

  // Returns the global instance which may be null if not initialized.
  static RmadClient* Get();

  // Returns true if RMA is supported and the RMA state files were detected.
  virtual bool WasRmaStateDetected() = 0;

  // Called by ChromeSessionManager, `session_manager_callback` is invoked when
  // the RMA check completes and it's determined that RMA is required.
  virtual void SetRmaRequiredCallbackForSessionManager(
      base::OnceClosure session_manager_callback) = 0;

  // Asynchronously gets the current RMA state.
  // The response contains an error code and the current state of the RMA
  // process.
  virtual void GetCurrentState(
      chromeos::DBusMethodCallback<rmad::GetStateReply> callback) = 0;
  // Asynchronously attempts to transition to the next RMA state.
  // The response contains an error code and the current state of the RMA
  // process.
  virtual void TransitionNextState(
      const rmad::RmadState& state,
      chromeos::DBusMethodCallback<rmad::GetStateReply> callback) = 0;
  // Asynchronously attempts to transition to the previous RMA state.
  // The response contains an error code and the current state of the RMA
  // process.
  virtual void TransitionPreviousState(
      chromeos::DBusMethodCallback<rmad::GetStateReply> callback) = 0;

  // Request the RMA process be cancelled.
  // There is no guarantee the callback is called if abort is successful because
  // the device will reboot.
  // Returns RMAD_ERROR_OK on success or an error code.
  virtual void AbortRma(
      chromeos::DBusMethodCallback<rmad::AbortRmaReply> callback) = 0;

  // Request the RMA process logs.
  virtual void GetLog(
      chromeos::DBusMethodCallback<rmad::GetLogReply> callback) = 0;

  // Save RMA logs to a USB drive.
  virtual void SaveLog(
      const std::string& diagnostics_log_text,
      chromeos::DBusMethodCallback<rmad::SaveLogReply> callback) = 0;

  // Send metrics to the platform side, which will upload them.
  virtual void RecordBrowserActionMetric(
      const rmad::RecordBrowserActionMetricRequest request,
      chromeos::DBusMethodCallback<rmad::RecordBrowserActionMetricReply>
          callback) = 0;

  // Extracts the diagnostics app from external sources.
  virtual void ExtractExternalDiagnosticsApp(
      chromeos::DBusMethodCallback<rmad::ExtractExternalDiagnosticsAppReply>
          callback) = 0;

  // Installs the diagnostics app extracted by last
  // `ExtractExternalDiagnosticsApp` call.
  virtual void InstallExtractedDiagnosticsApp(
      chromeos::DBusMethodCallback<rmad::InstallExtractedDiagnosticsAppReply>
          callback) = 0;

  // Gets the installed diagnostics app.
  virtual void GetInstalledDiagnosticsApp(
      chromeos::DBusMethodCallback<rmad::GetInstalledDiagnosticsAppReply>
          callback) = 0;

  // Adds and removes the observer.
  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;
  virtual bool HasObserver(const Observer* observer) const = 0;

  // Creates and initializes a fake global instance if not already created.
  static void InitializeFake();

 protected:
  // Initialize/Shutdown should be used instead.
  RmadClient();

  RmadClient(const RmadClient&) = delete;
  RmadClient& operator=(const RmadClient&) = delete;
  virtual ~RmadClient();
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_DBUS_RMAD_RMAD_CLIENT_H_