tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PerformanceWorker.cpp (2164B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "PerformanceWorker.h"
      8 
      9 #include "mozilla/StaticPrefs_dom.h"
     10 #include "mozilla/dom/WorkerScope.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 PerformanceWorker::PerformanceWorker(WorkerGlobalScope* aGlobalScope)
     15    : Performance(aGlobalScope) {
     16  MOZ_ASSERT(aGlobalScope);
     17  WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     18  MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
     19  workerPrivate->AssertIsOnWorkerThread();
     20 }
     21 
     22 PerformanceWorker::~PerformanceWorker() {
     23  WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     24  if (workerPrivate) {
     25    workerPrivate->AssertIsOnWorkerThread();
     26  }
     27 }
     28 
     29 void PerformanceWorker::InsertUserEntry(PerformanceEntry* aEntry) {
     30  if (StaticPrefs::dom_performance_enable_user_timing_logging()) {
     31    nsAutoCString uri;
     32    WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     33    MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
     34    nsCOMPtr<nsIURI> scriptURI = workerPrivate->GetResolvedScriptURI();
     35    if (!scriptURI || NS_FAILED(scriptURI->GetHost(uri))) {
     36      // If we have no URI, just put in "none".
     37      uri.AssignLiteral("none");
     38    }
     39    Performance::LogEntry(aEntry, uri);
     40  }
     41  Performance::InsertUserEntry(aEntry);
     42 }
     43 
     44 TimeStamp PerformanceWorker::CreationTimeStamp() const {
     45  WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     46  MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
     47  return workerPrivate->CreationTimeStamp();
     48 }
     49 
     50 DOMHighResTimeStamp PerformanceWorker::CreationTime() const {
     51  WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     52  MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
     53  return workerPrivate->CreationTime();
     54 }
     55 
     56 uint64_t PerformanceWorker::GetRandomTimelineSeed() {
     57  WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     58  MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
     59  return workerPrivate->GetRandomTimelineSeed();
     60 }
     61 
     62 }  // namespace mozilla::dom