nsStringBundleService.h (2091B)
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 #ifndef nsStringBundleService_h__ 7 #define nsStringBundleService_h__ 8 9 #include "nsCOMPtr.h" 10 #include "nsTHashMap.h" 11 #include "nsHashKeys.h" 12 #include "nsIStringBundle.h" 13 #include "nsIObserver.h" 14 #include "nsWeakReference.h" 15 #include "nsIMemoryReporter.h" 16 17 #include "mozilla/LinkedList.h" 18 #include "mozilla/UniquePtr.h" 19 20 struct bundleCacheEntry_t; 21 22 class nsStringBundleService : public nsIStringBundleService, 23 public nsIObserver, 24 public nsSupportsWeakReference, 25 public nsIMemoryReporter { 26 MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf); 27 28 public: 29 nsStringBundleService(); 30 31 nsresult Init(); 32 33 NS_DECL_ISUPPORTS 34 NS_DECL_NSISTRINGBUNDLESERVICE 35 NS_DECL_NSIOBSERVER 36 37 NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport, 38 nsISupports* aData, bool anonymize) override { 39 size_t amt = SizeOfIncludingThis(MallocSizeOf); 40 41 MOZ_COLLECT_REPORT("explicit/string-bundles/service", KIND_HEAP, 42 UNITS_BYTES, amt, 43 "Memory used for StringBundleService overhead"); 44 return NS_OK; 45 }; 46 47 private: 48 virtual ~nsStringBundleService(); 49 50 void flushBundleCache(bool ignoreShared = true); 51 52 mozilla::UniquePtr<bundleCacheEntry_t> evictOneEntry(); 53 54 bundleCacheEntry_t* insertIntoCache(already_AddRefed<nsIStringBundle> aBundle, 55 const nsACString& aHashKey); 56 57 nsTHashMap<nsCStringHashKey, bundleCacheEntry_t*> mBundleMap; 58 // LRU list of cached entries, with the least-recently-used entry first. 59 mozilla::LinkedList<bundleCacheEntry_t> mBundleCache; 60 // List of cached shared-memory string bundles, in arbitrary order. 61 mozilla::AutoCleanLinkedList<bundleCacheEntry_t> mSharedBundles; 62 }; 63 64 #endif