summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/connect_interceptor.h
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-02 18:36:18 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-02 18:36:18 +0000
commitef42e30fbfcd6db1c2a5ed77818db2329b5bd1a8 (patch)
tree1550b6a12c3774c490108d625321a9fe0186ba65 /chrome/browser/net/connect_interceptor.h
parentc3a9159653f81dbd82f41c826d6443d72500e18c (diff)
downloadchromium_src-ef42e30fbfcd6db1c2a5ed77818db2329b5bd1a8.zip
chromium_src-ef42e30fbfcd6db1c2a5ed77818db2329b5bd1a8.tar.gz
chromium_src-ef42e30fbfcd6db1c2a5ed77818db2329b5bd1a8.tar.bz2
Avoid learning about subresources of old navigations
Track all navigatinos, and keep a list of navigatinos in the last 10 seconds. If it was older than 10 seconds, any preconnection based on that navigation would be reset for lack of use. r=willchan bug=83094 Review URL: http://codereview.chromium.org/6960001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/connect_interceptor.h')
-rw-r--r--chrome/browser/net/connect_interceptor.h39
1 files changed, 38 insertions, 1 deletions
diff --git a/chrome/browser/net/connect_interceptor.h b/chrome/browser/net/connect_interceptor.h
index b0b15f1..c1f6177 100644
--- a/chrome/browser/net/connect_interceptor.h
+++ b/chrome/browser/net/connect_interceptor.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -8,6 +8,9 @@
#include "net/url_request/url_request.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/mru_cache.h"
+
namespace chrome_browser_net {
//------------------------------------------------------------------------------
@@ -29,6 +32,40 @@ class ConnectInterceptor : public net::URLRequest::Interceptor {
const GURL& location);
private:
+ // Provide access to local class TimedCache for testing.
+ FRIEND_TEST(ConnectInterceptorTest, TimedCacheRecall);
+ FRIEND_TEST(ConnectInterceptorTest, TimedCacheEviction);
+
+ // 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);
+
+ // 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);
+
+ // Adds the given url to the cache, where it will remain for max_duration_.
+ void SetRecentlySeen(const GURL& url);
+
+ 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;
+ 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);
+ };
+ TimedCache timed_cache_;
+
DISALLOW_COPY_AND_ASSIGN(ConnectInterceptor);
};