зеркало из https://github.com/mozilla/gecko-dev.git
bug 846690 - add a memory-pressure notification observer to the hyphenation manager, to discard dictionaries when we're low on memory. r=smontagu
This commit is contained in:
Родитель
3fd091d44a
Коммит
0c72637e86
|
@ -41,6 +41,7 @@
|
||||||
#include "nsInterfaceHashtable.h"
|
#include "nsInterfaceHashtable.h"
|
||||||
#include "nsRefPtrHashtable.h"
|
#include "nsRefPtrHashtable.h"
|
||||||
#include "nsHashKeys.h"
|
#include "nsHashKeys.h"
|
||||||
|
#include "nsIObserver.h"
|
||||||
#include "mozilla/Omnijar.h"
|
#include "mozilla/Omnijar.h"
|
||||||
|
|
||||||
class nsHyphenator;
|
class nsHyphenator;
|
||||||
|
@ -62,6 +63,13 @@ private:
|
||||||
~nsHyphenationManager();
|
~nsHyphenationManager();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
class MemoryPressureObserver MOZ_FINAL : public nsIObserver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIOBSERVER
|
||||||
|
};
|
||||||
|
|
||||||
void LoadPatternList();
|
void LoadPatternList();
|
||||||
void LoadPatternListFromOmnijar(mozilla::Omnijar::Type aType);
|
void LoadPatternListFromOmnijar(mozilla::Omnijar::Type aType);
|
||||||
void LoadPatternListFromDir(nsIFile *aDir);
|
void LoadPatternListFromDir(nsIFile *aDir);
|
||||||
|
|
|
@ -48,18 +48,48 @@
|
||||||
#include "nsUnicharUtils.h"
|
#include "nsUnicharUtils.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
#include "nsZipArchive.h"
|
#include "nsZipArchive.h"
|
||||||
|
#include "mozilla/Services.h"
|
||||||
|
#include "nsIObserverService.h"
|
||||||
|
#include "nsCRT.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
#define INTL_HYPHENATIONALIAS_PREFIX "intl.hyphenation-alias."
|
static const char kIntlHyphenationAliasPrefix[] = "intl.hyphenation-alias.";
|
||||||
|
static const char kMemoryPressureNotification[] = "memory-pressure";
|
||||||
|
|
||||||
nsHyphenationManager *nsHyphenationManager::sInstance = nullptr;
|
nsHyphenationManager *nsHyphenationManager::sInstance = nullptr;
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS1(nsHyphenationManager::MemoryPressureObserver,
|
||||||
|
nsIObserver)
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsHyphenationManager::MemoryPressureObserver::Observe(nsISupports *aSubject,
|
||||||
|
const char *aTopic,
|
||||||
|
const PRUnichar *aData)
|
||||||
|
{
|
||||||
|
if (!nsCRT::strcmp(aTopic, kMemoryPressureNotification)) {
|
||||||
|
// We don't call Instance() here, as we don't want to create a hyphenation
|
||||||
|
// manager if there isn't already one in existence.
|
||||||
|
// (This observer class is local to the hyphenation manager, so it can use
|
||||||
|
// the protected members directly.)
|
||||||
|
if (nsHyphenationManager::sInstance) {
|
||||||
|
nsHyphenationManager::sInstance->mHyphenators.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsHyphenationManager*
|
nsHyphenationManager*
|
||||||
nsHyphenationManager::Instance()
|
nsHyphenationManager::Instance()
|
||||||
{
|
{
|
||||||
if (sInstance == nullptr) {
|
if (sInstance == nullptr) {
|
||||||
sInstance = new nsHyphenationManager();
|
sInstance = new nsHyphenationManager();
|
||||||
|
|
||||||
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||||
|
if (obs) {
|
||||||
|
obs->AddObserver(new MemoryPressureObserver,
|
||||||
|
kMemoryPressureNotification, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
@ -296,14 +326,14 @@ nsHyphenationManager::LoadAliases()
|
||||||
}
|
}
|
||||||
uint32_t prefCount;
|
uint32_t prefCount;
|
||||||
char **prefNames;
|
char **prefNames;
|
||||||
nsresult rv = prefRootBranch->GetChildList(INTL_HYPHENATIONALIAS_PREFIX,
|
nsresult rv = prefRootBranch->GetChildList(kIntlHyphenationAliasPrefix,
|
||||||
&prefCount, &prefNames);
|
&prefCount, &prefNames);
|
||||||
if (NS_SUCCEEDED(rv) && prefCount > 0) {
|
if (NS_SUCCEEDED(rv) && prefCount > 0) {
|
||||||
for (uint32_t i = 0; i < prefCount; ++i) {
|
for (uint32_t i = 0; i < prefCount; ++i) {
|
||||||
nsAdoptingCString value = Preferences::GetCString(prefNames[i]);
|
nsAdoptingCString value = Preferences::GetCString(prefNames[i]);
|
||||||
if (value) {
|
if (value) {
|
||||||
nsAutoCString alias(prefNames[i]);
|
nsAutoCString alias(prefNames[i]);
|
||||||
alias.Cut(0, strlen(INTL_HYPHENATIONALIAS_PREFIX));
|
alias.Cut(0, sizeof(kIntlHyphenationAliasPrefix) - 1);
|
||||||
ToLowerCase(alias);
|
ToLowerCase(alias);
|
||||||
ToLowerCase(value);
|
ToLowerCase(value);
|
||||||
nsCOMPtr<nsIAtom> aliasAtom = do_GetAtom(alias);
|
nsCOMPtr<nsIAtom> aliasAtom = do_GetAtom(alias);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче