File: diagnostic_routine_converters.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (142 lines) | stat: -rw-r--r-- 5,630 bytes parent folder | download | duplicates (3)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_TELEMETRY_API_ROUTINES_DIAGNOSTIC_ROUTINE_CONVERTERS_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_TELEMETRY_API_ROUTINES_DIAGNOSTIC_ROUTINE_CONVERTERS_H_

#include <cstdint>
#include <type_traits>
#include <utility>

#include "base/uuid.h"
#include "chrome/common/chromeos/extensions/api/diagnostics.h"
#include "chromeos/crosapi/mojom/telemetry_diagnostic_routine_service.mojom.h"
#include "chromeos/crosapi/mojom/telemetry_extension_exception.mojom.h"

// This file contains helper functions used by the routine API to convert its
// types to/from telemetry service types.
namespace chromeos::converters::routines {

// Functions in unchecked namespace do not verify whether input pointer is
// nullptr, they should be called only via ConvertPtr wrapper that checks
// whether input pointer is nullptr.
namespace unchecked {

api::os_diagnostics::RoutineInitializedInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticRoutineStateInitializedPtr input,
    base::Uuid uuid);

api::os_diagnostics::RoutineRunningInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticRoutineStateRunningPtr input,
    base::Uuid uuid,
    uint32_t percentage);

api::os_diagnostics::NetworkBandwidthRoutineRunningInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticNetworkBandwidthRoutineRunningInfoPtr
        input);

api::os_diagnostics::RoutineInquiryUnion UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticRoutineInquiryPtr input);

api::os_diagnostics::RoutineInteractionUnion UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticRoutineInteractionPtr input);

api::os_diagnostics::RoutineWaitingInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticRoutineStateWaitingPtr input,
    base::Uuid uuid,
    uint32_t percentage);

api::os_diagnostics::MemtesterResult UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticMemtesterResultPtr input);

// For legacy finished events.
// TODO(b/331540565): Remove this function after the legacy event is removed.
api::os_diagnostics::LegacyMemoryRoutineFinishedInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticMemoryRoutineDetailPtr input,
    base::Uuid uuid,
    bool has_passed);

// For legacy finished events.
// TODO(b/331540565): Remove this function after the legacy event is removed.
api::os_diagnostics::LegacyVolumeButtonRoutineFinishedInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticVolumeButtonRoutineDetailPtr input,
    base::Uuid uuid,
    bool has_passed);

// For legacy finished events.
// TODO(b/331540565): Remove this function after the legacy event is removed.
api::os_diagnostics::LegacyFanRoutineFinishedInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticFanRoutineDetailPtr input,
    base::Uuid uuid,
    bool has_passed);

api::os_diagnostics::MemoryRoutineFinishedDetail UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticMemoryRoutineDetailPtr input);

api::os_diagnostics::FanRoutineFinishedDetail UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticFanRoutineDetailPtr input);

api::os_diagnostics::NetworkBandwidthRoutineFinishedDetail UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticNetworkBandwidthRoutineDetailPtr input);

api::os_diagnostics::CameraFrameAnalysisRoutineFinishedDetail
UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticCameraFrameAnalysisRoutineDetailPtr
        input);

api::os_diagnostics::RoutineFinishedInfo UncheckedConvertPtr(
    crosapi::mojom::TelemetryDiagnosticRoutineStateFinishedPtr input,
    base::Uuid uuid,
    bool has_passed);

}  // namespace unchecked

api::os_diagnostics::ExceptionReason Convert(
    crosapi::mojom::TelemetryExtensionException::Reason input);

api::os_diagnostics::RoutineWaitingReason Convert(
    crosapi::mojom::TelemetryDiagnosticRoutineStateWaiting::Reason input);

api::os_diagnostics::MemtesterTestItemEnum Convert(
    crosapi::mojom::TelemetryDiagnosticMemtesterTestItemEnum input);

api::os_diagnostics::HardwarePresenceStatus Convert(
    crosapi::mojom::TelemetryDiagnosticHardwarePresenceStatus input);

api::os_diagnostics::NetworkBandwidthRoutineRunningType Convert(
    crosapi::mojom::TelemetryDiagnosticNetworkBandwidthRoutineRunningInfo::Type
        input);

api::os_diagnostics::CameraFrameAnalysisIssue Convert(
    crosapi::mojom::TelemetryDiagnosticCameraFrameAnalysisRoutineDetail::Issue
        input);

api::os_diagnostics::CameraSubtestResult Convert(
    crosapi::mojom::TelemetryDiagnosticCameraSubtestResult input);

template <class InputT,
          class OutputT = decltype(Convert(std::declval<InputT>()))>
  requires(std::is_enum_v<InputT> || std::is_integral_v<InputT>)
std::vector<OutputT> ConvertVector(std::vector<InputT> input) {
  std::vector<OutputT> output;
  for (auto elem : input) {
    output.push_back(Convert(std::move(elem)));
  }
  return output;
}

template <class InputT,
          class... Types,
          class OutputT = decltype(unchecked::UncheckedConvertPtr(
              std::declval<InputT>(),
              std::declval<Types>()...))>
  requires(std::is_default_constructible_v<OutputT>)
OutputT ConvertPtr(InputT input, Types... args) {
  return (input) ? unchecked::UncheckedConvertPtr(std::move(input), args...)
                 : OutputT();
}

}  // namespace chromeos::converters::routines

#endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_TELEMETRY_API_ROUTINES_DIAGNOSTIC_ROUTINE_CONVERTERS_H_