From f910267fcfe9b12ec5e857f84329e84722db6164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Fri, 17 May 2024 14:03:21 +0000 Subject: [PATCH] Bug 1842682 - Remove unused ChromeUtils.requestIOActivity and IOActivityMonitor, r=necko-reviewers,valentin. Differential Revision: https://phabricator.services.mozilla.com/D210680 --- dom/base/ChromeUtils.cpp | 17 - dom/base/ChromeUtils.h | 3 - dom/chrome-webidl/ChromeUtils.webidl | 18 - dom/tests/browser/dummy.html | 3 - modules/libpref/init/all.js | 3 - netwerk/base/IOActivityMonitor.cpp | 495 ------------------ netwerk/base/IOActivityMonitor.h | 83 --- netwerk/base/moz.build | 2 - netwerk/base/nsFileStreams.cpp | 21 +- netwerk/base/nsPISocketTransportService.idl | 12 - netwerk/base/nsSocketTransport2.cpp | 4 - netwerk/base/nsSocketTransportService2.cpp | 12 - netwerk/base/nsUDPSocket.cpp | 4 - netwerk/test/browser/browser.toml | 4 - .../test/browser/browser_test_io_activity.js | 50 -- netwerk/test/browser/ioactivity.html | 11 - storage/BaseVFS.cpp | 26 +- tools/@types/lib.gecko.dom.d.ts | 7 - 18 files changed, 3 insertions(+), 772 deletions(-) delete mode 100644 netwerk/base/IOActivityMonitor.cpp delete mode 100644 netwerk/base/IOActivityMonitor.h delete mode 100644 netwerk/test/browser/browser_test_io_activity.js delete mode 100644 netwerk/test/browser/ioactivity.html diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index a64cffabf836..d412679e64c3 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -57,7 +57,6 @@ #include "mozilla/RemoteDecoderManagerChild.h" #include "mozilla/KeySystemConfig.h" #include "mozilla/WheelHandlingHelper.h" -#include "IOActivityMonitor.h" #include "nsNativeTheme.h" #include "nsThreadUtils.h" #include "mozJSModuleLoader.h" @@ -1851,22 +1850,6 @@ void ChromeUtils::CreateError(const GlobalObject& aGlobal, aRetVal.set(retVal); } -/* static */ -already_AddRefed ChromeUtils::RequestIOActivity(GlobalObject& aGlobal, - ErrorResult& aRv) { - MOZ_ASSERT(XRE_IsParentProcess()); - MOZ_ASSERT(Preferences::GetBool(IO_ACTIVITY_ENABLED_PREF, false)); - nsCOMPtr global = do_QueryInterface(aGlobal.GetAsSupports()); - MOZ_ASSERT(global); - RefPtr domPromise = Promise::Create(global, aRv); - if (NS_WARN_IF(aRv.Failed())) { - return nullptr; - } - MOZ_ASSERT(domPromise); - mozilla::net::IOActivityMonitor::RequestActivities(domPromise); - return domPromise.forget(); -} - /* static */ bool ChromeUtils::HasReportingHeaderForOrigin(GlobalObject& global, const nsAString& aOrigin, diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h index 4c2d043ecb74..707a04b1d398 100644 --- a/dom/base/ChromeUtils.h +++ b/dom/base/ChromeUtils.h @@ -240,9 +240,6 @@ class ChromeUtils { JS::MutableHandle aRetVal, ErrorResult& aRv); - static already_AddRefed RequestIOActivity(GlobalObject& aGlobal, - ErrorResult& aRv); - static bool HasReportingHeaderForOrigin(GlobalObject& global, const nsAString& aOrigin, ErrorResult& aRv); diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl index e1a4c3bedf79..22f6f1efb5b0 100644 --- a/dom/chrome-webidl/ChromeUtils.webidl +++ b/dom/chrome-webidl/ChromeUtils.webidl @@ -617,12 +617,6 @@ partial namespace ChromeUtils { [NewObject] Promise collectPerfStats(); - /** - * Returns a Promise containing a sequence of I/O activities - */ - [NewObject] - Promise> requestIOActivity(); - /** * Returns a Promise containing all processes info */ @@ -927,18 +921,6 @@ dictionary ParentProcInfoDictionary { WebIDLProcType type = "browser"; }; -/** - * Used by requestIOActivity() to return the number of bytes - * that were read (rx) and/or written (tx) for a given location. - * - * Locations can be sockets or files. - */ -dictionary IOActivityDataDictionary { - ByteString location = ""; - unsigned long long rx = 0; - unsigned long long tx = 0; -}; - /** * Used by principals and the script security manager to represent origin * attributes. The first dictionary is designed to contain the full set of diff --git a/dom/tests/browser/dummy.html b/dom/tests/browser/dummy.html index 6ec72c216048..4bb00a1d4b08 100644 --- a/dom/tests/browser/dummy.html +++ b/dom/tests/browser/dummy.html @@ -6,8 +6,5 @@

