/src/mozilla-central/intl/strres/nsStringBundleService.h
Line | Count | Source (jump to first uncovered line) |
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 "nsDataHashtable.h" |
11 | | #include "nsHashKeys.h" |
12 | | #include "nsIPersistentProperties2.h" |
13 | | #include "nsIStringBundle.h" |
14 | | #include "nsIObserver.h" |
15 | | #include "nsWeakReference.h" |
16 | | #include "nsIErrorService.h" |
17 | | #include "nsIMemoryReporter.h" |
18 | | |
19 | | #include "mozilla/LinkedList.h" |
20 | | #include "mozilla/UniquePtr.h" |
21 | | |
22 | | struct bundleCacheEntry_t; |
23 | | |
24 | | class nsStringBundleService : public nsIStringBundleService, |
25 | | public nsIObserver, |
26 | | public nsSupportsWeakReference, |
27 | | public nsIMemoryReporter |
28 | | { |
29 | | MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf); |
30 | | |
31 | | public: |
32 | | nsStringBundleService(); |
33 | | |
34 | | nsresult Init(); |
35 | | |
36 | | NS_DECL_ISUPPORTS |
37 | | NS_DECL_NSISTRINGBUNDLESERVICE |
38 | | NS_DECL_NSIOBSERVER |
39 | | |
40 | | NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport, |
41 | | nsISupports* aData, bool anonymize) override |
42 | 0 | { |
43 | 0 | size_t amt = SizeOfIncludingThis(MallocSizeOf); |
44 | 0 |
|
45 | 0 | MOZ_COLLECT_REPORT( |
46 | 0 | "explicit/string-bundles/service", KIND_HEAP, UNITS_BYTES, |
47 | 0 | amt, |
48 | 0 | "Memory used for StringBundleService overhead"); |
49 | 0 | return NS_OK; |
50 | 0 | }; |
51 | | |
52 | | size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; |
53 | | |
54 | | void SendContentBundles(mozilla::dom::ContentParent* aContentParent) const override; |
55 | | |
56 | | void RegisterContentBundle(const nsCString& aBundleURL, |
57 | | const mozilla::ipc::FileDescriptor& aMapFile, |
58 | | size_t aMapSize) override; |
59 | | |
60 | | private: |
61 | | virtual ~nsStringBundleService(); |
62 | | |
63 | | void getStringBundle(const char *aUrl, nsIStringBundle** aResult); |
64 | | nsresult FormatWithBundle(nsIStringBundle* bundle, nsresult aStatus, |
65 | | uint32_t argCount, char16_t** argArray, |
66 | | nsAString& result); |
67 | | |
68 | | void flushBundleCache(bool ignoreShared = true); |
69 | | |
70 | | mozilla::UniquePtr<bundleCacheEntry_t> evictOneEntry(); |
71 | | |
72 | | bundleCacheEntry_t* insertIntoCache(already_AddRefed<nsIStringBundle> aBundle, |
73 | | const nsACString &aHashKey); |
74 | | |
75 | | nsDataHashtable<nsCStringHashKey, bundleCacheEntry_t*> mBundleMap; |
76 | | // LRU list of cached entries, with the least-recently-used entry first. |
77 | | mozilla::LinkedList<bundleCacheEntry_t> mBundleCache; |
78 | | // List of cached shared-memory string bundles, in arbitrary order. |
79 | | mozilla::AutoCleanLinkedList<bundleCacheEntry_t> mSharedBundles; |
80 | | |
81 | | nsCOMPtr<nsIErrorService> mErrorService; |
82 | | }; |
83 | | |
84 | | #endif |