machine_learning_client.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2018 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. #ifndef CHROMEOS_DBUS_MACHINE_LEARNING_MACHINE_LEARNING_CLIENT_H_
  5. #define CHROMEOS_DBUS_MACHINE_LEARNING_MACHINE_LEARNING_CLIENT_H_
  6. #include "base/callback_forward.h"
  7. #include "base/component_export.h"
  8. #include "base/files/scoped_file.h"
  9. namespace dbus {
  10. class Bus;
  11. }
  12. namespace chromeos {
  13. // D-Bus client for ML service. Its only purpose is to bootstrap a Mojo
  14. // connection to the ML service daemon.
  15. class COMPONENT_EXPORT(MACHINE_LEARNING) MachineLearningClient {
  16. public:
  17. MachineLearningClient(const MachineLearningClient&) = delete;
  18. MachineLearningClient& operator=(const MachineLearningClient&) = delete;
  19. // Creates and initializes the global instance. |bus| must not be null.
  20. static void Initialize(dbus::Bus* bus);
  21. // Creates and initializes a fake global instance if not already created.
  22. static void InitializeFake();
  23. // Destroys the global instance.
  24. static void Shutdown();
  25. // Returns the global instance which may be null if not initialized.
  26. static MachineLearningClient* Get();
  27. // Passes the file descriptor |fd| over D-Bus to the ML service daemon.
  28. // * The daemon expects a Mojo invitation in |fd| with an attached Mojo pipe.
  29. // * The daemon will bind the Mojo pipe to an implementation of
  30. // chromeos::machine_learning::mojom::MachineLearningService.
  31. // * Upon completion of the D-Bus call, |result_callback| will be invoked to
  32. // indicate success or failure.
  33. // * This method will first wait for the ML service to become available.
  34. virtual void BootstrapMojoConnection(
  35. base::ScopedFD fd,
  36. base::OnceCallback<void(bool success)> result_callback) = 0;
  37. protected:
  38. // Initialize/Shutdown should be used instead.
  39. MachineLearningClient();
  40. virtual ~MachineLearningClient();
  41. };
  42. } // namespace chromeos
  43. // TODO(https://crbug.com/1164001): remove when it moved to ash
  44. namespace ash {
  45. using ::chromeos::MachineLearningClient;
  46. } // namespace ash
  47. #endif // CHROMEOS_DBUS_MACHINE_LEARNING_MACHINE_LEARNING_CLIENT_H_