Files
palemoon27/dom/workers/Performance.cpp
T
roytam1 9e4ed9857d import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1183825 - Hide PushMessageData methods until we support sending push data. r=mt,smaug (c07f6b6c9)
- Bug 1186880 - Performance timing api in workers should output entries if preference is enabled. r=baku (642bd335a)
- Bug 1188091 - Fix the exposure of Push interfaces; r=dougt,bzbarsky,nsm Currently we don't check the dom.push.enabled pref in some cases for some of these interfaces.  This patch unifies how all of these interfaces are exposed to Window, Worker, and ServiceWorker. (dbe4ebfcc)
- Bug 1188062 - Unship Request.context; r=baku (6ca2ebcf6)
- Bug 1162714 - Don't let YCM generate machc. r=ehsan (7c5f36c12)
- Bug 1160897 - Fixing .ycm_extra_conf for Fennec. r=ehsan (22adf0705)
- goanna->gecko (94b69bd6c)
- improve (e87b53162)
- Bug 1147939 - The expression decompiler can't assume that it's called directly from script. (r=bhackett) (4759a5210)
- Bug 1188609 - Remove mirroring support from RokuApp (Toolkit) r=snorp (81a0bb66a)
- Bug 1050749 - Expose BatteryManager via getBattery() returning a Promise. r=bz, r=baku, r=jgraham (67d2dd502)
- Bug 1182347 - Remove nsIPrincipal::cookieJar. r=sicking (855d0e8ce)
- remove double method, probably misspach (3c256c5b4)
- Bug 1182357 - Add an API to mint nsExpandedPrincipals. r=mrbkap (42de17cfd)
- Bug 1172080 - Part 1: Throw when requesting origin for poorly behaved URIs, r=bholley (c8410f3c6)
- Bug 1124126 - Retry database connection for the case of corrupted permissions.sqlite. r=bsmedberg (748e9205a)
2021-12-23 09:44:29 +08:00

96 lines
2.5 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Performance.h"
#include "mozilla/dom/PerformanceBinding.h"
#include "WorkerPrivate.h"
BEGIN_WORKERS_NAMESPACE
Performance::Performance(WorkerPrivate* aWorkerPrivate)
: mWorkerPrivate(aWorkerPrivate)
{
mWorkerPrivate->AssertIsOnWorkerThread();
}
Performance::~Performance()
{
mWorkerPrivate->AssertIsOnWorkerThread();
}
JSObject*
Performance::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return PerformanceBinding_workers::Wrap(aCx, this, aGivenProto);
}
DOMHighResTimeStamp
Performance::Now() const
{
TimeDuration duration =
TimeStamp::Now() - mWorkerPrivate->NowBaseTimeStamp();
double nowTime = duration.ToMilliseconds();
// Round down to the nearest 20us, because if the timer is too accurate people
// can do nasty timing attacks with it. See similar code in the non-worker
// Performance implementation.
const double maxResolutionMs = 0.020;
return floor(nowTime / maxResolutionMs) * maxResolutionMs;
}
// To be removed once bug 1124165 lands
bool
Performance::IsPerformanceTimingAttribute(const nsAString& aName)
{
// In workers we just support navigationStart.
return aName.EqualsASCII("navigationStart");
}
DOMHighResTimeStamp
Performance::GetPerformanceTimingFromString(const nsAString& aProperty)
{
if (!IsPerformanceTimingAttribute(aProperty)) {
return 0;
}
if (aProperty.EqualsLiteral("navigationStart")) {
return mWorkerPrivate->NowBaseTimeHighRes();
}
MOZ_CRASH("IsPerformanceTimingAttribute and GetPerformanceTimingFromString are out of sync");
return 0;
}
void
Performance::InsertUserEntry(PerformanceEntry* aEntry)
{
if (mWorkerPrivate->PerformanceLoggingEnabled()) {
PerformanceBase::LogEntry(aEntry,
NS_ConvertUTF16toUTF8(mWorkerPrivate->ScriptURL()));
}
PerformanceBase::InsertUserEntry(aEntry);
}
DOMHighResTimeStamp
Performance::DeltaFromNavigationStart(DOMHighResTimeStamp aTime)
{
if (aTime == 0) {
return 0;
}
return aTime - mWorkerPrivate->NowBaseTimeHighRes();
}
void
Performance::DispatchBufferFullEvent()
{
// This method is needed just for InsertResourceEntry, but this method is not
// exposed to workers.
MOZ_CRASH("This should not be called.");
}
END_WORKERS_NAMESPACE