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 <deque> | |
11 #include <map> | 12 #include <map> |
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" |
21 #include "base/message_loop_proxy.h" | |
erikwright (departed)
2011/08/11 13:58:24
Why is this added here?
ycxiao
2011/08/12 02:35:24
I think I can move this to .cc, and added an "clas
| |
20 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
21 #include "base/task.h" | 23 #include "base/task.h" |
22 #include "base/time.h" | 24 #include "base/time.h" |
23 #include "net/base/cookie_store.h" | 25 #include "net/base/cookie_store.h" |
24 #include "net/base/net_api.h" | 26 #include "net/base/net_api.h" |
25 | 27 |
26 class GURL; | 28 class GURL; |
27 | 29 |
28 namespace base { | 30 namespace base { |
29 class Histogram; | 31 class Histogram; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 Delegate* delegate, | 133 Delegate* delegate, |
132 int last_access_threshold_milliseconds); | 134 int last_access_threshold_milliseconds); |
133 | 135 |
134 // Parses the string with the cookie time (very forgivingly). | 136 // Parses the string with the cookie time (very forgivingly). |
135 static base::Time ParseCookieTime(const std::string& time_string); | 137 static base::Time ParseCookieTime(const std::string& time_string); |
136 | 138 |
137 // Returns true if a domain string represents a host-only cookie, | 139 // Returns true if a domain string represents a host-only cookie, |
138 // i.e. it doesn't begin with a leading '.' character. | 140 // i.e. it doesn't begin with a leading '.' character. |
139 static bool DomainIsHostOnly(const std::string& domain_string); | 141 static bool DomainIsHostOnly(const std::string& domain_string); |
140 | 142 |
143 // Helper function that adds all cookies from |cookie_monster| into this | |
144 // instance. | |
145 bool InitializeFrom(const CookieList& list); | |
erikwright (departed)
2011/08/11 13:58:24
Who uses this? Must it be public? If nothing else,
ycxiao
2011/08/12 02:35:24
The login_uitls.cc create this function. The previ
| |
146 | |
147 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | |
148 typedef base::Callback<void(int num_deleted)> DeleteCallback; | |
149 typedef SetCookiesCallback DeleteCookieCallback; | |
150 | |
141 // Sets a cookie given explicit user-provided cookie attributes. The cookie | 151 // Sets a cookie given explicit user-provided cookie attributes. The cookie |
142 // name, value, domain, etc. are each provided as separate strings. This | 152 // name, value, domain, etc. are each provided as separate strings. This |
143 // function expects each attribute to be well-formed. It will check for | 153 // function expects each attribute to be well-formed. It will check for |
144 // disallowed characters (e.g. the ';' character is disallowed within the | 154 // disallowed characters (e.g. the ';' character is disallowed within the |
145 // cookie value attribute) and will return false without setting the cookie | 155 // cookie value attribute) and will return false without setting the cookie |
146 // if such characters are found. | 156 // 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, | 157 void SetCookieWithDetailsAsync(const GURL& url, |
155 const std::string& name, | 158 const std::string& name, |
156 const std::string& value, | 159 const std::string& value, |
157 const std::string& domain, | 160 const std::string& domain, |
158 const std::string& path, | 161 const std::string& path, |
159 const base::Time& expiration_time, | 162 const base::Time& expiration_time, |
160 bool secure, bool http_only, | 163 bool secure, bool http_only, |
161 const SetCookiesCallback& callback); | 164 const SetCookiesCallback& callback); |
162 | 165 |
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 | 166 // Returns all the cookies, for use in management UI, etc. This does not mark |
169 // the cookies as having been accessed. | 167 // the cookies as having been accessed. |
170 // The returned cookies are ordered by longest path, then by earliest | 168 // The returned cookies are ordered by longest path, then by earliest |
171 // creation date. | 169 // creation date. |
172 CookieList GetAllCookies(); | |
173 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | |
174 void GetAllCookiesAsync(const GetCookieListCallback& callback); | 170 void GetAllCookiesAsync(const GetCookieListCallback& callback); |
175 | 171 |
176 // Returns all the cookies, for use in management UI, etc. Filters results | 172 // 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 | 173 // using given url scheme, host / domain and path and options. This does not |
178 // mark the cookies as having been accessed. | 174 // mark the cookies as having been accessed. |
179 // The returned cookies are ordered by longest path, then earliest | 175 // The returned cookies are ordered by longest path, then earliest |
180 // creation date. | 176 // creation date. |
181 CookieList GetAllCookiesForURLWithOptions(const GURL& url, | |
182 const CookieOptions& options); | |
183 void GetAllCookiesForURLWithOptionsAsync( | 177 void GetAllCookiesForURLWithOptionsAsync( |
184 const GURL& url, | 178 const GURL& url, |
185 const CookieOptions& options, | 179 const CookieOptions& options, |
186 const GetCookieListCallback& callback); | 180 const GetCookieListCallback& callback); |
187 | 181 |
188 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP | 182 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP |
189 // only cookies. | 183 // only cookies. |
190 CookieList GetAllCookiesForURL(const GURL& url); | |
191 void GetAllCookiesForURLAsync(const GURL& url, | 184 void GetAllCookiesForURLAsync(const GURL& url, |
192 const GetCookieListCallback& callback); | 185 const GetCookieListCallback& callback); |
193 | 186 |
194 // Deletes all of the cookies. | 187 // Deletes all of the cookies. |
195 int DeleteAll(bool sync_to_store); | 188 void DeleteAllAsync(bool sync_to_store, |
189 const DeleteCallback& callback); | |
190 | |
196 // Deletes all of the cookies that have a creation_date greater than or equal | 191 // Deletes all of the cookies that have a creation_date greater than or equal |
197 // to |delete_begin| and less than |delete_end| | 192 // to |delete_begin| and less than |delete_end| |
198 // Returns the number of cookies that have been deleted. | 193 // 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, | 194 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, |
204 const base::Time& delete_end, | 195 const base::Time& delete_end, |
205 bool sync_to_store, | 196 bool sync_to_store, |
206 const DeleteCallback& callback); | 197 const DeleteCallback& callback); |
207 | 198 |
208 // Deletes all cookies that match the host of the given URL | 199 // Deletes all cookies that match the host of the given URL |
209 // regardless of path. This includes all http_only and secure cookies, | 200 // 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. | 201 // but does not include any domain cookies that may apply to this host. |
211 // Returns the number of cookies deleted. | 202 // Returns the number of cookies deleted. |
212 int DeleteAllForHost(const GURL& url); | |
213 | |
214 void DeleteAllForHostAsync(const GURL& url, | 203 void DeleteAllForHostAsync(const GURL& url, |
215 const DeleteCallback& callback); | 204 const DeleteCallback& callback); |
216 | 205 |
217 // Deletes one specific cookie. | 206 // Deletes one specific cookie. |
218 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
219 | |
220 typedef SetCookiesCallback DeleteCookieCallback; | |
221 | |
222 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, | 207 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
223 const DeleteCookieCallback& callback); | 208 const DeleteCookieCallback& callback); |
224 | 209 |
225 // Override the default list of schemes that are allowed to be set in | 210 // Override the default list of schemes that are allowed to be set in |
226 // this cookie store. Calling his overrides the value of | 211 // this cookie store. Calling his overrides the value of |
227 // "enable_file_scheme_". | 212 // "enable_file_scheme_". |
228 // If this this method is called, it must be called before first use of | 213 // 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). | 214 // the instance (i.e. as part of the instance initialization process). |
230 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); | 215 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); |
231 | 216 |
(...skipping 21 matching lines...) Expand all Loading... | |
253 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. | 238 // 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 | 239 // 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 | 240 // actually does the flushing. Your Task should generally post a notification |
256 // to the thread you actually want to be notified on. | 241 // to the thread you actually want to be notified on. |
257 void FlushStore(Task* completion_task); | 242 void FlushStore(Task* completion_task); |
258 | 243 |
259 // CookieStore implementation. | 244 // CookieStore implementation. |
260 | 245 |
261 // Sets the cookies specified by |cookie_list| returned from |url| | 246 // Sets the cookies specified by |cookie_list| returned from |url| |
262 // with options |options| in effect. | 247 // with options |options| in effect. |
263 virtual bool SetCookieWithOptions(const GURL& url, | |
264 const std::string& cookie_line, | |
265 const CookieOptions& options); | |
266 | |
267 virtual void SetCookieWithOptionsAsync(const GURL& url, | 248 virtual void SetCookieWithOptionsAsync(const GURL& url, |
erikwright (departed)
2011/08/11 13:58:24
Add OVERRIDE as appropriate.
ycxiao
2011/08/12 02:35:24
Done.
| |
268 const std::string& cookie_line, | 249 const std::string& cookie_line, |
269 const CookieOptions& options, | 250 const CookieOptions& options, |
270 const SetCookiesCallback& callback); | 251 const SetCookiesCallback& callback); |
271 | 252 |
272 // Gets all cookies that apply to |url| given |options|. | 253 // Gets all cookies that apply to |url| given |options|. |
273 // The returned cookies are ordered by longest path, then earliest | 254 // The returned cookies are ordered by longest path, then earliest |
274 // creation date. | 255 // creation date. |
275 virtual std::string GetCookiesWithOptions(const GURL& url, | |
276 const CookieOptions& options); | |
277 | |
278 virtual void GetCookiesWithOptionsAsync( | 256 virtual void GetCookiesWithOptionsAsync( |
279 const GURL& url, | 257 const GURL& url, |
280 const CookieOptions& options, | 258 const CookieOptions& options, |
281 const GetCookiesCallback& callback); | 259 const GetCookiesCallback& callback); |
282 | 260 |
283 virtual void GetCookiesWithInfo(const GURL& url, | |
284 const CookieOptions& options, | |
285 std::string* cookie_line, | |
286 std::vector<CookieInfo>* cookie_infos); | |
287 | |
288 virtual void GetCookiesWithInfoAsync(const GURL& url, | 261 virtual void GetCookiesWithInfoAsync(const GURL& url, |
289 const CookieOptions& options, | 262 const CookieOptions& options, |
290 const GetCookieInfoCallback& callback); | 263 const GetCookieInfoCallback& callback); |
291 | 264 |
292 // Deletes all cookies with that might apply to |url| that has |cookie_name|. | 265 // 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( | 266 virtual void DeleteCookieAsync( |
295 const GURL& url, const std::string& cookie_name, | 267 const GURL& url, const std::string& cookie_name, |
296 const base::Closure& callback); | 268 const base::Closure& callback); |
297 | 269 |
298 virtual CookieMonster* GetCookieMonster(); | 270 virtual CookieMonster* GetCookieMonster(); |
299 | 271 |
300 // Debugging method to perform various validation checks on the map. | 272 // Debugging method to perform various validation checks on the map. |
301 // Currently just checking that there are no null CanonicalCookie pointers | 273 // Currently just checking that there are no null CanonicalCookie pointers |
302 // in the map. | 274 // in the map. |
303 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs | 275 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs |
304 // in the function trip. TODO(rdsmith):Remove hack. | 276 // in the function trip. TODO(rdsmith):Remove hack. |
305 void ValidateMap(int arg); | 277 void ValidateMap(int arg); |
306 | 278 |
279 // Reads the existing cookies loaded form the backing store. | |
280 void OnLoaded(const std::vector<CanonicalCookie*>& cookies); | |
erikwright (departed)
2011/08/11 13:58:24
Why is this not private?
ycxiao
2011/08/12 02:35:24
You are right, it should be.
| |
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: |
312 // Testing support. | 287 // Testing support. |
313 // For SetCookieWithCreationTime. | 288 // For SetCookieWithCreationTime. |
314 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, | 289 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, |
315 TestCookieDeleteAllCreatedBetweenTimestamps); | 290 TestCookieDeleteAllCreatedBetweenTimestamps); |
316 | 291 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 | 365 |
391 // Default value for key and expiry scheme scheme. | 366 // Default value for key and expiry scheme scheme. |
392 static const ExpiryAndKeyScheme expiry_and_key_default_ = | 367 static const ExpiryAndKeyScheme expiry_and_key_default_ = |
393 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; | 368 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; |
394 | 369 |
395 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. | 370 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. |
396 static const int kRecordStatisticsIntervalSeconds = 10 * 60; | 371 static const int kRecordStatisticsIntervalSeconds = 10 * 60; |
397 | 372 |
398 virtual ~CookieMonster(); | 373 virtual ~CookieMonster(); |
399 | 374 |
375 bool SetCookieWithDetails(const GURL& url, | |
376 const std::string& name, | |
377 const std::string& value, | |
378 const std::string& domain, | |
379 const std::string& path, | |
380 const base::Time& expiration_time, | |
381 bool secure, bool http_only); | |
382 | |
383 CookieList GetAllCookies(); | |
384 | |
385 CookieList GetAllCookiesForURLWithOptions(const GURL& url, | |
386 const CookieOptions& options); | |
387 | |
388 CookieList GetAllCookiesForURL(const GURL& url); | |
389 | |
390 int DeleteAll(bool sync_to_store); | |
391 | |
392 int DeleteAllCreatedBetween(const base::Time& delete_begin, | |
393 const base::Time& delete_end, | |
394 bool sync_to_store); | |
395 | |
396 int DeleteAllForHost(const GURL& url); | |
397 | |
398 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
399 | |
400 bool SetCookieWithOptions(const GURL& url, | |
401 const std::string& cookie_line, | |
402 const CookieOptions& options); | |
403 | |
404 std::string GetCookiesWithOptions(const GURL& url, | |
405 const CookieOptions& options); | |
406 | |
407 void GetCookiesWithInfo(const GURL& url, | |
408 const CookieOptions& options, | |
409 std::string* cookie_line, | |
410 std::vector<CookieInfo>* cookie_infos); | |
411 | |
412 void DeleteCookie(const GURL& url, const std::string& cookie_name); | |
413 | |
400 bool SetCookieWithCreationTime(const GURL& url, | 414 bool SetCookieWithCreationTime(const GURL& url, |
401 const std::string& cookie_line, | 415 const std::string& cookie_line, |
402 const base::Time& creation_time); | 416 const base::Time& creation_time); |
403 | 417 |
404 // Called by all non-static functions to ensure that the cookies store has | 418 // 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 | 419 // been initialized. This is not done during creating so it doesn't block |
406 // the window showing. | 420 // the window showing. |
407 // Note: this method should always be called with lock_ held. | 421 // Note: this method should always be called with lock_ held. |
408 void InitIfNecessary() { | 422 void InitIfNecessary() { |
409 if (!initialized_) { | 423 if (!initialized_) { |
410 if (store_) | 424 if (store_) { |
411 InitStore(); | 425 InitStore(); |
426 } else { | |
427 loaded_ = true; | |
428 } | |
412 initialized_ = true; | 429 initialized_ = true; |
413 } | 430 } |
414 } | 431 } |
415 | 432 |
416 // Initializes the backing store and reads existing cookies from it. | 433 // Initializes the backing store and reads existing cookies from it. |
417 // Should only be called by InitIfNecessary(). | 434 // Should only be called by InitIfNecessary(). |
418 void InitStore(); | 435 void InitStore(); |
419 | 436 |
437 // Invoke the queueing calls of CookieMonster when loading cookies from | |
438 // the back store is complete. | |
439 void InvokeQueue(); | |
440 | |
420 // Checks that |cookies_| matches our invariants, and tries to repair any | 441 // Checks that |cookies_| matches our invariants, and tries to repair any |
421 // inconsistencies. (In other words, it does not have duplicate cookies). | 442 // inconsistencies. (In other words, it does not have duplicate cookies). |
422 void EnsureCookiesMapIsValid(); | 443 void EnsureCookiesMapIsValid(); |
423 | 444 |
424 // Checks for any duplicate cookies for CookieMap key |key| which lie between | 445 // 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. | 446 // |begin| and |end|. If any are found, all but the most recent are deleted. |
426 // Returns the number of duplicate cookies that were deleted. | 447 // Returns the number of duplicate cookies that were deleted. |
427 int TrimDuplicateCookiesForKey(const std::string& key, | 448 int TrimDuplicateCookiesForKey(const std::string& key, |
428 CookieMap::iterator begin, | 449 CookieMap::iterator begin, |
429 CookieMap::iterator end); | 450 CookieMap::iterator end); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 void RecordPeriodicStats(const base::Time& current_time); | 540 void RecordPeriodicStats(const base::Time& current_time); |
520 | 541 |
521 // Initialize the above variables; should only be called from | 542 // Initialize the above variables; should only be called from |
522 // the constructor. | 543 // the constructor. |
523 void InitializeHistograms(); | 544 void InitializeHistograms(); |
524 | 545 |
525 // The resolution of our time isn't enough, so we do something | 546 // The resolution of our time isn't enough, so we do something |
526 // ugly and increment when we've seen the same time twice. | 547 // ugly and increment when we've seen the same time twice. |
527 base::Time CurrentTime(); | 548 base::Time CurrentTime(); |
528 | 549 |
550 // Store the parameters of cookie monster API. | |
551 class CookieAPIParameters { | |
erikwright (departed)
2011/08/11 13:58:24
In cookie_monster.cc, define a class named CookieM
ycxiao
2011/08/12 02:35:24
Done.
| |
552 public: | |
553 CookieAPIParameters() | |
554 : secure(false), | |
555 http_only(false), | |
556 sync_to_store(false) { } | |
557 | |
558 GURL* url; | |
559 CookieOptions options; | |
560 std::string name; | |
561 std::string value; | |
562 std::string domain; | |
563 std::string path; | |
564 std::string cookie_line; | |
565 bool secure; | |
566 bool http_only; | |
567 bool sync_to_store; | |
568 base::Time delete_begin; | |
569 base::Time delete_end; | |
570 base::Time expiration_time; | |
571 CanonicalCookie* cookie; | |
572 }; | |
573 | |
574 // Run the cookie request task if cookie loaded, otherwise added the task | |
575 // to task queue. | |
576 void DoCookieTask(const base::Closure& task); | |
erikwright (departed)
2011/08/11 13:58:24
All of these task methods go away and become class
ycxiao
2011/08/12 02:35:24
Done.
| |
577 | |
578 // Task functions for queueing the coming request. | |
579 | |
580 void SetCookieWithDetailsTask( | |
581 const SetCookiesCallback& callback, | |
582 const CookieAPIParameters& para, | |
583 scoped_refptr<base::MessageLoopProxy> thread); | |
584 | |
585 void GetAllCookiesTask( | |
586 const GetCookieListCallback& callback, | |
587 scoped_refptr<base::MessageLoopProxy> thread); | |
588 | |
589 void GetAllCookiesForURLWithOptionsTask( | |
590 const GetCookieListCallback& callback, | |
591 const CookieAPIParameters& para, | |
592 scoped_refptr<base::MessageLoopProxy> thread); | |
593 | |
594 void GetAllCookiesForURLTask( | |
595 const GetCookieListCallback& callback, | |
596 const CookieAPIParameters& para, | |
597 scoped_refptr<base::MessageLoopProxy> thread); | |
598 | |
599 void DeleteAllTask( | |
600 const DeleteCallback& callback, | |
601 const CookieAPIParameters& para, | |
602 scoped_refptr<base::MessageLoopProxy> thread); | |
603 | |
604 void DeleteAllCreatedBetweenTask( | |
605 const DeleteCallback& callback, | |
606 const CookieAPIParameters& para, | |
607 scoped_refptr<base::MessageLoopProxy> thread); | |
608 | |
609 void DeleteAllForHostTask( | |
610 const DeleteCallback& callback, | |
611 const CookieAPIParameters& para, | |
612 scoped_refptr<base::MessageLoopProxy> thread); | |
613 | |
614 void DeleteCanonicalCookieTask( | |
615 const DeleteCookieCallback& callback, | |
616 const CookieAPIParameters& para, | |
617 scoped_refptr<base::MessageLoopProxy> thread); | |
618 | |
619 void SetCookieWithOptionsTask( | |
620 const SetCookiesCallback& callback, | |
621 const CookieAPIParameters& para, | |
622 scoped_refptr<base::MessageLoopProxy> thread); | |
623 | |
624 void GetCookiesWithOptionsTask( | |
625 const GetCookiesCallback& callback, | |
626 const CookieAPIParameters& para, | |
627 scoped_refptr<base::MessageLoopProxy> thread); | |
628 | |
629 void GetCookiesWithInfoTask( | |
630 const GetCookieInfoCallback& callback, | |
631 const CookieAPIParameters& para, | |
632 scoped_refptr<base::MessageLoopProxy> thread); | |
633 | |
634 void DeleteCookieTask( | |
635 const base::Closure& callback, | |
636 const CookieAPIParameters& para, | |
637 scoped_refptr<base::MessageLoopProxy> thread); | |
638 | |
529 // Histogram variables; see CookieMonster::InitializeHistograms() in | 639 // Histogram variables; see CookieMonster::InitializeHistograms() in |
530 // cookie_monster.cc for details. | 640 // cookie_monster.cc for details. |
531 base::Histogram* histogram_expiration_duration_minutes_; | 641 base::Histogram* histogram_expiration_duration_minutes_; |
532 base::Histogram* histogram_between_access_interval_minutes_; | 642 base::Histogram* histogram_between_access_interval_minutes_; |
533 base::Histogram* histogram_evicted_last_access_minutes_; | 643 base::Histogram* histogram_evicted_last_access_minutes_; |
534 base::Histogram* histogram_count_; | 644 base::Histogram* histogram_count_; |
535 base::Histogram* histogram_domain_count_; | 645 base::Histogram* histogram_domain_count_; |
536 base::Histogram* histogram_etldp1_count_; | 646 base::Histogram* histogram_etldp1_count_; |
537 base::Histogram* histogram_domain_per_etldp1_count_; | 647 base::Histogram* histogram_domain_per_etldp1_count_; |
538 base::Histogram* histogram_number_duplicate_db_cookies_; | 648 base::Histogram* histogram_number_duplicate_db_cookies_; |
539 base::Histogram* histogram_cookie_deletion_cause_; | 649 base::Histogram* histogram_cookie_deletion_cause_; |
540 base::Histogram* histogram_time_get_; | 650 base::Histogram* histogram_time_get_; |
541 base::Histogram* histogram_time_mac_; | 651 base::Histogram* histogram_time_mac_; |
542 base::Histogram* histogram_time_load_; | 652 base::Histogram* histogram_time_load_; |
543 | 653 |
544 CookieMap cookies_; | 654 CookieMap cookies_; |
545 | 655 |
546 // Indicates whether the cookie store has been initialized. This happens | 656 // Indicates whether the cookie store has been initialized. This happens |
547 // lazily in InitStoreIfNecessary(). | 657 // lazily in InitStoreIfNecessary(). |
548 bool initialized_; | 658 bool initialized_; |
549 | 659 |
660 // Indicate whether the cookies are loaded from disk. | |
erikwright (departed)
2011/08/11 13:58:24
"Indicates whether loading from the backend store
ycxiao
2011/08/12 02:35:24
Done.
| |
661 bool loaded_; | |
662 | |
663 // Queue the calls of CookieMonster while the loadind form the back | |
erikwright (departed)
2011/08/11 13:58:24
"Queues calls to CookieMonster until loading from
ycxiao
2011/08/12 02:35:24
Done.
| |
664 // store haven't complete. | |
665 std::deque<base::Closure> queue_; | |
erikwright (departed)
2011/08/11 13:58:24
Can you define this as std::queue<base::Closure> i
ycxiao
2011/08/12 02:35:24
Done.
| |
666 | |
550 // Indicates whether this cookie monster uses the new effective domain | 667 // Indicates whether this cookie monster uses the new effective domain |
551 // key scheme or not. | 668 // key scheme or not. |
552 ExpiryAndKeyScheme expiry_and_key_scheme_; | 669 ExpiryAndKeyScheme expiry_and_key_scheme_; |
553 | 670 |
554 scoped_refptr<PersistentCookieStore> store_; | 671 scoped_refptr<PersistentCookieStore> store_; |
555 | 672 |
556 base::Time last_time_seen_; | 673 base::Time last_time_seen_; |
557 | 674 |
558 // Minimum delay after updating a cookie's LastAccessDate before we will | 675 // Minimum delay after updating a cookie's LastAccessDate before we will |
559 // update it again. | 676 // update it again. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 | 727 |
611 // This constructor does canonicalization but not validation. | 728 // This constructor does canonicalization but not validation. |
612 // The result of this constructor should not be relied on in contexts | 729 // The result of this constructor should not be relied on in contexts |
613 // in which pre-validation of the ParsedCookie has not been done. | 730 // in which pre-validation of the ParsedCookie has not been done. |
614 CanonicalCookie(const GURL& url, const ParsedCookie& pc); | 731 CanonicalCookie(const GURL& url, const ParsedCookie& pc); |
615 | 732 |
616 ~CanonicalCookie(); | 733 ~CanonicalCookie(); |
617 | 734 |
618 // Supports the default copy constructor. | 735 // Supports the default copy constructor. |
619 | 736 |
737 // Creates a canonical cookie from parsed cookie. | |
738 // Canonicalizes and validates inputs. May return NULL if an attribute | |
739 // value is invalid. | |
740 static CanonicalCookie* Create(const GURL& url, | |
741 const ParsedCookie& pc); | |
742 | |
620 // Creates a canonical cookie from unparsed attribute values. | 743 // Creates a canonical cookie from unparsed attribute values. |
621 // Canonicalizes and validates inputs. May return NULL if an attribute | 744 // Canonicalizes and validates inputs. May return NULL if an attribute |
622 // value is invalid. | 745 // value is invalid. |
623 static CanonicalCookie* Create(const GURL& url, | 746 static CanonicalCookie* Create(const GURL& url, |
624 const std::string& name, | 747 const std::string& name, |
625 const std::string& value, | 748 const std::string& value, |
626 const std::string& domain, | 749 const std::string& domain, |
627 const std::string& path, | 750 const std::string& path, |
628 const std::string& mac_key, | 751 const std::string& mac_key, |
629 const std::string& mac_algorithm, | 752 const std::string& mac_algorithm, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 }; | 971 }; |
849 | 972 |
850 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 973 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
851 RefcountedPersistentCookieStore; | 974 RefcountedPersistentCookieStore; |
852 | 975 |
853 class CookieMonster::PersistentCookieStore | 976 class CookieMonster::PersistentCookieStore |
854 : public RefcountedPersistentCookieStore { | 977 : public RefcountedPersistentCookieStore { |
855 public: | 978 public: |
856 virtual ~PersistentCookieStore() {} | 979 virtual ~PersistentCookieStore() {} |
857 | 980 |
981 typedef base::Callback<void(const std::vector< | |
982 CookieMonster::CanonicalCookie*>&)> LoadedCallback; | |
983 | |
858 // Initializes the store and retrieves the existing cookies. This will be | 984 // Initializes the store and retrieves the existing cookies. This will be |
859 // called only once at startup. | 985 // called only once at startup. |
860 virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0; | 986 virtual bool Load(const LoadedCallback& loaded_callback) = 0; |
861 | 987 |
862 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 988 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
863 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 989 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
864 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 990 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
865 | 991 |
866 // Sets the value of the user preference whether the persistent storage | 992 // Sets the value of the user preference whether the persistent storage |
867 // must be deleted upon destruction. | 993 // must be deleted upon destruction. |
868 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 994 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
869 | 995 |
870 // Flush the store and post the given Task when complete. | 996 // Flush the store and post the given Task when complete. |
871 virtual void Flush(Task* completion_task) = 0; | 997 virtual void Flush(Task* completion_task) = 0; |
872 | 998 |
873 protected: | 999 protected: |
874 PersistentCookieStore() {} | 1000 PersistentCookieStore() {} |
875 | 1001 |
876 private: | 1002 private: |
877 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 1003 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
878 }; | 1004 }; |
879 | 1005 |
880 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 1006 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
881 }; | 1007 }; |
882 | 1008 |
883 } // namespace net | 1009 } // namespace net |
884 | 1010 |
885 #endif // NET_BASE_COOKIE_MONSTER_H_ | 1011 #endif // NET_BASE_COOKIE_MONSTER_H_ |
OLD | NEW |