dom/quota/OriginCollection.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:2a9e0c2673c0
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_dom_quota_origincollection_h__
8 #define mozilla_dom_quota_origincollection_h__
9
10 #include "mozilla/dom/quota/QuotaCommon.h"
11
12 #include "nsHashKeys.h"
13 #include "nsTHashtable.h"
14
15 #include "Utilities.h"
16
17 BEGIN_QUOTA_NAMESPACE
18
19 class OriginCollection
20 {
21 public:
22 bool
23 ContainsPattern(const nsACString& aPattern)
24 {
25 return mPatterns.Contains(aPattern);
26 }
27
28 void
29 AddPattern(const nsACString& aPattern)
30 {
31 MOZ_ASSERT(!mOrigins.Count());
32 MOZ_ASSERT(!ContainsPattern(aPattern));
33 mPatterns.AppendElement(aPattern);
34 }
35
36 bool
37 ContainsOrigin(const nsACString& aOrigin)
38 {
39 for (uint32_t index = 0; index < mPatterns.Length(); index++) {
40 if (PatternMatchesOrigin(mPatterns[index], aOrigin)) {
41 return true;
42 }
43 }
44
45 return mOrigins.GetEntry(aOrigin);
46 }
47
48 void
49 AddOrigin(const nsACString& aOrigin)
50 {
51 MOZ_ASSERT(!ContainsOrigin(aOrigin));
52 mOrigins.PutEntry(aOrigin);
53 }
54
55 private:
56 nsTArray<nsCString> mPatterns;
57 nsTHashtable<nsCStringHashKey> mOrigins;
58 };
59
60 END_QUOTA_NAMESPACE
61
62 #endif // mozilla_dom_quota_origincollection_h__

mercurial