From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- netwerk/base/IOActivityMonitor.h | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 netwerk/base/IOActivityMonitor.h (limited to 'netwerk/base/IOActivityMonitor.h') diff --git a/netwerk/base/IOActivityMonitor.h b/netwerk/base/IOActivityMonitor.h new file mode 100644 index 0000000000..5e46bc9bfc --- /dev/null +++ b/netwerk/base/IOActivityMonitor.h @@ -0,0 +1,83 @@ +/* -*- 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___ */ -- cgit v1.2.3