quick_pair_process_manager.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2021 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 ASH_SERVICES_QUICK_PAIR_QUICK_PAIR_PROCESS_MANAGER_H_
  5. #define ASH_SERVICES_QUICK_PAIR_QUICK_PAIR_PROCESS_MANAGER_H_
  6. #include <memory>
  7. #include <ostream>
  8. #include "ash/services/quick_pair/public/mojom/fast_pair_data_parser.mojom-forward.h"
  9. #include "ash/services/quick_pair/public/mojom/fast_pair_data_parser.mojom.h"
  10. #include "ash/services/quick_pair/public/mojom/quick_pair_service.mojom-forward.h"
  11. #include "base/callback_forward.h"
  12. #include "mojo/public/cpp/bindings/shared_remote.h"
  13. namespace ash {
  14. namespace quick_pair {
  15. // Manages the life cycle of the Quick Pair utility process, which hosts
  16. // functionality for the Quick Pair system.
  17. class QuickPairProcessManager {
  18. public:
  19. class ProcessReference {
  20. public:
  21. virtual ~ProcessReference() = default;
  22. virtual const mojo::SharedRemote<mojom::FastPairDataParser>&
  23. GetFastPairDataParser() const = 0;
  24. };
  25. enum class ShutdownReason {
  26. kNormal = 0,
  27. kCrash = 1,
  28. kFastPairDataParserMojoPipeDisconnection = 2,
  29. kMaxValue = kFastPairDataParserMojoPipeDisconnection,
  30. };
  31. virtual ~QuickPairProcessManager() = default;
  32. using ProcessStoppedCallback = base::OnceCallback<void(ShutdownReason)>;
  33. // Returns a reference which allows clients to invoke functions implemented by
  34. // the Quick Pair utility process. If at least one reference is
  35. // held, we keep the process alive.
  36. //
  37. // Note that it is possible that the process could crash and shut down
  38. // while a reference is still held; if this occurs,
  39. // |on_process_stopped_callback| will be invoked, and the client should no
  40. // longer use the invalidated reference.
  41. //
  42. // Clients should delete their reference object when they are no
  43. // longer using it; when there are no remaining references
  44. // we shut down the utility process. Note that
  45. // once clients delete the returned reference, they will no
  46. // longer receive a callback once the process has stopped.
  47. virtual std::unique_ptr<ProcessReference> GetProcessReference(
  48. ProcessStoppedCallback on_process_stopped_callback) = 0;
  49. };
  50. std::ostream& operator<<(std::ostream& os,
  51. const QuickPairProcessManager::ShutdownReason& reason);
  52. } // namespace quick_pair
  53. } // namespace ash
  54. #endif // ASH_SERVICES_QUICK_PAIR_QUICK_PAIR_PROCESS_MANAGER_H_