MemoryReportRequest.h (2289B)
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 #ifndef mozilla_dom_MemoryReportRequest_h_ 8 #define mozilla_dom_MemoryReportRequest_h_ 9 10 #include <functional> 11 12 #include "mozilla/dom/MemoryReportTypes.h" 13 #include "mozilla/ipc/FileDescriptor.h" 14 #include "nsISupports.h" 15 16 class nsMemoryReporterManager; 17 18 namespace mozilla::dom { 19 20 class MemoryReport; 21 22 class MemoryReportRequestHost final { 23 public: 24 explicit MemoryReportRequestHost(uint32_t aGeneration); 25 ~MemoryReportRequestHost(); 26 27 void RecvReport(const MemoryReport& aReport); 28 void Finish(uint32_t aGeneration); 29 30 private: 31 const uint32_t mGeneration; 32 // Non-null if we haven't yet called EndProcessReport() on it. 33 RefPtr<nsMemoryReporterManager> mReporterManager; 34 bool mSuccess; 35 }; 36 37 class MemoryReportRequestClient final : public nsIRunnable { 38 public: 39 using ReportCallback = std::function<void(const MemoryReport&)>; 40 using FinishCallback = std::function<void(const uint32_t&)>; 41 42 NS_DECL_ISUPPORTS 43 44 static void Start(uint32_t aGeneration, bool aAnonymize, 45 bool aMinimizeMemoryUsage, 46 const Maybe<mozilla::ipc::FileDescriptor>& aDMDFile, 47 const nsACString& aProcessString, 48 const ReportCallback& aReportCallback, 49 const FinishCallback& aFinishCallback); 50 51 NS_IMETHOD Run() override; 52 53 private: 54 MemoryReportRequestClient(uint32_t aGeneration, bool aAnonymize, 55 const Maybe<mozilla::ipc::FileDescriptor>& aDMDFile, 56 const nsACString& aProcessString, 57 const ReportCallback& aReportCallback, 58 const FinishCallback& aFinishCallback); 59 60 private: 61 ~MemoryReportRequestClient(); 62 63 uint32_t mGeneration; 64 bool mAnonymize; 65 mozilla::ipc::FileDescriptor mDMDFile; 66 nsCString mProcessString; 67 ReportCallback mReportCallback; 68 FinishCallback mFinishCallback; 69 }; 70 71 } // namespace mozilla::dom 72 73 #endif // mozilla_dom_MemoryReportRequest_h_