2002-10-14 23:06:27 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-10-14 23:06:27 +04:00
|
|
|
|
|
|
|
#ifndef nsStringBundleService_h__
|
|
|
|
#define nsStringBundleService_h__
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2014-04-22 23:48:46 +04:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2002-10-14 23:06:27 +04:00
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsIErrorService.h"
|
2018-05-18 23:16:31 +03:00
|
|
|
#include "nsIMemoryReporter.h"
|
2002-10-14 23:06:27 +04:00
|
|
|
|
2012-11-01 18:03:41 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
2018-06-25 00:32:19 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2012-11-01 18:03:41 +04:00
|
|
|
|
2002-10-14 23:06:27 +04:00
|
|
|
struct bundleCacheEntry_t;
|
|
|
|
|
|
|
|
class nsStringBundleService : public nsIStringBundleService,
|
|
|
|
public nsIObserver,
|
2018-05-18 23:16:31 +03:00
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsIMemoryReporter {
|
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf);
|
|
|
|
|
2002-10-14 23:06:27 +04:00
|
|
|
public:
|
|
|
|
nsStringBundleService();
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
|
2014-04-22 23:48:46 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2002-10-14 23:06:27 +04:00
|
|
|
NS_DECL_NSISTRINGBUNDLESERVICE
|
|
|
|
NS_DECL_NSIOBSERVER
|
2014-04-21 20:41:56 +04:00
|
|
|
|
2018-05-18 23:16:31 +03:00
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData, bool anonymize) override {
|
|
|
|
size_t amt = SizeOfIncludingThis(MallocSizeOf);
|
|
|
|
|
2018-06-25 01:47:10 +03:00
|
|
|
MOZ_COLLECT_REPORT("explicit/string-bundles/service", KIND_HEAP,
|
|
|
|
UNITS_BYTES, amt,
|
|
|
|
"Memory used for StringBundleService overhead");
|
2018-05-18 23:16:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t SizeOfIncludingThis(
|
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const override;
|
|
|
|
|
2018-06-30 08:53:12 +03:00
|
|
|
void SendContentBundles(
|
|
|
|
mozilla::dom::ContentParent* aContentParent) const override;
|
|
|
|
|
|
|
|
void RegisterContentBundle(const nsCString& aBundleURL,
|
|
|
|
const mozilla::ipc::FileDescriptor& aMapFile,
|
|
|
|
size_t aMapSize) override;
|
|
|
|
|
2002-10-14 23:06:27 +04:00
|
|
|
private:
|
2014-06-24 02:40:02 +04:00
|
|
|
virtual ~nsStringBundleService();
|
|
|
|
|
2016-12-16 05:31:22 +03:00
|
|
|
void getStringBundle(const char* aUrl, nsIStringBundle** aResult);
|
2014-04-21 20:41:56 +04:00
|
|
|
nsresult FormatWithBundle(nsIStringBundle* bundle, nsresult aStatus,
|
2019-06-11 18:51:51 +03:00
|
|
|
const nsTArray<nsString>& argArray,
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAString& result);
|
2002-10-14 23:06:27 +04:00
|
|
|
|
2018-06-25 00:32:19 +03:00
|
|
|
void flushBundleCache(bool ignoreShared = true);
|
|
|
|
|
|
|
|
mozilla::UniquePtr<bundleCacheEntry_t> evictOneEntry();
|
2014-04-21 20:41:56 +04:00
|
|
|
|
2018-06-30 08:53:12 +03:00
|
|
|
bundleCacheEntry_t* insertIntoCache(already_AddRefed<nsIStringBundle> aBundle,
|
|
|
|
const nsACString& aHashKey);
|
2002-10-14 23:06:27 +04:00
|
|
|
|
2014-04-22 23:48:46 +04:00
|
|
|
nsDataHashtable<nsCStringHashKey, bundleCacheEntry_t*> mBundleMap;
|
2018-06-25 00:32:19 +03:00
|
|
|
// LRU list of cached entries, with the least-recently-used entry first.
|
2012-11-01 18:03:41 +04:00
|
|
|
mozilla::LinkedList<bundleCacheEntry_t> mBundleCache;
|
2018-06-25 00:32:19 +03:00
|
|
|
// List of cached shared-memory string bundles, in arbitrary order.
|
2018-06-29 00:45:21 +03:00
|
|
|
mozilla::AutoCleanLinkedList<bundleCacheEntry_t> mSharedBundles;
|
2002-10-14 23:06:27 +04:00
|
|
|
|
2014-04-22 23:48:46 +04:00
|
|
|
nsCOMPtr<nsIErrorService> mErrorService;
|
2002-10-14 23:06:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|