Bug 1883861 - Part 1: Move visitMemoryBarrier into the common CodeGenerator file...
[gecko.git] / layout / style / SharedStyleSheetCache.h
blobc5043944f56f0c5a125e2a299af7ce347043ecc1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_SharedStyleSheetCache_h__
8 #define mozilla_SharedStyleSheetCache_h__
10 // The shared style sheet cache is a cache that allows us to share sheets across
11 // documents.
13 // It's generally a singleton, but it is different from GlobalStyleSheetCache in
14 // the sense that:
16 // * It needs to be cycle-collectable, as it can keep alive style sheets from
17 // various documents.
19 // * It is conceptually a singleton, but given its cycle-collectable nature, we
20 // might re-create it.
22 #include "mozilla/SharedSubResourceCache.h"
23 #include "nsRefPtrHashtable.h"
24 #include "mozilla/MemoryReporting.h"
25 #include "mozilla/css/Loader.h"
27 namespace mozilla {
29 class StyleSheet;
30 class SheetLoadDataHashKey;
32 namespace css {
33 class SheetLoadData;
34 class Loader;
35 } // namespace css
37 struct SharedStyleSheetCacheTraits {
38 using Loader = css::Loader;
39 using Key = SheetLoadDataHashKey;
40 using Value = StyleSheet;
41 using LoadingValue = css::SheetLoadData;
43 static SheetLoadDataHashKey KeyFromLoadingValue(const LoadingValue& aValue) {
44 return SheetLoadDataHashKey(aValue);
48 class SharedStyleSheetCache final
49 : public SharedSubResourceCache<SharedStyleSheetCacheTraits,
50 SharedStyleSheetCache>,
51 public nsIMemoryReporter {
52 public:
53 using Base = SharedSubResourceCache<SharedStyleSheetCacheTraits,
54 SharedStyleSheetCache>;
56 NS_DECL_ISUPPORTS
57 NS_DECL_NSIMEMORYREPORTER
59 SharedStyleSheetCache();
60 void Init();
62 // This has to be static because it's also called for loaders that don't have
63 // a sheet cache (loaders that are not owned by a document).
64 static void LoadCompleted(SharedStyleSheetCache*, css::SheetLoadData&,
65 nsresult);
66 using Base::LoadCompleted;
67 static void LoadCompletedInternal(SharedStyleSheetCache*, css::SheetLoadData&,
68 nsTArray<RefPtr<css::SheetLoadData>>&);
69 static void Clear(nsIPrincipal* aForPrincipal = nullptr,
70 const nsACString* aBaseDomain = nullptr);
72 protected:
73 void InsertIfNeeded(css::SheetLoadData&);
75 ~SharedStyleSheetCache();
78 } // namespace mozilla
80 #endif