Chromium Code Reviews| Index: net/cookies/evicted_domain_cookie_counter.h |
| diff --git a/net/cookies/evicted_domain_cookie_counter.h b/net/cookies/evicted_domain_cookie_counter.h |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..11bbe2c25b7704f838f41a8420afaad5f1c9b9ab |
| --- /dev/null |
| +++ b/net/cookies/evicted_domain_cookie_counter.h |
| @@ -0,0 +1,145 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_COOKIES_EVICTED_DOMAIN_COOKIE_COUNTER_ |
| +#define NET_COOKIES_EVICTED_DOMAIN_COOKIE_COUNTER_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/time.h" |
| +#include "net/cookies/canonical_cookie.h" |
|
erikwright (departed)
2013/03/21 19:22:19
forward-decl
huangs
2013/03/21 22:08:09
Done.
|
| +#include "net/cookies/cookie_monster.h" |
| + |
| +namespace net { |
| + |
| +// The Evicted Domain Cookie Counter generates statistics on "wrongly evicted" |
| +// cookies, i.e., cookies that were "evicted" (on reacking domain cookie limit) |
|
erikwright (departed)
2013/03/21 19:22:19
typo
huangs
2013/03/21 22:08:09
Done.
|
| +// but are then "reinstated" later by a website because they were important. |
| +// Here is a specific scenario: a long-lived login session cookie gets evicted |
| +// due to its age, thereby forcing the user to lose session, and is reinstated |
| +// when the annoyed user reauthenticates. |
| +// |
| +// A solution to the above problem is the Cookie Priority Field, which gives |
| +// server a way to protect important cookies, thereby decreasing the chance |
| +// that these cookies are wrongly evicted. To measure the effictive of this |
| +// solution, we record eviction statistics before vs. after the fix. |
| +// |
| +// Specifically, we wish to record statistics on "reinstatement delay", i.e., |
| +// the duration between eviction and reinstatement of cookie. We expect that |
| +// after the fix, average reinstantement delay will increase, since low priority |
| +// cookies are less likely to be reinstated after eviction. |
| +// |
| +// Statistics for Google domains are tracked separately. |
| +// |
| +class NET_EXPORT EvictedDomainCookieCounter : public CookieMonster::Delegate { |
| + public: |
| + // Structure to store sanitized (no cookie value) data from CanonicalCookie. |
|
erikwright (departed)
2013/03/21 19:22:19
parenthetical is unnecessary
huangs
2013/03/21 22:08:09
Done.
|
| + struct EvictedCookie { |
| + base::Time eviction_time_; |
| + base::Time expiry_time_; |
| + bool is_google_; |
| + |
| + EvictedCookie(base::Time eviction_time, |
| + base::Time expiry_time, |
| + bool is_google) |
| + : eviction_time_(eviction_time), |
| + expiry_time_(expiry_time), |
| + is_google_(is_google) {} |
| + |
| + void set_expired() { |
| + expiry_time_ = base::Time::UnixEpoch(); |
| + } |
| + bool is_expired(const base::Time& current) { |
| + return !expiry_time_.is_null() && current >= expiry_time_; |
| + } |
| + }; |
| + |
| + class Delegate { |
| + public: |
|
erikwright (departed)
2013/03/21 19:22:19
Needs a virtual destructor.
huangs
2013/03/21 22:08:09
Done. Making it public instead of protected (else
|
| + // Called when a stored evicted cookie is reinstated. |
| + virtual void Report(const EvictedCookie& dc, |
| + const base::Time& reinstatement_time) = 0; |
| + |
| + // Getter of time is placed here to enable mocks. |
| + virtual base::Time CurrentTime() = 0; |
| + }; |
| + |
| + // Identifier of an evicted cookie. Can be obtained from GetKey(). |
|
erikwright (departed)
2013/03/21 19:22:19
These typedefs can be private, right?
huangs
2013/03/21 22:08:09
Done.
|
| + typedef std::string EvictedCookieKey; |
| + |
| + // Storage class of evicted cookie. |
| + typedef std::map<EvictedCookieKey, EvictedCookie*> EvictedCookieMap; |
| + |
| + explicit EvictedDomainCookieCounter(CookieMonster::Delegate* next_delegate); |
|
erikwright (departed)
2013/03/21 19:22:19
make scoped_refptr<CookieMonster::Delegate>
huangs
2013/03/21 22:08:09
Done.
|
| + |
| + EvictedDomainCookieCounter( |
| + scoped_refptr<CookieMonster::Delegate> next_delegate, |
|
erikwright (departed)
2013/03/21 19:22:19
ref_counted.h
huangs
2013/03/21 22:08:09
Done.
|
| + scoped_ptr<Delegate> reporter, |
|
erikwright (departed)
2013/03/21 19:22:19
scoped_ptr.h
huangs
2013/03/21 22:08:09
Done.
|
| + size_t max_size, |
| + size_t purge_count); |
| + |
| + // Returns whether or not |cc| is a cookie from Google. |
| + static bool IsGoogleCookie(const CanonicalCookie& cc); |
| + |
| + // Returns the number of evicted cookies stored. |
| + size_t GetStorageSize() const; |
| + |
| + // CookieMonster::Delegate implementation. |
| + virtual void OnCookieChanged(const CanonicalCookie& cc, |
| + bool removed, |
| + ChangeCause cause) OVERRIDE; |
|
erikwright (departed)
2013/03/21 19:22:19
compiler_specific.h for OVERRIDE
huangs
2013/03/21 22:08:09
Done.
|
| + |
| + private: |
| + ~EvictedDomainCookieCounter(); |
| + |
| + // Computes a key for |cc| compatible with CanonicalCookie::IsEquivalent(), |
| + // i.e., IsEquivalent(a, b) ==> GetKey(a) == GetKey(b). |
| + static EvictedCookieKey GetKey(const CanonicalCookie& cc); |
| + |
| + // Deallocates and removes an evicted cookie with given |key| if it is stored. |
| + void FreeEvictedCookie(const EvictedCookieKey& key); |
| + |
| + // Deallocates and removes all expired evicted cookies. |
| + void FreeExpiredEvictedCookies(base::Time time_bound); |
| + |
| + // If too many evicted cookies are stored, delete the expired oens, then |
| + // delete cookies that were evicted the longest, until size limit reached. |
| + void GarbageCollect(const base::Time& current); |
| + |
| + // Called when a cookie is evicted. Adds the evicted cookie to storage, |
| + // possibly replacing an existing evicted cookie. |
| + void StoreEvictedCookie(const EvictedCookieKey& key, |
| + const CanonicalCookie& cc, |
| + const base::Time& current); |
| + |
| + // Called when a new cookie is added, i.e., reinstatement may occur. |
| + // Returns true iff the reinstatement takes place. |
| + bool ProcessCookieReinstatement(const EvictedCookieKey& key, |
| + const CanonicalCookie& cc, |
| + const base::Time& current); |
| + |
| + // For chaining the OnCookieChanged() event. |
| + scoped_refptr<CookieMonster::Delegate> next_delegate_; |
| + |
| + // On reinstatement, data are passed here to report reinstatement delay. |
| + scoped_ptr<Delegate> reporter_; |
| + |
| + // In-memory-only buffer to store sanitized (no cookie value) evicted cookies. |
| + EvictedCookieMap evicted_cookies_; |
| + |
| + // Capacity of the evicted cookie storage. |
| + const size_t max_size_; |
| + |
| + // Minimum amount to decrease evicted cookie storage, on garbage collection. |
| + const size_t purge_count_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(EvictedDomainCookieCounter); |
|
erikwright (departed)
2013/03/21 19:22:19
basictypes.h
huangs
2013/03/21 22:08:09
Done.
|
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_COOKIES_EVICTED_DOMAIN_COOKIE_COUNTER_ |