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