Dummy test page

- diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 33ea5420d2dd..ef439f784133 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -3267,9 +3267,6 @@ pref("memory.dump_reports_on_oom", false); // Number of stack frames to capture in createObjectURL for about:memory. pref("memory.blob_report.stack_frames", 0); -// Activates the activity monitor -pref("io.activity.enabled", false); - // path to OSVR DLLs pref("gfx.vr.osvr.utilLibPath", ""); pref("gfx.vr.osvr.commonLibPath", ""); diff --git a/netwerk/base/IOActivityMonitor.cpp b/netwerk/base/IOActivityMonitor.cpp deleted file mode 100644 index 76047a7a0094..000000000000 --- a/netwerk/base/IOActivityMonitor.cpp +++ /dev/null @@ -1,495 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * 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 "IOActivityMonitor.h" -#include "nsPrintfCString.h" -#include "nsSocketTransport2.h" -#include "nsSocketTransportService2.h" -#include "nsThreadUtils.h" -#include "mozilla/Atomics.h" -#include "mozilla/ClearOnShutdown.h" -#include "mozilla/dom/Promise.h" -#include "prerror.h" -#include "prio.h" -#include "prmem.h" -#include - -using namespace mozilla; -using namespace mozilla::net; - -mozilla::StaticRefPtr gInstance; -static Atomic gActivated(false); -static PRDescIdentity sNetActivityMonitorLayerIdentity; -static PRIOMethods sNetActivityMonitorLayerMethods; -static PRIOMethods* sNetActivityMonitorLayerMethodsPtr = nullptr; - -// Maximum number of activities entries in the monitoring class -#define MAX_ACTIVITY_ENTRIES 1000 - -// ActivityMonitorSecret is stored in the activity monitor layer -// and provides a method to get the location. -// -// A location can be : -// - a TCP or UDP socket. The form will be socket://ip:port -// - a File. The form will be file://path -// -// For other cases, the location will be fd://number -class ActivityMonitorSecret final { - public: - // constructor used for sockets - explicit ActivityMonitorSecret(PRFileDesc* aFd) { - mFd = aFd; - mLocationSet = false; - } - - // constructor used for files - explicit ActivityMonitorSecret(PRFileDesc* aFd, const char* aLocation) { - mFd = aFd; - mLocation.AppendPrintf("file://%s", aLocation); - mLocationSet = true; - } - - nsCString getLocation() { - if (!mLocationSet) { - LazySetLocation(); - } - return mLocation; - } - - private: - // Called to set the location using the FD on the first getLocation() usage - // which is typically when a socket is opened. If done earlier, at - // construction time, the host won't be bound yet. - // - // If the location is a file, it needs to be initialized in the - // constructor. - void LazySetLocation() { - mLocationSet = true; - PRFileDesc* extract = mFd; - while (PR_GetDescType(extract) == PR_DESC_LAYERED) { - if (!extract->lower) { - break; - } - extract = extract->lower; - } - - PRDescType fdType = PR_GetDescType(extract); - // we should not use LazySetLocation for files - MOZ_ASSERT(fdType != PR_DESC_FILE); - - switch (fdType) { - case PR_DESC_SOCKET_TCP: - case PR_DESC_SOCKET_UDP: { - mLocation.AppendPrintf("socket://"); - PRNetAddr addr; - PRStatus status = PR_GetSockName(mFd, &addr); - if (NS_WARN_IF(status == PR_FAILURE)) { - mLocation.AppendPrintf("unknown"); - break; - } - - // grabbing the host - char netAddr[mozilla::net::kNetAddrMaxCStrBufSize] = {0}; - status = PR_NetAddrToString(&addr, netAddr, sizeof(netAddr) - 1); - if (NS_WARN_IF(status == PR_FAILURE) || netAddr[0] == 0) { - mLocation.AppendPrintf("unknown"); - break; - } - mLocation.Append(netAddr); - - // adding the port - uint16_t port; - if (addr.raw.family == PR_AF_INET) { - port = addr.inet.port; - } else { - port = addr.ipv6.port; - } - mLocation.AppendPrintf(":%d", port); - } break; - - // for all other cases, we just send back fd:// - default: { - mLocation.AppendLiteral("fd://"); - mLocation.AppendInt(PR_FileDesc2NativeHandle(mFd)); - } - } // end switch - } - - private: - nsCString mLocation; - bool mLocationSet; - PRFileDesc* mFd; -}; - -// FileDesc2Location converts a PRFileDesc into a "location" by -// grabbing the ActivityMonitorSecret in layer->secret -static nsAutoCString FileDesc2Location(PRFileDesc* fd) { - nsAutoCString location; - PRFileDesc* monitorLayer = - PR_GetIdentitiesLayer(fd, sNetActivityMonitorLayerIdentity); - if (!monitorLayer) { - location.AppendPrintf("unknown"); - return location; - } - - ActivityMonitorSecret* secret = (ActivityMonitorSecret*)monitorLayer->secret; - location.AppendPrintf("%s", secret->getLocation().get()); - return location; -} - -// -// Wrappers around the socket APIS -// -static PRStatus nsNetMon_Connect(PRFileDesc* fd, const PRNetAddr* addr, - PRIntervalTime timeout) { - return fd->lower->methods->connect(fd->lower, addr, timeout); -} - -static PRStatus nsNetMon_Close(PRFileDesc* fd) { - if (!fd) { - return PR_FAILURE; - } - PRFileDesc* layer = PR_PopIOLayer(fd, PR_TOP_IO_LAYER); - MOZ_RELEASE_ASSERT( - layer && layer->identity == sNetActivityMonitorLayerIdentity, - "NetActivityMonitor Layer not on top of stack"); - - if (layer->secret) { - delete (ActivityMonitorSecret*)layer->secret; - layer->secret = nullptr; - } - layer->dtor(layer); - return fd->methods->close(fd); -} - -static int32_t nsNetMon_Read(PRFileDesc* fd, void* buf, int32_t len) { - int32_t ret = fd->lower->methods->read(fd->lower, buf, len); - if (ret >= 0) { - IOActivityMonitor::Read(fd, len); - } - return ret; -} - -static int32_t nsNetMon_Write(PRFileDesc* fd, const void* buf, int32_t len) { - int32_t ret = fd->lower->methods->write(fd->lower, buf, len); - if (ret > 0) { - IOActivityMonitor::Write(fd, len); - } - return ret; -} - -static int32_t nsNetMon_Writev(PRFileDesc* fd, const PRIOVec* iov, int32_t size, - PRIntervalTime timeout) { - int32_t ret = fd->lower->methods->writev(fd->lower, iov, size, timeout); - if (ret > 0) { - IOActivityMonitor::Write(fd, size); - } - return ret; -} - -static int32_t nsNetMon_Recv(PRFileDesc* fd, void* buf, int32_t amount, - int flags, PRIntervalTime timeout) { - int32_t ret = - fd->lower->methods->recv(fd->lower, buf, amount, flags, timeout); - if (ret > 0) { - IOActivityMonitor::Read(fd, amount); - } - return ret; -} - -static int32_t nsNetMon_Send(PRFileDesc* fd, const void* buf, int32_t amount, - int flags, PRIntervalTime timeout) { - int32_t ret = - fd->lower->methods->send(fd->lower, buf, amount, flags, timeout); - if (ret > 0) { - IOActivityMonitor::Write(fd, amount); - } - return ret; -} - -static int32_t nsNetMon_RecvFrom(PRFileDesc* fd, void* buf, int32_t amount, - int flags, PRNetAddr* addr, - PRIntervalTime timeout) { - int32_t ret = fd->lower->methods->recvfrom(fd->lower, buf, amount, flags, - addr, timeout); - if (ret > 0) { - IOActivityMonitor::Read(fd, amount); - } - return ret; -} - -static int32_t nsNetMon_SendTo(PRFileDesc* fd, const void* buf, int32_t amount, - int flags, const PRNetAddr* addr, - PRIntervalTime timeout) { - int32_t ret = - fd->lower->methods->sendto(fd->lower, buf, amount, flags, addr, timeout); - if (ret > 0) { - IOActivityMonitor::Write(fd, amount); - } - return ret; -} - -static int32_t nsNetMon_AcceptRead(PRFileDesc* listenSock, - PRFileDesc** acceptedSock, - PRNetAddr** peerAddr, void* buf, - int32_t amount, PRIntervalTime timeout) { - int32_t ret = listenSock->lower->methods->acceptread( - listenSock->lower, acceptedSock, peerAddr, buf, amount, timeout); - if (ret > 0) { - IOActivityMonitor::Read(listenSock, amount); - } - return ret; -} - -// -// Class IOActivityMonitor -// -NS_IMPL_ISUPPORTS(IOActivityMonitor, nsINamed) - -IOActivityMonitor::IOActivityMonitor() : mLock("IOActivityMonitor::mLock") { - RefPtr mon(gInstance); - MOZ_ASSERT(!mon, "multiple IOActivityMonitor instances!"); -} - -// static -void IOActivityMonitor::RequestActivities(dom::Promise* aPromise) { - MOZ_ASSERT(aPromise); - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - aPromise->MaybeReject(NS_ERROR_FAILURE); - return; - } - - mon->RequestActivitiesInternal(aPromise); -} - -void IOActivityMonitor::RequestActivitiesInternal(dom::Promise* aPromise) { - nsresult result = NS_OK; - FallibleTArray activities; - - { - mozilla::MutexAutoLock lock(mLock); - // Remove inactive activities - for (auto iter = mActivities.Iter(); !iter.Done(); iter.Next()) { - dom::IOActivityDataDictionary* activity = &iter.Data(); - if (activity->mRx == 0 && activity->mTx == 0) { - iter.Remove(); - } else { - if (NS_WARN_IF(!activities.AppendElement(iter.Data(), fallible))) { - result = NS_ERROR_OUT_OF_MEMORY; - break; - } - } - } - } - - if (NS_WARN_IF(NS_FAILED(result))) { - aPromise->MaybeReject(result); - return; - } - aPromise->MaybeResolve(activities); -} - -NS_IMETHODIMP -IOActivityMonitor::GetName(nsACString& aName) { - aName.AssignLiteral("IOActivityMonitor"); - return NS_OK; -} - -// static -bool IOActivityMonitor::IsActive() { return gActivated; } - -// static -already_AddRefed IOActivityMonitor::Get() { - if (!gActivated) { - return nullptr; - } - - RefPtr mon = gInstance; - return mon.forget(); -} - -nsresult IOActivityMonitor::Init() { - if (IsActive()) { - return NS_ERROR_ALREADY_INITIALIZED; - } - RefPtr mon = new IOActivityMonitor(); - nsresult rv = mon->InitInternal(); - if (NS_SUCCEEDED(rv)) { - gInstance = mon; - ClearOnShutdown(&gInstance); - gActivated = true; - } - return rv; -} - -nsresult IOActivityMonitor::InitInternal() { - // wraps the socket APIs - if (!sNetActivityMonitorLayerMethodsPtr) { - sNetActivityMonitorLayerIdentity = - PR_GetUniqueIdentity("network activity monitor layer"); - sNetActivityMonitorLayerMethods = *PR_GetDefaultIOMethods(); - sNetActivityMonitorLayerMethods.connect = nsNetMon_Connect; - sNetActivityMonitorLayerMethods.read = nsNetMon_Read; - sNetActivityMonitorLayerMethods.write = nsNetMon_Write; - sNetActivityMonitorLayerMethods.writev = nsNetMon_Writev; - sNetActivityMonitorLayerMethods.recv = nsNetMon_Recv; - sNetActivityMonitorLayerMethods.send = nsNetMon_Send; - sNetActivityMonitorLayerMethods.recvfrom = nsNetMon_RecvFrom; - sNetActivityMonitorLayerMethods.sendto = nsNetMon_SendTo; - sNetActivityMonitorLayerMethods.acceptread = nsNetMon_AcceptRead; - sNetActivityMonitorLayerMethods.close = nsNetMon_Close; - sNetActivityMonitorLayerMethodsPtr = &sNetActivityMonitorLayerMethods; - } - - return NS_OK; -} - -nsresult IOActivityMonitor::Shutdown() { - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - return NS_ERROR_NOT_INITIALIZED; - } - return mon->ShutdownInternal(); -} - -nsresult IOActivityMonitor::ShutdownInternal() { - mozilla::MutexAutoLock lock(mLock); - mActivities.Clear(); - gActivated = false; - return NS_OK; -} - -nsresult IOActivityMonitor::MonitorSocket(PRFileDesc* aFd) { - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - return NS_OK; - } - PRFileDesc* layer; - PRStatus status; - layer = PR_CreateIOLayerStub(sNetActivityMonitorLayerIdentity, - sNetActivityMonitorLayerMethodsPtr); - if (!layer) { - return NS_ERROR_FAILURE; - } - - ActivityMonitorSecret* secret = new ActivityMonitorSecret(aFd); - layer->secret = reinterpret_cast(secret); - status = PR_PushIOLayer(aFd, PR_NSPR_IO_LAYER, layer); - - if (status == PR_FAILURE) { - delete secret; - PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc(). - return NS_ERROR_FAILURE; - } - return NS_OK; -} - -nsresult IOActivityMonitor::MonitorFile(PRFileDesc* aFd, const char* aPath) { - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - return NS_OK; - } - PRFileDesc* layer; - PRStatus status; - layer = PR_CreateIOLayerStub(sNetActivityMonitorLayerIdentity, - sNetActivityMonitorLayerMethodsPtr); - if (!layer) { - return NS_ERROR_FAILURE; - } - - ActivityMonitorSecret* secret = new ActivityMonitorSecret(aFd, aPath); - layer->secret = reinterpret_cast(secret); - - status = PR_PushIOLayer(aFd, PR_NSPR_IO_LAYER, layer); - if (status == PR_FAILURE) { - delete secret; - PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc(). - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -bool IOActivityMonitor::IncrementActivity(const nsACString& aLocation, - uint32_t aRx, uint32_t aTx) { - mLock.AssertCurrentThreadOwns(); - return mActivities.WithEntryHandle(aLocation, fallible, [&](auto&& entry) { - if (!entry) return false; - - if (*entry) { - // already registered - entry->Data().mTx += aTx; - entry->Data().mRx += aRx; - } else { - // Creating a new IOActivity. Notice that mActivities - // will grow indefinitely, which is OK since we won't - // have but a few hundreds entries at the most, but we - // want to assert we have at the most 1000 entries - MOZ_ASSERT(mActivities.Count() <= MAX_ACTIVITY_ENTRIES); - - dom::IOActivityDataDictionary activity; - activity.mLocation.Assign(aLocation); - activity.mTx = aTx; - activity.mRx = aRx; - - entry->Insert(std::move(activity)); - } - - return true; - }); -} - -nsresult IOActivityMonitor::Write(const nsACString& aLocation, - uint32_t aAmount) { - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - return NS_ERROR_FAILURE; - } - return mon->WriteInternal(aLocation, aAmount); -} - -nsresult IOActivityMonitor::Write(PRFileDesc* fd, uint32_t aAmount) { - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - return NS_ERROR_FAILURE; - } - return mon->Write(FileDesc2Location(fd), aAmount); -} - -nsresult IOActivityMonitor::WriteInternal(const nsACString& aLocation, - uint32_t aAmount) { - mozilla::MutexAutoLock lock(mLock); - if (!IncrementActivity(aLocation, aAmount, 0)) { - return NS_ERROR_FAILURE; - } - return NS_OK; -} - -nsresult IOActivityMonitor::Read(PRFileDesc* fd, uint32_t aAmount) { - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - return NS_ERROR_FAILURE; - } - return mon->Read(FileDesc2Location(fd), aAmount); -} - -nsresult IOActivityMonitor::Read(const nsACString& aLocation, - uint32_t aAmount) { - RefPtr mon = IOActivityMonitor::Get(); - if (!mon) { - return NS_ERROR_FAILURE; - } - return mon->ReadInternal(aLocation, aAmount); -} - -nsresult IOActivityMonitor::ReadInternal(const nsACString& aLocation, - uint32_t aAmount) { - mozilla::MutexAutoLock lock(mLock); - if (!IncrementActivity(aLocation, 0, aAmount)) { - return NS_ERROR_FAILURE; - } - return NS_OK; -} diff --git a/netwerk/base/IOActivityMonitor.h b/netwerk/base/IOActivityMonitor.h deleted file mode 100644 index 5e46bc9bfcb5..000000000000 --- a/netwerk/base/IOActivityMonitor.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * 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/. */ - -#ifndef IOActivityMonitor_h___ -#define IOActivityMonitor_h___ - -#include "mozilla/dom/ChromeUtilsBinding.h" -#include "mozilla/Mutex.h" -#include "nsCOMPtr.h" -#include "nscore.h" -#include "nsClassHashtable.h" -#include "nsTHashMap.h" -#include "nsHashKeys.h" -#include "nsINamed.h" -#include "nsISupports.h" -#include "prinrval.h" -#include "prio.h" -#include "private/pprio.h" -#include - -namespace mozilla { - -namespace dom { -class Promise; -} - -namespace net { - -#define IO_ACTIVITY_ENABLED_PREF "io.activity.enabled" - -using Activities = nsTHashMap; - -// IOActivityMonitor has several roles: -// - maintains an IOActivity per resource and updates it -// - sends a dump of the activities to a promise via RequestActivities -class IOActivityMonitor final : public nsINamed { - public: - IOActivityMonitor(); - - NS_DECL_THREADSAFE_ISUPPORTS - NS_DECL_NSINAMED - - // initializes and destroys the singleton - static nsresult Init(); - static nsresult Shutdown(); - - // collect amounts of data that are written/read by location - static nsresult Read(const nsACString& location, uint32_t aAmount); - static nsresult Write(const nsACString& location, uint32_t aAmount); - - static nsresult MonitorFile(PRFileDesc* aFd, const char* aPath); - static nsresult MonitorSocket(PRFileDesc* aFd); - static nsresult Read(PRFileDesc* fd, uint32_t aAmount); - static nsresult Write(PRFileDesc* fd, uint32_t aAmount); - - static bool IsActive(); - static void RequestActivities(dom::Promise* aPromise); - - private: - ~IOActivityMonitor() = default; - - static already_AddRefed Get(); - - nsresult InitInternal(); - nsresult ShutdownInternal(); - bool IncrementActivity(const nsACString& location, uint32_t aRx, - uint32_t aTx); - nsresult WriteInternal(const nsACString& location, uint32_t aAmount); - nsresult ReadInternal(const nsACString& location, uint32_t aAmount); - void RequestActivitiesInternal(dom::Promise* aPromise); - - Activities mActivities; - // protects mActivities accesses - Mutex mLock MOZ_UNANNOTATED; -}; - -} // namespace net -} // namespace mozilla - -#endif /* IOActivityMonitor_h___ */ diff --git a/netwerk/base/moz.build b/netwerk/base/moz.build index adeac62cd8ec..ebd056cec09a 100644 --- a/netwerk/base/moz.build +++ b/netwerk/base/moz.build @@ -163,7 +163,6 @@ EXPORTS.mozilla.net += [ "DashboardTypes.h", "DefaultURI.h", "InterceptionInfo.h", - "IOActivityMonitor.h", "MemoryDownloader.h", "NetworkConnectivityService.h", "Predictor.h", @@ -185,7 +184,6 @@ UNIFIED_SOURCES += [ "DefaultURI.cpp", "EventTokenBucket.cpp", "InterceptionInfo.cpp", - "IOActivityMonitor.cpp", "LoadContextInfo.cpp", "LoadInfo.cpp", "MemoryDownloader.cpp", diff --git a/netwerk/base/nsFileStreams.cpp b/netwerk/base/nsFileStreams.cpp index 32281f6d02e0..161a251afea9 100644 --- a/netwerk/base/nsFileStreams.cpp +++ b/netwerk/base/nsFileStreams.cpp @@ -15,27 +15,23 @@ #endif #include "private/pprio.h" -#include "prerror.h" -#include "IOActivityMonitor.h" #include "nsFileStreams.h" #include "nsIFile.h" #include "nsReadLine.h" #include "nsIClassInfoImpl.h" -#include "nsLiteralString.h" -#include "nsSocketTransport2.h" // for ErrorAccordingToNSPR() #include "mozilla/ipc/InputStreamUtils.h" #include "mozilla/ipc/RandomAccessStreamParams.h" #include "mozilla/Unused.h" #include "mozilla/FileUtils.h" #include "mozilla/UniquePtr.h" #include "nsNetCID.h" +#include "nsNetUtil.h" #include "nsXULAppAPI.h" using FileHandleType = mozilla::ipc::FileDescriptor::PlatformHandleType; using namespace mozilla::ipc; -using namespace mozilla::net; using mozilla::DebugOnly; using mozilla::Maybe; @@ -359,21 +355,6 @@ nsresult nsFileStreamBase::DoOpen() { mOpenParams.perm, &fd); } - if (rv == NS_OK && IOActivityMonitor::IsActive()) { - auto nativePath = mOpenParams.localFile->NativePath(); - if (!nativePath.IsEmpty()) { -// registering the file to the activity monitor -#ifdef XP_WIN - // 16 bits unicode - IOActivityMonitor::MonitorFile( - fd, NS_ConvertUTF16toUTF8(nativePath.get()).get()); -#else - // 8 bit unicode - IOActivityMonitor::MonitorFile(fd, nativePath.get()); -#endif - } - } - CleanUpOpen(); if (NS_FAILED(rv)) { diff --git a/netwerk/base/nsPISocketTransportService.idl b/netwerk/base/nsPISocketTransportService.idl index 8ea8d7ba55a6..a69149157dec 100644 --- a/netwerk/base/nsPISocketTransportService.idl +++ b/netwerk/base/nsPISocketTransportService.idl @@ -45,15 +45,3 @@ interface nsPISocketTransportService : nsIRoutedSocketTransportService */ readonly attribute long keepaliveProbeCount; }; - -%{C++ -/* - * I/O activity observer topic. Sends out information about the - * amount of data we're sending/receiving via sockets and disk files. - * - * Activated via the "io.activity.enabled" preference. - */ -#define NS_IO_ACTIVITY "io-activity" - - -%} diff --git a/netwerk/base/nsSocketTransport2.cpp b/netwerk/base/nsSocketTransport2.cpp index e12a37678884..89912169b211 100644 --- a/netwerk/base/nsSocketTransport2.cpp +++ b/netwerk/base/nsSocketTransport2.cpp @@ -8,7 +8,6 @@ #include "nsSocketTransport2.h" -#include "IOActivityMonitor.h" #include "NSSErrorsService.h" #include "NetworkDataCountLayer.h" #include "QuicSocketControl.h" @@ -1344,9 +1343,6 @@ nsresult nsSocketTransport::InitiateSocket() { return rv; } - // create proxy via IOActivityMonitor - IOActivityMonitor::MonitorSocket(fd); - #ifdef FUZZING if (StaticPrefs::fuzzing_necko_enabled()) { rv = AttachFuzzyIOLayer(fd); diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index a6aa24946520..59ecbe835e60 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -5,7 +5,6 @@ #include "nsSocketTransportService2.h" -#include "IOActivityMonitor.h" #include "mozilla/Atomics.h" #include "mozilla/ChaosMode.h" #include "mozilla/IntegerPrintfMacros.h" @@ -784,7 +783,6 @@ nsSocketTransportService::Init() { // socket process. We have to make sure the topics registered below are also // registered in nsIObserver::Init(). if (obsSvc) { - obsSvc->AddObserver(this, "profile-initial-state", false); obsSvc->AddObserver(this, "last-pb-context-exited", false); obsSvc->AddObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC, true); obsSvc->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true); @@ -860,7 +858,6 @@ nsresult nsSocketTransportService::ShutdownThread() { nsCOMPtr obsSvc = services::GetObserverService(); if (obsSvc) { - obsSvc->RemoveObserver(this, "profile-initial-state"); obsSvc->RemoveObserver(this, "last-pb-context-exited"); obsSvc->RemoveObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC); obsSvc->RemoveObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC); @@ -873,8 +870,6 @@ nsresult nsSocketTransportService::ShutdownThread() { mAfterWakeUpTimer = nullptr; } - IOActivityMonitor::Shutdown(); - mInitialized = false; mShuttingDown = false; @@ -1612,13 +1607,6 @@ nsSocketTransportService::Observe(nsISupports* subject, const char* topic, const char16_t* data) { SOCKET_LOG(("nsSocketTransportService::Observe topic=%s", topic)); - if (!strcmp(topic, "profile-initial-state")) { - if (!Preferences::GetBool(IO_ACTIVITY_ENABLED_PREF, false)) { - return NS_OK; - } - return net::IOActivityMonitor::Init(); - } - if (!strcmp(topic, "last-pb-context-exited")) { nsCOMPtr ev = NewRunnableMethod( "net::nsSocketTransportService::ClosePrivateConnections", this, diff --git a/netwerk/base/nsUDPSocket.cpp b/netwerk/base/nsUDPSocket.cpp index 991c28acf8e3..70177f289e08 100644 --- a/netwerk/base/nsUDPSocket.cpp +++ b/netwerk/base/nsUDPSocket.cpp @@ -21,7 +21,6 @@ #include "prio.h" #include "nsNetAddr.h" #include "nsNetSegmentUtils.h" -#include "IOActivityMonitor.h" #include "nsServiceManagerUtils.h" #include "nsStreamUtils.h" #include "prerror.h" @@ -639,9 +638,6 @@ nsUDPSocket::InitWithAddress(const NetAddr* aAddr, nsIPrincipal* aPrincipal, PRNetAddrToNetAddr(&addr, &mAddr); - // create proxy via IOActivityMonitor - IOActivityMonitor::MonitorSocket(mFD); - // wait until AsyncListen is called before polling the socket for // client connections. return NS_OK; diff --git a/netwerk/test/browser/browser.toml b/netwerk/test/browser/browser.toml index a12ffed21286..46feb6b3d4d4 100644 --- a/netwerk/test/browser/browser.toml +++ b/netwerk/test/browser/browser.toml @@ -1,7 +1,6 @@ [DEFAULT] support-files = [ "dummy.html", - "ioactivity.html", "redirect.sjs", "auth_post.sjs", "early_hint_main_html.sjs", @@ -189,7 +188,4 @@ support-files = [ "file_favicon.html", ] -["browser_test_io_activity.js"] -skip-if = ["socketprocess_networking"] - ["browser_test_offline_tab.js"] diff --git a/netwerk/test/browser/browser_test_io_activity.js b/netwerk/test/browser/browser_test_io_activity.js deleted file mode 100644 index b6f498ed5f8b..000000000000 --- a/netwerk/test/browser/browser_test_io_activity.js +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim: set ts=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/. */ -"use strict"; -const ROOT_URL = getRootDirectory(gTestPath).replace( - "chrome://mochitests/content/", - "https://example.com/" -); -const TEST_URL = "about:license"; -const TEST_URL2 = ROOT_URL + "ioactivity.html"; - -var gotSocket = false; -var gotFile = false; -var gotSqlite = false; -var gotEmptyData = false; - -function processResults(results) { - for (let data of results) { - console.log(data.location); - gotEmptyData = data.rx == 0 && data.tx == 0 && !gotEmptyData; - gotSocket = data.location.startsWith("socket://127.0.0.1:") || gotSocket; - gotFile = data.location.endsWith("aboutLicense.css") || gotFile; - gotSqlite = data.location.endsWith("places.sqlite") || gotSqlite; - // check for the write-ahead file as well - gotSqlite = data.location.endsWith("places.sqlite-wal") || gotSqlite; - } -} - -add_task(async function testRequestIOActivity() { - await SpecialPowers.pushPrefEnv({ - set: [["io.activity.enabled", true]], - }); - waitForExplicitFinish(); - Services.obs.notifyObservers(null, "profile-initial-state"); - - await BrowserTestUtils.withNewTab(TEST_URL, async function () { - await BrowserTestUtils.withNewTab(TEST_URL2, async function () { - let results = await ChromeUtils.requestIOActivity(); - processResults(results); - - ok(gotSocket, "A socket was used"); - // test deactivated for now - // ok(gotFile, "A file was used"); - ok(gotSqlite, "A sqlite DB was used"); - ok(!gotEmptyData, "Every I/O event had data"); - }); - }); -}); diff --git a/netwerk/test/browser/ioactivity.html b/netwerk/test/browser/ioactivity.html deleted file mode 100644 index 5e23f6f117e6..000000000000 --- a/netwerk/test/browser/ioactivity.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - -

