diff --git a/api/rtc_event_log/rtc_event_log_factory.cc b/api/rtc_event_log/rtc_event_log_factory.cc index 30fc6f126f..bfe272d2a8 100644 --- a/api/rtc_event_log/rtc_event_log_factory.cc +++ b/api/rtc_event_log/rtc_event_log_factory.cc @@ -31,12 +31,7 @@ absl::Nonnull> RtcEventLogFactory::Create( if (env.field_trials().IsEnabled("WebRTC-RtcEventLogKillSwitch")) { return std::make_unique(); } - RtcEventLog::EncodingType encoding_type = - env.field_trials().IsDisabled("WebRTC-RtcEventLogNewFormat") - ? RtcEventLog::EncodingType::Legacy - : RtcEventLog::EncodingType::NewFormat; - return std::make_unique( - RtcEventLogImpl::CreateEncoder(encoding_type), &env.task_queue_factory()); + return std::make_unique(env); #endif } diff --git a/logging/BUILD.gn b/logging/BUILD.gn index 92f55edfa0..b1fb5404e9 100644 --- a/logging/BUILD.gn +++ b/logging/BUILD.gn @@ -450,8 +450,10 @@ if (rtc_enable_protobuf) { ":ice_log", ":rtc_event_log_api", ":rtc_event_log_impl_encoder", + "../api:field_trials_view", "../api:libjingle_logging_api", "../api:sequence_checker", + "../api/environment", "../api/rtc_event_log", "../api/task_queue", "../api/units:time_delta", diff --git a/logging/rtc_event_log/rtc_event_log_impl.cc b/logging/rtc_event_log/rtc_event_log_impl.cc index f2b3f22d6a..77af6966de 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/logging/rtc_event_log/rtc_event_log_impl.cc @@ -17,6 +17,8 @@ #include #include "absl/strings/string_view.h" +#include "api/environment/environment.h" +#include "api/field_trials_view.h" #include "api/task_queue/task_queue_base.h" #include "api/units/time_delta.h" #include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h" @@ -29,24 +31,23 @@ #include "rtc_base/time_utils.h" namespace webrtc { +namespace { -std::unique_ptr RtcEventLogImpl::CreateEncoder( - RtcEventLog::EncodingType type) { - switch (type) { - case RtcEventLog::EncodingType::Legacy: - RTC_DLOG(LS_INFO) << "Creating legacy encoder for RTC event log."; - return std::make_unique(); - case RtcEventLog::EncodingType::NewFormat: - RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log."; - return std::make_unique(); - default: - RTC_LOG(LS_ERROR) << "Unknown RtcEventLog encoder type (" << int(type) - << ")"; - RTC_DCHECK_NOTREACHED(); - return std::unique_ptr(nullptr); +std::unique_ptr CreateEncoder(const Environment& env) { + if (env.field_trials().IsDisabled("WebRTC-RtcEventLogNewFormat")) { + RTC_DLOG(LS_INFO) << "Creating legacy encoder for RTC event log."; + return std::make_unique(); + } else { + RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log."; + return std::make_unique(); } } +} // namespace + +RtcEventLogImpl::RtcEventLogImpl(const Environment& env) + : RtcEventLogImpl(CreateEncoder(env), &env.task_queue_factory()) {} + RtcEventLogImpl::RtcEventLogImpl(std::unique_ptr encoder, TaskQueueFactory* task_queue_factory, size_t max_events_in_history, diff --git a/logging/rtc_event_log/rtc_event_log_impl.h b/logging/rtc_event_log/rtc_event_log_impl.h index 3187a7fe87..69ed204da4 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.h +++ b/logging/rtc_event_log/rtc_event_log_impl.h @@ -18,6 +18,7 @@ #include #include "absl/strings/string_view.h" +#include "api/environment/environment.h" #include "api/rtc_event_log/rtc_event.h" #include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log_output.h" @@ -39,6 +40,7 @@ class RtcEventLogImpl final : public RtcEventLog { // bound to prevent an attack via unreasonable memory use. static constexpr size_t kMaxEventsInConfigHistory = 1000; + explicit RtcEventLogImpl(const Environment& env); RtcEventLogImpl( std::unique_ptr encoder, TaskQueueFactory* task_queue_factory, @@ -49,9 +51,6 @@ class RtcEventLogImpl final : public RtcEventLog { ~RtcEventLogImpl() override; - static std::unique_ptr CreateEncoder( - EncodingType encoding_type); - // TODO(eladalon): We should change these name to reflect that what we're // actually starting/stopping is the output of the log, not the log itself. bool StartLogging(std::unique_ptr output,