#ifndef REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_
#define REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_
#include <memory>
#include <string>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "remoting/base/chromoting_event.h"
#include "remoting/base/chromoting_event_log_writer.h"
#include "remoting/base/url_request.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/performance_tracker.h"
#include "remoting/protocol/transport.h"
namespace remoting {
class ClientTelemetryLogger {
public:
ClientTelemetryLogger(ChromotingEventLogWriter* log_writer,
ChromotingEvent::Mode mode,
ChromotingEvent::SessionEntryPoint entry_point);
ClientTelemetryLogger(const ClientTelemetryLogger&) = delete;
ClientTelemetryLogger& operator=(const ClientTelemetryLogger&) = delete;
~ClientTelemetryLogger();
void SetAuthMethod(ChromotingEvent::AuthMethod auth_method);
void SetHostInfo(const std::string& host_version,
ChromotingEvent::Os host_os,
const std::string& host_os_version);
void SetSignalStrategyType(ChromotingEvent::SignalStrategyType type);
void SetTransportRoute(const protocol::TransportRoute& route);
void LogSessionStateChange(ChromotingEvent::SessionState state,
ChromotingEvent::ConnectionError error);
void LogStatistics(const protocol::PerformanceTracker& perf_tracker);
const std::string& session_id() const { return session_id_; }
void SetSessionIdGenerationTimeForTest(base::TimeTicks gen_time);
const ChromotingEvent& current_session_state_event() const {
return current_session_state_event_;
}
static ChromotingEvent::SessionState TranslateState(
protocol::ConnectionToHost::State current_state,
protocol::ConnectionToHost::State previous_state);
static ChromotingEvent::ConnectionError TranslateError(
protocol::ErrorCode state);
static ChromotingEvent::ConnectionType TranslateConnectionType(
protocol::TransportRoute::RouteType type);
private:
struct HostInfo;
void FillEventContext(ChromotingEvent* event) const;
void GenerateSessionId();
void PrintLogStatistics(const protocol::PerformanceTracker& perf_tracker);
void RefreshSessionIdIfOutdated();
ChromotingEvent MakeStatsEvent(
const protocol::PerformanceTracker& perf_tracker);
ChromotingEvent MakeSessionStateChangeEvent(
ChromotingEvent::SessionState state,
ChromotingEvent::ConnectionError error);
ChromotingEvent MakeSessionIdOldEvent();
ChromotingEvent MakeSessionIdNewEvent();
std::string session_id_;
base::TimeTicks session_start_time_;
base::TimeTicks session_id_generation_time_;
ChromotingEvent current_session_state_event_;
ChromotingEvent::AuthMethod auth_method_ =
ChromotingEvent::AuthMethod::NOT_SET;
ChromotingEvent::Mode mode_;
ChromotingEvent::SessionEntryPoint entry_point_;
ChromotingEvent::SignalStrategyType signal_strategy_type_ =
ChromotingEvent::SignalStrategyType::NOT_SET;
std::unique_ptr<HostInfo> host_info_;
std::unique_ptr<protocol::TransportRoute> transport_route_;
raw_ptr<ChromotingEventLogWriter> log_writer_;
base::ThreadChecker thread_checker_;
};
}
#endif