/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
// Use this class as the initial value of // nsAvailableMemoryWatcherBase::mCallback until RegisterCallback() is called // so that nsAvailableMemoryWatcherBase does not have to check if its callback // object is valid or not. class NullTabUnloader final : public nsITabUnloader {
~NullTabUnloader() = default;
nsAvailableMemoryWatcherBase::nsAvailableMemoryWatcherBase()
: mMutex("nsAvailableMemoryWatcher mutex"),
mNumOfTabUnloading(0),
mNumOfMemoryPressure(0),
mTabUnloader(new NullTabUnloader),
mInteracting(false) {
MOZ_ASSERT(XRE_IsParentProcess(), "Watching memory only in the main process.");
}
constchar* const nsAvailableMemoryWatcherBase::kObserverTopics[] = { // Use this shutdown phase to make sure the instance is destroyed in GTest "xpcom-shutdown", "user-interaction-active", "user-interaction-inactive",
};
nsresult nsAvailableMemoryWatcherBase::Init() {
MOZ_ASSERT(NS_IsMainThread(), "nsAvailableMemoryWatcherBase needs to be initialized " "in the main thread.");
if (mObserverSvc) { return NS_ERROR_ALREADY_INITIALIZED;
}
// This method is called as a part of UnloadTabAsync(). Like Notify(), if we // call this method synchronously without releasing the lock first we can lead // to deadlock.
nsresult nsAvailableMemoryWatcherBase::OnUnloadAttemptCompleted(
nsresult aResult) {
MutexAutoLock lock(mMutex); switch (aResult) { // A tab was unloaded successfully. case NS_OK:
++mNumOfTabUnloading; break;
// There was no unloadable tab. case NS_ERROR_NOT_AVAILABLE:
++mNumOfMemoryPressure;
NS_NotifyOfEventualMemoryPressure(MemoryPressureState::LowMemory); break;
// There was a pending task to unload a tab. case NS_ERROR_ABORT: break;
// Define the fallback method for a platform for which a platform-specific // CreateAvailableMemoryWatcher() is not defined. #ifdefined(ANDROID) || \
!defined(XP_WIN) && !defined(XP_DARWIN) && !defined(XP_LINUX)
already_AddRefed<nsAvailableMemoryWatcherBase> CreateAvailableMemoryWatcher() {
RefPtr instance(new nsAvailableMemoryWatcherBase); return do_AddRef(instance);
} #endif
} // namespace mozilla
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.