Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Brought to you by the letter D and the number 2. | 5 // Brought to you by the letter D and the number 2. |
| 6 | 6 |
| 7 #ifndef NET_BASE_COOKIE_MONSTER_H_ | 7 #ifndef NET_BASE_COOKIE_MONSTER_H_ |
| 8 #define NET_BASE_COOKIE_MONSTER_H_ | 8 #define NET_BASE_COOKIE_MONSTER_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <queue> | |
| 12 #include <string> | 13 #include <string> |
| 13 #include <utility> | 14 #include <utility> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 17 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 21 #include "base/task.h" | 22 #include "base/task.h" |
| 22 #include "base/time.h" | 23 #include "base/time.h" |
| 23 #include "net/base/cookie_store.h" | 24 #include "net/base/cookie_store.h" |
| 24 #include "net/base/net_api.h" | 25 #include "net/base/net_api.h" |
| 25 | 26 |
| 26 class GURL; | 27 class GURL; |
| 27 | 28 |
| 28 namespace base { | 29 namespace base { |
| 29 class Histogram; | 30 class Histogram; |
| 31 class MessageLoopProxy; | |
|
Randy Smith (Not in Mondays)
2011/08/19 21:40:05
Not used in this file--maybe it should be in cooki
erikwright (departed)
2011/09/06 17:34:45
Done.
| |
| 30 } | 32 } |
| 31 | 33 |
| 32 namespace net { | 34 namespace net { |
| 33 | 35 |
| 34 class CookieList; | 36 class CookieList; |
| 37 class CookieMonsterTask; | |
| 35 | 38 |
| 36 // The cookie monster is the system for storing and retrieving cookies. It has | 39 // The cookie monster is the system for storing and retrieving cookies. It has |
| 37 // an in-memory list of all cookies, and synchronizes non-session cookies to an | 40 // an in-memory list of all cookies, and synchronizes non-session cookies to an |
| 38 // optional permanent storage that implements the PersistentCookieStore | 41 // optional permanent storage that implements the PersistentCookieStore |
| 39 // interface. | 42 // interface. |
| 40 // | 43 // |
| 41 // This class IS thread-safe. Normally, it is only used on the I/O thread, but | 44 // This class IS thread-safe. Normally, it is only used on the I/O thread, but |
| 42 // is also accessed directly through Automation for UI testing. | 45 // is also accessed directly through Automation for UI testing. |
| 43 // | 46 // |
| 44 // Several methods exist in asynchronous forms. Calls may be deferred if all | 47 // Several methods exist in asynchronous forms. Calls may be deferred if all |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 Delegate* delegate, | 134 Delegate* delegate, |
| 132 int last_access_threshold_milliseconds); | 135 int last_access_threshold_milliseconds); |
| 133 | 136 |
| 134 // Parses the string with the cookie time (very forgivingly). | 137 // Parses the string with the cookie time (very forgivingly). |
| 135 static base::Time ParseCookieTime(const std::string& time_string); | 138 static base::Time ParseCookieTime(const std::string& time_string); |
| 136 | 139 |
| 137 // Returns true if a domain string represents a host-only cookie, | 140 // Returns true if a domain string represents a host-only cookie, |
| 138 // i.e. it doesn't begin with a leading '.' character. | 141 // i.e. it doesn't begin with a leading '.' character. |
| 139 static bool DomainIsHostOnly(const std::string& domain_string); | 142 static bool DomainIsHostOnly(const std::string& domain_string); |
| 140 | 143 |
| 144 // Helper function that adds all cookies from |cookie_monster| into this | |
| 145 // instance. | |
| 146 bool InitializeFrom(const CookieList& list); | |
| 147 | |
| 148 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | |
| 149 typedef base::Callback<void(int num_deleted)> DeleteCallback; | |
| 150 typedef SetCookiesCallback DeleteCookieCallback; | |
| 151 | |
| 141 // Sets a cookie given explicit user-provided cookie attributes. The cookie | 152 // Sets a cookie given explicit user-provided cookie attributes. The cookie |
| 142 // name, value, domain, etc. are each provided as separate strings. This | 153 // name, value, domain, etc. are each provided as separate strings. This |
| 143 // function expects each attribute to be well-formed. It will check for | 154 // function expects each attribute to be well-formed. It will check for |
| 144 // disallowed characters (e.g. the ';' character is disallowed within the | 155 // disallowed characters (e.g. the ';' character is disallowed within the |
| 145 // cookie value attribute) and will return false without setting the cookie | 156 // cookie value attribute) and will return false without setting the cookie |
| 146 // if such characters are found. | 157 // if such characters are found. |
| 147 bool SetCookieWithDetails(const GURL& url, | |
| 148 const std::string& name, | |
| 149 const std::string& value, | |
| 150 const std::string& domain, | |
| 151 const std::string& path, | |
| 152 const base::Time& expiration_time, | |
| 153 bool secure, bool http_only); | |
| 154 void SetCookieWithDetailsAsync(const GURL& url, | 158 void SetCookieWithDetailsAsync(const GURL& url, |
| 155 const std::string& name, | 159 const std::string& name, |
| 156 const std::string& value, | 160 const std::string& value, |
| 157 const std::string& domain, | 161 const std::string& domain, |
| 158 const std::string& path, | 162 const std::string& path, |
| 159 const base::Time& expiration_time, | 163 const base::Time& expiration_time, |
| 160 bool secure, bool http_only, | 164 bool secure, bool http_only, |
| 161 const SetCookiesCallback& callback); | 165 const SetCookiesCallback& callback); |
| 162 | 166 |
| 163 | |
| 164 // Helper function that adds all cookies from |cookie_monster| into this | |
| 165 // instance. | |
| 166 bool InitializeFrom(CookieMonster* cookie_monster); | |
| 167 | |
| 168 // Returns all the cookies, for use in management UI, etc. This does not mark | 167 // Returns all the cookies, for use in management UI, etc. This does not mark |
| 169 // the cookies as having been accessed. | 168 // the cookies as having been accessed. |
| 170 // The returned cookies are ordered by longest path, then by earliest | 169 // The returned cookies are ordered by longest path, then by earliest |
| 171 // creation date. | 170 // creation date. |
| 172 CookieList GetAllCookies(); | |
| 173 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | |
| 174 void GetAllCookiesAsync(const GetCookieListCallback& callback); | 171 void GetAllCookiesAsync(const GetCookieListCallback& callback); |
| 175 | 172 |
| 176 // Returns all the cookies, for use in management UI, etc. Filters results | 173 // Returns all the cookies, for use in management UI, etc. Filters results |
| 177 // using given url scheme, host / domain and path and options. This does not | 174 // using given url scheme, host / domain and path and options. This does not |
| 178 // mark the cookies as having been accessed. | 175 // mark the cookies as having been accessed. |
| 179 // The returned cookies are ordered by longest path, then earliest | 176 // The returned cookies are ordered by longest path, then earliest |
| 180 // creation date. | 177 // creation date. |
| 181 CookieList GetAllCookiesForURLWithOptions(const GURL& url, | |
| 182 const CookieOptions& options); | |
| 183 void GetAllCookiesForURLWithOptionsAsync( | 178 void GetAllCookiesForURLWithOptionsAsync( |
| 184 const GURL& url, | 179 const GURL& url, |
| 185 const CookieOptions& options, | 180 const CookieOptions& options, |
| 186 const GetCookieListCallback& callback); | 181 const GetCookieListCallback& callback); |
| 187 | 182 |
| 188 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP | 183 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP |
| 189 // only cookies. | 184 // only cookies. |
| 190 CookieList GetAllCookiesForURL(const GURL& url); | |
| 191 void GetAllCookiesForURLAsync(const GURL& url, | 185 void GetAllCookiesForURLAsync(const GURL& url, |
| 192 const GetCookieListCallback& callback); | 186 const GetCookieListCallback& callback); |
| 193 | 187 |
| 194 // Deletes all of the cookies. | 188 // Deletes all of the cookies. |
| 195 int DeleteAll(bool sync_to_store); | 189 void DeleteAllAsync(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, | |
| 206 const DeleteCallback& callback); | 196 const DeleteCallback& callback); |
| 207 | 197 |
| 208 // Deletes all cookies that match the host of the given URL | 198 // Deletes all cookies that match the host of the given URL |
| 209 // regardless of path. This includes all http_only and secure cookies, | 199 // 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. | 200 // but does not include any domain cookies that may apply to this host. |
| 211 // Returns the number of cookies deleted. | 201 // Returns the number of cookies deleted. |
| 212 int DeleteAllForHost(const GURL& url); | |
| 213 | |
| 214 void DeleteAllForHostAsync(const GURL& url, | 202 void DeleteAllForHostAsync(const GURL& url, |
| 215 const DeleteCallback& callback); | 203 const DeleteCallback& callback); |
| 216 | 204 |
| 217 // Deletes one specific cookie. | 205 // Deletes one specific cookie. |
| 218 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
| 219 | |
| 220 typedef SetCookiesCallback DeleteCookieCallback; | |
| 221 | |
| 222 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, | 206 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
| 223 const DeleteCookieCallback& callback); | 207 const DeleteCookieCallback& callback); |
| 224 | 208 |
| 225 // Override the default list of schemes that are allowed to be set in | 209 // Override the default list of schemes that are allowed to be set in |
| 226 // this cookie store. Calling his overrides the value of | 210 // this cookie store. Calling his overrides the value of |
| 227 // "enable_file_scheme_". | 211 // "enable_file_scheme_". |
| 228 // If this this method is called, it must be called before first use of | 212 // 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). | 213 // the instance (i.e. as part of the instance initialization process). |
| 230 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); | 214 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); |
| 231 | 215 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 253 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. | 237 // 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 | 238 // 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 | 239 // actually does the flushing. Your Task should generally post a notification |
| 256 // to the thread you actually want to be notified on. | 240 // to the thread you actually want to be notified on. |
| 257 void FlushStore(Task* completion_task); | 241 void FlushStore(Task* completion_task); |
| 258 | 242 |
| 259 // CookieStore implementation. | 243 // CookieStore implementation. |
| 260 | 244 |
| 261 // Sets the cookies specified by |cookie_list| returned from |url| | 245 // Sets the cookies specified by |cookie_list| returned from |url| |
| 262 // with options |options| in effect. | 246 // with options |options| in effect. |
| 263 virtual bool SetCookieWithOptions(const GURL& url, | 247 virtual void SetCookieWithOptionsAsync( |
| 264 const std::string& cookie_line, | 248 const GURL& url, |
| 265 const CookieOptions& options); | 249 const std::string& cookie_line, |
| 266 | 250 const CookieOptions& options, |
| 267 virtual void SetCookieWithOptionsAsync(const GURL& url, | 251 const SetCookiesCallback& callback) OVERRIDE; |
| 268 const std::string& cookie_line, | |
| 269 const CookieOptions& options, | |
| 270 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) OVERRIDE; |
| 282 | 260 |
| 283 virtual void GetCookiesWithInfo(const GURL& url, | 261 virtual void GetCookiesWithInfoAsync( |
| 284 const CookieOptions& options, | 262 const GURL& url, |
| 285 std::string* cookie_line, | 263 const CookieOptions& options, |
| 286 std::vector<CookieInfo>* cookie_infos); | 264 const GetCookieInfoCallback& callback) OVERRIDE; |
| 287 | |
| 288 virtual void GetCookiesWithInfoAsync(const GURL& url, | |
| 289 const CookieOptions& options, | |
| 290 const GetCookieInfoCallback& callback); | |
| 291 | 265 |
| 292 // Deletes all cookies with that might apply to |url| that has |cookie_name|. | 266 // 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( | 267 virtual void DeleteCookieAsync( |
| 295 const GURL& url, const std::string& cookie_name, | 268 const GURL& url, const std::string& cookie_name, |
| 296 const base::Closure& callback); | 269 const base::Closure& callback) OVERRIDE; |
| 297 | 270 |
| 298 virtual CookieMonster* GetCookieMonster(); | 271 virtual CookieMonster* GetCookieMonster() OVERRIDE; |
| 299 | 272 |
| 300 // Debugging method to perform various validation checks on the map. | 273 // Debugging method to perform various validation checks on the map. |
| 301 // Currently just checking that there are no null CanonicalCookie pointers | 274 // Currently just checking that there are no null CanonicalCookie pointers |
| 302 // in the map. | 275 // in the map. |
| 303 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs | 276 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs |
| 304 // in the function trip. TODO(rdsmith):Remove hack. | 277 // in the function trip. TODO(rdsmith):Remove hack. |
| 305 void ValidateMap(int arg); | 278 void ValidateMap(int arg); |
| 306 | 279 |
| 307 // The default list of schemes the cookie monster can handle. | 280 // The default list of schemes the cookie monster can handle. |
| 308 static const char* kDefaultCookieableSchemes[]; | 281 static const char* kDefaultCookieableSchemes[]; |
| 309 static const int kDefaultCookieableSchemesCount; | 282 static const int kDefaultCookieableSchemesCount; |
| 310 | 283 |
| 311 private: | 284 private: |
| 285 // For queueing the cookie monster calls. | |
| 286 friend class DeleteAllCreatedBetweenTask; | |
| 287 friend class DeleteAllForHostTask; | |
| 288 friend class DeleteAllTask; | |
| 289 friend class DeleteCookieTask; | |
| 290 friend class DeleteCanonicalCookieTask; | |
| 291 friend class GetAllCookiesForURLWithOptionsTask; | |
| 292 friend class GetAllCookiesTask; | |
| 293 friend class GetCookiesWithOptionsTask; | |
| 294 friend class GetCookiesWithInfoTask; | |
| 295 friend class SetCookieWithDetailsTask; | |
| 296 friend class SetCookieWithOptionsTask; | |
|
Randy Smith (Not in Mondays)
2011/08/19 21:40:05
I'm feeling torn about this long list of friend cl
erikwright (departed)
2011/09/06 17:34:45
The case statement, IME is more error prone in add
Randy Smith (Not in Mondays)
2011/09/07 15:46:27
Ok.
| |
| 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 bool SetCookieWithDetails(const GURL& url, | |
|
Randy Smith (Not in Mondays)
2011/08/19 21:40:05
Maybe a comment before these indicating how they'r
erikwright (departed)
2011/09/06 17:34:45
Done.
| |
| 387 const std::string& name, | |
| 388 const std::string& value, | |
| 389 const std::string& domain, | |
| 390 const std::string& path, | |
| 391 const base::Time& expiration_time, | |
| 392 bool secure, bool http_only); | |
| 393 | |
| 394 CookieList GetAllCookies(); | |
| 395 | |
| 396 CookieList GetAllCookiesForURLWithOptions(const GURL& url, | |
| 397 const CookieOptions& options); | |
| 398 | |
| 399 CookieList GetAllCookiesForURL(const GURL& url); | |
|
Randy Smith (Not in Mondays)
2011/08/19 21:40:05
nit: If this is now only a helper call called from
erikwright (departed)
2011/09/06 17:34:45
It has four callers besides tests. For now I'll le
| |
| 400 | |
| 401 int DeleteAll(bool sync_to_store); | |
| 402 | |
| 403 int DeleteAllCreatedBetween(const base::Time& delete_begin, | |
| 404 const base::Time& delete_end); | |
| 405 | |
| 406 int DeleteAllForHost(const GURL& url); | |
| 407 | |
| 408 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
| 409 | |
| 410 bool SetCookieWithOptions(const GURL& url, | |
| 411 const std::string& cookie_line, | |
| 412 const CookieOptions& options); | |
| 413 | |
| 414 std::string GetCookiesWithOptions(const GURL& url, | |
| 415 const CookieOptions& options); | |
| 416 | |
| 417 void GetCookiesWithInfo(const GURL& url, | |
| 418 const CookieOptions& options, | |
| 419 std::string* cookie_line, | |
| 420 std::vector<CookieInfo>* cookie_infos); | |
| 421 | |
| 422 void DeleteCookie(const GURL& url, const std::string& cookie_name); | |
| 423 | |
| 400 bool SetCookieWithCreationTime(const GURL& url, | 424 bool SetCookieWithCreationTime(const GURL& url, |
| 401 const std::string& cookie_line, | 425 const std::string& cookie_line, |
| 402 const base::Time& creation_time); | 426 const base::Time& creation_time); |
| 403 | 427 |
| 404 // Called by all non-static functions to ensure that the cookies store has | 428 // 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 | 429 // been initialized. This is not done during creating so it doesn't block |
| 406 // the window showing. | 430 // the window showing. |
| 407 // Note: this method should always be called with lock_ held. | 431 // Note: this method should always be called with lock_ held. |
| 408 void InitIfNecessary() { | 432 void InitIfNecessary() { |
| 409 if (!initialized_) { | 433 if (!initialized_) { |
| 410 if (store_) | 434 if (store_) { |
| 411 InitStore(); | 435 InitStore(); |
| 436 } else { | |
| 437 loaded_ = true; | |
| 438 } | |
| 412 initialized_ = true; | 439 initialized_ = true; |
| 413 } | 440 } |
| 414 } | 441 } |
| 415 | 442 |
| 416 // Initializes the backing store and reads existing cookies from it. | 443 // Initializes the backing store and reads existing cookies from it. |
| 417 // Should only be called by InitIfNecessary(). | 444 // Should only be called by InitIfNecessary(). |
| 418 void InitStore(); | 445 void InitStore(); |
| 419 | 446 |
| 447 // Reads the existing cookies loaded form the backing store. | |
|
Randy Smith (Not in Mondays)
2011/08/19 21:40:05
I'd suggest instead "Called when loading of the ex
erikwright (departed)
2011/09/06 17:34:45
Done.
| |
| 448 void OnLoaded(const std::vector<CanonicalCookie*>& cookies); | |
| 449 | |
| 450 // Ininitalize the cookies. | |
| 451 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); | |
| 452 | |
| 453 // Invoke the queueing calls of CookieMonster when loading cookies from | |
|
Randy Smith (Not in Mondays)
2011/08/19 21:40:05
nit: "queueing" -> "queued".
erikwright (departed)
2011/09/06 17:34:45
Done.
| |
| 454 // the back store is complete. | |
| 455 void InvokeQueue(); | |
| 456 | |
| 420 // Checks that |cookies_| matches our invariants, and tries to repair any | 457 // Checks that |cookies_| matches our invariants, and tries to repair any |
| 421 // inconsistencies. (In other words, it does not have duplicate cookies). | 458 // inconsistencies. (In other words, it does not have duplicate cookies). |
| 422 void EnsureCookiesMapIsValid(); | 459 void EnsureCookiesMapIsValid(); |
| 423 | 460 |
| 424 // Checks for any duplicate cookies for CookieMap key |key| which lie between | 461 // 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. | 462 // |begin| and |end|. If any are found, all but the most recent are deleted. |
| 426 // Returns the number of duplicate cookies that were deleted. | 463 // Returns the number of duplicate cookies that were deleted. |
| 427 int TrimDuplicateCookiesForKey(const std::string& key, | 464 int TrimDuplicateCookiesForKey(const std::string& key, |
| 428 CookieMap::iterator begin, | 465 CookieMap::iterator begin, |
| 429 CookieMap::iterator end); | 466 CookieMap::iterator end); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 void RecordPeriodicStats(const base::Time& current_time); | 556 void RecordPeriodicStats(const base::Time& current_time); |
| 520 | 557 |
| 521 // Initialize the above variables; should only be called from | 558 // Initialize the above variables; should only be called from |
| 522 // the constructor. | 559 // the constructor. |
| 523 void InitializeHistograms(); | 560 void InitializeHistograms(); |
| 524 | 561 |
| 525 // The resolution of our time isn't enough, so we do something | 562 // The resolution of our time isn't enough, so we do something |
| 526 // ugly and increment when we've seen the same time twice. | 563 // ugly and increment when we've seen the same time twice. |
| 527 base::Time CurrentTime(); | 564 base::Time CurrentTime(); |
| 528 | 565 |
| 566 // Run the cookie request task if cookie loaded, otherwise added the task | |
| 567 // to task queue. | |
| 568 void DoCookieTask(scoped_refptr<CookieMonsterTask> task_item); | |
| 569 | |
| 529 // Histogram variables; see CookieMonster::InitializeHistograms() in | 570 // Histogram variables; see CookieMonster::InitializeHistograms() in |
| 530 // cookie_monster.cc for details. | 571 // cookie_monster.cc for details. |
| 531 base::Histogram* histogram_expiration_duration_minutes_; | 572 base::Histogram* histogram_expiration_duration_minutes_; |
| 532 base::Histogram* histogram_between_access_interval_minutes_; | 573 base::Histogram* histogram_between_access_interval_minutes_; |
| 533 base::Histogram* histogram_evicted_last_access_minutes_; | 574 base::Histogram* histogram_evicted_last_access_minutes_; |
| 534 base::Histogram* histogram_count_; | 575 base::Histogram* histogram_count_; |
| 535 base::Histogram* histogram_domain_count_; | 576 base::Histogram* histogram_domain_count_; |
| 536 base::Histogram* histogram_etldp1_count_; | 577 base::Histogram* histogram_etldp1_count_; |
| 537 base::Histogram* histogram_domain_per_etldp1_count_; | 578 base::Histogram* histogram_domain_per_etldp1_count_; |
| 538 base::Histogram* histogram_number_duplicate_db_cookies_; | 579 base::Histogram* histogram_number_duplicate_db_cookies_; |
| 539 base::Histogram* histogram_cookie_deletion_cause_; | 580 base::Histogram* histogram_cookie_deletion_cause_; |
| 540 base::Histogram* histogram_time_get_; | 581 base::Histogram* histogram_time_get_; |
| 541 base::Histogram* histogram_time_mac_; | 582 base::Histogram* histogram_time_mac_; |
| 542 base::Histogram* histogram_time_load_; | 583 base::Histogram* histogram_time_load_; |
| 543 | 584 |
| 544 CookieMap cookies_; | 585 CookieMap cookies_; |
| 545 | 586 |
| 546 // Indicates whether the cookie store has been initialized. This happens | 587 // Indicates whether the cookie store has been initialized. This happens |
| 547 // lazily in InitStoreIfNecessary(). | 588 // lazily in InitStoreIfNecessary(). |
| 548 bool initialized_; | 589 bool initialized_; |
| 549 | 590 |
| 591 // Indicates whether loading from the backend store is completed and | |
| 592 // calls may be immediately processed. | |
| 593 bool loaded_; | |
| 594 | |
| 595 // Queues calls to CookieMonster until loading from the backend store is | |
| 596 // completed. | |
| 597 std::queue<base::Closure> queue_; | |
| 598 | |
| 550 // Indicates whether this cookie monster uses the new effective domain | 599 // Indicates whether this cookie monster uses the new effective domain |
| 551 // key scheme or not. | 600 // key scheme or not. |
| 552 ExpiryAndKeyScheme expiry_and_key_scheme_; | 601 ExpiryAndKeyScheme expiry_and_key_scheme_; |
| 553 | 602 |
| 554 scoped_refptr<PersistentCookieStore> store_; | 603 scoped_refptr<PersistentCookieStore> store_; |
| 555 | 604 |
| 556 base::Time last_time_seen_; | 605 base::Time last_time_seen_; |
| 557 | 606 |
| 558 // Minimum delay after updating a cookie's LastAccessDate before we will | 607 // Minimum delay after updating a cookie's LastAccessDate before we will |
| 559 // update it again. | 608 // update it again. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 | 659 |
| 611 // This constructor does canonicalization but not validation. | 660 // This constructor does canonicalization but not validation. |
| 612 // The result of this constructor should not be relied on in contexts | 661 // The result of this constructor should not be relied on in contexts |
| 613 // in which pre-validation of the ParsedCookie has not been done. | 662 // in which pre-validation of the ParsedCookie has not been done. |
| 614 CanonicalCookie(const GURL& url, const ParsedCookie& pc); | 663 CanonicalCookie(const GURL& url, const ParsedCookie& pc); |
| 615 | 664 |
| 616 ~CanonicalCookie(); | 665 ~CanonicalCookie(); |
| 617 | 666 |
| 618 // Supports the default copy constructor. | 667 // Supports the default copy constructor. |
| 619 | 668 |
| 669 // Creates a canonical cookie from parsed cookie. | |
| 670 // Canonicalizes and validates inputs. May return NULL if an attribute | |
| 671 // value is invalid. | |
| 672 static CanonicalCookie* Create(const GURL& url, | |
| 673 const ParsedCookie& pc); | |
| 674 | |
| 620 // Creates a canonical cookie from unparsed attribute values. | 675 // Creates a canonical cookie from unparsed attribute values. |
| 621 // Canonicalizes and validates inputs. May return NULL if an attribute | 676 // Canonicalizes and validates inputs. May return NULL if an attribute |
| 622 // value is invalid. | 677 // value is invalid. |
| 623 static CanonicalCookie* Create(const GURL& url, | 678 static CanonicalCookie* Create(const GURL& url, |
| 624 const std::string& name, | 679 const std::string& name, |
| 625 const std::string& value, | 680 const std::string& value, |
| 626 const std::string& domain, | 681 const std::string& domain, |
| 627 const std::string& path, | 682 const std::string& path, |
| 628 const std::string& mac_key, | 683 const std::string& mac_key, |
| 629 const std::string& mac_algorithm, | 684 const std::string& mac_algorithm, |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 }; | 903 }; |
| 849 | 904 |
| 850 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 905 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
| 851 RefcountedPersistentCookieStore; | 906 RefcountedPersistentCookieStore; |
| 852 | 907 |
| 853 class CookieMonster::PersistentCookieStore | 908 class CookieMonster::PersistentCookieStore |
| 854 : public RefcountedPersistentCookieStore { | 909 : public RefcountedPersistentCookieStore { |
| 855 public: | 910 public: |
| 856 virtual ~PersistentCookieStore() {} | 911 virtual ~PersistentCookieStore() {} |
| 857 | 912 |
| 913 typedef base::Callback<void(const std::vector< | |
| 914 CookieMonster::CanonicalCookie*>&)> LoadedCallback; | |
| 915 | |
| 858 // Initializes the store and retrieves the existing cookies. This will be | 916 // Initializes the store and retrieves the existing cookies. This will be |
| 859 // called only once at startup. | 917 // called only once at startup. |
| 860 virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0; | 918 virtual bool Load(const LoadedCallback& loaded_callback) = 0; |
| 861 | 919 |
| 862 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 920 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
| 863 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 921 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
| 864 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 922 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
| 865 | 923 |
| 866 // Sets the value of the user preference whether the persistent storage | 924 // Sets the value of the user preference whether the persistent storage |
| 867 // must be deleted upon destruction. | 925 // must be deleted upon destruction. |
| 868 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 926 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
| 869 | 927 |
| 870 // Flush the store and post the given Task when complete. | 928 // Flush the store and post the given Task when complete. |
| 871 virtual void Flush(Task* completion_task) = 0; | 929 virtual void Flush(Task* completion_task) = 0; |
| 872 | 930 |
| 873 protected: | 931 protected: |
| 874 PersistentCookieStore() {} | 932 PersistentCookieStore() {} |
| 875 | 933 |
| 876 private: | 934 private: |
| 877 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 935 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 878 }; | 936 }; |
| 879 | 937 |
| 880 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 938 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
| 881 }; | 939 }; |
| 882 | 940 |
| 883 } // namespace net | 941 } // namespace net |
| 884 | 942 |
| 885 #endif // NET_BASE_COOKIE_MONSTER_H_ | 943 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |