Commit 012ba293 authored by Elad Alon's avatar Elad Alon Committed by Commit Bot

Clear WebRTC event logs from disk along with cache

* When Chrome's cache is cleared, remove pending WebRTC event logs
  as well.
* Logs which are currently being written to are not cleared; this
  is by design.
* Logs which are currently being uploaded are also not cleared.
  It is debatable whether they should be. Erring on the side of
  caution is probably more user-friendly here; a TODO is left for
  a later CL to clear those logs as well.

Bug: 775415
Change-Id: Icf13c363ff7d04e082ed0ccf52e000b5bdbf75a4
Reviewed-on: https://chromium-review.googlesource.com/966562
Commit-Queue: Elad Alon <eladalon@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarTommi <tommi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548388}
parent a49026ac
...@@ -125,6 +125,7 @@ ...@@ -125,6 +125,7 @@
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if BUILDFLAG(ENABLE_WEBRTC) #if BUILDFLAG(ENABLE_WEBRTC)
#include "chrome/browser/media/webrtc/webrtc_event_log_manager.h"
#include "components/webrtc_logging/browser/log_cleanup.h" #include "components/webrtc_logging/browser/log_cleanup.h"
#include "components/webrtc_logging/browser/log_list.h" #include "components/webrtc_logging/browser/log_list.h"
#endif // BUILDFLAG(ENABLE_WEBRTC) #endif // BUILDFLAG(ENABLE_WEBRTC)
...@@ -983,6 +984,18 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( ...@@ -983,6 +984,18 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
CreatePendingTaskCompletionClosure()))); CreatePendingTaskCompletionClosure())));
} }
#endif #endif
#if BUILDFLAG(ENABLE_WEBRTC)
// TODO(crbug.com/829321): Remove null-check.
auto* webrtc_event_log_manager = WebRtcEventLogManager::GetInstance();
if (webrtc_event_log_manager) {
webrtc_event_log_manager->ClearCacheForBrowserContext(
profile_, delete_begin_, delete_end_,
CreatePendingTaskCompletionClosure());
} else {
LOG(ERROR) << "WebRtcEventLogManager not instantiated.";
}
#endif
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
......
...@@ -311,6 +311,23 @@ void WebRtcEventLogManager::StartRemoteLogging( ...@@ -311,6 +311,23 @@ void WebRtcEventLogManager::StartRemoteLogging(
std::move(reply))); std::move(reply)));
} }
void WebRtcEventLogManager::ClearCacheForBrowserContext(
const BrowserContext* browser_context,
const base::Time& delete_begin,
const base::Time& delete_end,
base::OnceClosure reply) {
const auto browser_context_id = GetBrowserContextId(browser_context);
DCHECK_NE(browser_context_id, kNullBrowserContextId);
// The object outlives the task queue - base::Unretained(this) is safe.
task_runner_->PostTaskAndReply(
FROM_HERE,
base::BindOnce(
&WebRtcEventLogManager::ClearCacheForBrowserContextInternal,
base::Unretained(this), browser_context_id, delete_begin, delete_end),
std::move(reply));
}
void WebRtcEventLogManager::SetLocalLogsObserver( void WebRtcEventLogManager::SetLocalLogsObserver(
WebRtcLocalEventLogsObserver* observer, WebRtcLocalEventLogsObserver* observer,
base::OnceClosure reply) { base::OnceClosure reply) {
...@@ -581,6 +598,18 @@ void WebRtcEventLogManager::StartRemoteLoggingInternal( ...@@ -581,6 +598,18 @@ void WebRtcEventLogManager::StartRemoteLoggingInternal(
} }
} }
void WebRtcEventLogManager::ClearCacheForBrowserContextInternal(
BrowserContextId browser_context_id,
const base::Time& delete_begin,
const base::Time& delete_end) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
if (remote_logs_manager_) {
remote_logs_manager_->ClearCacheForBrowserContext(browser_context_id,
delete_begin, delete_end);
}
}
void WebRtcEventLogManager::RenderProcessExitedInternal(int render_process_id) { void WebRtcEventLogManager::RenderProcessExitedInternal(int render_process_id) {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
local_logs_manager_.RenderProcessHostExitedDestroyed(render_process_id); local_logs_manager_.RenderProcessHostExitedDestroyed(render_process_id);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/time/clock.h" #include "base/time/clock.h"
#include "base/time/time.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h" #include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager_local.h" #include "chrome/browser/media/webrtc/webrtc_event_log_manager_local.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager_remote.h" #include "chrome/browser/media/webrtc/webrtc_event_log_manager_remote.h"
...@@ -144,6 +145,16 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver, ...@@ -144,6 +145,16 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver,
const std::string& metadata = "", const std::string& metadata = "",
base::OnceCallback<void(bool)> reply = base::OnceCallback<void(bool)>()); base::OnceCallback<void(bool)> reply = base::OnceCallback<void(bool)>());
// Clear WebRTC event logs associated with a given browser context, in a given
// time range (|delete_begin| inclusive, |delete_end| exclusive), then
// post |reply| back to the thread from which the method was originally
// invoked (which can be any thread).
void ClearCacheForBrowserContext(
const content::BrowserContext* browser_context,
const base::Time& delete_begin,
const base::Time& delete_end,
base::OnceClosure reply);
// Set (or unset) an observer that will be informed whenever a local log file // Set (or unset) an observer that will be informed whenever a local log file
// is started/stopped. The observer needs to be able to either run from // is started/stopped. The observer needs to be able to either run from
// anywhere. If you need the code to run on specific runners or queues, have // anywhere. If you need the code to run on specific runners or queues, have
...@@ -165,6 +176,7 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver, ...@@ -165,6 +176,7 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver,
base::OnceClosure reply = base::OnceClosure()); base::OnceClosure reply = base::OnceClosure());
private: private:
friend class SigninManagerAndroidTest; // Calls *ForTesting() methods.
friend class WebRtcEventLogManagerTestBase; // Calls *ForTesting() methods. friend class WebRtcEventLogManagerTestBase; // Calls *ForTesting() methods.
using PeerConnectionKey = WebRtcEventLogPeerConnectionKey; using PeerConnectionKey = WebRtcEventLogPeerConnectionKey;
...@@ -235,6 +247,10 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver, ...@@ -235,6 +247,10 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver,
const std::string& metadata, const std::string& metadata,
base::OnceCallback<void(bool)> reply); base::OnceCallback<void(bool)> reply);
void ClearCacheForBrowserContextInternal(BrowserContextId browser_context_id,
const base::Time& delete_begin,
const base::Time& delete_end);
void RenderProcessExitedInternal(int render_process_id); void RenderProcessExitedInternal(int render_process_id);
void SetLocalLogsObserverInternal(WebRtcLocalEventLogsObserver* observer, void SetLocalLogsObserverInternal(WebRtcLocalEventLogsObserver* observer,
......
...@@ -238,6 +238,14 @@ bool WebRtcRemoteEventLogManager::EventLogWrite(const PeerConnectionKey& key, ...@@ -238,6 +238,14 @@ bool WebRtcRemoteEventLogManager::EventLogWrite(const PeerConnectionKey& key,
return WriteToLogFile(it, message); return WriteToLogFile(it, message);
} }
void WebRtcRemoteEventLogManager::ClearCacheForBrowserContext(
BrowserContextId browser_context_id,
const base::Time& delete_begin,
const base::Time& delete_end) {
DCHECK_CALLED_ON_VALID_SEQUENCE(io_task_sequence_checker_);
RemovePendingLogs(delete_begin, delete_end, browser_context_id);
}
void WebRtcRemoteEventLogManager::RenderProcessHostExitedDestroyed( void WebRtcRemoteEventLogManager::RenderProcessHostExitedDestroyed(
int render_process_id) { int render_process_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(io_task_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(io_task_sequence_checker_);
...@@ -472,15 +480,29 @@ void WebRtcRemoteEventLogManager::MaybeStopRemoteLogging( ...@@ -472,15 +480,29 @@ void WebRtcRemoteEventLogManager::MaybeStopRemoteLogging(
void WebRtcRemoteEventLogManager::PrunePendingLogs() { void WebRtcRemoteEventLogManager::PrunePendingLogs() {
DCHECK_CALLED_ON_VALID_SEQUENCE(io_task_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(io_task_sequence_checker_);
const base::Time oldest_non_expired_timestamp = RemovePendingLogs(
base::Time::Now() - kRemoteBoundWebRtcEventLogsMaxRetention; base::Time::Min(),
base::Time::Now() - kRemoteBoundWebRtcEventLogsMaxRetention);
}
void WebRtcRemoteEventLogManager::RemovePendingLogs(
const base::Time& delete_begin,
const base::Time& delete_end,
base::Optional<BrowserContextId> browser_context_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(io_task_sequence_checker_);
for (auto it = pending_logs_.begin(); it != pending_logs_.end();) { for (auto it = pending_logs_.begin(); it != pending_logs_.end();) {
if (it->last_modified < oldest_non_expired_timestamp) { const bool relevant_browser_content =
!browser_context_id || it->browser_context_id == browser_context_id;
if (relevant_browser_content &&
(delete_begin.is_null() || delete_begin <= it->last_modified) &&
(delete_end.is_null() || it->last_modified < delete_end)) {
DVLOG(1) << "Removing " << it->path << ".";
if (!base::DeleteFile(it->path, /*recursive=*/false)) { if (!base::DeleteFile(it->path, /*recursive=*/false)) {
LOG(ERROR) << "Failed to delete " << it->path << "."; LOG(ERROR) << "Failed to delete " << it->path << ".";
} }
it = pending_logs_.erase(it); it = pending_logs_.erase(it);
} else { } else {
DVLOG(1) << "Keeping " << it->path << " on disk.";
++it; ++it;
} }
} }
......
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include "base/optional.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h" #include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_uploader.h" #include "chrome/browser/media/webrtc/webrtc_event_log_uploader.h"
// TODO(eladalon): Prevent uploading of logs when Chrome shutdown imminent. // TODO(crbug.com/775415): Avoid uploading logs when Chrome shutdown imminent.
// https://crbug.com/775415
class WebRtcRemoteEventLogManager final class WebRtcRemoteEventLogManager final
: public LogFileWriter, : public LogFileWriter,
...@@ -79,6 +79,16 @@ class WebRtcRemoteEventLogManager final ...@@ -79,6 +79,16 @@ class WebRtcRemoteEventLogManager final
// an active log. // an active log.
bool EventLogWrite(const PeerConnectionKey& key, const std::string& message); bool EventLogWrite(const PeerConnectionKey& key, const std::string& message);
// Clear PENDING WebRTC event logs associated with a given browser context,
// in a given time range, then post |reply| back to the thread from which
// the method was originally invoked (which can be any thread).
// Log files currently being written are not interrupted.
// Active uploads are not interrupted.
// TODO(crbug.com/775415): Allow interrupting active uploads.
void ClearCacheForBrowserContext(BrowserContextId browser_context_id,
const base::Time& delete_begin,
const base::Time& delete_end);
// An implicit PeerConnectionRemoved() on all of the peer connections that // An implicit PeerConnectionRemoved() on all of the peer connections that
// were associated with the renderer process. // were associated with the renderer process.
void RenderProcessHostExitedDestroyed(int render_process_id); void RenderProcessHostExitedDestroyed(int render_process_id);
...@@ -178,6 +188,17 @@ class WebRtcRemoteEventLogManager final ...@@ -178,6 +188,17 @@ class WebRtcRemoteEventLogManager final
// this check is not too expensive. // this check is not too expensive.
void PrunePendingLogs(); void PrunePendingLogs();
// Removes pending logs whose last modification date was between at or later
// than |delete_begin|, and earlier than |delete_end|.
// If a null time-point is given as either |delete_begin| or |delete_begin|,
// it is treated as "beginning-of-time" or "end-of-time", respectively.
// If |browser_context_id| is set, only logs associated with it are considered
// for removal; otherwise, all logs are considered.
void RemovePendingLogs(const base::Time& delete_begin,
const base::Time& delete_end,
base::Optional<BrowserContextId> browser_context_id =
base::Optional<BrowserContextId>());
// Return |true| if and only if we can start another active log (with respect // Return |true| if and only if we can start another active log (with respect
// to limitations on the numbers active and pending logs). // to limitations on the numbers active and pending logs).
bool AdditionalActiveLogAllowed(BrowserContextId browser_context_id) const; bool AdditionalActiveLogAllowed(BrowserContextId browser_context_id) const;
...@@ -185,11 +206,11 @@ class WebRtcRemoteEventLogManager final ...@@ -185,11 +206,11 @@ class WebRtcRemoteEventLogManager final
// Initiating a new upload is only allowed when there are no active peer // Initiating a new upload is only allowed when there are no active peer
// connection which might be adversely affected by the bandwidth consumption // connection which might be adversely affected by the bandwidth consumption
// of the upload. // of the upload.
// This can be overridden by a command line flag - see // This can be overridden by a command line flag - see
// kWebRtcRemoteEventLogUploadNoSuppression. // kWebRtcRemoteEventLogUploadNoSuppression.
// TODO(eladalon): Add support for pausing/resuming an upload when peer // TODO(crbug.com/775415): Add support for pausing/resuming an upload when
// connections are added/removed after an upload was already initiated. // peer connections are added/removed after an upload was already initiated.
// https://crbug.com/775415
bool UploadingAllowed() const; bool UploadingAllowed() const;
// If no upload is in progress, and if uploading is currently permissible, // If no upload is in progress, and if uploading is currently permissible,
......
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