Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_dom_quota_quotaobject_h__ |
michael@0 | 8 | #define mozilla_dom_quota_quotaobject_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/dom/quota/QuotaCommon.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "nsDataHashtable.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "PersistenceType.h" |
michael@0 | 15 | |
michael@0 | 16 | BEGIN_QUOTA_NAMESPACE |
michael@0 | 17 | |
michael@0 | 18 | class GroupInfo; |
michael@0 | 19 | class GroupInfoPair; |
michael@0 | 20 | class OriginInfo; |
michael@0 | 21 | class QuotaManager; |
michael@0 | 22 | |
michael@0 | 23 | class QuotaObject |
michael@0 | 24 | { |
michael@0 | 25 | friend class OriginInfo; |
michael@0 | 26 | friend class QuotaManager; |
michael@0 | 27 | |
michael@0 | 28 | public: |
michael@0 | 29 | void |
michael@0 | 30 | AddRef(); |
michael@0 | 31 | |
michael@0 | 32 | void |
michael@0 | 33 | Release(); |
michael@0 | 34 | |
michael@0 | 35 | void |
michael@0 | 36 | UpdateSize(int64_t aSize); |
michael@0 | 37 | |
michael@0 | 38 | bool |
michael@0 | 39 | MaybeAllocateMoreSpace(int64_t aOffset, int32_t aCount); |
michael@0 | 40 | |
michael@0 | 41 | private: |
michael@0 | 42 | QuotaObject(OriginInfo* aOriginInfo, const nsAString& aPath, int64_t aSize) |
michael@0 | 43 | : mOriginInfo(aOriginInfo), mPath(aPath), mSize(aSize) |
michael@0 | 44 | { |
michael@0 | 45 | MOZ_COUNT_CTOR(QuotaObject); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | ~QuotaObject() |
michael@0 | 49 | { |
michael@0 | 50 | MOZ_COUNT_DTOR(QuotaObject); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | already_AddRefed<QuotaObject> |
michael@0 | 54 | LockedAddRef() |
michael@0 | 55 | { |
michael@0 | 56 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 57 | |
michael@0 | 58 | ++mRefCnt; |
michael@0 | 59 | |
michael@0 | 60 | nsRefPtr<QuotaObject> result = dont_AddRef(this); |
michael@0 | 61 | return result.forget(); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | mozilla::ThreadSafeAutoRefCnt mRefCnt; |
michael@0 | 65 | |
michael@0 | 66 | OriginInfo* mOriginInfo; |
michael@0 | 67 | nsString mPath; |
michael@0 | 68 | int64_t mSize; |
michael@0 | 69 | }; |
michael@0 | 70 | |
michael@0 | 71 | class OriginInfo MOZ_FINAL |
michael@0 | 72 | { |
michael@0 | 73 | friend class GroupInfo; |
michael@0 | 74 | friend class QuotaManager; |
michael@0 | 75 | friend class QuotaObject; |
michael@0 | 76 | |
michael@0 | 77 | public: |
michael@0 | 78 | OriginInfo(GroupInfo* aGroupInfo, const nsACString& aOrigin, uint64_t aLimit, |
michael@0 | 79 | uint64_t aUsage, int64_t aAccessTime) |
michael@0 | 80 | : mGroupInfo(aGroupInfo), mOrigin(aOrigin), mLimit(aLimit), mUsage(aUsage), |
michael@0 | 81 | mAccessTime(aAccessTime) |
michael@0 | 82 | { |
michael@0 | 83 | MOZ_COUNT_CTOR(OriginInfo); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OriginInfo) |
michael@0 | 87 | |
michael@0 | 88 | int64_t |
michael@0 | 89 | AccessTime() const |
michael@0 | 90 | { |
michael@0 | 91 | return mAccessTime; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | private: |
michael@0 | 95 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 96 | ~OriginInfo() |
michael@0 | 97 | { |
michael@0 | 98 | MOZ_COUNT_DTOR(OriginInfo); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | void |
michael@0 | 102 | LockedDecreaseUsage(int64_t aSize); |
michael@0 | 103 | |
michael@0 | 104 | void |
michael@0 | 105 | LockedUpdateAccessTime(int64_t aAccessTime) |
michael@0 | 106 | { |
michael@0 | 107 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 108 | |
michael@0 | 109 | mAccessTime = aAccessTime; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | void |
michael@0 | 113 | LockedClearOriginInfos() |
michael@0 | 114 | { |
michael@0 | 115 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 116 | |
michael@0 | 117 | mQuotaObjects.EnumerateRead(ClearOriginInfoCallback, nullptr); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | static PLDHashOperator |
michael@0 | 121 | ClearOriginInfoCallback(const nsAString& aKey, |
michael@0 | 122 | QuotaObject* aValue, void* aUserArg); |
michael@0 | 123 | |
michael@0 | 124 | nsDataHashtable<nsStringHashKey, QuotaObject*> mQuotaObjects; |
michael@0 | 125 | |
michael@0 | 126 | GroupInfo* mGroupInfo; |
michael@0 | 127 | nsCString mOrigin; |
michael@0 | 128 | uint64_t mLimit; |
michael@0 | 129 | uint64_t mUsage; |
michael@0 | 130 | int64_t mAccessTime; |
michael@0 | 131 | }; |
michael@0 | 132 | |
michael@0 | 133 | class OriginInfoLRUComparator |
michael@0 | 134 | { |
michael@0 | 135 | public: |
michael@0 | 136 | bool |
michael@0 | 137 | Equals(const OriginInfo* a, const OriginInfo* b) const |
michael@0 | 138 | { |
michael@0 | 139 | return |
michael@0 | 140 | a && b ? a->AccessTime() == b->AccessTime() : !a && !b ? true : false; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | bool |
michael@0 | 144 | LessThan(const OriginInfo* a, const OriginInfo* b) const |
michael@0 | 145 | { |
michael@0 | 146 | return a && b ? a->AccessTime() < b->AccessTime() : b ? true : false; |
michael@0 | 147 | } |
michael@0 | 148 | }; |
michael@0 | 149 | |
michael@0 | 150 | class GroupInfo MOZ_FINAL |
michael@0 | 151 | { |
michael@0 | 152 | friend class GroupInfoPair; |
michael@0 | 153 | friend class OriginInfo; |
michael@0 | 154 | friend class QuotaManager; |
michael@0 | 155 | friend class QuotaObject; |
michael@0 | 156 | |
michael@0 | 157 | public: |
michael@0 | 158 | GroupInfo(PersistenceType aPersistenceType, const nsACString& aGroup) |
michael@0 | 159 | : mPersistenceType(aPersistenceType), mGroup(aGroup), mUsage(0) |
michael@0 | 160 | { |
michael@0 | 161 | MOZ_COUNT_CTOR(GroupInfo); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GroupInfo) |
michael@0 | 165 | |
michael@0 | 166 | bool |
michael@0 | 167 | IsForPersistentStorage() const |
michael@0 | 168 | { |
michael@0 | 169 | return mPersistenceType == PERSISTENCE_TYPE_PERSISTENT; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | bool |
michael@0 | 173 | IsForTemporaryStorage() const |
michael@0 | 174 | { |
michael@0 | 175 | return mPersistenceType == PERSISTENCE_TYPE_TEMPORARY; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | private: |
michael@0 | 179 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 180 | ~GroupInfo() |
michael@0 | 181 | { |
michael@0 | 182 | MOZ_COUNT_DTOR(GroupInfo); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | already_AddRefed<OriginInfo> |
michael@0 | 186 | LockedGetOriginInfo(const nsACString& aOrigin); |
michael@0 | 187 | |
michael@0 | 188 | void |
michael@0 | 189 | LockedAddOriginInfo(OriginInfo* aOriginInfo); |
michael@0 | 190 | |
michael@0 | 191 | void |
michael@0 | 192 | LockedRemoveOriginInfo(const nsACString& aOrigin); |
michael@0 | 193 | |
michael@0 | 194 | void |
michael@0 | 195 | LockedRemoveOriginInfos(); |
michael@0 | 196 | |
michael@0 | 197 | void |
michael@0 | 198 | LockedRemoveOriginInfosForPattern(const nsACString& aPattern); |
michael@0 | 199 | |
michael@0 | 200 | bool |
michael@0 | 201 | LockedHasOriginInfos() |
michael@0 | 202 | { |
michael@0 | 203 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 204 | |
michael@0 | 205 | return !mOriginInfos.IsEmpty(); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | nsTArray<nsRefPtr<OriginInfo> > mOriginInfos; |
michael@0 | 209 | |
michael@0 | 210 | PersistenceType mPersistenceType; |
michael@0 | 211 | nsCString mGroup; |
michael@0 | 212 | uint64_t mUsage; |
michael@0 | 213 | }; |
michael@0 | 214 | |
michael@0 | 215 | class GroupInfoPair |
michael@0 | 216 | { |
michael@0 | 217 | friend class QuotaManager; |
michael@0 | 218 | |
michael@0 | 219 | public: |
michael@0 | 220 | GroupInfoPair() |
michael@0 | 221 | { |
michael@0 | 222 | MOZ_COUNT_CTOR(GroupInfoPair); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | ~GroupInfoPair() |
michael@0 | 226 | { |
michael@0 | 227 | MOZ_COUNT_DTOR(GroupInfoPair); |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | private: |
michael@0 | 231 | already_AddRefed<GroupInfo> |
michael@0 | 232 | LockedGetGroupInfo(PersistenceType aPersistenceType) |
michael@0 | 233 | { |
michael@0 | 234 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 235 | |
michael@0 | 236 | nsRefPtr<GroupInfo> groupInfo = |
michael@0 | 237 | GetGroupInfoForPersistenceType(aPersistenceType); |
michael@0 | 238 | return groupInfo.forget(); |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | void |
michael@0 | 242 | LockedSetGroupInfo(GroupInfo* aGroupInfo) |
michael@0 | 243 | { |
michael@0 | 244 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 245 | |
michael@0 | 246 | nsRefPtr<GroupInfo>& groupInfo = |
michael@0 | 247 | GetGroupInfoForPersistenceType(aGroupInfo->mPersistenceType); |
michael@0 | 248 | groupInfo = aGroupInfo; |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | void |
michael@0 | 252 | LockedClearGroupInfo(PersistenceType aPersistenceType) |
michael@0 | 253 | { |
michael@0 | 254 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 255 | |
michael@0 | 256 | nsRefPtr<GroupInfo>& groupInfo = |
michael@0 | 257 | GetGroupInfoForPersistenceType(aPersistenceType); |
michael@0 | 258 | groupInfo = nullptr; |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | bool |
michael@0 | 262 | LockedHasGroupInfos() |
michael@0 | 263 | { |
michael@0 | 264 | AssertCurrentThreadOwnsQuotaMutex(); |
michael@0 | 265 | |
michael@0 | 266 | return mPersistentStorageGroupInfo || mTemporaryStorageGroupInfo; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | nsRefPtr<GroupInfo>& |
michael@0 | 270 | GetGroupInfoForPersistenceType(PersistenceType aPersistenceType); |
michael@0 | 271 | |
michael@0 | 272 | nsRefPtr<GroupInfo> mPersistentStorageGroupInfo; |
michael@0 | 273 | nsRefPtr<GroupInfo> mTemporaryStorageGroupInfo; |
michael@0 | 274 | }; |
michael@0 | 275 | |
michael@0 | 276 | END_QUOTA_NAMESPACE |
michael@0 | 277 | |
michael@0 | 278 | #endif // mozilla_dom_quota_quotaobject_h__ |