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

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

Issue 3032014: Support both preconnection, and pre-resolution for subresources... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/net/predictor_unittest.cc ('k') | chrome/browser/net/referrer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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 // This class helps to remember what domains may be needed to be resolved when a 5 // This class helps to remember what domains may be needed to be resolved when a
6 // navigation takes place to a given URL. This information is gathered when a 6 // navigation takes place to a given URL. This information is gathered when a
7 // navigation to a subresource identifies a referring URL. 7 // navigation to a subresource identifies a referring URL.
8 // When future navigations take place to known referrer sites, then we 8 // When future navigations take place to known referrer sites, then we
9 // speculatively either pre-warm a TCP/IP conneciton, or at a minimum, resolve 9 // speculatively either pre-warm a TCP/IP conneciton, or at a minimum, resolve
10 // the host name via DNS. 10 // the host name via DNS.
(...skipping 20 matching lines...) Expand all
31 // For each hostname in a Referrer, we have a ReferrerValue. It indicates 31 // For each hostname in a Referrer, we have a ReferrerValue. It indicates
32 // exactly how much value (re: latency reduction, or connection use) has 32 // exactly how much value (re: latency reduction, or connection use) has
33 // resulted from having this entry. 33 // resulted from having this entry.
34 class ReferrerValue { 34 class ReferrerValue {
35 public: 35 public:
36 ReferrerValue(); 36 ReferrerValue();
37 37
38 // Used during deserialization. 38 // Used during deserialization.
39 void SetSubresourceUseRate(double rate) { subresource_use_rate_ = rate; } 39 void SetSubresourceUseRate(double rate) { subresource_use_rate_ = rate; }
40 40
41 base::TimeDelta latency() const { return latency_; }
42 base::Time birth_time() const { return birth_time_; } 41 base::Time birth_time() const { return birth_time_; }
43 void AccrueValue(const base::TimeDelta& delta) { latency_ += delta; }
44 42
45 // Record the fact that we navigated to the associated subresource URL. 43 // Record the fact that we navigated to the associated subresource URL. This
44 // will increase the value of the expected subresource_use_rate_
46 void SubresourceIsNeeded(); 45 void SubresourceIsNeeded();
47 46
48 // Evaluate if it is worth making this preconnection, and return true if it 47 // Record the fact that the referrer of this subresource was observed. This
49 // seems worthwhile. As a side effect, we also tally the proconnection for 48 // will diminish the expected subresource_use_rate_ (and will only be
50 // statistical purposes only. 49 // counteracted later if we really needed this subresource as a consequence
51 bool IsPreconnectWorthDoing(); 50 // of our associated referrer.)
51 void ReferrerWasObserved();
52 52
53 int64 navigation_count() const { return navigation_count_; } 53 int64 navigation_count() const { return navigation_count_; }
54 int64 preconnection_count() const { return preconnection_count_; }
55 double subresource_use_rate() const { return subresource_use_rate_; } 54 double subresource_use_rate() const { return subresource_use_rate_; }
56 55
57 // Reduce the latency figure by a factor of 2, and return true if any latency 56 int64 preconnection_count() const { return preconnection_count_; }
58 // remains. 57 void IncrementPreconnectionCount() { ++preconnection_count_; }
58
59 int64 preresolution_count() const { return preresolution_count_; }
60 void preresolution_increment() { ++preresolution_count_; }
61
62 // Reduce the latency figure by a factor of 2, and return true if it still has
63 // subresources that could potentially be used.
59 bool Trim(); 64 bool Trim();
60 65
61 private: 66 private:
62 base::TimeDelta latency_; // Accumulated DNS resolution latency savings.
63 const base::Time birth_time_; 67 const base::Time birth_time_;
64 68
65 // The number of times this item was navigated to with the fixed referrer. 69 // The number of times this item was navigated to with the fixed referrer.
66 int64 navigation_count_; 70 int64 navigation_count_;
67 71
68 // The number of times this item was preconnected as a consequence of its 72 // The number of times this item was preconnected as a consequence of its
69 // referrer. 73 // referrer.
70 int64 preconnection_count_; 74 int64 preconnection_count_;
71 75
72 // A smoothed estimate of the probability that a connection will be needed. 76 // The number of times this item was pre-resolved (via DNS) as a consequence
77 // of its referrer.
78 int64 preresolution_count_;
79
80 // A smoothed estimate of the expected number of connections that will be made
81 // to this subresource.
73 double subresource_use_rate_; 82 double subresource_use_rate_;
74 }; 83 };
75 84
76 //------------------------------------------------------------------------------ 85 //------------------------------------------------------------------------------
77 // A list of domain names to pre-resolve. The names are the keys to this map, 86 // A list of domain names to pre-resolve. The names are the keys to this map,
78 // and the values indicate the amount of benefit derived from having each name 87 // and the values indicate the amount of benefit derived from having each name
79 // around. 88 // around.
80 typedef std::map<GURL, ReferrerValue> SubresourceMap; 89 typedef std::map<GURL, ReferrerValue> SubresourceMap;
81 90
82 //------------------------------------------------------------------------------ 91 //------------------------------------------------------------------------------
83 // There is one Referrer instance for each hostname that has acted as an HTTP 92 // There is one Referrer instance for each hostname that has acted as an HTTP
84 // referer (note mispelling is intentional) for a hostname that was otherwise 93 // referer (note mispelling is intentional) for a hostname that was otherwise
85 // unexpectedly navgated towards ("unexpected" in the sense that the hostname 94 // unexpectedly navgated towards ("unexpected" in the sense that the hostname
86 // was probably needed as a subresource of a page, and was not otherwise 95 // was probably needed as a subresource of a page, and was not otherwise
87 // predictable until the content with the reference arrived). Most typically, 96 // predictable until the content with the reference arrived). Most typically,
88 // an outer page was a page fetched by the user, and this instance lists names 97 // an outer page was a page fetched by the user, and this instance lists names
89 // in SubresourceMap which are subresources and that were needed to complete the 98 // in SubresourceMap which are subresources and that were needed to complete the
90 // rendering of the outer page. 99 // rendering of the outer page.
91 class Referrer : public SubresourceMap { 100 class Referrer : public SubresourceMap {
92 public: 101 public:
93 Referrer() : use_count_(1) {} 102 Referrer() : use_count_(1) {}
94 void IncrementUseCount() { ++use_count_; } 103 void IncrementUseCount() { ++use_count_; }
95 int64 use_count() const { return use_count_; } 104 int64 use_count() const { return use_count_; }
96 105
97 // Add the indicated url to the list that are resolved via DNS when the user 106 // Add the indicated url to the list that are resolved via DNS when the user
98 // navigates to this referrer. Note that if the list is long, an entry may be 107 // navigates to this referrer. Note that if the list is long, an entry may be
99 // discarded to make room for this insertion. 108 // discarded to make room for this insertion.
100 void SuggestHost(const GURL& url); 109 void SuggestHost(const GURL& url);
101 110
102 // Record additional usefulness of having this url in the list. 111 // Trim the Referrer, by first diminishing (scaling down) the subresource
103 // Value is expressed as positive latency of amount delta. 112 // use expectation for each ReferredValue.
104 void AccrueValue(const base::TimeDelta& delta, 113 // Returns true if there are any referring names left.
105 const GURL& url);
106
107 // Trim the Referrer, by first diminishing (scaling down) the latency for each
108 // ReferredValue.
109 // Returns true if there are any referring names with some latency left.
110 bool Trim(); 114 bool Trim();
111 115
112 // Provide methods for persisting, and restoring contents into a Value class. 116 // Provide methods for persisting, and restoring contents into a Value class.
113 Value* Serialize() const; 117 Value* Serialize() const;
114 void Deserialize(const Value& referrers); 118 void Deserialize(const Value& referrers);
115 119
116 static void SetUsePreconnectValuations(bool dns) { 120 static void SetUsePreconnectValuations(bool dns) {
117 use_preconnect_valuations_ = dns; 121 use_preconnect_valuations_ = dns;
118 } 122 }
119 123
(...skipping 16 matching lines...) Expand all
136 140
137 // We put these into a std::map<>, so we need copy constructors. 141 // We put these into a std::map<>, so we need copy constructors.
138 // DISALLOW_COPY_AND_ASSIGN(Referrer); 142 // DISALLOW_COPY_AND_ASSIGN(Referrer);
139 // TODO(jar): Consider optimization to use pointers to these instances, and 143 // TODO(jar): Consider optimization to use pointers to these instances, and
140 // avoid deep copies during re-alloc of the containing map. 144 // avoid deep copies during re-alloc of the containing map.
141 }; 145 };
142 146
143 } // namespace chrome_browser_net 147 } // namespace chrome_browser_net
144 148
145 #endif // CHROME_BROWSER_NET_REFERRER_H_ 149 #endif // CHROME_BROWSER_NET_REFERRER_H_
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor_unittest.cc ('k') | chrome/browser/net/referrer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698