| 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" |
| 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); |
| 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, |
| 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); |
| 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 // Ininitalize the cookies. |
| 438 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); |
| 439 |
| 440 // Invoke the queueing calls of CookieMonster when loading cookies from |
| 441 // the back store is complete. |
| 442 void InvokeQueue(); |
| 443 |
| 420 // Checks that |cookies_| matches our invariants, and tries to repair any | 444 // Checks that |cookies_| matches our invariants, and tries to repair any |
| 421 // inconsistencies. (In other words, it does not have duplicate cookies). | 445 // inconsistencies. (In other words, it does not have duplicate cookies). |
| 422 void EnsureCookiesMapIsValid(); | 446 void EnsureCookiesMapIsValid(); |
| 423 | 447 |
| 424 // Checks for any duplicate cookies for CookieMap key |key| which lie between | 448 // 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. | 449 // |begin| and |end|. If any are found, all but the most recent are deleted. |
| 426 // Returns the number of duplicate cookies that were deleted. | 450 // Returns the number of duplicate cookies that were deleted. |
| 427 int TrimDuplicateCookiesForKey(const std::string& key, | 451 int TrimDuplicateCookiesForKey(const std::string& key, |
| 428 CookieMap::iterator begin, | 452 CookieMap::iterator begin, |
| 429 CookieMap::iterator end); | 453 CookieMap::iterator end); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 void RecordPeriodicStats(const base::Time& current_time); | 543 void RecordPeriodicStats(const base::Time& current_time); |
| 520 | 544 |
| 521 // Initialize the above variables; should only be called from | 545 // Initialize the above variables; should only be called from |
| 522 // the constructor. | 546 // the constructor. |
| 523 void InitializeHistograms(); | 547 void InitializeHistograms(); |
| 524 | 548 |
| 525 // The resolution of our time isn't enough, so we do something | 549 // The resolution of our time isn't enough, so we do something |
| 526 // ugly and increment when we've seen the same time twice. | 550 // ugly and increment when we've seen the same time twice. |
| 527 base::Time CurrentTime(); | 551 base::Time CurrentTime(); |
| 528 | 552 |
| 553 // Store the parameters of cookie monster API. |
| 554 class CookieAPIParameters { |
| 555 public: |
| 556 CookieAPIParameters() |
| 557 : secure(false), |
| 558 http_only(false), |
| 559 sync_to_store(false) { } |
| 560 |
| 561 GURL* url; |
| 562 CookieOptions options; |
| 563 std::string name; |
| 564 std::string value; |
| 565 std::string domain; |
| 566 std::string path; |
| 567 std::string cookie_line; |
| 568 bool secure; |
| 569 bool http_only; |
| 570 bool sync_to_store; |
| 571 base::Time delete_begin; |
| 572 base::Time delete_end; |
| 573 base::Time expiration_time; |
| 574 CanonicalCookie* cookie; |
| 575 }; |
| 576 |
| 577 // Run the cookie request task if cookie loaded, otherwise added the task |
| 578 // to task queue. |
| 579 void DoCookieTask(const base::Closure& task); |
| 580 |
| 581 // Task functions for queueing the coming request. |
| 582 |
| 583 void SetCookieWithDetailsTask( |
| 584 const SetCookiesCallback& callback, |
| 585 const CookieAPIParameters& para, |
| 586 scoped_refptr<base::MessageLoopProxy> thread); |
| 587 |
| 588 void GetAllCookiesTask( |
| 589 const GetCookieListCallback& callback, |
| 590 scoped_refptr<base::MessageLoopProxy> thread); |
| 591 |
| 592 void GetAllCookiesForURLWithOptionsTask( |
| 593 const GetCookieListCallback& callback, |
| 594 const CookieAPIParameters& para, |
| 595 scoped_refptr<base::MessageLoopProxy> thread); |
| 596 |
| 597 void GetAllCookiesForURLTask( |
| 598 const GetCookieListCallback& callback, |
| 599 const CookieAPIParameters& para, |
| 600 scoped_refptr<base::MessageLoopProxy> thread); |
| 601 |
| 602 void DeleteAllTask( |
| 603 const DeleteCallback& callback, |
| 604 const CookieAPIParameters& para, |
| 605 scoped_refptr<base::MessageLoopProxy> thread); |
| 606 |
| 607 void DeleteAllCreatedBetweenTask( |
| 608 const DeleteCallback& callback, |
| 609 const CookieAPIParameters& para, |
| 610 scoped_refptr<base::MessageLoopProxy> thread); |
| 611 |
| 612 void DeleteAllForHostTask( |
| 613 const DeleteCallback& callback, |
| 614 const CookieAPIParameters& para, |
| 615 scoped_refptr<base::MessageLoopProxy> thread); |
| 616 |
| 617 void DeleteCanonicalCookieTask( |
| 618 const DeleteCookieCallback& callback, |
| 619 const CookieAPIParameters& para, |
| 620 scoped_refptr<base::MessageLoopProxy> thread); |
| 621 |
| 622 void SetCookieWithOptionsTask( |
| 623 const SetCookiesCallback& callback, |
| 624 const CookieAPIParameters& para, |
| 625 scoped_refptr<base::MessageLoopProxy> thread); |
| 626 |
| 627 void GetCookiesWithOptionsTask( |
| 628 const GetCookiesCallback& callback, |
| 629 const CookieAPIParameters& para, |
| 630 scoped_refptr<base::MessageLoopProxy> thread); |
| 631 |
| 632 void GetCookiesWithInfoTask( |
| 633 const GetCookieInfoCallback& callback, |
| 634 const CookieAPIParameters& para, |
| 635 scoped_refptr<base::MessageLoopProxy> thread); |
| 636 |
| 637 void DeleteCookieTask( |
| 638 const base::Closure& callback, |
| 639 const CookieAPIParameters& para, |
| 640 scoped_refptr<base::MessageLoopProxy> thread); |
| 641 |
| 529 // Histogram variables; see CookieMonster::InitializeHistograms() in | 642 // Histogram variables; see CookieMonster::InitializeHistograms() in |
| 530 // cookie_monster.cc for details. | 643 // cookie_monster.cc for details. |
| 531 base::Histogram* histogram_expiration_duration_minutes_; | 644 base::Histogram* histogram_expiration_duration_minutes_; |
| 532 base::Histogram* histogram_between_access_interval_minutes_; | 645 base::Histogram* histogram_between_access_interval_minutes_; |
| 533 base::Histogram* histogram_evicted_last_access_minutes_; | 646 base::Histogram* histogram_evicted_last_access_minutes_; |
| 534 base::Histogram* histogram_count_; | 647 base::Histogram* histogram_count_; |
| 535 base::Histogram* histogram_domain_count_; | 648 base::Histogram* histogram_domain_count_; |
| 536 base::Histogram* histogram_etldp1_count_; | 649 base::Histogram* histogram_etldp1_count_; |
| 537 base::Histogram* histogram_domain_per_etldp1_count_; | 650 base::Histogram* histogram_domain_per_etldp1_count_; |
| 538 base::Histogram* histogram_number_duplicate_db_cookies_; | 651 base::Histogram* histogram_number_duplicate_db_cookies_; |
| 539 base::Histogram* histogram_cookie_deletion_cause_; | 652 base::Histogram* histogram_cookie_deletion_cause_; |
| 540 base::Histogram* histogram_time_get_; | 653 base::Histogram* histogram_time_get_; |
| 541 base::Histogram* histogram_time_mac_; | 654 base::Histogram* histogram_time_mac_; |
| 542 base::Histogram* histogram_time_load_; | 655 base::Histogram* histogram_time_load_; |
| 543 | 656 |
| 544 CookieMap cookies_; | 657 CookieMap cookies_; |
| 545 | 658 |
| 546 // Indicates whether the cookie store has been initialized. This happens | 659 // Indicates whether the cookie store has been initialized. This happens |
| 547 // lazily in InitStoreIfNecessary(). | 660 // lazily in InitStoreIfNecessary(). |
| 548 bool initialized_; | 661 bool initialized_; |
| 549 | 662 |
| 663 // Indicate whether the cookies are loaded from disk. |
| 664 bool loaded_; |
| 665 |
| 666 // Queue the calls of CookieMonster while the loadind form the back |
| 667 // store haven't complete. |
| 668 std::deque<base::Closure> queue_; |
| 669 |
| 550 // Indicates whether this cookie monster uses the new effective domain | 670 // Indicates whether this cookie monster uses the new effective domain |
| 551 // key scheme or not. | 671 // key scheme or not. |
| 552 ExpiryAndKeyScheme expiry_and_key_scheme_; | 672 ExpiryAndKeyScheme expiry_and_key_scheme_; |
| 553 | 673 |
| 554 scoped_refptr<PersistentCookieStore> store_; | 674 scoped_refptr<PersistentCookieStore> store_; |
| 555 | 675 |
| 556 base::Time last_time_seen_; | 676 base::Time last_time_seen_; |
| 557 | 677 |
| 558 // Minimum delay after updating a cookie's LastAccessDate before we will | 678 // Minimum delay after updating a cookie's LastAccessDate before we will |
| 559 // update it again. | 679 // update it again. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 730 |
| 611 // This constructor does canonicalization but not validation. | 731 // This constructor does canonicalization but not validation. |
| 612 // The result of this constructor should not be relied on in contexts | 732 // The result of this constructor should not be relied on in contexts |
| 613 // in which pre-validation of the ParsedCookie has not been done. | 733 // in which pre-validation of the ParsedCookie has not been done. |
| 614 CanonicalCookie(const GURL& url, const ParsedCookie& pc); | 734 CanonicalCookie(const GURL& url, const ParsedCookie& pc); |
| 615 | 735 |
| 616 ~CanonicalCookie(); | 736 ~CanonicalCookie(); |
| 617 | 737 |
| 618 // Supports the default copy constructor. | 738 // Supports the default copy constructor. |
| 619 | 739 |
| 740 // Creates a canonical cookie from parsed cookie. |
| 741 // Canonicalizes and validates inputs. May return NULL if an attribute |
| 742 // value is invalid. |
| 743 static CanonicalCookie* Create(const GURL& url, |
| 744 const ParsedCookie& pc); |
| 745 |
| 620 // Creates a canonical cookie from unparsed attribute values. | 746 // Creates a canonical cookie from unparsed attribute values. |
| 621 // Canonicalizes and validates inputs. May return NULL if an attribute | 747 // Canonicalizes and validates inputs. May return NULL if an attribute |
| 622 // value is invalid. | 748 // value is invalid. |
| 623 static CanonicalCookie* Create(const GURL& url, | 749 static CanonicalCookie* Create(const GURL& url, |
| 624 const std::string& name, | 750 const std::string& name, |
| 625 const std::string& value, | 751 const std::string& value, |
| 626 const std::string& domain, | 752 const std::string& domain, |
| 627 const std::string& path, | 753 const std::string& path, |
| 628 const std::string& mac_key, | 754 const std::string& mac_key, |
| 629 const std::string& mac_algorithm, | 755 const std::string& mac_algorithm, |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 }; | 974 }; |
| 849 | 975 |
| 850 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 976 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
| 851 RefcountedPersistentCookieStore; | 977 RefcountedPersistentCookieStore; |
| 852 | 978 |
| 853 class CookieMonster::PersistentCookieStore | 979 class CookieMonster::PersistentCookieStore |
| 854 : public RefcountedPersistentCookieStore { | 980 : public RefcountedPersistentCookieStore { |
| 855 public: | 981 public: |
| 856 virtual ~PersistentCookieStore() {} | 982 virtual ~PersistentCookieStore() {} |
| 857 | 983 |
| 984 typedef base::Callback<void(const std::vector< |
| 985 CookieMonster::CanonicalCookie*>&)> LoadedCallback; |
| 986 |
| 858 // Initializes the store and retrieves the existing cookies. This will be | 987 // Initializes the store and retrieves the existing cookies. This will be |
| 859 // called only once at startup. | 988 // called only once at startup. |
| 860 virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0; | 989 virtual bool Load(const LoadedCallback& loaded_callback) = 0; |
| 861 | 990 |
| 862 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 991 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
| 863 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 992 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
| 864 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 993 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
| 865 | 994 |
| 866 // Sets the value of the user preference whether the persistent storage | 995 // Sets the value of the user preference whether the persistent storage |
| 867 // must be deleted upon destruction. | 996 // must be deleted upon destruction. |
| 868 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 997 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
| 869 | 998 |
| 870 // Flush the store and post the given Task when complete. | 999 // Flush the store and post the given Task when complete. |
| 871 virtual void Flush(Task* completion_task) = 0; | 1000 virtual void Flush(Task* completion_task) = 0; |
| 872 | 1001 |
| 873 protected: | 1002 protected: |
| 874 PersistentCookieStore() {} | 1003 PersistentCookieStore() {} |
| 875 | 1004 |
| 876 private: | 1005 private: |
| 877 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 1006 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 878 }; | 1007 }; |
| 879 | 1008 |
| 880 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 1009 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
| 881 }; | 1010 }; |
| 882 | 1011 |
| 883 } // namespace net | 1012 } // namespace net |
| 884 | 1013 |
| 885 #endif // NET_BASE_COOKIE_MONSTER_H_ | 1014 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |