OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 // cookies with low-priority. Then, if cookies still need to be removed, | 1894 // cookies with low-priority. Then, if cookies still need to be removed, |
1895 // bump the quota and remove low- and medium-priority. Then, if cookies | 1895 // bump the quota and remove low- and medium-priority. Then, if cookies |
1896 // _still_ need to be removed, bump the quota and remove cookies with | 1896 // _still_ need to be removed, bump the quota and remove cookies with |
1897 // any priority. | 1897 // any priority. |
1898 const size_t kQuotas[3] = {kDomainCookiesQuotaLow, | 1898 const size_t kQuotas[3] = {kDomainCookiesQuotaLow, |
1899 kDomainCookiesQuotaMedium, | 1899 kDomainCookiesQuotaMedium, |
1900 kDomainCookiesQuotaHigh}; | 1900 kDomainCookiesQuotaHigh}; |
1901 size_t quota = 0; | 1901 size_t quota = 0; |
1902 for (size_t i = 0; i < arraysize(kQuotas) && purge_goal > 0; i++) { | 1902 for (size_t i = 0; i < arraysize(kQuotas) && purge_goal > 0; i++) { |
1903 quota += kQuotas[i]; | 1903 quota += kQuotas[i]; |
1904 size_t just_deleted = | 1904 size_t just_deleted = PurgeLeastRecentMatches( |
1905 PurgeLeastRecentMatches(cookie_its, static_cast<CookiePriority>(i), | 1905 cookie_its, static_cast<CookiePriority>(i), quota, purge_goal); |
1906 quota, purge_goal, safe_date); | |
1907 DCHECK_LE(just_deleted, purge_goal); | 1906 DCHECK_LE(just_deleted, purge_goal); |
1908 purge_goal -= just_deleted; | 1907 purge_goal -= just_deleted; |
1909 num_deleted += just_deleted; | 1908 num_deleted += just_deleted; |
1910 } | 1909 } |
1911 | 1910 |
1912 DCHECK_EQ(0U, purge_goal); | 1911 DCHECK_EQ(0U, purge_goal); |
1913 } | 1912 } |
1914 } | 1913 } |
1915 | 1914 |
1916 // Collect garbage for everything. With firefox style we want to preserve | 1915 // Collect garbage for everything. With firefox style we want to preserve |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 } | 1951 } |
1953 } | 1952 } |
1954 } | 1953 } |
1955 | 1954 |
1956 return num_deleted; | 1955 return num_deleted; |
1957 } | 1956 } |
1958 | 1957 |
1959 size_t CookieMonster::PurgeLeastRecentMatches(CookieItVector* cookies, | 1958 size_t CookieMonster::PurgeLeastRecentMatches(CookieItVector* cookies, |
1960 CookiePriority priority, | 1959 CookiePriority priority, |
1961 size_t to_protect, | 1960 size_t to_protect, |
1962 size_t purge_goal, | 1961 size_t purge_goal) { |
1963 const base::Time& safe_date) { | |
1964 DCHECK(thread_checker_.CalledOnValidThread()); | 1962 DCHECK(thread_checker_.CalledOnValidThread()); |
1965 | 1963 |
1966 // Find the first protected cookie by walking down from the end of the list | 1964 // Find the first protected cookie by walking down from the end of the list |
1967 // cookie list (most-recently accessed) until |to_protect| cookies that match | 1965 // cookie list (most-recently accessed) until |to_protect| cookies that match |
1968 // |priority| are found. | 1966 // |priority| are found. |
1969 size_t protection_boundary = cookies->size(); | 1967 size_t protection_boundary = cookies->size(); |
1970 while (to_protect > 0 && protection_boundary > 0) { | 1968 while (to_protect > 0 && protection_boundary > 0) { |
1971 protection_boundary--; | 1969 protection_boundary--; |
1972 if (cookies->at(protection_boundary)->second->Priority() <= priority) | 1970 if (cookies->at(protection_boundary)->second->Priority() <= priority) |
1973 to_protect--; | 1971 to_protect--; |
1974 } | 1972 } |
1975 | 1973 |
1976 // Now, walk up from the beginning of the list (least-recently accessed) until | 1974 // Now, walk up from the beginning of the list (least-recently accessed) until |
1977 // |purge_goal| cookies are removed, or the iterator hits | 1975 // |purge_goal| cookies are removed, or the iterator hits |
1978 // |protection_boundary|. | 1976 // |protection_boundary|. |
1979 size_t removed = 0; | 1977 size_t removed = 0; |
1980 size_t current = 0; | 1978 size_t current = 0; |
1981 while (removed < purge_goal && current < protection_boundary) { | 1979 while (removed < purge_goal && current < protection_boundary) { |
1982 if (cookies->at(current)->second->Priority() <= priority) { | 1980 if (cookies->at(current)->second->Priority() <= priority) { |
1983 InternalDeleteCookie( | 1981 InternalDeleteCookie(cookies->at(current), true, |
1984 cookies->at(current), true, | 1982 DELETE_COOKIE_EVICTED_DOMAIN); |
1985 cookies->at(current)->second->LastAccessDate() > safe_date | |
1986 ? DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE | |
1987 : DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE); | |
1988 cookies->erase(cookies->begin() + current); | 1983 cookies->erase(cookies->begin() + current); |
1989 removed++; | 1984 removed++; |
1990 | 1985 |
1991 // The call to 'erase' above shifts the contents of the vector, but | 1986 // The call to 'erase' above shifts the contents of the vector, but |
1992 // doesn't shift |protection_boundary|. Decrement that here to ensure that | 1987 // doesn't shift |protection_boundary|. Decrement that here to ensure that |
1993 // the correct set of cookies is protected. | 1988 // the correct set of cookies is protected. |
1994 protection_boundary--; | 1989 protection_boundary--; |
1995 } else { | 1990 } else { |
1996 current++; | 1991 current++; |
1997 } | 1992 } |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2339 it != hook_map_.end(); ++it) { | 2334 it != hook_map_.end(); ++it) { |
2340 std::pair<GURL, std::string> key = it->first; | 2335 std::pair<GURL, std::string> key = it->first; |
2341 if (cookie.IncludeForRequestURL(key.first, opts) && | 2336 if (cookie.IncludeForRequestURL(key.first, opts) && |
2342 cookie.Name() == key.second) { | 2337 cookie.Name() == key.second) { |
2343 it->second->Notify(cookie, removed); | 2338 it->second->Notify(cookie, removed); |
2344 } | 2339 } |
2345 } | 2340 } |
2346 } | 2341 } |
2347 | 2342 |
2348 } // namespace net | 2343 } // namespace net |
OLD | NEW |