service_connector.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef CHROMECAST_BROWSER_SERVICE_CONNECTOR_H_
  5. #define CHROMECAST_BROWSER_SERVICE_CONNECTOR_H_
  6. #include "base/types/id_type.h"
  7. #include "chromecast/common/mojom/service_connector.mojom.h"
  8. #include "mojo/public/cpp/bindings/pending_receiver.h"
  9. #include "mojo/public/cpp/bindings/pending_remote.h"
  10. #include "mojo/public/cpp/bindings/receiver_set.h"
  11. namespace chromecast {
  12. class ServiceConnector;
  13. // An opaque identifier type so that bound ServiceConnector endpoints can reason
  14. // about who's making connection requests.
  15. //
  16. // We don't use an enum because the definition of these IDs is split across
  17. // public and internal sources.
  18. using ServiceConnectorClientId = base::IdType32<ServiceConnector>;
  19. // Something in browser process itself (e.g. CastAudioManager)
  20. extern const ServiceConnectorClientId kBrowserProcessClientId;
  21. // The Media Service hosted by Content.
  22. extern const ServiceConnectorClientId kMediaServiceClientId;
  23. // Browser-side implementation of the ServiceConnector mojom interface to route
  24. // interface binding requests to various Cast-related services on behalf of
  25. // clients both inside and outside of the browser process.
  26. class ServiceConnector : public mojom::ServiceConnector {
  27. public:
  28. ServiceConnector();
  29. ServiceConnector(const ServiceConnector&) = delete;
  30. ServiceConnector& operator=(const ServiceConnector&) = delete;
  31. ~ServiceConnector() override;
  32. // Connects a new pipe to the global ServiceConnector instance and returns its
  33. // PendingRemote. Callable from any thread.
  34. //
  35. // |client_id| indicates the identity of the client that will ultimately use
  36. // the returned ServiceConnector endpoint.
  37. static mojo::PendingRemote<mojom::ServiceConnector> MakeRemote(
  38. ServiceConnectorClientId client_id);
  39. // Binds a receiver to the global ServiceConnector. Callable from any thread.
  40. // |client_id| indicates the identity of the client holding the other end of
  41. // the ServiceConnector pipe.
  42. static void BindReceiver(
  43. ServiceConnectorClientId client_id,
  44. mojo::PendingReceiver<mojom::ServiceConnector> receiver);
  45. // mojom::ServiceConnector implementation:
  46. void Connect(const std::string& service_name,
  47. mojo::GenericPendingReceiver receiver) override;
  48. private:
  49. mojo::ReceiverSet<mojom::ServiceConnector, ServiceConnectorClientId>
  50. receivers_;
  51. };
  52. } // namespace chromecast
  53. #endif // CHROMECAST_BROWSER_SERVICE_CONNECTOR_H_