Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/net/timed_cache.h

Issue 15675002: Add the UMA recording recall of URLRequests preconnected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move logic to predictor Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // 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.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_NET_TIMED_CACHE_H_
6 #define CHROME_BROWSER_NET_TIMED_CACHE_H_
7
8 #include "base/containers/mru_cache.h"
9 #include "base/time.h"
10
11 class GURL;
12
13 namespace chrome_browser_net {
14
15 // We don't bother learning to preconnect via a GET if the original URL
16 // navigation was so long ago, that a preconnection would have been dropped
17 // anyway. We believe most servers will drop the connection in 10 seconds, so
18 // we currently estimate this time-till-drop at 10 seconds.
19 // TODO(jar): We should do a persistent field trial to validate/optimize this.
20 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.
21
22 // Define a LRU cache that recalls all navigations within the last N seconds.
23 // When we learn about subresources to possibly preconnect to, it would be a
24 // waste to preconnect when the original navigation was too long ago. Any
25 // connected, but unused TCP/IP connection, will generally be reset by the
26 // server if it is not used quickly (i.e., GET or POST is sent).
27 class TimedCache {
28 public:
29 explicit TimedCache(const base::TimeDelta& max_duration);
30 ~TimedCache();
31
32 // Evicts any entries that have been in the FIFO "too long," and then checks
33 // to see if the given url is (still) in the FIFO cache.
34 bool WasRecentlySeen(const GURL& url) const;
35
36 // Adds the given url to the cache, where it will remain for max_duration_.
37 void SetRecentlySeen(const GURL& url) const;
38
39 private:
40 // Our cache will be keyed on a URL (actually, just a scheme/host/port).
41 // We will always track the time it was last added to the FIFO cache by
42 // remembering a TimeTicks value.
43 typedef base::MRUCache<GURL, base::TimeTicks> UrlMruTimedCache;
44 // mru_cache_ has to be mutable in order to be accessed from the overriden
45 // URLRequestJob functions. It is mutable because it tracks the urls and
46 // caches them.
47 mutable UrlMruTimedCache mru_cache_;
48
49 // The longest time an entry can persist in the cache, and still be found.
50 const base::TimeDelta max_duration_;
51
52 DISALLOW_COPY_AND_ASSIGN(TimedCache);
mmenke 2013/05/23 15:28:36 Include base/basictypes.h for this.
53 };
54
55 } // namespace chrome_browser_net
56
57 #endif // CHROME_BROWSER_NET_TIMED_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698