Bug 1221786: clear about:webrtc logs for private browsing sessions. r=jib

No WebRTC session statistics will be saved until all PeerConnections
in private browsing window end. In addition, the shared
WebRTC ICE signalling log for that e10s process is disabled until the
private session close.
This commit is contained in:
Paul Kerr [:pkerr] 2016-01-26 08:08:25 -08:00
parent 227a29a044
commit 3d9ecccf0b
5 changed files with 80 additions and 5 deletions

View File

@ -388,7 +388,6 @@ RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
// Initialize the crypto callbacks and logging stuff
if (!initialized) {
NR_reg_init(NR_REG_MODE_LOCAL);
RLogRingBuffer::CreateInstance();
nr_crypto_vtbl = &nr_ice_crypto_nss_vtbl;
initialized = true;

View File

@ -21,6 +21,7 @@
extern "C" {
#include <csi_platform.h>
#include "r_log.h"
#include "registry.h"
}
/* Matches r_dest_vlog type defined in r_log.h */
@ -44,7 +45,8 @@ RLogRingBuffer* RLogRingBuffer::instance;
RLogRingBuffer::RLogRingBuffer()
: log_limit_(4096),
mutex_("RLogRingBuffer::mutex_") {
mutex_("RLogRingBuffer::mutex_"),
disableCount_(0) {
}
RLogRingBuffer::~RLogRingBuffer() {
@ -58,7 +60,13 @@ void RLogRingBuffer::SetLogLimit(uint32_t new_limit) {
void RLogRingBuffer::Log(std::string&& log) {
OffTheBooksMutexAutoLock lock(mutex_);
log_messages_.push_front(Move(log));
if (disableCount_ == 0) {
AddMsg(Move(log));
}
}
void RLogRingBuffer::AddMsg(std::string&& msg) {
log_messages_.push_front(Move(msg));
RemoveOld();
}
@ -68,10 +76,10 @@ inline void RLogRingBuffer::RemoveOld() {
}
}
RLogRingBuffer* RLogRingBuffer::CreateInstance() {
if (!instance) {
instance = new RLogRingBuffer;
NR_reg_init(NR_REG_MODE_LOCAL);
r_log_set_extra_destination(LOG_INFO, &ringbuffer_vlog);
}
return instance;
@ -88,6 +96,30 @@ void RLogRingBuffer::DestroyInstance() {
instance = nullptr;
}
// As long as at least one PeerConnection exists in a Private Window rlog messages will not
// be saved in the RLogRingBuffer. This is necessary because the log_messages buffer
// is shared across all instances of PeerConnectionImpls. There is no way with the current
// structure of r_log to run separate logs.
void RLogRingBuffer::EnterPrivateMode() {
OffTheBooksMutexAutoLock lock(mutex_);
++disableCount_;
MOZ_ASSERT(disableCount_ != 0);
if (disableCount_ == 1) {
AddMsg("LOGGING SUSPENDED: a connection is active in a Private Window ***");
}
}
void RLogRingBuffer::ExitPrivateMode() {
OffTheBooksMutexAutoLock lock(mutex_);
MOZ_ASSERT(disableCount_ != 0);
if (--disableCount_ == 0) {
AddMsg("LOGGING RESUMED: no connections are active in a Private Window ***");
}
}
void RLogRingBuffer::Clear() {
OffTheBooksMutexAutoLock lock(mutex_);
log_messages_.clear();

View File

@ -98,10 +98,16 @@ class RLogRingBuffer {
void Log(std::string&& log);
void Clear();
// Methods to signal when a PeerConnection exists in a Private Window.
void EnterPrivateMode();
void ExitPrivateMode();
private:
RLogRingBuffer();
~RLogRingBuffer();
void RemoveOld();
void AddMsg(std::string&& msg);
static RLogRingBuffer* instance;
/*
@ -113,6 +119,7 @@ class RLogRingBuffer {
/* Max size of log buffer (should we use time-depth instead/also?) */
uint32_t log_limit_;
OffTheBooksMutex mutex_;
uint32_t disableCount_;
DISALLOW_COPY_ASSIGN(RLogRingBuffer);
}; // class RLogRingBuffer

View File

@ -375,6 +375,24 @@ bool PCUuidGenerator::Generate(std::string* idp) {
return true;
}
bool IsPrivateBrowsing(nsPIDOMWindow* aWindow)
{
#if defined(MOZILLA_EXTERNAL_LINKAGE)
return false;
#else
if (!aWindow) {
return false;
}
nsIDocument *doc = aWindow->GetExtantDoc();
if (!doc) {
return false;
}
nsILoadContext *loadContext = doc->GetLoadContext();
return loadContext && loadContext->UsePrivateBrowsing();
#endif
}
PeerConnectionImpl::PeerConnectionImpl(const GlobalObject* aGlobal)
: mTimeCard(MOZ_LOG_TEST(signalingLogInfo(),LogLevel::Error) ?
@ -403,11 +421,17 @@ PeerConnectionImpl::PeerConnectionImpl(const GlobalObject* aGlobal)
, mAddCandidateErrorCount(0)
, mTrickle(true) // TODO(ekr@rtfm.com): Use pref
, mNegotiationNeeded(false)
, mPrivateWindow(false)
{
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
MOZ_ASSERT(NS_IsMainThread());
auto log = RLogRingBuffer::CreateInstance();
if (aGlobal) {
mWindow = do_QueryInterface(aGlobal->GetAsSupports());
if (IsPrivateBrowsing(mWindow)) {
mPrivateWindow = true;
log->EnterPrivateMode();
}
}
#endif
CSFLogInfo(logTag, "%s: PeerConnectionImpl constructor for %s",
@ -433,6 +457,15 @@ PeerConnectionImpl::~PeerConnectionImpl()
}
// This aborts if not on main thread (in Debug builds)
PC_AUTO_ENTER_API_CALL_NO_CHECK();
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
if (mPrivateWindow) {
auto * log = RLogRingBuffer::GetInstance();
if (log) {
log->ExitPrivateMode();
}
mPrivateWindow = false;
}
#endif
if (PeerConnectionCtx::isActive()) {
PeerConnectionCtx::GetInstance()->mPeerConnections.erase(mHandle);
} else {
@ -2667,7 +2700,9 @@ PeerConnectionImpl::CloseInt()
// for all trickle ICE candidates to come in; this can happen well after we've
// transitioned to connected. As a bonus, this allows us to detect race
// conditions where a stats dispatch happens right as the PC closes.
RecordLongtermICEStatistics();
if (!mPrivateWindow) {
RecordLongtermICEStatistics();
}
RecordEndOfCallTelemetry();
CSFLogInfo(logTag, "%s: Closing PeerConnectionImpl %s; "
"ending call", __FUNCTION__, mHandle.c_str());

View File

@ -833,6 +833,8 @@ private:
bool mNegotiationNeeded;
bool mPrivateWindow;
// storage for Telemetry data
uint16_t mMaxReceiving[SdpMediaSection::kMediaTypes];
uint16_t mMaxSending[SdpMediaSection::kMediaTypes];