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 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
18 #include "base/histogram.h" | |
19 #include "base/lock.h" | 18 #include "base/lock.h" |
20 #include "base/ref_counted.h" | 19 #include "base/ref_counted.h" |
21 #include "base/scoped_ptr.h" | 20 #include "base/scoped_ptr.h" |
22 #include "base/time.h" | 21 #include "base/time.h" |
23 #include "net/base/cookie_store.h" | 22 #include "net/base/cookie_store.h" |
24 | 23 |
25 class GURL; | 24 class GURL; |
| 25 class Histogram; |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 // The cookie monster is the system for storing and retrieving cookies. It has | 29 // The cookie monster is the system for storing and retrieving cookies. It has |
30 // an in-memory list of all cookies, and synchronizes non-session cookies to an | 30 // an in-memory list of all cookies, and synchronizes non-session cookies to an |
31 // optional permanent storage that implements the PersistentCookieStore | 31 // optional permanent storage that implements the PersistentCookieStore |
32 // interface. | 32 // interface. |
33 // | 33 // |
34 // This class IS thread-safe. Normally, it is only used on the I/O thread, but | 34 // This class IS thread-safe. Normally, it is only used on the I/O thread, but |
35 // is also accessed directly through Automation for UI testing. | 35 // is also accessed directly through Automation for UI testing. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 typedef std::vector<CanonicalCookie> CookieList; | 93 typedef std::vector<CanonicalCookie> CookieList; |
94 | 94 |
95 // The store passed in should not have had Init() called on it yet. This | 95 // The store passed in should not have had Init() called on it yet. This |
96 // class will take care of initializing it. The backing store is NOT owned by | 96 // class will take care of initializing it. The backing store is NOT owned by |
97 // this class, but it must remain valid for the duration of the cookie | 97 // this class, but it must remain valid for the duration of the cookie |
98 // monster's existence. If |store| is NULL, then no backing store will be | 98 // monster's existence. If |store| is NULL, then no backing store will be |
99 // updated. If |delegate| is non-NULL, it will be notified on | 99 // updated. If |delegate| is non-NULL, it will be notified on |
100 // creation/deletion of cookies. | 100 // creation/deletion of cookies. |
101 CookieMonster(PersistentCookieStore* store, Delegate* delegate); | 101 CookieMonster(PersistentCookieStore* store, Delegate* delegate); |
102 | 102 |
103 #ifdef UNIT_TEST | 103 // Only used during unit testing. |
104 CookieMonster(PersistentCookieStore* store, | 104 CookieMonster(PersistentCookieStore* store, |
105 Delegate* delegate, | 105 Delegate* delegate, |
106 int last_access_threshold_milliseconds) | 106 int last_access_threshold_milliseconds); |
107 : initialized_(false), | |
108 use_effective_domain_key_scheme_(use_effective_domain_key_default_), | |
109 store_(store), | |
110 last_access_threshold_(base::TimeDelta::FromMilliseconds( | |
111 last_access_threshold_milliseconds)), | |
112 delegate_(delegate), | |
113 last_statistic_record_time_(base::Time::Now()) { | |
114 InitializeHistograms(); | |
115 SetDefaultCookieableSchemes(); | |
116 } | |
117 #endif | |
118 | 107 |
119 // Parses the string with the cookie time (very forgivingly). | 108 // Parses the string with the cookie time (very forgivingly). |
120 static base::Time ParseCookieTime(const std::string& time_string); | 109 static base::Time ParseCookieTime(const std::string& time_string); |
121 | 110 |
122 // Returns true if a domain string represents a host-only cookie, | 111 // Returns true if a domain string represents a host-only cookie, |
123 // i.e. it doesn't begin with a leading '.' character. | 112 // i.e. it doesn't begin with a leading '.' character. |
124 static bool DomainIsHostOnly(const std::string& domain_string); | 113 static bool DomainIsHostOnly(const std::string& domain_string); |
125 | 114 |
126 // CookieStore implementation. | 115 // CookieStore implementation. |
127 | 116 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 DISALLOW_COPY_AND_ASSIGN(CookieMonster); | 423 DISALLOW_COPY_AND_ASSIGN(CookieMonster); |
435 }; | 424 }; |
436 | 425 |
437 class CookieMonster::CanonicalCookie { | 426 class CookieMonster::CanonicalCookie { |
438 public: | 427 public: |
439 | 428 |
440 // These constructors do no validation or canonicalization of their inputs; | 429 // These constructors do no validation or canonicalization of their inputs; |
441 // the resulting CanonicalCookies should not be relied on to be canonical | 430 // the resulting CanonicalCookies should not be relied on to be canonical |
442 // unless the caller has done appropriate validation and canonicalization | 431 // unless the caller has done appropriate validation and canonicalization |
443 // themselves. | 432 // themselves. |
444 CanonicalCookie() { } | 433 CanonicalCookie(); |
445 CanonicalCookie(const std::string& name, | 434 CanonicalCookie(const std::string& name, |
446 const std::string& value, | 435 const std::string& value, |
447 const std::string& domain, | 436 const std::string& domain, |
448 const std::string& path, | 437 const std::string& path, |
449 bool secure, | 438 bool secure, |
450 bool httponly, | 439 bool httponly, |
451 const base::Time& creation, | 440 const base::Time& creation, |
452 const base::Time& last_access, | 441 const base::Time& last_access, |
453 bool has_expires, | 442 bool has_expires, |
454 const base::Time& expires) | 443 const base::Time& expires); |
455 : name_(name), | |
456 value_(value), | |
457 domain_(domain), | |
458 path_(path), | |
459 creation_date_(creation), | |
460 last_access_date_(last_access), | |
461 expiry_date_(expires), | |
462 has_expires_(has_expires), | |
463 secure_(secure), | |
464 httponly_(httponly) { | |
465 } | |
466 | 444 |
467 // This constructor does canonicalization but not validation. | 445 // This constructor does canonicalization but not validation. |
468 // The result of this constructor should not be relied on in contexts | 446 // The result of this constructor should not be relied on in contexts |
469 // in which pre-validation of the ParsedCookie has not been done. | 447 // in which pre-validation of the ParsedCookie has not been done. |
470 CanonicalCookie(const GURL& url, const ParsedCookie& pc); | 448 CanonicalCookie(const GURL& url, const ParsedCookie& pc); |
471 | 449 |
| 450 ~CanonicalCookie(); |
| 451 |
472 // Supports the default copy constructor. | 452 // Supports the default copy constructor. |
473 | 453 |
474 // Creates a canonical cookie from unparsed attribute values. | 454 // Creates a canonical cookie from unparsed attribute values. |
475 // Canonicalizes and validates inputs. May return NULL if an attribute | 455 // Canonicalizes and validates inputs. May return NULL if an attribute |
476 // value is invalid. | 456 // value is invalid. |
477 static CanonicalCookie* Create( | 457 static CanonicalCookie* Create( |
478 const GURL& url, const std::string& name, const std::string& value, | 458 const GURL& url, const std::string& name, const std::string& value, |
479 const std::string& domain, const std::string& path, | 459 const std::string& domain, const std::string& path, |
480 const base::Time& creation_time, const base::Time& expiration_time, | 460 const base::Time& creation_time, const base::Time& expiration_time, |
481 bool secure, bool http_only); | 461 bool secure, bool http_only); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 protected: | 639 protected: |
660 PersistentCookieStore() { } | 640 PersistentCookieStore() { } |
661 | 641 |
662 private: | 642 private: |
663 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 643 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
664 }; | 644 }; |
665 | 645 |
666 } // namespace net | 646 } // namespace net |
667 | 647 |
668 #endif // NET_BASE_COOKIE_MONSTER_H_ | 648 #endif // NET_BASE_COOKIE_MONSTER_H_ |
OLD | NEW |