| 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_export.h" | 25 #include "net/base/net_export.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 TimeTicks; |
| 30 } | 32 } |
| 31 | 33 |
| 32 namespace net { | 34 namespace net { |
| 33 | 35 |
| 34 class CookieList; | 36 class CookieList; |
| 35 | 37 |
| 36 // The cookie monster is the system for storing and retrieving cookies. It has | 38 // 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 | 39 // an in-memory list of all cookies, and synchronizes non-session cookies to an |
| 38 // optional permanent storage that implements the PersistentCookieStore | 40 // optional permanent storage that implements the PersistentCookieStore |
| 39 // interface. | 41 // interface. |
| (...skipping 91 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 |list| into this instance. |
| 144 bool InitializeFrom(const CookieList& list); |
| 145 |
| 146 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; |
| 147 typedef base::Callback<void(int num_deleted)> DeleteCallback; |
| 148 typedef base::Callback<void(bool success)> DeleteCookieCallback; |
| 149 |
| 141 // Sets a cookie given explicit user-provided cookie attributes. The cookie | 150 // Sets a cookie given explicit user-provided cookie attributes. The cookie |
| 142 // name, value, domain, etc. are each provided as separate strings. This | 151 // name, value, domain, etc. are each provided as separate strings. This |
| 143 // function expects each attribute to be well-formed. It will check for | 152 // function expects each attribute to be well-formed. It will check for |
| 144 // disallowed characters (e.g. the ';' character is disallowed within the | 153 // disallowed characters (e.g. the ';' character is disallowed within the |
| 145 // cookie value attribute) and will return false without setting the cookie | 154 // cookie value attribute) and will return false without setting the cookie |
| 146 // if such characters are found. | 155 // 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, | 156 void SetCookieWithDetailsAsync(const GURL& url, |
| 155 const std::string& name, | 157 const std::string& name, |
| 156 const std::string& value, | 158 const std::string& value, |
| 157 const std::string& domain, | 159 const std::string& domain, |
| 158 const std::string& path, | 160 const std::string& path, |
| 159 const base::Time& expiration_time, | 161 const base::Time& expiration_time, |
| 160 bool secure, bool http_only, | 162 bool secure, bool http_only, |
| 161 const SetCookiesCallback& callback); | 163 const SetCookiesCallback& callback); |
| 162 | 164 |
| 163 | 165 |
| 164 // Helper function that adds all cookies from |cookie_monster| into this | |
| 165 // instance. | |
| 166 bool InitializeFrom(const CookieList& list); | |
| 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(const DeleteCallback& callback); |
| 189 |
| 196 // Deletes all of the cookies that have a creation_date greater than or equal | 190 // Deletes all of the cookies that have a creation_date greater than or equal |
| 197 // to |delete_begin| and less than |delete_end| | 191 // to |delete_begin| and less than |delete_end| |
| 198 // Returns the number of cookies that have been deleted. | 192 // 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, | 193 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, |
| 204 const base::Time& delete_end, | 194 const base::Time& delete_end, |
| 205 bool sync_to_store, | |
| 206 const DeleteCallback& callback); | 195 const DeleteCallback& callback); |
| 207 | 196 |
| 208 // Deletes all cookies that match the host of the given URL | 197 // Deletes all cookies that match the host of the given URL |
| 209 // regardless of path. This includes all http_only and secure cookies, | 198 // 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. | 199 // but does not include any domain cookies that may apply to this host. |
| 211 // Returns the number of cookies deleted. | 200 // Returns the number of cookies deleted. |
| 212 int DeleteAllForHost(const GURL& url); | |
| 213 | |
| 214 void DeleteAllForHostAsync(const GURL& url, | 201 void DeleteAllForHostAsync(const GURL& url, |
| 215 const DeleteCallback& callback); | 202 const DeleteCallback& callback); |
| 216 | 203 |
| 217 // Deletes one specific cookie. | 204 // Deletes one specific cookie. |
| 218 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
| 219 | |
| 220 typedef SetCookiesCallback DeleteCookieCallback; | |
| 221 | |
| 222 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, | 205 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
| 223 const DeleteCookieCallback& callback); | 206 const DeleteCookieCallback& callback); |
| 224 | 207 |
| 225 // Override the default list of schemes that are allowed to be set in | 208 // Override the default list of schemes that are allowed to be set in |
| 226 // this cookie store. Calling his overrides the value of | 209 // this cookie store. Calling his overrides the value of |
| 227 // "enable_file_scheme_". | 210 // "enable_file_scheme_". |
| 228 // If this this method is called, it must be called before first use of | 211 // 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). | 212 // the instance (i.e. as part of the instance initialization process). |
| 230 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); | 213 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); |
| 231 | 214 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 253 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. | 236 // 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 | 237 // 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 | 238 // actually does the flushing. Your Task should generally post a notification |
| 256 // to the thread you actually want to be notified on. | 239 // to the thread you actually want to be notified on. |
| 257 void FlushStore(Task* completion_task); | 240 void FlushStore(Task* completion_task); |
| 258 | 241 |
| 259 // CookieStore implementation. | 242 // CookieStore implementation. |
| 260 | 243 |
| 261 // Sets the cookies specified by |cookie_list| returned from |url| | 244 // Sets the cookies specified by |cookie_list| returned from |url| |
| 262 // with options |options| in effect. | 245 // with options |options| in effect. |
| 263 virtual bool SetCookieWithOptions(const GURL& url, | 246 virtual void SetCookieWithOptionsAsync( |
| 264 const std::string& cookie_line, | 247 const GURL& url, |
| 265 const CookieOptions& options); | 248 const std::string& cookie_line, |
| 266 | 249 const CookieOptions& options, |
| 267 virtual void SetCookieWithOptionsAsync(const GURL& url, | 250 const SetCookiesCallback& callback) OVERRIDE; |
| 268 const std::string& cookie_line, | |
| 269 const CookieOptions& options, | |
| 270 const SetCookiesCallback& callback); | |
| 271 | 251 |
| 272 // Gets all cookies that apply to |url| given |options|. | 252 // Gets all cookies that apply to |url| given |options|. |
| 273 // The returned cookies are ordered by longest path, then earliest | 253 // The returned cookies are ordered by longest path, then earliest |
| 274 // creation date. | 254 // creation date. |
| 275 virtual std::string GetCookiesWithOptions(const GURL& url, | |
| 276 const CookieOptions& options); | |
| 277 | |
| 278 virtual void GetCookiesWithOptionsAsync( | 255 virtual void GetCookiesWithOptionsAsync( |
| 279 const GURL& url, | 256 const GURL& url, |
| 280 const CookieOptions& options, | 257 const CookieOptions& options, |
| 281 const GetCookiesCallback& callback); | 258 const GetCookiesCallback& callback) OVERRIDE; |
| 282 | 259 |
| 283 virtual void GetCookiesWithInfo(const GURL& url, | 260 virtual void GetCookiesWithInfoAsync( |
| 284 const CookieOptions& options, | 261 const GURL& url, |
| 285 std::string* cookie_line, | 262 const CookieOptions& options, |
| 286 std::vector<CookieInfo>* cookie_infos); | 263 const GetCookieInfoCallback& callback) OVERRIDE; |
| 287 | |
| 288 virtual void GetCookiesWithInfoAsync(const GURL& url, | |
| 289 const CookieOptions& options, | |
| 290 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) OVERRIDE; |
| 297 | 269 |
| 298 virtual CookieMonster* GetCookieMonster(); | 270 virtual CookieMonster* GetCookieMonster() OVERRIDE; |
| 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 |
| 307 // The default list of schemes the cookie monster can handle. | 279 // The default list of schemes the cookie monster can handle. |
| 308 static const char* kDefaultCookieableSchemes[]; | 280 static const char* kDefaultCookieableSchemes[]; |
| 309 static const int kDefaultCookieableSchemesCount; | 281 static const int kDefaultCookieableSchemesCount; |
| 310 | 282 |
| 311 private: | 283 private: |
| 284 // For queueing the cookie monster calls. |
| 285 class CookieMonsterTask; |
| 286 class DeleteAllCreatedBetweenTask; |
| 287 class DeleteAllForHostTask; |
| 288 class DeleteAllTask; |
| 289 class DeleteCookieTask; |
| 290 class DeleteCanonicalCookieTask; |
| 291 class GetAllCookiesForURLWithOptionsTask; |
| 292 class GetAllCookiesTask; |
| 293 class GetCookiesWithOptionsTask; |
| 294 class GetCookiesWithInfoTask; |
| 295 class SetCookieWithDetailsTask; |
| 296 class SetCookieWithOptionsTask; |
| 297 |
| 312 // Testing support. | 298 // Testing support. |
| 313 // For SetCookieWithCreationTime. | 299 // For SetCookieWithCreationTime. |
| 314 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, | 300 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, |
| 315 TestCookieDeleteAllCreatedBetweenTimestamps); | 301 TestCookieDeleteAllCreatedBetweenTimestamps); |
| 316 | 302 |
| 317 // For gargage collection constants. | 303 // For gargage collection constants. |
| 318 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); | 304 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); |
| 319 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection); | 305 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection); |
| 320 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers); | 306 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers); |
| 321 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes); | 307 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 376 |
| 391 // Default value for key and expiry scheme scheme. | 377 // Default value for key and expiry scheme scheme. |
| 392 static const ExpiryAndKeyScheme expiry_and_key_default_ = | 378 static const ExpiryAndKeyScheme expiry_and_key_default_ = |
| 393 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; | 379 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; |
| 394 | 380 |
| 395 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. | 381 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. |
| 396 static const int kRecordStatisticsIntervalSeconds = 10 * 60; | 382 static const int kRecordStatisticsIntervalSeconds = 10 * 60; |
| 397 | 383 |
| 398 virtual ~CookieMonster(); | 384 virtual ~CookieMonster(); |
| 399 | 385 |
| 386 // The following are synchronous calls to which the asynchronous methods |
| 387 // delegate either immediately (if the store is loaded) or through a deferred |
| 388 // task (if the store is not yet loaded). |
| 389 bool SetCookieWithDetails(const GURL& url, |
| 390 const std::string& name, |
| 391 const std::string& value, |
| 392 const std::string& domain, |
| 393 const std::string& path, |
| 394 const base::Time& expiration_time, |
| 395 bool secure, bool http_only); |
| 396 |
| 397 CookieList GetAllCookies(); |
| 398 |
| 399 CookieList GetAllCookiesForURLWithOptions(const GURL& url, |
| 400 const CookieOptions& options); |
| 401 |
| 402 CookieList GetAllCookiesForURL(const GURL& url); |
| 403 |
| 404 int DeleteAll(bool sync_to_store); |
| 405 |
| 406 int DeleteAllCreatedBetween(const base::Time& delete_begin, |
| 407 const base::Time& delete_end); |
| 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 // Stores cookies loaded from the backing store and invokes any deferred |
| 451 // calls. |beginning_time| should be the moment PersistentCookieStore::Load |
| 452 // was invoked and is used for reporting histogram_time_load_. |
| 453 void OnLoaded(base::TimeTicks beginning_time, |
| 454 const std::vector<CanonicalCookie*>& cookies); |
| 455 |
| 456 // Stores the loaded cookies. |
| 457 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); |
| 458 |
| 459 // Invokes deferred calls. |
| 460 void InvokeQueue(); |
| 461 |
| 420 // Checks that |cookies_| matches our invariants, and tries to repair any | 462 // Checks that |cookies_| matches our invariants, and tries to repair any |
| 421 // inconsistencies. (In other words, it does not have duplicate cookies). | 463 // inconsistencies. (In other words, it does not have duplicate cookies). |
| 422 void EnsureCookiesMapIsValid(); | 464 void EnsureCookiesMapIsValid(); |
| 423 | 465 |
| 424 // Checks for any duplicate cookies for CookieMap key |key| which lie between | 466 // 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. | 467 // |begin| and |end|. If any are found, all but the most recent are deleted. |
| 426 // Returns the number of duplicate cookies that were deleted. | 468 // Returns the number of duplicate cookies that were deleted. |
| 427 int TrimDuplicateCookiesForKey(const std::string& key, | 469 int TrimDuplicateCookiesForKey(const std::string& key, |
| 428 CookieMap::iterator begin, | 470 CookieMap::iterator begin, |
| 429 CookieMap::iterator end); | 471 CookieMap::iterator end); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 void RecordPeriodicStats(const base::Time& current_time); | 561 void RecordPeriodicStats(const base::Time& current_time); |
| 520 | 562 |
| 521 // Initialize the above variables; should only be called from | 563 // Initialize the above variables; should only be called from |
| 522 // the constructor. | 564 // the constructor. |
| 523 void InitializeHistograms(); | 565 void InitializeHistograms(); |
| 524 | 566 |
| 525 // The resolution of our time isn't enough, so we do something | 567 // The resolution of our time isn't enough, so we do something |
| 526 // ugly and increment when we've seen the same time twice. | 568 // ugly and increment when we've seen the same time twice. |
| 527 base::Time CurrentTime(); | 569 base::Time CurrentTime(); |
| 528 | 570 |
| 571 // Run the cookie request task if cookie loaded, otherwise added the task |
| 572 // to task queue. |
| 573 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); |
| 574 |
| 529 // Histogram variables; see CookieMonster::InitializeHistograms() in | 575 // Histogram variables; see CookieMonster::InitializeHistograms() in |
| 530 // cookie_monster.cc for details. | 576 // cookie_monster.cc for details. |
| 531 base::Histogram* histogram_expiration_duration_minutes_; | 577 base::Histogram* histogram_expiration_duration_minutes_; |
| 532 base::Histogram* histogram_between_access_interval_minutes_; | 578 base::Histogram* histogram_between_access_interval_minutes_; |
| 533 base::Histogram* histogram_evicted_last_access_minutes_; | 579 base::Histogram* histogram_evicted_last_access_minutes_; |
| 534 base::Histogram* histogram_count_; | 580 base::Histogram* histogram_count_; |
| 535 base::Histogram* histogram_domain_count_; | 581 base::Histogram* histogram_domain_count_; |
| 536 base::Histogram* histogram_etldp1_count_; | 582 base::Histogram* histogram_etldp1_count_; |
| 537 base::Histogram* histogram_domain_per_etldp1_count_; | 583 base::Histogram* histogram_domain_per_etldp1_count_; |
| 538 base::Histogram* histogram_number_duplicate_db_cookies_; | 584 base::Histogram* histogram_number_duplicate_db_cookies_; |
| 539 base::Histogram* histogram_cookie_deletion_cause_; | 585 base::Histogram* histogram_cookie_deletion_cause_; |
| 540 base::Histogram* histogram_time_get_; | 586 base::Histogram* histogram_time_get_; |
| 541 base::Histogram* histogram_time_mac_; | 587 base::Histogram* histogram_time_mac_; |
| 542 base::Histogram* histogram_time_load_; | 588 base::Histogram* histogram_time_load_; |
| 543 | 589 |
| 544 CookieMap cookies_; | 590 CookieMap cookies_; |
| 545 | 591 |
| 546 // Indicates whether the cookie store has been initialized. This happens | 592 // Indicates whether the cookie store has been initialized. This happens |
| 547 // lazily in InitStoreIfNecessary(). | 593 // lazily in InitStoreIfNecessary(). |
| 548 bool initialized_; | 594 bool initialized_; |
| 549 | 595 |
| 596 // Indicates whether loading from the backend store is completed and |
| 597 // calls may be immediately processed. |
| 598 bool loaded_; |
| 599 |
| 600 // Queues calls to CookieMonster until loading from the backend store is |
| 601 // completed. |
| 602 std::queue<scoped_refptr<CookieMonsterTask> > queue_; |
| 603 |
| 550 // Indicates whether this cookie monster uses the new effective domain | 604 // Indicates whether this cookie monster uses the new effective domain |
| 551 // key scheme or not. | 605 // key scheme or not. |
| 552 ExpiryAndKeyScheme expiry_and_key_scheme_; | 606 ExpiryAndKeyScheme expiry_and_key_scheme_; |
| 553 | 607 |
| 554 scoped_refptr<PersistentCookieStore> store_; | 608 scoped_refptr<PersistentCookieStore> store_; |
| 555 | 609 |
| 556 base::Time last_time_seen_; | 610 base::Time last_time_seen_; |
| 557 | 611 |
| 558 // Minimum delay after updating a cookie's LastAccessDate before we will | 612 // Minimum delay after updating a cookie's LastAccessDate before we will |
| 559 // update it again. | 613 // update it again. |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 }; | 908 }; |
| 855 | 909 |
| 856 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 910 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
| 857 RefcountedPersistentCookieStore; | 911 RefcountedPersistentCookieStore; |
| 858 | 912 |
| 859 class CookieMonster::PersistentCookieStore | 913 class CookieMonster::PersistentCookieStore |
| 860 : public RefcountedPersistentCookieStore { | 914 : public RefcountedPersistentCookieStore { |
| 861 public: | 915 public: |
| 862 virtual ~PersistentCookieStore() {} | 916 virtual ~PersistentCookieStore() {} |
| 863 | 917 |
| 918 typedef base::Callback<void(const std::vector< |
| 919 CookieMonster::CanonicalCookie*>&)> LoadedCallback; |
| 920 |
| 864 // Initializes the store and retrieves the existing cookies. This will be | 921 // Initializes the store and retrieves the existing cookies. This will be |
| 865 // called only once at startup. | 922 // called only once at startup. |
| 866 virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0; | 923 virtual bool Load(const LoadedCallback& loaded_callback) = 0; |
| 867 | 924 |
| 868 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 925 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
| 869 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 926 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
| 870 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 927 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
| 871 | 928 |
| 872 // Sets the value of the user preference whether the persistent storage | 929 // Sets the value of the user preference whether the persistent storage |
| 873 // must be deleted upon destruction. | 930 // must be deleted upon destruction. |
| 874 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 931 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
| 875 | 932 |
| 876 // Flush the store and post the given Task when complete. | 933 // Flush the store and post the given Task when complete. |
| 877 virtual void Flush(Task* completion_task) = 0; | 934 virtual void Flush(Task* completion_task) = 0; |
| 878 | 935 |
| 879 protected: | 936 protected: |
| 880 PersistentCookieStore() {} | 937 PersistentCookieStore() {} |
| 881 | 938 |
| 882 private: | 939 private: |
| 883 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 940 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 884 }; | 941 }; |
| 885 | 942 |
| 886 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 943 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
| 887 }; | 944 }; |
| 888 | 945 |
| 889 } // namespace net | 946 } // namespace net |
| 890 | 947 |
| 891 #endif // NET_BASE_COOKIE_MONSTER_H_ | 948 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |