| 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/lock.h" | 16 #include "base/lock.h" |
| 17 #include "base/logging.h" |
| 18 #include "base/non_thread_safe.h" |
| 17 #include "base/ref_counted.h" | 19 #include "base/ref_counted.h" |
| 18 #include "base/scoped_ptr.h" | 20 #include "base/scoped_ptr.h" |
| 19 #include "base/time.h" | 21 #include "base/time.h" |
| 20 #include "net/base/cookie_store.h" | 22 #include "net/base/cookie_store.h" |
| 21 | 23 |
| 22 class GURL; | 24 class GURL; |
| 23 | 25 |
| 24 namespace net { | 26 namespace net { |
| 25 | 27 |
| 26 // The cookie monster is the system for storing and retrieving cookies. It has | 28 // The cookie monster is the system for storing and retrieving cookies. It has |
| 27 // an in-memory list of all cookies, and synchronizes non-session cookies to an | 29 // an in-memory list of all cookies, and synchronizes non-session cookies to an |
| 28 // optional permanent storage that implements the PersistentCookieStore | 30 // optional permanent storage that implements the PersistentCookieStore |
| 29 // interface. | 31 // interface. |
| 30 // | 32 // |
| 31 // This class IS thread-safe. Normally, it is only used on the I/O thread, but | 33 // This class IS thread-safe. Normally, it is only used on the I/O thread, but |
| 32 // is also accessed directly through Automation for UI testing. | 34 // is also accessed directly through Automation for UI testing. |
| 33 // | 35 // |
| 34 // TODO(deanm) Implement CookieMonster, the cookie database. | 36 // TODO(deanm) Implement CookieMonster, the cookie database. |
| 35 // - Verify that our domain enforcement and non-dotted handling is correct | 37 // - Verify that our domain enforcement and non-dotted handling is correct |
| 36 class CookieMonster : public CookieStore { | 38 class CookieMonster : public CookieStore, NonThreadSafe { |
| 37 public: | 39 public: |
| 38 class CanonicalCookie; | 40 class CanonicalCookie; |
| 39 class Delegate; | 41 class Delegate; |
| 40 class ParsedCookie; | 42 class ParsedCookie; |
| 41 class PersistentCookieStore; | 43 class PersistentCookieStore; |
| 42 | 44 |
| 43 // NOTE(deanm): | 45 // NOTE(deanm): |
| 44 // I benchmarked hash_multimap vs multimap. We're going to be query-heavy | 46 // I benchmarked hash_multimap vs multimap. We're going to be query-heavy |
| 45 // so it would seem like hashing would help. However they were very | 47 // so it would seem like hashing would help. However they were very |
| 46 // close, with multimap being a tiny bit faster. I think this is because | 48 // close, with multimap being a tiny bit faster. I think this is because |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 83 | 85 |
| 84 // CookieStore implementation. | 86 // CookieStore implementation. |
| 85 virtual bool SetCookieWithOptions(const GURL& url, | 87 virtual bool SetCookieWithOptions(const GURL& url, |
| 86 const std::string& cookie_line, | 88 const std::string& cookie_line, |
| 87 const CookieOptions& options); | 89 const CookieOptions& options); |
| 88 virtual std::string GetCookiesWithOptions(const GURL& url, | 90 virtual std::string GetCookiesWithOptions(const GURL& url, |
| 89 const CookieOptions& options); | 91 const CookieOptions& options); |
| 90 virtual void DeleteCookie(const GURL& url, const std::string& cookie_name); | 92 virtual void DeleteCookie(const GURL& url, const std::string& cookie_name); |
| 91 virtual CookieMonster* GetCookieMonster() { return this; } | 93 virtual CookieMonster* GetCookieMonster() { |
| 94 DCHECK(CalledOnValidThread()); |
| 95 return this; |
| 96 } |
| 92 | 97 |
| 93 // Sets a cookie given explicit user-provided cookie attributes. The cookie | 98 // Sets a cookie given explicit user-provided cookie attributes. The cookie |
| 94 // name, value, domain, etc. are each provided as separate strings. This | 99 // name, value, domain, etc. are each provided as separate strings. This |
| 95 // function expects each attribute to be well-formed. It will check for | 100 // function expects each attribute to be well-formed. It will check for |
| 96 // disallowed characters (e.g. the ';' character is disallowed within the | 101 // disallowed characters (e.g. the ';' character is disallowed within the |
| 97 // cookie value attribute) and will return false without setting the cookie | 102 // cookie value attribute) and will return false without setting the cookie |
| 98 // if such characters are found. | 103 // if such characters are found. |
| 99 bool SetCookieWithDetails(const GURL& url, | 104 bool SetCookieWithDetails(const GURL& url, |
| 100 const std::string& name, | 105 const std::string& name, |
| 101 const std::string& value, | 106 const std::string& value, |
| 102 const std::string& domain, | 107 const std::string& domain, |
| 103 const std::string& path, | 108 const std::string& path, |
| 104 const base::Time& expiration_time, | 109 const base::Time& expiration_time, |
| 105 bool secure, bool http_only); | 110 bool secure, bool http_only); |
| 106 | 111 |
| 107 // Exposed for unit testing. | 112 // Exposed for unit testing. |
| 108 bool SetCookieWithCreationTimeAndOptions(const GURL& url, | 113 bool SetCookieWithCreationTimeAndOptions(const GURL& url, |
| 109 const std::string& cookie_line, | 114 const std::string& cookie_line, |
| 110 const base::Time& creation_time, | 115 const base::Time& creation_time, |
| 111 const CookieOptions& options); | 116 const CookieOptions& options); |
| 112 bool SetCookieWithCreationTime(const GURL& url, | 117 bool SetCookieWithCreationTime(const GURL& url, |
| 113 const std::string& cookie_line, | 118 const std::string& cookie_line, |
| 114 const base::Time& creation_time) { | 119 const base::Time& creation_time) { |
| 120 DCHECK(CalledOnValidThread()); |
| 115 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, | 121 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, |
| 116 CookieOptions()); | 122 CookieOptions()); |
| 117 } | 123 } |
| 118 | 124 |
| 119 // Returns all the cookies, for use in management UI, etc. This does not mark | 125 // Returns all the cookies, for use in management UI, etc. This does not mark |
| 120 // the cookies as having been accessed. | 126 // the cookies as having been accessed. |
| 121 CookieList GetAllCookies(); | 127 CookieList GetAllCookies(); |
| 122 | 128 |
| 123 // Returns all the cookies, for use in management UI, etc. Filters results | 129 // Returns all the cookies, for use in management UI, etc. Filters results |
| 124 // using given url scheme, host / domain and path. This does not mark the | 130 // using given url scheme, host / domain and path. This does not mark the |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 base::Time last_time_seen_; | 280 base::Time last_time_seen_; |
| 275 | 281 |
| 276 // Minimum delay after updating a cookie's LastAccessDate before we will | 282 // Minimum delay after updating a cookie's LastAccessDate before we will |
| 277 // update it again. | 283 // update it again. |
| 278 const base::TimeDelta last_access_threshold_; | 284 const base::TimeDelta last_access_threshold_; |
| 279 | 285 |
| 280 std::vector<std::string> cookieable_schemes_; | 286 std::vector<std::string> cookieable_schemes_; |
| 281 | 287 |
| 282 scoped_refptr<Delegate> delegate_; | 288 scoped_refptr<Delegate> delegate_; |
| 283 | 289 |
| 290 // TODO(willchan): Remove this lock after making sure CookieMonster is |
| 291 // completely single threaded. |
| 284 // Lock for thread-safety | 292 // Lock for thread-safety |
| 285 Lock lock_; | 293 Lock lock_; |
| 286 | 294 |
| 287 DISALLOW_COPY_AND_ASSIGN(CookieMonster); | 295 DISALLOW_COPY_AND_ASSIGN(CookieMonster); |
| 288 }; | 296 }; |
| 289 | 297 |
| 290 class CookieMonster::CanonicalCookie { | 298 class CookieMonster::CanonicalCookie { |
| 291 public: | 299 public: |
| 292 CanonicalCookie() { } | 300 CanonicalCookie() { } |
| 293 CanonicalCookie(const std::string& name, | 301 CanonicalCookie(const std::string& name, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 protected: | 497 protected: |
| 490 PersistentCookieStore() { } | 498 PersistentCookieStore() { } |
| 491 | 499 |
| 492 private: | 500 private: |
| 493 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 501 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 494 }; | 502 }; |
| 495 | 503 |
| 496 } // namespace net | 504 } // namespace net |
| 497 | 505 |
| 498 #endif // NET_BASE_COOKIE_MONSTER_H_ | 506 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |