Bug 1397925 - Refresh OSPreferences mSystemLocales when intl.locale.os changes. r?rnewman draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Thu, 07 Sep 2017 14:53:36 -0700
changeset 661544 fff31cdf14fdeb58046c8da9997dad7a77b7b56c
parent 661321 50857982881ae7803ceb438fee90650a282f7f05
child 730628 323e6b521a3d827edac1c02966f1d4b362fbd9ab
push id78822
push userbmo:gandalf@aviary.pl
push dateFri, 08 Sep 2017 18:50:28 +0000
reviewersrnewman
bugs1397925
milestone57.0a1
Bug 1397925 - Refresh OSPreferences mSystemLocales when intl.locale.os changes. r?rnewman MozReview-Commit-ID: oJdWUXwhZw
intl/locale/LocaleService.cpp
intl/locale/OSPreferences.h
--- a/intl/locale/LocaleService.cpp
+++ b/intl/locale/LocaleService.cpp
@@ -525,19 +525,24 @@ LocaleService::IsAppLocaleRTL()
 }
 
 NS_IMETHODIMP
 LocaleService::Observe(nsISupports *aSubject, const char *aTopic,
                       const char16_t *aData)
 {
   MOZ_ASSERT(mIsServer, "This should only be called in the server mode.");
 
+  NS_ConvertUTF16toUTF8 pref(aData);
+
+  // This is a temporary solution until we get bug 1337078 landed.
+  if (pref.EqualsLiteral(ANDROID_OS_LOCALE_PREF)) {
+    OSPreferences::GetInstance()->Refresh();
+  }
   // At the moment the only thing we're observing are settings indicating
   // user requested locales.
-  NS_ConvertUTF16toUTF8 pref(aData);
   if (pref.EqualsLiteral(MATCH_OS_LOCALE_PREF) ||
       pref.EqualsLiteral(SELECTED_LOCALE_PREF) ||
       pref.EqualsLiteral(ANDROID_OS_LOCALE_PREF)) {
     OnRequestedLocalesChanged();
   }
   return NS_OK;
 }
 
--- a/intl/locale/OSPreferences.h
+++ b/intl/locale/OSPreferences.h
@@ -123,16 +123,29 @@ public:
    *
    * (See mozIOSPreferences.idl for a JS-callable version of this.)
    */
   bool GetRegionalPrefsLocales(nsTArray<nsCString>& aRetVal);
 
   static bool GetDateTimeConnectorPattern(const nsACString& aLocale,
                                           nsAString& aRetVal);
 
+  /**
+   * Triggers a refresh of retrieving data from host environment.
+   *
+   * If the result differs from the previous list, it will additionally
+   * trigger global events for changed values:
+   *
+   *  * SystemLocales: "intl:system-locales-changed"
+   *
+   * This method should not be called from anywhere except of per-platform
+   * hooks into OS events.
+   */
+  void Refresh();
+
 protected:
   nsTArray<nsCString> mSystemLocales;
   nsTArray<nsCString> mRegionalPrefsLocales;
 
 private:
   virtual ~OSPreferences() {};
 
   static StaticRefPtr<OSPreferences> sInstance;
@@ -182,27 +195,14 @@ private:
    * Callers should always be prepared to handle that scenario.
    *
    * The heuristic may depend on the OS API and HIG guidelines.
    */
   bool ReadDateTimePattern(DateTimeFormatStyle aDateFormatStyle,
                            DateTimeFormatStyle aTimeFormatStyle,
                            const nsACString& aLocale,
                            nsAString& aRetVal);
-
-  /**
-   * Triggers a refresh of retrieving data from host environment.
-   *
-   * If the result differs from the previous list, it will additionally
-   * trigger global events for changed values:
-   *
-   *  * SystemLocales: "intl:system-locales-changed"
-   *
-   * This method should not be called from anywhere except of per-platform
-   * hooks into OS events.
-   */
-  void Refresh();
 };
 
 } // intl
 } // namespace mozilla
 
 #endif /* mozilla_intl_IntlOSPreferences_h__ */