LCOV - code coverage report
Current view: top level - intl/locale - nsLanguageAtomService.h (source / functions) Hit Total Coverage
Test: output.info Lines: 1 1 100.0 %
Date: 2017-07-14 16:53:18 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /*
       7             :  * The nsILanguageAtomService provides a mapping from languages or charsets
       8             :  * to language groups, and access to the system locale language.
       9             :  */
      10             : 
      11             : #ifndef nsLanguageAtomService_h_
      12             : #define nsLanguageAtomService_h_
      13             : 
      14             : #include "mozilla/NotNull.h"
      15             : #include "nsCOMPtr.h"
      16             : #include "nsIAtom.h"
      17             : #include "nsInterfaceHashtable.h"
      18             : 
      19             : namespace mozilla {
      20             : class Encoding;
      21             : }
      22             : 
      23           3 : class nsLanguageAtomService final
      24             : {
      25             :   using Encoding = mozilla::Encoding;
      26             :   template <typename T> using NotNull = mozilla::NotNull<T>;
      27             : public:
      28             :   static nsLanguageAtomService* GetService();
      29             : 
      30             :   nsIAtom* LookupLanguage(const nsACString &aLanguage);
      31             :   already_AddRefed<nsIAtom> LookupCharSet(NotNull<const Encoding*> aCharSet);
      32             :   nsIAtom* GetLocaleLanguage();
      33             : 
      34             :   // Returns the language group that the specified language is a part of.
      35             :   //
      36             :   // aNeedsToCache is used for two things.  If null, it indicates that
      37             :   // the nsLanguageAtomService is safe to cache the result of the
      38             :   // language group lookup, either because we're on the main thread,
      39             :   // or because we're on a style worker thread but the font lock has
      40             :   // been acquired.  If non-null, it indicates that it's not safe to
      41             :   // cache the result of the language group lookup (because we're on
      42             :   // a style worker thread without the lock acquired).  In this case,
      43             :   // GetLanguageGroup will store true in *aNeedsToCache true if we
      44             :   // would have cached the result of a new lookup, and false if we
      45             :   // were able to use an existing cached result.  Thus, callers that
      46             :   // get a true *aNeedsToCache outparam value should make an effort
      47             :   // to re-call GetLanguageGroup when it is safe to cache, to avoid
      48             :   // recomputing the language group again later.
      49             :   nsIAtom* GetLanguageGroup(nsIAtom* aLanguage, bool* aNeedsToCache = nullptr);
      50             :   already_AddRefed<nsIAtom> GetUncachedLanguageGroup(nsIAtom* aLanguage) const;
      51             : 
      52             : private:
      53             :   nsInterfaceHashtable<nsISupportsHashKey, nsIAtom> mLangToGroup;
      54             :   nsCOMPtr<nsIAtom> mLocaleLanguage;
      55             : };
      56             : 
      57             : #endif

Generated by: LCOV version 1.13