Bumping manifests a=b2g-bump
[gecko.git] / netwerk / cache2 / CacheFileUtils.h
blobea5ef373cb2952c046f5b7a6b8540981e24eda5f
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef CacheFileUtils__h__
6 #define CacheFileUtils__h__
8 #include "nsError.h"
9 #include "nsCOMPtr.h"
10 #include "nsString.h"
11 #include "nsTArray.h"
13 class nsILoadContextInfo;
14 class nsACString;
16 namespace mozilla {
17 namespace net {
18 namespace CacheFileUtils {
20 already_AddRefed<nsILoadContextInfo>
21 ParseKey(const nsCSubstring &aKey,
22 nsCSubstring *aIdEnhance = nullptr,
23 nsCSubstring *aURISpec = nullptr);
25 void
26 AppendKeyPrefix(nsILoadContextInfo *aInfo, nsACString &_retval);
28 void
29 AppendTagWithValue(nsACString & aTarget, char const aTag, nsCSubstring const & aValue);
31 nsresult
32 KeyMatchesLoadContextInfo(const nsACString &aKey,
33 nsILoadContextInfo *aInfo,
34 bool *_retval);
36 class ValidityPair {
37 public:
38 ValidityPair(uint32_t aOffset, uint32_t aLen);
40 ValidityPair& operator=(const ValidityPair& aOther);
42 // Returns true when two pairs can be merged, i.e. they do overlap or the one
43 // ends exactly where the other begins.
44 bool CanBeMerged(const ValidityPair& aOther) const;
46 // Returns true when aOffset is placed anywhere in the validity interval or
47 // exactly after its end.
48 bool IsInOrFollows(uint32_t aOffset) const;
50 // Returns true when this pair has lower offset than the other pair. In case
51 // both pairs have the same offset it returns true when this pair has a
52 // shorter length.
53 bool LessThan(const ValidityPair& aOther) const;
55 // Merges two pair into one.
56 void Merge(const ValidityPair& aOther);
58 uint32_t Offset() const { return mOffset; }
59 uint32_t Len() const { return mLen; }
61 private:
62 uint32_t mOffset;
63 uint32_t mLen;
66 class ValidityMap {
67 public:
68 // Prints pairs in the map into log.
69 void Log() const;
71 // Returns number of pairs in the map.
72 uint32_t Length() const;
74 // Adds a new pair to the map. It keeps the pairs ordered and merges pairs
75 // when possible.
76 void AddPair(uint32_t aOffset, uint32_t aLen);
78 // Removes all pairs from the map.
79 void Clear();
81 size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
83 ValidityPair& operator[](uint32_t aIdx);
85 private:
86 nsTArray<ValidityPair> mMap;
89 } // CacheFileUtils
90 } // net
91 } // mozilla
93 #endif