1 // Copyright 2019 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_DBUS_CROS_HEALTHD_CROS_HEALTHD_CLIENT_H_
6 #define CHROMEOS_DBUS_CROS_HEALTHD_CROS_HEALTHD_CLIENT_H_
7 
8 #include <memory>
9 
10 #include "base/callback_forward.h"
11 #include "base/component_export.h"
12 #include "base/files/scoped_file.h"
13 #include "base/macros.h"
14 #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
15 #include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h"
16 #include "mojo/public/cpp/bindings/pending_remote.h"
17 #include "mojo/public/cpp/bindings/remote.h"
18 
19 namespace dbus {
20 class Bus;
21 }
22 
23 namespace chromeos {
24 
25 // D-Bus client for the cros_healthd service. Its only purpose is to bootstrap a
26 // Mojo connection to the cros_healthd daemon.
COMPONENT_EXPORT(CROS_HEALTHD)27 class COMPONENT_EXPORT(CROS_HEALTHD) CrosHealthdClient {
28  public:
29   using BootstrapMojoConnectionCallback =
30       base::OnceCallback<void(bool success)>;
31 
32   // Creates and initializes the global instance. |bus| must not be null.
33   static void Initialize(dbus::Bus* bus);
34 
35   // Creates and initializes a fake global instance if not already created.
36   static void InitializeFake();
37 
38   // Destroys the global instance.
39   static void Shutdown();
40 
41   // Returns the global instance which may be null if not initialized.
42   static CrosHealthdClient* Get();
43 
44   // Uses D-Bus to bootstrap the Mojo connection between the cros_healthd daemon
45   // and the browser. Returns a bound remote.
46   virtual mojo::Remote<cros_healthd::mojom::CrosHealthdServiceFactory>
47       BootstrapMojoConnection(BootstrapMojoConnectionCallback) = 0;
48 
49  protected:
50   // Initialize/Shutdown should be used instead.
51   CrosHealthdClient();
52   virtual ~CrosHealthdClient();
53 
54  private:
55   DISALLOW_COPY_AND_ASSIGN(CrosHealthdClient);
56 };
57 
58 }  // namespace chromeos
59 
60 #endif  // CHROMEOS_DBUS_CROS_HEALTHD_CROS_HEALTHD_CLIENT_H_
61