191682 patch by dwitte@stanford.edu r=biesi sr=darin Cookie manager uses O(2n^2) algorithm to display cookies

This commit is contained in:
cbiesinger%web.de 2003-02-24 22:02:44 +00:00
Родитель a97874bfb4
Коммит 7f30fa0cea
3 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -56,13 +56,23 @@ class nsCookieEnumerator : public nsISimpleEnumerator
NS_DECL_ISUPPORTS
nsCookieEnumerator() : mCookieCount(0)
// note: mCookieCount is initialized just once in the ctor. While it might
// appear that the cookie list can change while the cookiemanager is running,
// the cookieservice is actually on the same thread, so it can't. Note that
// a new nsCookieEnumerator is created each time the cookiemanager is loaded.
// So we only need to get the count once. If we ever change the cookieservice to
// run on a different thread, then something to the effect of a lock will be
// required. see bug 191682 for details.
// note also that COOKIE_Count() removes expired cookies from the list before
// returning the count, so that they're not displayed in the cookiemanager.
nsCookieEnumerator() : mCookieIndex(0),
mCookieCount(COOKIE_Count())
{
}
NS_IMETHOD HasMoreElements(PRBool *result)
{
*result = COOKIE_Count() > mCookieCount;
*result = mCookieCount > mCookieIndex;
return NS_OK;
}
@ -78,7 +88,7 @@ class nsCookieEnumerator : public nsISimpleEnumerator
nsCookieStatus status;
nsCookiePolicy policy;
nsresult rv = COOKIE_Enumerate
(mCookieCount++, name, value, isDomain, host, path, isSecure, expires,
(mCookieIndex++, name, value, &isDomain, host, path, &isSecure, &expires,
status, policy);
if (NS_SUCCEEDED(rv)) {
nsICookie *cookie =
@ -97,6 +107,7 @@ class nsCookieEnumerator : public nsISimpleEnumerator
}
protected:
PRInt32 mCookieIndex;
PRInt32 mCookieCount;
};

Просмотреть файл

@ -1957,12 +1957,12 @@ COOKIE_Enumerate (PRInt32 count, nsACString &name, nsACString &value, PRBool &is
nsACString &host, nsACString &path, PRBool &isSecure, PRUint64 &expires,
nsCookieStatus &status, nsCookiePolicy &policy)
{
if (count > COOKIE_Count()) {
if (!cookie_list) {
return NS_ERROR_FAILURE;
}
cookie_CookieStruct *cookie;
NS_ASSERTION(count >= 0 && count < cookie_list->Count(), "bad cookie index");
if (count < 0 || count >= cookie_list->Count()) {
NS_ERROR("bad cookie index");
return NS_ERROR_UNEXPECTED;
}
cookie = NS_STATIC_CAST(cookie_CookieStruct*, cookie_list->ElementAt(count));

Просмотреть файл

@ -199,6 +199,7 @@ function loadCookies() {
var showPolicyField = false;
while (enumerator.hasMoreElements()) {
var nextCookie = enumerator.getNext();
if (!nextCookie) break;
nextCookie = nextCookie.QueryInterface(Components.interfaces.nsICookie);
var host = nextCookie.host;
if (nextCookie.policy != nsICookie.POLICY_UNKNOWN) {