multi_capture_service_client.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2022 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_MULTI_CAPTURE_MULTI_CAPTURE_SERVICE_CLIENT_H_
  5. #define ASH_MULTI_CAPTURE_MULTI_CAPTURE_SERVICE_CLIENT_H_
  6. #include <string>
  7. #include "base/observer_list.h"
  8. #include "base/observer_list_types.h"
  9. #include "mojo/public/cpp/bindings/receiver.h"
  10. #include "mojo/public/cpp/bindings/remote.h"
  11. #include "services/video_capture/public/mojom/multi_capture_service.mojom.h"
  12. #include "url/origin.h"
  13. namespace ash {
  14. // Client of the MultiCaptureService mojo interface. Receives events about
  15. // multi captures being started / stopped and forwards it to ash clients to
  16. // show usage indicators.
  17. class MultiCaptureServiceClient
  18. : public video_capture::mojom::MultiCaptureServiceClient {
  19. public:
  20. class Observer : public base::CheckedObserver {
  21. public:
  22. // Event to inform about a started multi capture. The label is a unique
  23. // identifier that can be used to connect started / stopped events.
  24. // The origin is the capturer's origin.
  25. // TODO(crbug.com/1325750): Consider transferred tracks by either adding
  26. // a MultiCaptureTransferred event or by making sure the label remains
  27. // constant throughout the lifetime of the capture.
  28. virtual void MultiCaptureStarted(const std::string& label,
  29. const url::Origin& origin) = 0;
  30. virtual void MultiCaptureStopped(const std::string& label) = 0;
  31. protected:
  32. ~Observer() override = default;
  33. };
  34. explicit MultiCaptureServiceClient(
  35. mojo::PendingRemote<video_capture::mojom::MultiCaptureService>
  36. multi_capture_service);
  37. ~MultiCaptureServiceClient() override;
  38. MultiCaptureServiceClient(const MultiCaptureServiceClient&) = delete;
  39. MultiCaptureServiceClient& operator=(const MultiCaptureServiceClient&) =
  40. delete;
  41. void AddObserver(Observer* observer);
  42. void RemoveObserver(Observer* observer);
  43. // video_capture::mojom::MultiCaptureService:
  44. void MultiCaptureStarted(const std::string& label,
  45. const url::Origin& origin) override;
  46. void MultiCaptureStopped(const std::string& label) override;
  47. private:
  48. mojo::Remote<video_capture::mojom::MultiCaptureService>
  49. multi_capture_service_;
  50. mojo::Receiver<video_capture::mojom::MultiCaptureServiceClient>
  51. multi_capture_service_observer_receiver_{this};
  52. base::ObserverList<Observer> observers_;
  53. };
  54. } // namespace ash
  55. #endif // ASH_VIDEO_CAPTURE_MULTI_CAPTURE_SERVICE_CLIENT_H_