| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 namespace net { | 69 namespace net { |
| 70 | 70 |
| 71 // Cookie garbage collection thresholds. Based off of the Mozilla defaults. | 71 // Cookie garbage collection thresholds. Based off of the Mozilla defaults. |
| 72 // It might seem scary to have a high purge value, but really it's not. You | 72 // It might seem scary to have a high purge value, but really it's not. You |
| 73 // just make sure that you increase the max to cover the increase in purge, | 73 // just make sure that you increase the max to cover the increase in purge, |
| 74 // and we would have been purging the same amount of cookies. We're just | 74 // and we would have been purging the same amount of cookies. We're just |
| 75 // going through the garbage collection process less often. | 75 // going through the garbage collection process less often. |
| 76 static const size_t kNumCookiesPerHost = 70; // ~50 cookies | 76 static const size_t kNumCookiesPerHost = 70; // ~50 cookies |
| 77 static const size_t kNumCookiesPerHostPurge = 20; | 77 static const size_t kNumCookiesPerHostPurge = 20; |
| 78 static const size_t kNumCookiesTotal = 1100; // ~1000 cookies | 78 static const size_t kNumCookiesTotal = 50500; // ~50000 cookies |
| 79 static const size_t kNumCookiesTotalPurge = 100; | 79 static const size_t kNumCookiesTotalPurge = 500; |
| 80 | 80 |
| 81 // Default minimum delay after updating a cookie's LastAccessDate before we | 81 // Default minimum delay after updating a cookie's LastAccessDate before we |
| 82 // will update it again. | 82 // will update it again. |
| 83 static const int kDefaultAccessUpdateThresholdSeconds = 60; | 83 static const int kDefaultAccessUpdateThresholdSeconds = 60; |
| 84 | 84 |
| 85 // static | 85 // static |
| 86 bool CookieMonster::enable_file_scheme_ = false; | 86 bool CookieMonster::enable_file_scheme_ = false; |
| 87 | 87 |
| 88 // static | 88 // static |
| 89 void CookieMonster::EnableFileScheme() { | 89 void CookieMonster::EnableFileScheme() { |
| 90 enable_file_scheme_ = true; | 90 enable_file_scheme_ = true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 CookieMonster::CookieMonster() | 93 CookieMonster::CookieMonster() |
| 94 : initialized_(false), | 94 : initialized_(false), |
| 95 store_(NULL), | 95 store_(NULL), |
| 96 last_access_threshold_( | 96 last_access_threshold_( |
| 97 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)) { | 97 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)) { |
| 98 } | 98 } |
| 99 | 99 |
| 100 CookieMonster::CookieMonster(PersistentCookieStore* store) | 100 CookieMonster::CookieMonster(PersistentCookieStore* store) |
| 101 : initialized_(false), | 101 : initialized_(false), |
| 102 store_(store), | 102 store_(store), |
| 103 last_access_threshold_( | 103 last_access_threshold_( |
| 104 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)) { | 104 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)) { |
| 105 } | 105 } |
| 106 | 106 |
| 107 CookieMonster::~CookieMonster() { | 107 CookieMonster::~CookieMonster() { |
| 108 GarbageCollectExpired(Time::Now(), |
| 109 CookieMapItPair(cookies_.begin(), cookies_.end()), |
| 110 NULL); |
| 108 DeleteAll(false); | 111 DeleteAll(false); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void CookieMonster::InitStore() { | 114 void CookieMonster::InitStore() { |
| 112 DCHECK(store_) << "Store must exist to initialize"; | 115 DCHECK(store_) << "Store must exist to initialize"; |
| 113 | 116 |
| 114 // Initialize the store and sync in any saved persistent cookies. We don't | 117 // Initialize the store and sync in any saved persistent cookies. We don't |
| 115 // care if it's expired, insert it so it can be garbage collected, removed, | 118 // care if it's expired, insert it so it can be garbage collected, removed, |
| 116 // and sync'd. | 119 // and sync'd. |
| 117 std::vector<KeyedCanonicalCookie> cookies; | 120 std::vector<KeyedCanonicalCookie> cookies; |
| 118 // Reserve space for the maximum amount of cookies a database should have. | |
| 119 // This prevents multiple vector growth / copies as we append cookies. | |
| 120 cookies.reserve(kNumCookiesTotal); | |
| 121 store_->Load(&cookies); | 121 store_->Load(&cookies); |
| 122 for (std::vector<KeyedCanonicalCookie>::const_iterator it = cookies.begin(); | 122 for (std::vector<KeyedCanonicalCookie>::const_iterator it = cookies.begin(); |
| 123 it != cookies.end(); ++it) { | 123 it != cookies.end(); ++it) { |
| 124 InternalInsertCookie(it->first, it->second, false); | 124 InternalInsertCookie(it->first, it->second, false); |
| 125 } | 125 } |
| 126 GarbageCollectExpired(Time::Now(), |
| 127 CookieMapItPair(cookies_.begin(), cookies_.end()), |
| 128 NULL); |
| 129 |
| 126 } | 130 } |
| 127 | 131 |
| 128 // The system resolution is not high enough, so we can have multiple | 132 // The system resolution is not high enough, so we can have multiple |
| 129 // set cookies that result in the same system time. When this happens, we | 133 // set cookies that result in the same system time. When this happens, we |
| 130 // increment by one Time unit. Let's hope computers don't get too fast. | 134 // increment by one Time unit. Let's hope computers don't get too fast. |
| 131 Time CookieMonster::CurrentTime() { | 135 Time CookieMonster::CurrentTime() { |
| 132 return std::max(Time::Now(), | 136 return std::max(Time::Now(), |
| 133 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 137 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
| 134 } | 138 } |
| 135 | 139 |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 } | 1117 } |
| 1114 | 1118 |
| 1115 std::string CookieMonster::CanonicalCookie::DebugString() const { | 1119 std::string CookieMonster::CanonicalCookie::DebugString() const { |
| 1116 return StringPrintf("name: %s value: %s path: %s creation: %llu", | 1120 return StringPrintf("name: %s value: %s path: %s creation: %llu", |
| 1117 name_.c_str(), value_.c_str(), path_.c_str(), | 1121 name_.c_str(), value_.c_str(), path_.c_str(), |
| 1118 creation_date_.ToTimeT()); | 1122 creation_date_.ToTimeT()); |
| 1119 } | 1123 } |
| 1120 | 1124 |
| 1121 } // namespace | 1125 } // namespace |
| 1122 | 1126 |
| OLD | NEW |