CookiePrivateStorage.cpp (1425B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "CookiePrivateStorage.h" 7 #include "Cookie.h" 8 9 namespace mozilla { 10 namespace net { 11 12 // static 13 already_AddRefed<CookiePrivateStorage> CookiePrivateStorage::Create() { 14 RefPtr<CookiePrivateStorage> storage = new CookiePrivateStorage(); 15 storage->Init(); 16 17 return storage.forget(); 18 } 19 20 void CookiePrivateStorage::StaleCookies( 21 const nsTArray<RefPtr<Cookie>>& aCookieList, int64_t aCurrentTimeInUsec) { 22 int32_t count = aCookieList.Length(); 23 for (int32_t i = 0; i < count; ++i) { 24 Cookie* cookie = aCookieList.ElementAt(i); 25 26 if (cookie->IsStale()) { 27 cookie->SetLastAccessedInUSec(aCurrentTimeInUsec); 28 } 29 } 30 } 31 32 // purges expired and old cookies in a batch operation. 33 already_AddRefed<nsIArray> CookiePrivateStorage::PurgeCookies( 34 int64_t aCurrentTimeInUsec, uint16_t aMaxNumberOfCookies, 35 int64_t aCookiePurgeAge) { 36 RefPtr<CookiePrivateStorage> self = this; 37 return PurgeCookiesWithCallbacks( 38 aCurrentTimeInUsec, aMaxNumberOfCookies, aCookiePurgeAge, 39 [self](const CookieListIter& iter) { self->RemoveCookieFromList(iter); }, 40 nullptr); 41 } 42 43 } // namespace net 44 } // namespace mozilla