Chromium Code Reviews| Index: chrome/browser/net/timed_cache.h |
| diff --git a/chrome/browser/net/timed_cache.h b/chrome/browser/net/timed_cache.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..71de583b6b745a283105943ff7f2534f3ffe557c |
| --- /dev/null |
| +++ b/chrome/browser/net/timed_cache.h |
| @@ -0,0 +1,57 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
mmenke
2013/05/23 15:28:36
nit: 2013. Also, remove the (c) (The latest pref
kouhei (in TOK)
2013/05/24 00:34:37
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_NET_TIMED_CACHE_H_ |
| +#define CHROME_BROWSER_NET_TIMED_CACHE_H_ |
| + |
| +#include "base/containers/mru_cache.h" |
| +#include "base/time.h" |
| + |
| +class GURL; |
| + |
| +namespace chrome_browser_net { |
| + |
| +// We don't bother learning to preconnect via a GET if the original URL |
| +// navigation was so long ago, that a preconnection would have been dropped |
| +// anyway. We believe most servers will drop the connection in 10 seconds, so |
| +// we currently estimate this time-till-drop at 10 seconds. |
| +// TODO(jar): We should do a persistent field trial to validate/optimize this. |
| +static const int kMaxUnusedSocketLifetimeSecondsWithoutAGet = 10; |
|
mmenke
2013/05/23 15:28:36
This comment and variable seem a little odd here.
kouhei (in TOK)
2013/05/24 00:34:37
Done.
|
| + |
| +// Define a LRU cache that recalls all navigations within the last N seconds. |
| +// When we learn about subresources to possibly preconnect to, it would be a |
| +// waste to preconnect when the original navigation was too long ago. Any |
| +// connected, but unused TCP/IP connection, will generally be reset by the |
| +// server if it is not used quickly (i.e., GET or POST is sent). |
| +class TimedCache { |
| + public: |
| + explicit TimedCache(const base::TimeDelta& max_duration); |
| + ~TimedCache(); |
| + |
| + // Evicts any entries that have been in the FIFO "too long," and then checks |
| + // to see if the given url is (still) in the FIFO cache. |
| + bool WasRecentlySeen(const GURL& url) const; |
| + |
| + // Adds the given url to the cache, where it will remain for max_duration_. |
| + void SetRecentlySeen(const GURL& url) const; |
| + |
| + private: |
| + // Our cache will be keyed on a URL (actually, just a scheme/host/port). |
| + // We will always track the time it was last added to the FIFO cache by |
| + // remembering a TimeTicks value. |
| + typedef base::MRUCache<GURL, base::TimeTicks> UrlMruTimedCache; |
| + // mru_cache_ has to be mutable in order to be accessed from the overriden |
| + // URLRequestJob functions. It is mutable because it tracks the urls and |
| + // caches them. |
| + mutable UrlMruTimedCache mru_cache_; |
| + |
| + // The longest time an entry can persist in the cache, and still be found. |
| + const base::TimeDelta max_duration_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TimedCache); |
|
mmenke
2013/05/23 15:28:36
Include base/basictypes.h for this.
|
| +}; |
| + |
| +} // namespace chrome_browser_net |
| + |
| +#endif // CHROME_BROWSER_NET_TIMED_CACHE_H_ |