OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <queue> | |
12 #include <string> | 13 #include <string> |
13 #include <utility> | 14 #include <utility> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
17 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
21 #include "base/task.h" | 22 #include "base/task.h" |
22 #include "base/time.h" | 23 #include "base/time.h" |
23 #include "net/base/cookie_store.h" | 24 #include "net/base/cookie_store.h" |
24 #include "net/base/net_api.h" | 25 #include "net/base/net_api.h" |
25 | 26 |
26 class GURL; | 27 class GURL; |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class Histogram; | 30 class Histogram; |
31 class MessageLoopProxy; | |
30 } | 32 } |
31 | 33 |
32 namespace net { | 34 namespace net { |
33 | 35 |
34 class CookieList; | 36 class CookieList; |
37 class CookieMonsterTask; | |
35 | 38 |
36 // The cookie monster is the system for storing and retrieving cookies. It has | 39 // The cookie monster is the system for storing and retrieving cookies. It has |
37 // an in-memory list of all cookies, and synchronizes non-session cookies to an | 40 // an in-memory list of all cookies, and synchronizes non-session cookies to an |
38 // optional permanent storage that implements the PersistentCookieStore | 41 // optional permanent storage that implements the PersistentCookieStore |
39 // interface. | 42 // interface. |
40 // | 43 // |
41 // This class IS thread-safe. Normally, it is only used on the I/O thread, but | 44 // This class IS thread-safe. Normally, it is only used on the I/O thread, but |
42 // is also accessed directly through Automation for UI testing. | 45 // is also accessed directly through Automation for UI testing. |
43 // | 46 // |
44 // Several methods exist in asynchronous forms. Calls may be deferred if all | 47 // Several methods exist in asynchronous forms. Calls may be deferred if all |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 Delegate* delegate, | 134 Delegate* delegate, |
132 int last_access_threshold_milliseconds); | 135 int last_access_threshold_milliseconds); |
133 | 136 |
134 // Parses the string with the cookie time (very forgivingly). | 137 // Parses the string with the cookie time (very forgivingly). |
135 static base::Time ParseCookieTime(const std::string& time_string); | 138 static base::Time ParseCookieTime(const std::string& time_string); |
136 | 139 |
137 // Returns true if a domain string represents a host-only cookie, | 140 // Returns true if a domain string represents a host-only cookie, |
138 // i.e. it doesn't begin with a leading '.' character. | 141 // i.e. it doesn't begin with a leading '.' character. |
139 static bool DomainIsHostOnly(const std::string& domain_string); | 142 static bool DomainIsHostOnly(const std::string& domain_string); |
140 | 143 |
144 // Helper function that adds all cookies from |cookie_monster| into this | |
145 // instance. | |
146 bool InitializeFrom(const CookieList& list); | |
147 | |
148 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | |
149 typedef base::Callback<void(int num_deleted)> DeleteCallback; | |
150 typedef SetCookiesCallback DeleteCookieCallback; | |
151 | |
141 // Sets a cookie given explicit user-provided cookie attributes. The cookie | 152 // Sets a cookie given explicit user-provided cookie attributes. The cookie |
142 // name, value, domain, etc. are each provided as separate strings. This | 153 // name, value, domain, etc. are each provided as separate strings. This |
143 // function expects each attribute to be well-formed. It will check for | 154 // function expects each attribute to be well-formed. It will check for |
144 // disallowed characters (e.g. the ';' character is disallowed within the | 155 // disallowed characters (e.g. the ';' character is disallowed within the |
145 // cookie value attribute) and will return false without setting the cookie | 156 // cookie value attribute) and will return false without setting the cookie |
146 // if such characters are found. | 157 // if such characters are found. |
147 bool SetCookieWithDetails(const GURL& url, | |
148 const std::string& name, | |
149 const std::string& value, | |
150 const std::string& domain, | |
151 const std::string& path, | |
152 const base::Time& expiration_time, | |
153 bool secure, bool http_only); | |
154 void SetCookieWithDetailsAsync(const GURL& url, | 158 void SetCookieWithDetailsAsync(const GURL& url, |
155 const std::string& name, | 159 const std::string& name, |
156 const std::string& value, | 160 const std::string& value, |
157 const std::string& domain, | 161 const std::string& domain, |
158 const std::string& path, | 162 const std::string& path, |
159 const base::Time& expiration_time, | 163 const base::Time& expiration_time, |
160 bool secure, bool http_only, | 164 bool secure, bool http_only, |
161 const SetCookiesCallback& callback); | 165 const SetCookiesCallback& callback); |
162 | 166 |
163 | |
164 // Helper function that adds all cookies from |cookie_monster| into this | |
165 // instance. | |
166 bool InitializeFrom(CookieMonster* cookie_monster); | |
167 | |
168 // Returns all the cookies, for use in management UI, etc. This does not mark | 167 // Returns all the cookies, for use in management UI, etc. This does not mark |
169 // the cookies as having been accessed. | 168 // the cookies as having been accessed. |
170 // The returned cookies are ordered by longest path, then by earliest | 169 // The returned cookies are ordered by longest path, then by earliest |
171 // creation date. | 170 // creation date. |
172 CookieList GetAllCookies(); | |
173 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | |
174 void GetAllCookiesAsync(const GetCookieListCallback& callback); | 171 void GetAllCookiesAsync(const GetCookieListCallback& callback); |
175 | 172 |
176 // Returns all the cookies, for use in management UI, etc. Filters results | 173 // Returns all the cookies, for use in management UI, etc. Filters results |
177 // using given url scheme, host / domain and path and options. This does not | 174 // using given url scheme, host / domain and path and options. This does not |
178 // mark the cookies as having been accessed. | 175 // mark the cookies as having been accessed. |
179 // The returned cookies are ordered by longest path, then earliest | 176 // The returned cookies are ordered by longest path, then earliest |
180 // creation date. | 177 // creation date. |
181 CookieList GetAllCookiesForURLWithOptions(const GURL& url, | |
182 const CookieOptions& options); | |
183 void GetAllCookiesForURLWithOptionsAsync( | 178 void GetAllCookiesForURLWithOptionsAsync( |
184 const GURL& url, | 179 const GURL& url, |
185 const CookieOptions& options, | 180 const CookieOptions& options, |
186 const GetCookieListCallback& callback); | 181 const GetCookieListCallback& callback); |
187 | 182 |
188 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP | 183 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP |
189 // only cookies. | 184 // only cookies. |
190 CookieList GetAllCookiesForURL(const GURL& url); | |
191 void GetAllCookiesForURLAsync(const GURL& url, | 185 void GetAllCookiesForURLAsync(const GURL& url, |
192 const GetCookieListCallback& callback); | 186 const GetCookieListCallback& callback); |
193 | 187 |
194 // Deletes all of the cookies. | 188 // Deletes all of the cookies. |
195 int DeleteAll(bool sync_to_store); | 189 void DeleteAllAsync(bool sync_to_store, |
190 const DeleteCallback& callback); | |
191 | |
196 // Deletes all of the cookies that have a creation_date greater than or equal | 192 // Deletes all of the cookies that have a creation_date greater than or equal |
197 // to |delete_begin| and less than |delete_end| | 193 // to |delete_begin| and less than |delete_end| |
198 // Returns the number of cookies that have been deleted. | 194 // Returns the number of cookies that have been deleted. |
199 int DeleteAllCreatedBetween(const base::Time& delete_begin, | |
200 const base::Time& delete_end, | |
201 bool sync_to_store); | |
202 typedef base::Callback<void(int num_deleted)> DeleteCallback; | |
203 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, | 195 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, |
204 const base::Time& delete_end, | 196 const base::Time& delete_end, |
205 bool sync_to_store, | 197 bool sync_to_store, |
206 const DeleteCallback& callback); | 198 const DeleteCallback& callback); |
207 | 199 |
208 // Deletes all cookies that match the host of the given URL | 200 // Deletes all cookies that match the host of the given URL |
209 // regardless of path. This includes all http_only and secure cookies, | 201 // regardless of path. This includes all http_only and secure cookies, |
210 // but does not include any domain cookies that may apply to this host. | 202 // but does not include any domain cookies that may apply to this host. |
211 // Returns the number of cookies deleted. | 203 // Returns the number of cookies deleted. |
212 int DeleteAllForHost(const GURL& url); | |
213 | |
214 void DeleteAllForHostAsync(const GURL& url, | 204 void DeleteAllForHostAsync(const GURL& url, |
215 const DeleteCallback& callback); | 205 const DeleteCallback& callback); |
216 | 206 |
217 // Deletes one specific cookie. | 207 // Deletes one specific cookie. |
218 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
219 | |
220 typedef SetCookiesCallback DeleteCookieCallback; | |
221 | |
222 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, | 208 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
223 const DeleteCookieCallback& callback); | 209 const DeleteCookieCallback& callback); |
224 | 210 |
225 // Override the default list of schemes that are allowed to be set in | 211 // Override the default list of schemes that are allowed to be set in |
226 // this cookie store. Calling his overrides the value of | 212 // this cookie store. Calling his overrides the value of |
227 // "enable_file_scheme_". | 213 // "enable_file_scheme_". |
228 // If this this method is called, it must be called before first use of | 214 // If this this method is called, it must be called before first use of |
229 // the instance (i.e. as part of the instance initialization process). | 215 // the instance (i.e. as part of the instance initialization process). |
230 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); | 216 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); |
231 | 217 |
(...skipping 21 matching lines...) Expand all Loading... | |
253 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. | 239 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. |
254 // It may be posted to the current thread, or it may run on the thread that | 240 // It may be posted to the current thread, or it may run on the thread that |
255 // actually does the flushing. Your Task should generally post a notification | 241 // actually does the flushing. Your Task should generally post a notification |
256 // to the thread you actually want to be notified on. | 242 // to the thread you actually want to be notified on. |
257 void FlushStore(Task* completion_task); | 243 void FlushStore(Task* completion_task); |
258 | 244 |
259 // CookieStore implementation. | 245 // CookieStore implementation. |
260 | 246 |
261 // Sets the cookies specified by |cookie_list| returned from |url| | 247 // Sets the cookies specified by |cookie_list| returned from |url| |
262 // with options |options| in effect. | 248 // with options |options| in effect. |
263 virtual bool SetCookieWithOptions(const GURL& url, | 249 virtual void SetCookieWithOptionsAsync( |
264 const std::string& cookie_line, | 250 const GURL& url, |
265 const CookieOptions& options); | 251 const std::string& cookie_line, |
266 | 252 const CookieOptions& options, |
267 virtual void SetCookieWithOptionsAsync(const GURL& url, | 253 const SetCookiesCallback& callback) OVERRIDE; |
268 const std::string& cookie_line, | |
269 const CookieOptions& options, | |
270 const SetCookiesCallback& callback); | |
271 | 254 |
272 // Gets all cookies that apply to |url| given |options|. | 255 // Gets all cookies that apply to |url| given |options|. |
273 // The returned cookies are ordered by longest path, then earliest | 256 // The returned cookies are ordered by longest path, then earliest |
274 // creation date. | 257 // creation date. |
275 virtual std::string GetCookiesWithOptions(const GURL& url, | |
276 const CookieOptions& options); | |
277 | |
278 virtual void GetCookiesWithOptionsAsync( | 258 virtual void GetCookiesWithOptionsAsync( |
279 const GURL& url, | 259 const GURL& url, |
280 const CookieOptions& options, | 260 const CookieOptions& options, |
281 const GetCookiesCallback& callback); | 261 const GetCookiesCallback& callback) OVERRIDE; |
282 | 262 |
283 virtual void GetCookiesWithInfo(const GURL& url, | 263 virtual void GetCookiesWithInfoAsync( |
284 const CookieOptions& options, | 264 const GURL& url, |
285 std::string* cookie_line, | 265 const CookieOptions& options, |
286 std::vector<CookieInfo>* cookie_infos); | 266 const GetCookieInfoCallback& callback) OVERRIDE; |
287 | |
288 virtual void GetCookiesWithInfoAsync(const GURL& url, | |
289 const CookieOptions& options, | |
290 const GetCookieInfoCallback& callback); | |
291 | 267 |
292 // Deletes all cookies with that might apply to |url| that has |cookie_name|. | 268 // Deletes all cookies with that might apply to |url| that has |cookie_name|. |
293 virtual void DeleteCookie(const GURL& url, const std::string& cookie_name); | |
294 virtual void DeleteCookieAsync( | 269 virtual void DeleteCookieAsync( |
295 const GURL& url, const std::string& cookie_name, | 270 const GURL& url, const std::string& cookie_name, |
296 const base::Closure& callback); | 271 const base::Closure& callback) OVERRIDE; |
297 | 272 |
298 virtual CookieMonster* GetCookieMonster(); | 273 virtual CookieMonster* GetCookieMonster() OVERRIDE; |
299 | 274 |
300 // Debugging method to perform various validation checks on the map. | 275 // Debugging method to perform various validation checks on the map. |
301 // Currently just checking that there are no null CanonicalCookie pointers | 276 // Currently just checking that there are no null CanonicalCookie pointers |
302 // in the map. | 277 // in the map. |
303 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs | 278 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs |
304 // in the function trip. TODO(rdsmith):Remove hack. | 279 // in the function trip. TODO(rdsmith):Remove hack. |
305 void ValidateMap(int arg); | 280 void ValidateMap(int arg); |
306 | 281 |
307 // The default list of schemes the cookie monster can handle. | 282 // The default list of schemes the cookie monster can handle. |
308 static const char* kDefaultCookieableSchemes[]; | 283 static const char* kDefaultCookieableSchemes[]; |
309 static const int kDefaultCookieableSchemesCount; | 284 static const int kDefaultCookieableSchemesCount; |
310 | 285 |
311 private: | 286 private: |
287 // For queueing the cookie monater calls. | |
erikwright (departed)
2011/08/12 16:00:34
monater -> monster
ycxiao
2011/08/12 17:51:25
Done.
| |
288 friend class DeleteAllCreatedBetweenTask; | |
289 friend class DeleteAllForHostTask; | |
290 friend class DeleteAllTask; | |
291 friend class DeleteCookieTask; | |
292 friend class DeleteCanonicalCookieTask; | |
293 friend class GetAllCookiesForURLWithOptionsTask; | |
294 friend class GetAllCookiesTask; | |
295 friend class GetCookiesWithOptionsTask; | |
296 friend class GetCookiesWithInfoTask; | |
297 friend class SetCookieWithDetailsTask; | |
298 friend class SetCookieWithOptionsTask; | |
299 | |
312 // Testing support. | 300 // Testing support. |
313 // For SetCookieWithCreationTime. | 301 // For SetCookieWithCreationTime. |
314 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, | 302 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, |
315 TestCookieDeleteAllCreatedBetweenTimestamps); | 303 TestCookieDeleteAllCreatedBetweenTimestamps); |
316 | 304 |
317 // For gargage collection constants. | 305 // For gargage collection constants. |
318 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); | 306 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); |
319 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection); | 307 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection); |
320 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers); | 308 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers); |
321 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes); | 309 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 | 378 |
391 // Default value for key and expiry scheme scheme. | 379 // Default value for key and expiry scheme scheme. |
392 static const ExpiryAndKeyScheme expiry_and_key_default_ = | 380 static const ExpiryAndKeyScheme expiry_and_key_default_ = |
393 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; | 381 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; |
394 | 382 |
395 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. | 383 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. |
396 static const int kRecordStatisticsIntervalSeconds = 10 * 60; | 384 static const int kRecordStatisticsIntervalSeconds = 10 * 60; |
397 | 385 |
398 virtual ~CookieMonster(); | 386 virtual ~CookieMonster(); |
399 | 387 |
388 bool SetCookieWithDetails(const GURL& url, | |
389 const std::string& name, | |
390 const std::string& value, | |
391 const std::string& domain, | |
392 const std::string& path, | |
393 const base::Time& expiration_time, | |
394 bool secure, bool http_only); | |
395 | |
396 CookieList GetAllCookies(); | |
397 | |
398 CookieList GetAllCookiesForURLWithOptions(const GURL& url, | |
399 const CookieOptions& options); | |
400 | |
401 CookieList GetAllCookiesForURL(const GURL& url); | |
402 | |
403 int DeleteAll(bool sync_to_store); | |
404 | |
405 int DeleteAllCreatedBetween(const base::Time& delete_begin, | |
406 const base::Time& delete_end, | |
407 bool sync_to_store); | |
408 | |
409 int DeleteAllForHost(const GURL& url); | |
410 | |
411 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
412 | |
413 bool SetCookieWithOptions(const GURL& url, | |
414 const std::string& cookie_line, | |
415 const CookieOptions& options); | |
416 | |
417 std::string GetCookiesWithOptions(const GURL& url, | |
418 const CookieOptions& options); | |
419 | |
420 void GetCookiesWithInfo(const GURL& url, | |
421 const CookieOptions& options, | |
422 std::string* cookie_line, | |
423 std::vector<CookieInfo>* cookie_infos); | |
424 | |
425 void DeleteCookie(const GURL& url, const std::string& cookie_name); | |
426 | |
400 bool SetCookieWithCreationTime(const GURL& url, | 427 bool SetCookieWithCreationTime(const GURL& url, |
401 const std::string& cookie_line, | 428 const std::string& cookie_line, |
402 const base::Time& creation_time); | 429 const base::Time& creation_time); |
403 | 430 |
404 // Called by all non-static functions to ensure that the cookies store has | 431 // Called by all non-static functions to ensure that the cookies store has |
405 // been initialized. This is not done during creating so it doesn't block | 432 // been initialized. This is not done during creating so it doesn't block |
406 // the window showing. | 433 // the window showing. |
407 // Note: this method should always be called with lock_ held. | 434 // Note: this method should always be called with lock_ held. |
408 void InitIfNecessary() { | 435 void InitIfNecessary() { |
409 if (!initialized_) { | 436 if (!initialized_) { |
410 if (store_) | 437 if (store_) { |
411 InitStore(); | 438 InitStore(); |
439 } else { | |
440 loaded_ = true; | |
441 } | |
412 initialized_ = true; | 442 initialized_ = true; |
413 } | 443 } |
414 } | 444 } |
415 | 445 |
416 // Initializes the backing store and reads existing cookies from it. | 446 // Initializes the backing store and reads existing cookies from it. |
417 // Should only be called by InitIfNecessary(). | 447 // Should only be called by InitIfNecessary(). |
418 void InitStore(); | 448 void InitStore(); |
419 | 449 |
450 // Reads the existing cookies loaded form the backing store. | |
451 void OnLoaded(const std::vector<CanonicalCookie*>& cookies); | |
452 | |
453 // Ininitalize the cookies. | |
454 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); | |
455 | |
456 // Invoke the queueing calls of CookieMonster when loading cookies from | |
457 // the back store is complete. | |
458 void InvokeQueue(); | |
459 | |
420 // Checks that |cookies_| matches our invariants, and tries to repair any | 460 // Checks that |cookies_| matches our invariants, and tries to repair any |
421 // inconsistencies. (In other words, it does not have duplicate cookies). | 461 // inconsistencies. (In other words, it does not have duplicate cookies). |
422 void EnsureCookiesMapIsValid(); | 462 void EnsureCookiesMapIsValid(); |
423 | 463 |
424 // Checks for any duplicate cookies for CookieMap key |key| which lie between | 464 // Checks for any duplicate cookies for CookieMap key |key| which lie between |
425 // |begin| and |end|. If any are found, all but the most recent are deleted. | 465 // |begin| and |end|. If any are found, all but the most recent are deleted. |
426 // Returns the number of duplicate cookies that were deleted. | 466 // Returns the number of duplicate cookies that were deleted. |
427 int TrimDuplicateCookiesForKey(const std::string& key, | 467 int TrimDuplicateCookiesForKey(const std::string& key, |
428 CookieMap::iterator begin, | 468 CookieMap::iterator begin, |
429 CookieMap::iterator end); | 469 CookieMap::iterator end); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 void RecordPeriodicStats(const base::Time& current_time); | 559 void RecordPeriodicStats(const base::Time& current_time); |
520 | 560 |
521 // Initialize the above variables; should only be called from | 561 // Initialize the above variables; should only be called from |
522 // the constructor. | 562 // the constructor. |
523 void InitializeHistograms(); | 563 void InitializeHistograms(); |
524 | 564 |
525 // The resolution of our time isn't enough, so we do something | 565 // The resolution of our time isn't enough, so we do something |
526 // ugly and increment when we've seen the same time twice. | 566 // ugly and increment when we've seen the same time twice. |
527 base::Time CurrentTime(); | 567 base::Time CurrentTime(); |
528 | 568 |
569 // Store the parameters of cookie monster API. | |
570 class CookieAPIParameters { | |
erikwright (departed)
2011/08/12 16:00:34
Presumably you can now remove CookieAPIParameters?
ycxiao
2011/08/12 17:51:25
Done.
| |
571 public: | |
572 CookieAPIParameters() | |
573 : secure(false), | |
574 http_only(false), | |
575 sync_to_store(false) { } | |
576 | |
577 GURL* url; | |
578 CookieOptions options; | |
579 std::string name; | |
580 std::string value; | |
581 std::string domain; | |
582 std::string path; | |
583 std::string cookie_line; | |
584 bool secure; | |
585 bool http_only; | |
586 bool sync_to_store; | |
587 base::Time delete_begin; | |
588 base::Time delete_end; | |
589 base::Time expiration_time; | |
590 CanonicalCookie* cookie; | |
591 }; | |
592 | |
593 // Run the cookie request task if cookie loaded, otherwise added the task | |
594 // to task queue. | |
595 void DoCookieTask(scoped_refptr<CookieMonsterTask> task_item); | |
596 | |
597 // // Task functions for queueing the coming request. | |
598 | |
599 // void SetCookieWithDetailsTask( | |
600 // const SetCookiesCallback& callback, | |
601 // const CookieAPIParameters& para, | |
602 // scoped_refptr<base::MessageLoopProxy> thread); | |
603 | |
604 // void GetAllCookiesTask( | |
605 // const GetCookieListCallback& callback, | |
606 // scoped_refptr<base::MessageLoopProxy> thread); | |
607 | |
608 // void GetAllCookiesForURLWithOptionsTask( | |
609 // const GetCookieListCallback& callback, | |
610 // const CookieAPIParameters& para, | |
611 // scoped_refptr<base::MessageLoopProxy> thread); | |
612 | |
613 // void GetAllCookiesForURLTask( | |
614 // const GetCookieListCallback& callback, | |
615 // const CookieAPIParameters& para, | |
616 // scoped_refptr<base::MessageLoopProxy> thread); | |
617 | |
618 // void DeleteAllTask( | |
619 // const DeleteCallback& callback, | |
620 // const CookieAPIParameters& para, | |
621 // scoped_refptr<base::MessageLoopProxy> thread); | |
622 | |
623 // void DeleteAllCreatedBetweenTask( | |
624 // const DeleteCallback& callback, | |
625 // const CookieAPIParameters& para, | |
626 // scoped_refptr<base::MessageLoopProxy> thread); | |
627 | |
628 // void DeleteAllForHostTask( | |
629 // const DeleteCallback& callback, | |
630 // const CookieAPIParameters& para, | |
631 // scoped_refptr<base::MessageLoopProxy> thread); | |
632 | |
633 // void DeleteCanonicalCookieTask( | |
634 // const DeleteCookieCallback& callback, | |
635 // const CookieAPIParameters& para, | |
636 // scoped_refptr<base::MessageLoopProxy> thread); | |
637 | |
638 // void SetCookieWithOptionsTask( | |
639 // const SetCookiesCallback& callback, | |
640 // const CookieAPIParameters& para, | |
641 // scoped_refptr<base::MessageLoopProxy> thread); | |
642 | |
643 // // void GetCookiesWithOptionsTask( | |
644 // // const GetCookiesCallback& callback, | |
645 // // const CookieAPIParameters& para, | |
646 // // scoped_refptr<base::MessageLoopProxy> thread); | |
647 | |
648 // void GetCookiesWithInfoTask( | |
649 // const GetCookieInfoCallback& callback, | |
650 // const CookieAPIParameters& para, | |
651 // scoped_refptr<base::MessageLoopProxy> thread); | |
652 | |
653 // void DeleteCookieTask( | |
654 // const base::Closure& callback, | |
655 // const CookieAPIParameters& para, | |
656 // scoped_refptr<base::MessageLoopProxy> thread); | |
657 | |
529 // Histogram variables; see CookieMonster::InitializeHistograms() in | 658 // Histogram variables; see CookieMonster::InitializeHistograms() in |
530 // cookie_monster.cc for details. | 659 // cookie_monster.cc for details. |
531 base::Histogram* histogram_expiration_duration_minutes_; | 660 base::Histogram* histogram_expiration_duration_minutes_; |
532 base::Histogram* histogram_between_access_interval_minutes_; | 661 base::Histogram* histogram_between_access_interval_minutes_; |
533 base::Histogram* histogram_evicted_last_access_minutes_; | 662 base::Histogram* histogram_evicted_last_access_minutes_; |
534 base::Histogram* histogram_count_; | 663 base::Histogram* histogram_count_; |
535 base::Histogram* histogram_domain_count_; | 664 base::Histogram* histogram_domain_count_; |
536 base::Histogram* histogram_etldp1_count_; | 665 base::Histogram* histogram_etldp1_count_; |
537 base::Histogram* histogram_domain_per_etldp1_count_; | 666 base::Histogram* histogram_domain_per_etldp1_count_; |
538 base::Histogram* histogram_number_duplicate_db_cookies_; | 667 base::Histogram* histogram_number_duplicate_db_cookies_; |
539 base::Histogram* histogram_cookie_deletion_cause_; | 668 base::Histogram* histogram_cookie_deletion_cause_; |
540 base::Histogram* histogram_time_get_; | 669 base::Histogram* histogram_time_get_; |
541 base::Histogram* histogram_time_mac_; | 670 base::Histogram* histogram_time_mac_; |
542 base::Histogram* histogram_time_load_; | 671 base::Histogram* histogram_time_load_; |
543 | 672 |
544 CookieMap cookies_; | 673 CookieMap cookies_; |
545 | 674 |
546 // Indicates whether the cookie store has been initialized. This happens | 675 // Indicates whether the cookie store has been initialized. This happens |
547 // lazily in InitStoreIfNecessary(). | 676 // lazily in InitStoreIfNecessary(). |
548 bool initialized_; | 677 bool initialized_; |
549 | 678 |
679 // Indicates whether loading from the backend store is completed and | |
680 // calls may be immediately processed. | |
681 bool loaded_; | |
682 | |
683 // Queues calls to CookieMonster until loading from the backend store is | |
684 // completed. | |
685 std::queue<base::Closure> queue_; | |
686 | |
550 // Indicates whether this cookie monster uses the new effective domain | 687 // Indicates whether this cookie monster uses the new effective domain |
551 // key scheme or not. | 688 // key scheme or not. |
552 ExpiryAndKeyScheme expiry_and_key_scheme_; | 689 ExpiryAndKeyScheme expiry_and_key_scheme_; |
553 | 690 |
554 scoped_refptr<PersistentCookieStore> store_; | 691 scoped_refptr<PersistentCookieStore> store_; |
555 | 692 |
556 base::Time last_time_seen_; | 693 base::Time last_time_seen_; |
557 | 694 |
558 // Minimum delay after updating a cookie's LastAccessDate before we will | 695 // Minimum delay after updating a cookie's LastAccessDate before we will |
559 // update it again. | 696 // update it again. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 | 747 |
611 // This constructor does canonicalization but not validation. | 748 // This constructor does canonicalization but not validation. |
612 // The result of this constructor should not be relied on in contexts | 749 // The result of this constructor should not be relied on in contexts |
613 // in which pre-validation of the ParsedCookie has not been done. | 750 // in which pre-validation of the ParsedCookie has not been done. |
614 CanonicalCookie(const GURL& url, const ParsedCookie& pc); | 751 CanonicalCookie(const GURL& url, const ParsedCookie& pc); |
615 | 752 |
616 ~CanonicalCookie(); | 753 ~CanonicalCookie(); |
617 | 754 |
618 // Supports the default copy constructor. | 755 // Supports the default copy constructor. |
619 | 756 |
757 // Creates a canonical cookie from parsed cookie. | |
758 // Canonicalizes and validates inputs. May return NULL if an attribute | |
759 // value is invalid. | |
760 static CanonicalCookie* Create(const GURL& url, | |
761 const ParsedCookie& pc); | |
762 | |
620 // Creates a canonical cookie from unparsed attribute values. | 763 // Creates a canonical cookie from unparsed attribute values. |
621 // Canonicalizes and validates inputs. May return NULL if an attribute | 764 // Canonicalizes and validates inputs. May return NULL if an attribute |
622 // value is invalid. | 765 // value is invalid. |
623 static CanonicalCookie* Create(const GURL& url, | 766 static CanonicalCookie* Create(const GURL& url, |
624 const std::string& name, | 767 const std::string& name, |
625 const std::string& value, | 768 const std::string& value, |
626 const std::string& domain, | 769 const std::string& domain, |
627 const std::string& path, | 770 const std::string& path, |
628 const std::string& mac_key, | 771 const std::string& mac_key, |
629 const std::string& mac_algorithm, | 772 const std::string& mac_algorithm, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 }; | 991 }; |
849 | 992 |
850 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 993 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
851 RefcountedPersistentCookieStore; | 994 RefcountedPersistentCookieStore; |
852 | 995 |
853 class CookieMonster::PersistentCookieStore | 996 class CookieMonster::PersistentCookieStore |
854 : public RefcountedPersistentCookieStore { | 997 : public RefcountedPersistentCookieStore { |
855 public: | 998 public: |
856 virtual ~PersistentCookieStore() {} | 999 virtual ~PersistentCookieStore() {} |
857 | 1000 |
1001 typedef base::Callback<void(const std::vector< | |
1002 CookieMonster::CanonicalCookie*>&)> LoadedCallback; | |
1003 | |
858 // Initializes the store and retrieves the existing cookies. This will be | 1004 // Initializes the store and retrieves the existing cookies. This will be |
859 // called only once at startup. | 1005 // called only once at startup. |
860 virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0; | 1006 virtual bool Load(const LoadedCallback& loaded_callback) = 0; |
861 | 1007 |
862 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 1008 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
863 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 1009 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
864 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 1010 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
865 | 1011 |
866 // Sets the value of the user preference whether the persistent storage | 1012 // Sets the value of the user preference whether the persistent storage |
867 // must be deleted upon destruction. | 1013 // must be deleted upon destruction. |
868 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 1014 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
869 | 1015 |
870 // Flush the store and post the given Task when complete. | 1016 // Flush the store and post the given Task when complete. |
871 virtual void Flush(Task* completion_task) = 0; | 1017 virtual void Flush(Task* completion_task) = 0; |
872 | 1018 |
873 protected: | 1019 protected: |
874 PersistentCookieStore() {} | 1020 PersistentCookieStore() {} |
875 | 1021 |
876 private: | 1022 private: |
877 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 1023 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
878 }; | 1024 }; |
879 | 1025 |
880 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 1026 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
881 }; | 1027 }; |
882 | 1028 |
883 } // namespace net | 1029 } // namespace net |
884 | 1030 |
885 #endif // NET_BASE_COOKIE_MONSTER_H_ | 1031 #endif // NET_BASE_COOKIE_MONSTER_H_ |
OLD | NEW |