1 // Copyright 2020 The Chromium 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 
5 #ifndef CHROMEOS_COMPONENTS_TELEMETRY_EXTENSION_UI_PROBE_SERVICE_H_
6 #define CHROMEOS_COMPONENTS_TELEMETRY_EXTENSION_UI_PROBE_SERVICE_H_
7 
8 #if defined(OFFICIAL_BUILD)
9 #error Probe service should only be included in unofficial builds.
10 #endif
11 
12 #include <vector>
13 
14 #include "chromeos/components/telemetry_extension_ui/mojom/probe_service.mojom.h"
15 #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
16 #include "mojo/public/cpp/bindings/pending_receiver.h"
17 #include "mojo/public/cpp/bindings/receiver.h"
18 #include "mojo/public/cpp/bindings/remote.h"
19 
20 namespace chromeos {
21 
22 class ProbeService : public health::mojom::ProbeService {
23  public:
24   explicit ProbeService(
25       mojo::PendingReceiver<health::mojom::ProbeService> receiver);
26   ProbeService(const ProbeService&) = delete;
27   ProbeService& operator=(const ProbeService&) = delete;
28   ~ProbeService() override;
29 
30  private:
31   void ProbeTelemetryInfo(
32       const std::vector<health::mojom::ProbeCategoryEnum>& categories,
33       ProbeTelemetryInfoCallback callback) override;
34 
35   // Ensures that |service_| created and connected to the
36   // CrosHealthdProbeService.
37   cros_healthd::mojom::CrosHealthdProbeService* GetService();
38 
39   void OnDisconnect();
40 
41   // Pointer to real implementation.
42   mojo::Remote<cros_healthd::mojom::CrosHealthdProbeService> service_;
43 
44   // We must destroy |receiver_| before destroying |service_|, so we will close
45   // interface pipe before destroying pending response callbacks owned by
46   // |service_|. It is an error to drop response callbacks which still
47   // correspond to an open interface pipe.
48   mojo::Receiver<health::mojom::ProbeService> receiver_;
49 };
50 
51 }  // namespace chromeos
52 
53 #endif  // CHROMEOS_COMPONENTS_TELEMETRY_EXTENSION_UI_PROBE_SERVICE_H_
54