receiver_setup_querier.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2020 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 COMPONENTS_MIRRORING_SERVICE_RECEIVER_SETUP_QUERIER_H_
  5. #define COMPONENTS_MIRRORING_SERVICE_RECEIVER_SETUP_QUERIER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/component_export.h"
  9. #include "base/containers/circular_deque.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/timer/timer.h"
  12. #include "components/mirroring/mojom/session_observer.mojom.h"
  13. #include "mojo/public/cpp/bindings/pending_remote.h"
  14. #include "mojo/public/cpp/bindings/remote.h"
  15. #include "net/base/ip_address.h"
  16. #include "services/network/public/mojom/url_loader_factory.mojom.h"
  17. namespace network {
  18. class SimpleURLLoader;
  19. }
  20. namespace mirroring {
  21. // The ReceiverSetupQuerier sends a message to the receiver in order to gather
  22. // its setup information, especially build version and the receiver's friendly
  23. // name. This can be used to apply model-specific mirroring tuning.
  24. class COMPONENT_EXPORT(MIRRORING_SERVICE) ReceiverSetupQuerier {
  25. public:
  26. ReceiverSetupQuerier(
  27. const net::IPAddress& address,
  28. mojo::PendingRemote<network::mojom::URLLoaderFactory> loader_factory);
  29. ReceiverSetupQuerier(const ReceiverSetupQuerier&) = delete;
  30. ReceiverSetupQuerier(ReceiverSetupQuerier&&) = delete;
  31. ReceiverSetupQuerier& operator=(const ReceiverSetupQuerier&) = delete;
  32. ReceiverSetupQuerier& operator=(ReceiverSetupQuerier&&) = delete;
  33. ~ReceiverSetupQuerier();
  34. // The build version of the receiver.
  35. const std::string& build_version() const { return build_version_; }
  36. // The friendly name (human readable) of the receiver.
  37. const std::string& friendly_name() const { return friendly_name_; }
  38. private:
  39. // Query the receiver for its current setup and uptime.
  40. void Query();
  41. // Callback for the url loader response to populate the query results.
  42. void ProcessResponse(std::unique_ptr<network::SimpleURLLoader> loader,
  43. std::unique_ptr<std::string> response);
  44. const net::IPAddress address_;
  45. std::string build_version_;
  46. std::string friendly_name_;
  47. mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_;
  48. base::WeakPtrFactory<ReceiverSetupQuerier> weak_factory_{this};
  49. };
  50. } // namespace mirroring
  51. #endif // COMPONENTS_MIRRORING_SERVICE_RECEIVER_SETUP_QUERIER_H_