Commit 56f14a19 authored by Elad Alon's avatar Elad Alon Committed by Commit Bot

Clear pending WebRTC remote-bound logs if policy disabled at start

When a profile is loaded for the first time, if the policy
controlling remote-bound WebRTC event logs is disabled, clear
any pending logs from previous times the profile was loaded, when
the policy might have been enabled.

Bug: 775415
Change-Id: If20928ba660f0be5a73c52a11ae521c5246c174a
Reviewed-on: https://chromium-review.googlesource.com/1162322
Commit-Queue: Elad Alon <eladalon@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582869}
parent e6540481
......@@ -130,8 +130,6 @@ WebRtcEventLogManager::~WebRtcEventLogManager() {
g_webrtc_event_log_manager = nullptr;
}
// TODO(crbug.com/775415): If a BrowserContext had the policy as active in
// the past, but no longer does, purge pending log files from before.
void WebRtcEventLogManager::EnableForBrowserContext(
BrowserContext* browser_context,
base::OnceClosure reply) {
......@@ -147,7 +145,18 @@ void WebRtcEventLogManager::EnableForBrowserContext(
StartListeningForPrefChangeForBrowserContext(browser_context);
if (!IsRemoteLoggingAllowedForBrowserContext(browser_context)) {
MaybeReply(FROM_HERE, std::move(reply));
// If remote-bound logging was enabled during a previous Chrome session,
// it might have produced some pending log files, which we will now
// wish to remove.
// |this| is destroyed by ~BrowserProcessImpl(), so base::Unretained(this)
// will not be dereferenced after destruction.
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&WebRtcEventLogManager::
RemovePendingRemoteBoundLogsForNotEnabledBrowserContext,
base::Unretained(this), GetBrowserContextId(browser_context),
browser_context->GetPath(), std::move(reply)));
return;
}
......@@ -674,6 +683,19 @@ void WebRtcEventLogManager::DisableRemoteBoundLoggingForBrowserContext(
MaybeReply(FROM_HERE, std::move(reply));
}
void WebRtcEventLogManager::
RemovePendingRemoteBoundLogsForNotEnabledBrowserContext(
BrowserContextId browser_context_id,
const base::FilePath& browser_context_dir,
base::OnceClosure reply) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
remote_logs_manager_.RemovePendingLogsForNotEnabledBrowserContext(
browser_context_id, browser_context_dir);
MaybeReply(FROM_HERE, std::move(reply));
}
void WebRtcEventLogManager::PeerConnectionAddedInternal(
PeerConnectionKey key,
const std::string& peer_connection_id,
......
......@@ -229,6 +229,11 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver,
BrowserContextId browser_context_id,
base::OnceClosure reply);
void RemovePendingRemoteBoundLogsForNotEnabledBrowserContext(
BrowserContextId browser_context_id,
const base::FilePath& browser_context_dir,
base::OnceClosure reply);
void PeerConnectionAddedInternal(PeerConnectionKey key,
const std::string& peer_connection_id,
base::OnceCallback<void(bool)> reply);
......
......@@ -402,6 +402,18 @@ void WebRtcRemoteEventLogManager::ClearCacheForBrowserContext(
MaybeCancelUpload(delete_begin, delete_end, browser_context_id);
}
void WebRtcRemoteEventLogManager::RemovePendingLogsForNotEnabledBrowserContext(
BrowserContextId browser_context_id,
const base::FilePath& browser_context_dir) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK(!BrowserContextEnabled(browser_context_id));
const base::FilePath remote_bound_logs_dir =
GetRemoteBoundWebRtcEventLogsDir(browser_context_dir);
if (!base::DeleteFile(remote_bound_logs_dir, /*recursive=*/true)) {
LOG(ERROR) << "Failed to delete `" << remote_bound_logs_dir << ".";
}
}
void WebRtcRemoteEventLogManager::RenderProcessHostExitedDestroyed(
int render_process_id) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
......
......@@ -139,6 +139,13 @@ class WebRtcRemoteEventLogManager final
const base::Time& delete_begin,
const base::Time& delete_end);
// Works on not-enabled BrowserContext-s, which means the logs are never made
// eligible for upload. Useful when a BrowserContext is loaded which in
// the past had remote-logging enabled, but no longer does.
void RemovePendingLogsForNotEnabledBrowserContext(
BrowserContextId browser_context_id,
const base::FilePath& browser_context_dir);
// An implicit PeerConnectionRemoved() on all of the peer connections that
// were associated with the renderer process.
void RenderProcessHostExitedDestroyed(int render_process_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment