зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1755181 - Invalidate locale cache in AppDateTimeFormat; r=platform-i18n-reviewers,nordzilla
Differential Revision: https://phabricator.services.mozilla.com/D140666
This commit is contained in:
Родитель
b925c500e4
Коммит
0737dd81d2
|
@ -252,4 +252,11 @@ void AppDateTimeFormat::Shutdown() {
|
|||
delete sLocale;
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void AppDateTimeFormat::ClearLocaleCache() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
delete sLocale;
|
||||
sLocale = nullptr;
|
||||
}
|
||||
|
||||
} // namespace mozilla::intl
|
||||
|
|
|
@ -49,6 +49,11 @@ class AppDateTimeFormat {
|
|||
const PRExplodedTime* aExplodedTime,
|
||||
nsAString& aStringOut);
|
||||
|
||||
/**
|
||||
* If the app locale changes, the cached locale needs to be reset.
|
||||
*/
|
||||
static void ClearLocaleCache();
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
private:
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/StaticPrefs_privacy.h"
|
||||
#include "mozilla/intl/AppDateTimeFormat.h"
|
||||
#include "mozilla/intl/Locale.h"
|
||||
#include "mozilla/intl/OSPreferences.h"
|
||||
#include "nsDirectoryService.h"
|
||||
|
@ -175,6 +176,15 @@ LocaleService* LocaleService::GetInstance() {
|
|||
return sInstance;
|
||||
}
|
||||
|
||||
static void NotifyAppLocaleChanged() {
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->NotifyObservers(nullptr, "intl:app-locales-changed", nullptr);
|
||||
}
|
||||
// The locale in AppDateTimeFormat is cached statically.
|
||||
AppDateTimeFormat::ClearLocaleCache();
|
||||
}
|
||||
|
||||
void LocaleService::RemoveObservers() {
|
||||
if (mIsServer) {
|
||||
Preferences::RemoveObservers(this, kObservedPrefs);
|
||||
|
@ -192,10 +202,7 @@ void LocaleService::AssignAppLocales(const nsTArray<nsCString>& aAppLocales) {
|
|||
"This should only be called for LocaleService in client mode.");
|
||||
|
||||
mAppLocales = aAppLocales.Clone();
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->NotifyObservers(nullptr, "intl:app-locales-changed", nullptr);
|
||||
}
|
||||
NotifyAppLocaleChanged();
|
||||
}
|
||||
|
||||
void LocaleService::AssignRequestedLocales(
|
||||
|
@ -249,10 +256,7 @@ void LocaleService::LocalesChanged() {
|
|||
|
||||
if (mAppLocales != newLocales) {
|
||||
mAppLocales = std::move(newLocales);
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->NotifyObservers(nullptr, "intl:app-locales-changed", nullptr);
|
||||
}
|
||||
NotifyAppLocaleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче