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_AvailableMemoryWatcher_h 8 #define mozilla_AvailableMemoryWatcher_h 9 10 #include "nsCOMPtr.h" 11 #include "nsIAvailableMemoryWatcherBase.h" 12 13 namespace mozilla { 14 15 // This class implements a platform-independent part to watch the system's 16 // memory situation and invoke the registered callbacks when we detect 17 // a low-memory situation or a high-memory situation. 18 // The actual logic to monitor the memory status is implemented in a subclass 19 // of nsAvailableMemoryWatcherBase per platform. 20 class nsAvailableMemoryWatcherBase : public nsIAvailableMemoryWatcherBase { 21 static StaticRefPtr<nsAvailableMemoryWatcherBase> sSingleton; 22 23 protected: 24 nsCOMPtr<nsITabUnloader> mTabUnloader; 25 26 virtual ~nsAvailableMemoryWatcherBase() = default; 27 28 public: 29 static already_AddRefed<nsAvailableMemoryWatcherBase> GetSingleton(); 30 31 nsAvailableMemoryWatcherBase(); 32 33 NS_DECL_THREADSAFE_ISUPPORTS 34 NS_DECL_NSIAVAILABLEMEMORYWATCHERBASE 35 }; 36 37 // Method to create a platform-specific object 38 already_AddRefed<nsAvailableMemoryWatcherBase> CreateAvailableMemoryWatcher(); 39 40 } // namespace mozilla 41 42 #endif // ifndef mozilla_AvailableMemoryWatcher_h 43