#include "chrome/browser/media/webrtc/webrtc_event_log_manager_remote.h"
#include <iterator>
#include <utility>
#include "base/command_line.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
namespace webrtc_event_logging {
const size_t kMaxRemoteLogFileSizeBytes = …;
const int kDefaultOutputPeriodMs = …;
const int kMaxOutputPeriodMs = …;
namespace {
const base::TimeDelta kDefaultProactivePruningDelta = …;
const base::TimeDelta kDefaultWebRtcRemoteEventLogUploadDelay = …;
const base::TimeDelta kProactiveHistoryFilesPruneDelta = …;
base::TimeDelta GetProactivePendingLogsPruneDelta() { … }
base::TimeDelta GetUploadDelay() { … }
bool TimePointInRange(const base::Time& time_point,
const base::Time& range_begin,
const base::Time& range_end) { … }
bool UploadSupportedUsingConnectionType(
network::mojom::ConnectionType connection) { … }
void CreateHistoryFile(const base::FilePath& log_file_path,
const base::Time& capture_time) { … }
namespace history {
UploadList::UploadInfo CreateActivelyCapturedLogEntry(
const base::FilePath& path,
const base::Time& capture_time) { … }
UploadList::UploadInfo CreatePendingLogEntry(
const WebRtcLogFileInfo& log_info) { … }
UploadList::UploadInfo CreateActivelyUploadedLogEntry(
const WebRtcLogFileInfo& log_info,
const base::Time& upload_time) { … }
UploadList::UploadInfo CreateEntryFromHistoryFileReader(
const WebRtcEventLogHistoryFileReader& reader) { … }
}
}
const size_t kMaxActiveRemoteBoundWebRtcEventLogs = …;
const size_t kMaxPendingRemoteBoundWebRtcEventLogs = …;
static_assert …;
const size_t kMaxWebRtcEventLogHistoryFiles = …;
const base::TimeDelta kRemoteBoundWebRtcEventLogsMaxRetention = …;
const base::TimeDelta kHistoryFileRetention = …;
WebRtcRemoteEventLogManager::WebRtcRemoteEventLogManager(
WebRtcRemoteEventLogsObserver* observer,
scoped_refptr<base::SequencedTaskRunner> task_runner)
: … { … }
WebRtcRemoteEventLogManager::~WebRtcRemoteEventLogManager() { … }
void WebRtcRemoteEventLogManager::SetNetworkConnectionTracker(
network::NetworkConnectionTracker* network_connection_tracker) { … }
void WebRtcRemoteEventLogManager::SetLogFileWriterFactory(
std::unique_ptr<LogFileWriter::Factory> log_file_writer_factory) { … }
void WebRtcRemoteEventLogManager::EnableForBrowserContext(
BrowserContextId browser_context_id,
const base::FilePath& browser_context_dir) { … }
void WebRtcRemoteEventLogManager::DisableForBrowserContext(
BrowserContextId browser_context_id) { … }
bool WebRtcRemoteEventLogManager::OnPeerConnectionAdded(
const PeerConnectionKey& key) { … }
bool WebRtcRemoteEventLogManager::OnPeerConnectionRemoved(
const PeerConnectionKey& key) { … }
bool WebRtcRemoteEventLogManager::OnPeerConnectionSessionIdSet(
const PeerConnectionKey& key,
const std::string& session_id) { … }
bool WebRtcRemoteEventLogManager::StartRemoteLogging(
int render_process_id,
BrowserContextId browser_context_id,
const std::string& session_id,
const base::FilePath& browser_context_dir,
size_t max_file_size_bytes,
int output_period_ms,
size_t web_app_id,
std::string* log_id,
std::string* error_message) { … }
bool WebRtcRemoteEventLogManager::EventLogWrite(const PeerConnectionKey& key,
const std::string& message) { … }
void WebRtcRemoteEventLogManager::ClearCacheForBrowserContext(
BrowserContextId browser_context_id,
const base::Time& delete_begin,
const base::Time& delete_end) { … }
void WebRtcRemoteEventLogManager::GetHistory(
BrowserContextId browser_context_id,
base::OnceCallback<void(const std::vector<UploadList::UploadInfo>&)>
reply) { … }
void WebRtcRemoteEventLogManager::RemovePendingLogsForNotEnabledBrowserContext(
BrowserContextId browser_context_id,
const base::FilePath& browser_context_dir) { … }
void WebRtcRemoteEventLogManager::RenderProcessHostExitedDestroyed(
int render_process_id) { … }
void WebRtcRemoteEventLogManager::OnConnectionChanged(
network::mojom::ConnectionType type) { … }
void WebRtcRemoteEventLogManager::SetWebRtcEventLogUploaderFactoryForTesting(
std::unique_ptr<WebRtcEventLogUploader::Factory> uploader_factory) { … }
void WebRtcRemoteEventLogManager::UploadConditionsHoldForTesting(
base::OnceCallback<void(bool)> callback) { … }
void WebRtcRemoteEventLogManager::ShutDownForTesting(base::OnceClosure reply) { … }
bool WebRtcRemoteEventLogManager::AreLogParametersValid(
size_t max_file_size_bytes,
int output_period_ms,
size_t web_app_id,
std::string* error_message) const { … }
bool WebRtcRemoteEventLogManager::BrowserContextEnabled(
BrowserContextId browser_context_id) const { … }
WebRtcRemoteEventLogManager::LogFilesMap::iterator
WebRtcRemoteEventLogManager::CloseLogFile(LogFilesMap::iterator it,
bool make_pending) { … }
bool WebRtcRemoteEventLogManager::MaybeCreateLogsDirectory(
const base::FilePath& remote_bound_logs_dir) { … }
void WebRtcRemoteEventLogManager::LoadLogsDirectory(
BrowserContextId browser_context_id,
const base::FilePath& remote_bound_logs_dir) { … }
bool WebRtcRemoteEventLogManager::LoadPendingLogInfo(
BrowserContextId browser_context_id,
const base::FilePath& path,
base::Time last_modified) { … }
std::unique_ptr<WebRtcEventLogHistoryFileReader>
WebRtcRemoteEventLogManager::LoadHistoryFile(
BrowserContextId browser_context_id,
const base::FilePath& path,
const base::Time& prune_begin,
const base::Time& prune_end) { … }
std::set<WebRtcEventLogHistoryFileReader>
WebRtcRemoteEventLogManager::PruneAndLoadHistoryFilesForBrowserContext(
const base::Time& prune_begin,
const base::Time& prune_end,
BrowserContextId browser_context_id) { … }
bool WebRtcRemoteEventLogManager::StartWritingLog(
const PeerConnectionKey& key,
const base::FilePath& browser_context_dir,
size_t max_file_size_bytes,
int output_period_ms,
size_t web_app_id,
std::string* log_id_out,
std::string* error_message_out) { … }
void WebRtcRemoteEventLogManager::MaybeStopRemoteLogging(
const PeerConnectionKey& key) { … }
void WebRtcRemoteEventLogManager::PrunePendingLogs(
std::optional<BrowserContextId> browser_context_id) { … }
void WebRtcRemoteEventLogManager::RecurringlyPrunePendingLogs() { … }
void WebRtcRemoteEventLogManager::PruneHistoryFiles() { … }
void WebRtcRemoteEventLogManager::RecurringlyPruneHistoryFiles() { … }
void WebRtcRemoteEventLogManager::MaybeCancelActiveLogs(
const base::Time& delete_begin,
const base::Time& delete_end,
BrowserContextId browser_context_id) { … }
void WebRtcRemoteEventLogManager::MaybeRemovePendingLogs(
const base::Time& delete_begin,
const base::Time& delete_end,
std::optional<BrowserContextId> browser_context_id,
bool is_cache_clear) { … }
void WebRtcRemoteEventLogManager::MaybeRemoveHistoryFiles(
const base::Time& delete_begin,
const base::Time& delete_end,
BrowserContextId browser_context_id) { … }
void WebRtcRemoteEventLogManager::MaybeCancelUpload(
const base::Time& delete_begin,
const base::Time& delete_end,
BrowserContextId browser_context_id) { … }
bool WebRtcRemoteEventLogManager::MatchesFilter(
BrowserContextId log_browser_context_id,
const base::Time& log_last_modification,
std::optional<BrowserContextId> filter_browser_context_id,
const base::Time& filter_range_begin,
const base::Time& filter_range_end) const { … }
bool WebRtcRemoteEventLogManager::AdditionalActiveLogAllowed(
BrowserContextId browser_context_id) const { … }
bool WebRtcRemoteEventLogManager::UploadSuppressed() const { … }
bool WebRtcRemoteEventLogManager::UploadConditionsHold() const { … }
void WebRtcRemoteEventLogManager::ManageUploadSchedule() { … }
void WebRtcRemoteEventLogManager::MaybeStartUploading() { … }
void WebRtcRemoteEventLogManager::OnWebRtcEventLogUploadComplete(
const base::FilePath& log_file,
bool upload_successful) { … }
bool WebRtcRemoteEventLogManager::FindPeerConnection(
int render_process_id,
const std::string& session_id,
PeerConnectionKey* key) const { … }
WebRtcRemoteEventLogManager::PeerConnectionMap::const_iterator
WebRtcRemoteEventLogManager::FindNextPeerConnection(
PeerConnectionMap::const_iterator begin,
int render_process_id,
const std::string& session_id) const { … }
}