Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Brought to you by the letter D and the number 2. | 5 // Brought to you by the letter D and the number 2. |
| 6 | 6 |
| 7 #ifndef NET_BASE_COOKIE_MONSTER_H_ | 7 #ifndef NET_BASE_COOKIE_MONSTER_H_ |
| 8 #define NET_BASE_COOKIE_MONSTER_H_ | 8 #define NET_BASE_COOKIE_MONSTER_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/histogram.h" | |
| 16 #include "base/lock.h" | 17 #include "base/lock.h" |
| 17 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
| 18 #include "base/scoped_ptr.h" | 19 #include "base/scoped_ptr.h" |
| 19 #include "base/time.h" | 20 #include "base/time.h" |
| 20 #include "net/base/cookie_store.h" | 21 #include "net/base/cookie_store.h" |
| 21 | 22 |
| 22 class GURL; | 23 class GURL; |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 | 26 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 CookieMonster(PersistentCookieStore* store, Delegate* delegate); | 63 CookieMonster(PersistentCookieStore* store, Delegate* delegate); |
| 63 | 64 |
| 64 #ifdef UNIT_TEST | 65 #ifdef UNIT_TEST |
| 65 CookieMonster(PersistentCookieStore* store, | 66 CookieMonster(PersistentCookieStore* store, |
| 66 Delegate* delegate, | 67 Delegate* delegate, |
| 67 int last_access_threshold_milliseconds) | 68 int last_access_threshold_milliseconds) |
| 68 : initialized_(false), | 69 : initialized_(false), |
| 69 store_(store), | 70 store_(store), |
| 70 last_access_threshold_(base::TimeDelta::FromMilliseconds( | 71 last_access_threshold_(base::TimeDelta::FromMilliseconds( |
| 71 last_access_threshold_milliseconds)), | 72 last_access_threshold_milliseconds)), |
| 72 delegate_(delegate) { | 73 delegate_(delegate), |
| 74 last_statistic_record_time_(base::Time::Now()) { | |
| 73 SetDefaultCookieableSchemes(); | 75 SetDefaultCookieableSchemes(); |
| 74 } | 76 } |
| 75 #endif | 77 #endif |
| 76 | 78 |
| 77 // Parse the string with the cookie time (very forgivingly). | 79 // Parse the string with the cookie time (very forgivingly). |
| 78 static base::Time ParseCookieTime(const std::string& time_string); | 80 static base::Time ParseCookieTime(const std::string& time_string); |
| 79 | 81 |
| 80 // Returns true if a domain string represents a host-only cookie, | 82 // Returns true if a domain string represents a host-only cookie, |
| 81 // i.e. it doesn't begin with a leading '.' character. | 83 // i.e. it doesn't begin with a leading '.' character. |
| 82 static bool DomainIsHostOnly(const std::string& domain_string); | 84 static bool DomainIsHostOnly(const std::string& domain_string); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 | 225 |
| 224 // Helper function that sets a canonical cookie, deleting equivalents and | 226 // Helper function that sets a canonical cookie, deleting equivalents and |
| 225 // performing garbage collection. | 227 // performing garbage collection. |
| 226 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, | 228 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, |
| 227 const std::string& cookie_domain, | 229 const std::string& cookie_domain, |
| 228 const base::Time& creation_time, | 230 const base::Time& creation_time, |
| 229 const CookieOptions& options); | 231 const CookieOptions& options); |
| 230 | 232 |
| 231 void InternalUpdateCookieAccessTime(CanonicalCookie* cc); | 233 void InternalUpdateCookieAccessTime(CanonicalCookie* cc); |
| 232 | 234 |
| 233 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store); | 235 enum DeletionCause { kDeleteCookieExplicit, |
|
darin (slow to review)
2010/07/02 16:35:00
"Though the style guide says to use kConstantNamin
| |
| 236 kDeleteCookieOverwrite, | |
| 237 kDeleteCookieExpired, | |
| 238 kDeleteCookieEvicted, | |
| 239 kDeleteCookieDuplicateInBackingStore, | |
| 240 kDeleteCookieDontRecord, | |
| 241 kDeleteCookieLastEntry = kDeleteCookieDontRecord }; | |
| 242 | |
| 243 // |deletion_cause| argument is for collecting statistics. | |
| 244 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store, | |
| 245 DeletionCause deletion_cause); | |
| 234 | 246 |
| 235 // If the number of cookies for host |key|, or globally, are over preset | 247 // If the number of cookies for host |key|, or globally, are over preset |
| 236 // maximums, garbage collects, first for the host and then globally, as | 248 // maximums, garbage collects, first for the host and then globally, as |
| 237 // described by GarbageCollectRange(). The limits can be found as constants | 249 // described by GarbageCollectRange(). The limits can be found as constants |
| 238 // at the top of the function body. | 250 // at the top of the function body. |
| 239 // | 251 // |
| 240 // Returns the number of cookies deleted (useful for debugging). | 252 // Returns the number of cookies deleted (useful for debugging). |
| 241 int GarbageCollect(const base::Time& current, const std::string& key); | 253 int GarbageCollect(const base::Time& current, const std::string& key); |
| 242 | 254 |
| 243 // Deletes all expired cookies in |itpair|; | 255 // Deletes all expired cookies in |itpair|; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 255 // all expired cookies in |itpair|. If |cookie_its| is non-NULL, it is | 267 // all expired cookies in |itpair|. If |cookie_its| is non-NULL, it is |
| 256 // populated with all the non-expired cookies from |itpair|. | 268 // populated with all the non-expired cookies from |itpair|. |
| 257 // | 269 // |
| 258 // Returns the number of cookies deleted. | 270 // Returns the number of cookies deleted. |
| 259 int GarbageCollectExpired(const base::Time& current, | 271 int GarbageCollectExpired(const base::Time& current, |
| 260 const CookieMapItPair& itpair, | 272 const CookieMapItPair& itpair, |
| 261 std::vector<CookieMap::iterator>* cookie_its); | 273 std::vector<CookieMap::iterator>* cookie_its); |
| 262 | 274 |
| 263 bool HasCookieableScheme(const GURL& url); | 275 bool HasCookieableScheme(const GURL& url); |
| 264 | 276 |
| 277 // Statistics support | |
| 278 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. | |
| 279 static const int kRecordStatisticsIntervalSeconds = 10 * 60; | |
| 280 | |
| 281 // This function should be called repeatedly, and will record | |
| 282 // statistics if a sufficient time period has passed. | |
| 283 void RecordPeriodicStats(const base::Time ¤t_time); | |
|
eroman
2010/06/21 18:22:43
style nit: |const base::Time& current_time|
| |
| 284 | |
| 265 CookieMap cookies_; | 285 CookieMap cookies_; |
| 266 | 286 |
| 267 // Indicates whether the cookie store has been initialized. This happens | 287 // Indicates whether the cookie store has been initialized. This happens |
| 268 // lazily in InitStoreIfNecessary(). | 288 // lazily in InitStoreIfNecessary(). |
| 269 bool initialized_; | 289 bool initialized_; |
| 270 | 290 |
| 271 scoped_refptr<PersistentCookieStore> store_; | 291 scoped_refptr<PersistentCookieStore> store_; |
| 272 | 292 |
| 273 // The resolution of our time isn't enough, so we do something | 293 // The resolution of our time isn't enough, so we do something |
| 274 // ugly and increment when we've seen the same time twice. | 294 // ugly and increment when we've seen the same time twice. |
| 275 base::Time CurrentTime(); | 295 base::Time CurrentTime(); |
| 276 base::Time last_time_seen_; | 296 base::Time last_time_seen_; |
| 277 | 297 |
| 278 // Minimum delay after updating a cookie's LastAccessDate before we will | 298 // Minimum delay after updating a cookie's LastAccessDate before we will |
| 279 // update it again. | 299 // update it again. |
| 280 const base::TimeDelta last_access_threshold_; | 300 const base::TimeDelta last_access_threshold_; |
| 281 | 301 |
| 282 std::vector<std::string> cookieable_schemes_; | 302 std::vector<std::string> cookieable_schemes_; |
| 283 | 303 |
| 284 scoped_refptr<Delegate> delegate_; | 304 scoped_refptr<Delegate> delegate_; |
| 285 | 305 |
| 286 // Lock for thread-safety | 306 // Lock for thread-safety |
| 287 Lock lock_; | 307 Lock lock_; |
| 288 | 308 |
| 309 base::Time last_statistic_record_time_; | |
| 310 | |
| 289 DISALLOW_COPY_AND_ASSIGN(CookieMonster); | 311 DISALLOW_COPY_AND_ASSIGN(CookieMonster); |
| 290 }; | 312 }; |
| 291 | 313 |
| 292 class CookieMonster::CanonicalCookie { | 314 class CookieMonster::CanonicalCookie { |
| 293 public: | 315 public: |
| 294 CanonicalCookie() { } | 316 CanonicalCookie() { } |
| 295 CanonicalCookie(const std::string& name, | 317 CanonicalCookie(const std::string& name, |
| 296 const std::string& value, | 318 const std::string& value, |
| 297 const std::string& path, | 319 const std::string& path, |
| 298 bool secure, | 320 bool secure, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 protected: | 513 protected: |
| 492 PersistentCookieStore() { } | 514 PersistentCookieStore() { } |
| 493 | 515 |
| 494 private: | 516 private: |
| 495 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 517 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 496 }; | 518 }; |
| 497 | 519 |
| 498 } // namespace net | 520 } // namespace net |
| 499 | 521 |
| 500 #endif // NET_BASE_COOKIE_MONSTER_H_ | 522 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |