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 _NSSYSTEMINFO_H_ 8 #define _NSSYSTEMINFO_H_ 9 10 #include "nsHashPropertyBag.h" 11 #include "nsISystemInfo.h" 12 #include "mozilla/MozPromise.h" 13 14 #ifdef MOZ_WIDGET_ANDROID 15 # include "mozilla/dom/PContent.h" 16 #endif // MOZ_WIDGET_ANDROID 17 18 class nsISerialEventTarget; 19 20 struct FolderDiskInfo { 21 nsCString model; 22 nsCString revision; 23 bool isSSD; 24 }; 25 26 struct DiskInfo { 27 FolderDiskInfo binary; 28 FolderDiskInfo profile; 29 FolderDiskInfo system; 30 }; 31 32 struct OSInfo { 33 uint32_t installYear; 34 bool hasSuperfetch; 35 bool hasPrefetch; 36 }; 37 38 struct ProcessInfo { 39 bool isWow64; 40 bool isWowARM64; 41 int32_t cpuCount; 42 int32_t cpuCores; 43 nsCString cpuVendor; 44 int32_t cpuFamily; 45 int32_t cpuModel; 46 int32_t cpuStepping; 47 int32_t l2cacheKB; 48 int32_t l3cacheKB; 49 int32_t cpuSpeed; 50 }; 51 52 typedef mozilla::MozPromise<DiskInfo, nsresult, /* IsExclusive */ false> 53 DiskInfoPromise; 54 55 typedef mozilla::MozPromise<nsAutoString, nsresult, /* IsExclusive */ false> 56 CountryCodePromise; 57 58 typedef mozilla::MozPromise<OSInfo, nsresult, /* IsExclusive */ false> 59 OSInfoPromise; 60 61 typedef mozilla::MozPromise<ProcessInfo, nsresult, /* IsExclusive */ false> 62 ProcessInfoPromise; 63 64 // Synchronous info collection, avoid calling it from the main thread, consider 65 // using the promise-based `nsISystemInfo::GetProcessInfo()` instead. 66 // Note that only known fields will be written. 67 nsresult CollectProcessInfo(ProcessInfo& info); 68 69 class nsSystemInfo final : public nsISystemInfo, public nsHashPropertyBag { 70 public: 71 NS_DECL_ISUPPORTS_INHERITED 72 NS_DECL_NSISYSTEMINFO 73 74 nsSystemInfo(); 75 76 nsresult Init(); 77 78 // Slot for NS_InitXPCOM to pass information to nsSystemInfo::Init. 79 // See comments above the variable definition and in NS_InitXPCOM. 80 static uint32_t gUserUmask; 81 82 #ifdef MOZ_WIDGET_ANDROID 83 static void GetAndroidSystemInfo(mozilla::dom::AndroidSystemInfo* aInfo); 84 85 protected: 86 void SetupAndroidInfo(const mozilla::dom::AndroidSystemInfo&); 87 #endif 88 89 protected: 90 void SetInt32Property(const nsAString& aPropertyName, const int32_t aValue); 91 void SetUint32Property(const nsAString& aPropertyName, const uint32_t aValue); 92 void SetUint64Property(const nsAString& aPropertyName, const uint64_t aValue); 93 94 private: 95 ~nsSystemInfo(); 96 97 RefPtr<DiskInfoPromise> mDiskInfoPromise; 98 RefPtr<CountryCodePromise> mCountryCodePromise; 99 RefPtr<OSInfoPromise> mOSInfoPromise; 100 RefPtr<ProcessInfoPromise> mProcessInfoPromise; 101 RefPtr<nsISerialEventTarget> mBackgroundET; 102 RefPtr<nsISerialEventTarget> GetBackgroundTarget(); 103 }; 104 105 #define NS_SYSTEMINFO_CONTRACTID "@mozilla.org/system-info;1" 106 #define NS_SYSTEMINFO_CID \ 107 { \ 108 0xd962398a, 0x99e5, 0x49b2, { \ 109 0x85, 0x7a, 0xc1, 0x59, 0x04, 0x9c, 0x7f, 0x6c \ 110 } \ 111 } 112 113 #endif /* _NSSYSTEMINFO_H_ */ 114