dom/quota/OriginCollection.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/quota/OriginCollection.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_quota_origincollection_h__
    1.11 +#define mozilla_dom_quota_origincollection_h__
    1.12 +
    1.13 +#include "mozilla/dom/quota/QuotaCommon.h"
    1.14 +
    1.15 +#include "nsHashKeys.h"
    1.16 +#include "nsTHashtable.h"
    1.17 +
    1.18 +#include "Utilities.h"
    1.19 +
    1.20 +BEGIN_QUOTA_NAMESPACE
    1.21 +
    1.22 +class OriginCollection
    1.23 +{
    1.24 +public:
    1.25 +  bool
    1.26 +  ContainsPattern(const nsACString& aPattern)
    1.27 +  {
    1.28 +    return mPatterns.Contains(aPattern);
    1.29 +  }
    1.30 +
    1.31 +  void
    1.32 +  AddPattern(const nsACString& aPattern)
    1.33 +  {
    1.34 +    MOZ_ASSERT(!mOrigins.Count());
    1.35 +    MOZ_ASSERT(!ContainsPattern(aPattern));
    1.36 +    mPatterns.AppendElement(aPattern);
    1.37 +  }
    1.38 +
    1.39 +  bool
    1.40 +  ContainsOrigin(const nsACString& aOrigin)
    1.41 +  {
    1.42 +    for (uint32_t index = 0; index < mPatterns.Length(); index++) {
    1.43 +      if (PatternMatchesOrigin(mPatterns[index], aOrigin)) {
    1.44 +        return true;
    1.45 +      }
    1.46 +    }
    1.47 +
    1.48 +    return mOrigins.GetEntry(aOrigin);
    1.49 +  }
    1.50 +
    1.51 +  void
    1.52 +  AddOrigin(const nsACString& aOrigin)
    1.53 +  {
    1.54 +    MOZ_ASSERT(!ContainsOrigin(aOrigin));
    1.55 +    mOrigins.PutEntry(aOrigin);
    1.56 +  }
    1.57 +
    1.58 +private:
    1.59 +  nsTArray<nsCString> mPatterns;
    1.60 +  nsTHashtable<nsCStringHashKey> mOrigins;
    1.61 +};
    1.62 +
    1.63 +END_QUOTA_NAMESPACE
    1.64 +
    1.65 +#endif // mozilla_dom_quota_origincollection_h__

mercurial