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/. */
6 #ifndef nsStringBundleService_h__
7 #define nsStringBundleService_h__
10 #include "nsTHashMap.h"
11 #include "nsHashKeys.h"
12 #include "nsIStringBundle.h"
13 #include "nsIObserver.h"
14 #include "nsWeakReference.h"
15 #include "nsIErrorService.h"
16 #include "nsIMemoryReporter.h"
18 #include "mozilla/LinkedList.h"
19 #include "mozilla/UniquePtr.h"
21 struct bundleCacheEntry_t
;
23 class nsStringBundleService
: public nsIStringBundleService
,
25 public nsSupportsWeakReference
,
26 public nsIMemoryReporter
{
27 MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf
);
30 nsStringBundleService();
35 NS_DECL_NSISTRINGBUNDLESERVICE
38 NS_IMETHOD
CollectReports(nsIHandleReportCallback
* aHandleReport
,
39 nsISupports
* aData
, bool anonymize
) override
{
40 size_t amt
= SizeOfIncludingThis(MallocSizeOf
);
42 MOZ_COLLECT_REPORT("explicit/string-bundles/service", KIND_HEAP
,
44 "Memory used for StringBundleService overhead");
48 size_t SizeOfIncludingThis(
49 mozilla::MallocSizeOf aMallocSizeOf
) const override
;
51 void SendContentBundles(
52 mozilla::dom::ContentParent
* aContentParent
) const override
;
54 void RegisterContentBundle(const nsCString
& aBundleURL
,
55 const mozilla::ipc::FileDescriptor
& aMapFile
,
56 size_t aMapSize
) override
;
59 virtual ~nsStringBundleService();
61 void getStringBundle(const char* aUrl
, nsIStringBundle
** aResult
);
62 nsresult
FormatWithBundle(nsIStringBundle
* bundle
, nsresult aStatus
,
63 const nsTArray
<nsString
>& argArray
,
66 void flushBundleCache(bool ignoreShared
= true);
68 mozilla::UniquePtr
<bundleCacheEntry_t
> evictOneEntry();
70 bundleCacheEntry_t
* insertIntoCache(already_AddRefed
<nsIStringBundle
> aBundle
,
71 const nsACString
& aHashKey
);
73 nsTHashMap
<nsCStringHashKey
, bundleCacheEntry_t
*> mBundleMap
;
74 // LRU list of cached entries, with the least-recently-used entry first.
75 mozilla::LinkedList
<bundleCacheEntry_t
> mBundleCache
;
76 // List of cached shared-memory string bundles, in arbitrary order.
77 mozilla::AutoCleanLinkedList
<bundleCacheEntry_t
> mSharedBundles
;
79 nsCOMPtr
<nsIErrorService
> mErrorService
;