IOActivity Test Page

- - diff --git a/storage/BaseVFS.cpp b/storage/BaseVFS.cpp index f6090bf008fd..7793c9f24104 100644 --- a/storage/BaseVFS.cpp +++ b/storage/BaseVFS.cpp @@ -8,7 +8,6 @@ #include #include "sqlite3.h" -#include "mozilla/net/IOActivityMonitor.h" namespace { @@ -19,40 +18,28 @@ constexpr int kLastKnowVfsVersion = 3; constexpr int kLastKnownIOMethodsVersion = 3; using namespace mozilla; -using namespace mozilla::net; struct BaseFile { // Base class. Must be first sqlite3_file base; - // The filename - char* location; // This points to the underlying sqlite3_file sqlite3_file pReal[1]; }; int BaseClose(sqlite3_file* pFile) { BaseFile* p = (BaseFile*)pFile; - delete[] p->location; return p->pReal->pMethods->xClose(p->pReal); } int BaseRead(sqlite3_file* pFile, void* zBuf, int iAmt, sqlite_int64 iOfst) { BaseFile* p = (BaseFile*)pFile; - int rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst); - if (rc == SQLITE_OK && IOActivityMonitor::IsActive()) { - IOActivityMonitor::Read(nsDependentCString(p->location), iAmt); - } - return rc; + return p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst); } int BaseWrite(sqlite3_file* pFile, const void* zBuf, int iAmt, sqlite_int64 iOfst) { BaseFile* p = (BaseFile*)pFile; - int rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst); - if (rc == SQLITE_OK && IOActivityMonitor::IsActive()) { - IOActivityMonitor::Write(nsDependentCString(p->location), iAmt); - } - return rc; + return p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst); } int BaseTruncate(sqlite3_file* pFile, sqlite_int64 size) { @@ -148,15 +135,6 @@ int BaseUnfetch(sqlite3_file* pFile, sqlite3_int64 iOfst, void* pPage) { int BaseOpen(sqlite3_vfs* vfs, const char* zName, sqlite3_file* pFile, int flags, int* pOutFlags) { BaseFile* p = (BaseFile*)pFile; - if (zName) { - p->location = new char[7 + strlen(zName) + 1]; - strcpy(p->location, "file://"); - strcpy(p->location + 7, zName); - } else { - p->location = new char[8]; - strcpy(p->location, "file://"); - } - sqlite3_vfs* origVfs = (sqlite3_vfs*)(vfs->pAppData); int rc = origVfs->xOpen(origVfs, zName, p->pReal, flags, pOutFlags); if (rc) { diff --git a/tools/@types/lib.gecko.dom.d.ts b/tools/@types/lib.gecko.dom.d.ts index bb1e11010494..e3d181ec6770 100644 --- a/tools/@types/lib.gecko.dom.d.ts +++ b/tools/@types/lib.gecko.dom.d.ts @@ -1250,12 +1250,6 @@ interface IIRFilterOptions extends AudioNodeOptions { feedforward: number[]; } -interface IOActivityDataDictionary { - location?: string; - rx?: number; - tx?: number; -} - interface IdentityCredentialLogoutRPsRequest { accountId: UTF8String; url: UTF8String; @@ -35509,7 +35503,6 @@ declare namespace ChromeUtils { function registerProcessActor(aName: UTF8String, aOptions?: ProcessActorOptions): void; function registerWindowActor(aName: UTF8String, aOptions?: WindowActorOptions): void; function releaseAssert(condition: boolean, message?: string): void; - function requestIOActivity(): Promise; function requestProcInfo(): Promise; function resetLastExternalProtocolIframeAllowed(): void; function saveHeapSnapshot(boundaries?: HeapSnapshotBoundaries): string;