host_event_reporter_impl.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 REMOTING_HOST_CHROMEOS_HOST_EVENT_REPORTER_IMPL_H_
  5. #define REMOTING_HOST_CHROMEOS_HOST_EVENT_REPORTER_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/strings/string_piece.h"
  9. #include "chrome/browser/policy/messaging_layer/proto/synced/crd_event.pb.h"
  10. #include "components/reporting/proto/synced/record_constants.pb.h"
  11. #include "remoting/host/host_event_reporter.h"
  12. #include "remoting/host/host_status_monitor.h"
  13. #include "remoting/host/host_status_observer.h"
  14. namespace remoting {
  15. // Remoting host events reporter.
  16. // Configured with the delegate for actual events delivery.
  17. class HostEventReporterImpl : public HostEventReporter,
  18. public HostStatusObserver {
  19. public:
  20. class Delegate {
  21. public:
  22. Delegate();
  23. Delegate(const Delegate& other) = delete;
  24. Delegate& operator=(const Delegate& other) = delete;
  25. virtual ~Delegate();
  26. // API to enqueue event. Must be implemented by subclass.
  27. virtual void EnqueueEvent(::ash::reporting::CRDRecord record) = 0;
  28. };
  29. HostEventReporterImpl(scoped_refptr<HostStatusMonitor> monitor,
  30. std::unique_ptr<Delegate> delegate);
  31. HostEventReporterImpl(const HostEventReporterImpl& other) = delete;
  32. HostEventReporterImpl& operator=(const HostEventReporterImpl& other) = delete;
  33. ~HostEventReporterImpl() override;
  34. // HostStatusObserver implementation. These methods will be called from the
  35. // network thread.
  36. void OnClientAccessDenied(const std::string& signaling_id) override;
  37. void OnClientAuthenticated(const std::string& signaling_id) override;
  38. void OnClientConnected(const std::string& signaling_id) override;
  39. void OnClientDisconnected(const std::string& signaling_id) override;
  40. void OnClientRouteChange(const std::string& signaling_id,
  41. const std::string& channel_name,
  42. const protocol::TransportRoute& route) override;
  43. void OnHostStarted(const std::string& owner_email) override;
  44. void OnHostShutdown() override;
  45. private:
  46. void ReportEvent(::ash::reporting::CRDRecord record);
  47. // Host user email.
  48. // Empty before the first call to ReportStart or after ReportStop.
  49. std::string host_user_;
  50. // Connection state (set piece by piece).
  51. std::string host_ip_;
  52. std::string client_ip_;
  53. std::string session_id_;
  54. // Event enqueueing delegate.
  55. std::unique_ptr<Delegate> delegate_;
  56. // Status monitor to observe.
  57. scoped_refptr<HostStatusMonitor> monitor_;
  58. };
  59. } // namespace remoting
  60. #endif // REMOTING_HOST_CHROMEOS_HOST_EVENT_REPORTER_IMPL_H_