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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 323 |
324 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) | 324 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) |
325 : initialized_(false), | 325 : initialized_(false), |
326 loaded_(false), | 326 loaded_(false), |
327 store_(store), | 327 store_(store), |
328 last_access_threshold_( | 328 last_access_threshold_( |
329 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), | 329 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), |
330 delegate_(delegate), | 330 delegate_(delegate), |
331 last_statistic_record_time_(Time::Now()), | 331 last_statistic_record_time_(Time::Now()), |
332 keep_expired_cookies_(false), | 332 keep_expired_cookies_(false), |
333 persist_session_cookies_(false), | 333 persist_session_cookies_(false) { |
334 priority_aware_garbage_collection_(false) { | |
335 InitializeHistograms(); | 334 InitializeHistograms(); |
336 SetDefaultCookieableSchemes(); | 335 SetDefaultCookieableSchemes(); |
337 } | 336 } |
338 | 337 |
339 CookieMonster::CookieMonster(PersistentCookieStore* store, | 338 CookieMonster::CookieMonster(PersistentCookieStore* store, |
340 Delegate* delegate, | 339 Delegate* delegate, |
341 int last_access_threshold_milliseconds) | 340 int last_access_threshold_milliseconds) |
342 : initialized_(false), | 341 : initialized_(false), |
343 loaded_(false), | 342 loaded_(false), |
344 store_(store), | 343 store_(store), |
345 last_access_threshold_(base::TimeDelta::FromMilliseconds( | 344 last_access_threshold_(base::TimeDelta::FromMilliseconds( |
346 last_access_threshold_milliseconds)), | 345 last_access_threshold_milliseconds)), |
347 delegate_(delegate), | 346 delegate_(delegate), |
348 last_statistic_record_time_(base::Time::Now()), | 347 last_statistic_record_time_(base::Time::Now()), |
349 keep_expired_cookies_(false), | 348 keep_expired_cookies_(false), |
350 persist_session_cookies_(false), | 349 persist_session_cookies_(false) { |
351 priority_aware_garbage_collection_(false) { | |
352 InitializeHistograms(); | 350 InitializeHistograms(); |
353 SetDefaultCookieableSchemes(); | 351 SetDefaultCookieableSchemes(); |
354 } | 352 } |
355 | 353 |
356 | 354 |
357 // Task classes for queueing the coming request. | 355 // Task classes for queueing the coming request. |
358 | 356 |
359 class CookieMonster::CookieMonsterTask | 357 class CookieMonster::CookieMonsterTask |
360 : public base::RefCountedThreadSafe<CookieMonsterTask> { | 358 : public base::RefCountedThreadSafe<CookieMonsterTask> { |
361 public: | 359 public: |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 CookieMonster* CookieMonster::GetCookieMonster() { | 1410 CookieMonster* CookieMonster::GetCookieMonster() { |
1413 return this; | 1411 return this; |
1414 } | 1412 } |
1415 | 1413 |
1416 // This function must be called before the CookieMonster is used. | 1414 // This function must be called before the CookieMonster is used. |
1417 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { | 1415 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { |
1418 DCHECK(!initialized_); | 1416 DCHECK(!initialized_); |
1419 persist_session_cookies_ = persist_session_cookies; | 1417 persist_session_cookies_ = persist_session_cookies; |
1420 } | 1418 } |
1421 | 1419 |
1422 // This function must be called before the CookieMonster is used. | |
1423 void CookieMonster::SetPriorityAwareGarbageCollection( | |
1424 bool priority_aware_garbage_collection) { | |
1425 DCHECK(!initialized_); | |
1426 priority_aware_garbage_collection_ = priority_aware_garbage_collection; | |
1427 } | |
1428 | |
1429 void CookieMonster::SetForceKeepSessionState() { | 1420 void CookieMonster::SetForceKeepSessionState() { |
1430 if (store_.get()) { | 1421 if (store_.get()) { |
1431 store_->SetForceKeepSessionState(); | 1422 store_->SetForceKeepSessionState(); |
1432 } | 1423 } |
1433 } | 1424 } |
1434 | 1425 |
1435 CookieMonster::~CookieMonster() { | 1426 CookieMonster::~CookieMonster() { |
1436 DeleteAll(false); | 1427 DeleteAll(false); |
1437 } | 1428 } |
1438 | 1429 |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1961 // Round 1: consider low-priority cookies only: evict least-recently | 1952 // Round 1: consider low-priority cookies only: evict least-recently |
1962 // accessed, while protecting quota[0] of these from deletion. | 1953 // accessed, while protecting quota[0] of these from deletion. |
1963 // Round 2: consider {low, medium}-priority cookies, evict least-recently | 1954 // Round 2: consider {low, medium}-priority cookies, evict least-recently |
1964 // accessed, while protecting quota[0] + quota[1]. | 1955 // accessed, while protecting quota[0] + quota[1]. |
1965 // Round 3: consider all cookies, evict least-recently accessed. | 1956 // Round 3: consider all cookies, evict least-recently accessed. |
1966 size_t accumulated_quota = 0; | 1957 size_t accumulated_quota = 0; |
1967 CookieItVector::iterator it_purge_begin = it_bdd[0]; | 1958 CookieItVector::iterator it_purge_begin = it_bdd[0]; |
1968 for (int i = 0; i < 3 && purge_goal > 0; ++i) { | 1959 for (int i = 0; i < 3 && purge_goal > 0; ++i) { |
1969 accumulated_quota += quota[i]; | 1960 accumulated_quota += quota[i]; |
1970 | 1961 |
1971 // If we are not using priority, only do Round 3. This reproduces the | |
1972 // old way of indiscriminately purging least-recently accessed cookies. | |
1973 if (!priority_aware_garbage_collection_ && i < 2) | |
1974 continue; | |
1975 | |
1976 size_t num_considered = it_bdd[i + 1] - it_purge_begin; | 1962 size_t num_considered = it_bdd[i + 1] - it_purge_begin; |
1977 if (num_considered <= accumulated_quota) | 1963 if (num_considered <= accumulated_quota) |
1978 continue; | 1964 continue; |
1979 | 1965 |
1980 // Number of cookies that will be purged in this round. | 1966 // Number of cookies that will be purged in this round. |
1981 size_t round_goal = | 1967 size_t round_goal = |
1982 std::min(purge_goal, num_considered - accumulated_quota); | 1968 std::min(purge_goal, num_considered - accumulated_quota); |
1983 purge_goal -= round_goal; | 1969 purge_goal -= round_goal; |
1984 | 1970 |
1985 SortLeastRecentlyAccessed(it_purge_begin, it_bdd[i + 1], round_goal); | 1971 SortLeastRecentlyAccessed(it_purge_begin, it_bdd[i + 1], round_goal); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2270 | 2256 |
2271 // The system resolution is not high enough, so we can have multiple | 2257 // The system resolution is not high enough, so we can have multiple |
2272 // set cookies that result in the same system time. When this happens, we | 2258 // set cookies that result in the same system time. When this happens, we |
2273 // increment by one Time unit. Let's hope computers don't get too fast. | 2259 // increment by one Time unit. Let's hope computers don't get too fast. |
2274 Time CookieMonster::CurrentTime() { | 2260 Time CookieMonster::CurrentTime() { |
2275 return std::max(Time::Now(), | 2261 return std::max(Time::Now(), |
2276 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2262 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
2277 } | 2263 } |
2278 | 2264 |
2279 } // namespace net | 2265 } // namespace net |
OLD | NEW |