1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/http/SpdyZlibReporter.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set sw=2 ts=8 et tw=80 : */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* A memory allocator for zlib use in SPDY that reports to about:memory. */ 1.11 + 1.12 +#include "mozilla/Assertions.h" 1.13 +#include "mozilla/Atomics.h" 1.14 +#include "mozilla/Attributes.h" 1.15 +#include "nsIMemoryReporter.h" 1.16 +#include "zlib.h" 1.17 + 1.18 +namespace mozilla { 1.19 + 1.20 +class SpdyZlibReporter MOZ_FINAL : public nsIMemoryReporter 1.21 +{ 1.22 +public: 1.23 + NS_DECL_ISUPPORTS 1.24 + 1.25 + SpdyZlibReporter() 1.26 + { 1.27 +#ifdef DEBUG 1.28 + // There must be only one instance of this class, due to |sAmount| 1.29 + // being static. 1.30 + static bool hasRun = false; 1.31 + MOZ_ASSERT(!hasRun); 1.32 + hasRun = true; 1.33 +#endif 1.34 + sAmount = 0; 1.35 + } 1.36 + 1.37 + static void* Alloc(void*, uInt items, uInt size); 1.38 + static void Free(void*, void* p); 1.39 + 1.40 +private: 1.41 + // |sAmount| can be (implicitly) accessed by multiple threads, so it 1.42 + // must be thread-safe. 1.43 + static Atomic<size_t> sAmount; 1.44 + 1.45 + MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf) 1.46 + MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MallocSizeOfOnAlloc) 1.47 + MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MallocSizeOfOnFree) 1.48 + 1.49 + NS_IMETHODIMP 1.50 + CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData); 1.51 +}; 1.52 + 1.53 +} // namespace mozilla