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

Side by Side Diff: chrome/browser/net/url_info.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/referrer.cc ('k') | chrome/browser/net/url_info.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 // A UrlInfo object is used to store prediction related information about a host 5 // A UrlInfo object is used to store prediction related information about a host
6 // port and scheme triplet. When performing DNS pre-resolution of the host/port 6 // port and scheme triplet. When performing DNS pre-resolution of the host/port
7 // pair, its state is monitored as it is resolved. 7 // pair, its state is monitored as it is resolved.
8 // It includes progress, from placement in the Predictor's queue, to resolution 8 // It includes progress, from placement in the Predictor's queue, to resolution
9 // by the DNS service as either FOUND or NO_SUCH_NAME. Each instance may also 9 // by the DNS service as either FOUND or NO_SUCH_NAME. Each instance may also
10 // hold records of previous resolution times, which might later be shown to be 10 // hold records of previous resolution times, which might later be shown to be
(...skipping 11 matching lines...) Expand all
22 22
23 #include "base/time.h" 23 #include "base/time.h"
24 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
25 #include "net/base/host_port_pair.h" 25 #include "net/base/host_port_pair.h"
26 26
27 namespace chrome_browser_net { 27 namespace chrome_browser_net {
28 28
29 // Use command line switch to enable detailed logging. 29 // Use command line switch to enable detailed logging.
30 void EnablePredictorDetailedLog(bool enable); 30 void EnablePredictorDetailedLog(bool enable);
31 31
32 enum DnsBenefit {
33 PREFETCH_NO_BENEFIT, // Prefetch never hit the network. Name was pre-cached.
34 PREFETCH_CACHE_EVICTION, // Prefetch used network, but so did HTTP stack.
35 PREFETCH_NAME_NONEXISTANT, // Valuable prefetch of "name not found" was used.
36 PREFETCH_NAME_FOUND, // Valuable prefetch was used.
37 PREFETCH_OBLIVIOUS // No prefetch attempt was even made.
38 };
39
40 class UrlInfo { 32 class UrlInfo {
41 public: 33 public:
42 // Reasons for a domain to be resolved. 34 // Reasons for a domain to be resolved.
43 enum ResolutionMotivation { 35 enum ResolutionMotivation {
44 MOUSE_OVER_MOTIVATED, // Mouse-over link induced resolution. 36 MOUSE_OVER_MOTIVATED, // Mouse-over link induced resolution.
45 PAGE_SCAN_MOTIVATED, // Scan of rendered page induced resolution. 37 PAGE_SCAN_MOTIVATED, // Scan of rendered page induced resolution.
46 UNIT_TEST_MOTIVATED, 38 UNIT_TEST_MOTIVATED,
47 LINKED_MAX_MOTIVATED, // enum demarkation above motivation from links. 39 LINKED_MAX_MOTIVATED, // enum demarkation above motivation from links.
48 OMNIBOX_MOTIVATED, // Omni-box suggested resolving this. 40 OMNIBOX_MOTIVATED, // Omni-box suggested resolving this.
49 STARTUP_LIST_MOTIVATED, // Startup list caused this resolution. 41 STARTUP_LIST_MOTIVATED, // Startup list caused this resolution.
50 42
51 NO_PREFETCH_MOTIVATION, // Browser navigation info (not prefetch related). 43 NO_PREFETCH_MOTIVATION, // Browser navigation info (not prefetch related).
52 44
53 // The following involve predictive prefetching, triggered by a navigation. 45 // The following involve predictive prefetching, triggered by a navigation.
54 // The referrinrg_url_ is also set when these are used. 46 // The referrinrg_url_ is also set when these are used.
55 // TODO(jar): Support STATIC_REFERAL_MOTIVATED API and integration. 47 // TODO(jar): Support STATIC_REFERAL_MOTIVATED API and integration.
56 STATIC_REFERAL_MOTIVATED, // External database suggested this resolution. 48 STATIC_REFERAL_MOTIVATED, // External database suggested this resolution.
57 LEARNED_REFERAL_MOTIVATED, // Prior navigation taught us this resolution. 49 LEARNED_REFERAL_MOTIVATED, // Prior navigation taught us this resolution.
50
51 MAX_MOTIVATED // Beyond all enums, for use in histogram bounding.
58 }; 52 };
59 53
60 enum DnsProcessingState { 54 enum DnsProcessingState {
61 // When processed by our prefetching system, the states are: 55 // When processed by our prefetching system, the states are:
62 PENDING, // Constructor has completed. 56 PENDING, // Constructor has completed.
63 QUEUED, // In name queue but not yet being resolved. 57 QUEUED, // In name queue but not yet being resolved.
64 ASSIGNED, // Being resolved (or being reset to earlier state) 58 ASSIGNED, // Being resolved (or being reset to earlier state)
65 ASSIGNED_BUT_MARKED, // Needs to be deleted as soon as it's resolved. 59 ASSIGNED_BUT_MARKED, // Needs to be deleted as soon as it's resolved.
66 FOUND, // DNS resolution completed. 60 FOUND, // DNS resolution completed.
67 NO_SUCH_NAME, // DNS resolution completed. 61 NO_SUCH_NAME, // DNS resolution completed.
68 // When processed by the network stack during navigation, the states are: 62 };
69 STARTED, // Resolution has begun for a navigation.
70 FINISHED, // Resolution has completed for a navigation.
71 FINISHED_UNRESOLVED}; // No resolution found, so navigation will fail.
72 static const base::TimeDelta kMaxNonNetworkDnsLookupDuration; 63 static const base::TimeDelta kMaxNonNetworkDnsLookupDuration;
73 // The number of OS cache entries we can guarantee(?) before cache eviction 64 // The number of OS cache entries we can guarantee(?) before cache eviction
74 // might likely take place. 65 // might likely take place.
75 static const int kMaxGuaranteedDnsCacheSize = 50; 66 static const int kMaxGuaranteedDnsCacheSize = 50;
76 67
77 typedef std::vector<UrlInfo> DnsInfoTable; 68 typedef std::vector<UrlInfo> UrlInfoTable;
78 69
79 static const base::TimeDelta kNullDuration; 70 static const base::TimeDelta kNullDuration;
80 71
81 // UrlInfo are usually made by the default constructor during 72 // UrlInfo are usually made by the default constructor during
82 // initializing of the Predictor's map (of info for Hostnames). 73 // initializing of the Predictor's map (of info for Hostnames).
83 UrlInfo() 74 UrlInfo()
84 : state_(PENDING), 75 : state_(PENDING),
85 old_prequeue_state_(state_), 76 old_prequeue_state_(state_),
86 resolve_duration_(kNullDuration), 77 resolve_duration_(kNullDuration),
87 queue_duration_(kNullDuration), 78 queue_duration_(kNullDuration),
88 benefits_remaining_(),
89 sequence_number_(0), 79 sequence_number_(0),
90 motivation_(NO_PREFETCH_MOTIVATION), 80 motivation_(NO_PREFETCH_MOTIVATION),
91 was_linked_(false) { 81 was_linked_(false) {
92 } 82 }
93 83
94 ~UrlInfo() {} 84 ~UrlInfo() {}
95 85
96 // NeedDnsUpdate decides, based on our internal info, 86 // NeedDnsUpdate decides, based on our internal info,
97 // if it would be valuable to attempt to update (prefectch) 87 // if it would be valuable to attempt to update (prefectch)
98 // DNS data for hostname. This decision is based 88 // DNS data for hostname. This decision is based
99 // on how recently we've done DNS prefetching for hostname. 89 // on how recently we've done DNS prefetching for hostname.
100 bool NeedsDnsUpdate(); 90 bool NeedsDnsUpdate();
101 91
102 static void set_cache_expiration(base::TimeDelta time); 92 static void set_cache_expiration(base::TimeDelta time);
103 93
104 // The prefetching lifecycle. 94 // The prefetching lifecycle.
105 void SetQueuedState(ResolutionMotivation motivation); 95 void SetQueuedState(ResolutionMotivation motivation);
106 void SetAssignedState(); 96 void SetAssignedState();
107 void RemoveFromQueue(); 97 void RemoveFromQueue();
108 void SetPendingDeleteState(); 98 void SetPendingDeleteState();
109 void SetFoundState(); 99 void SetFoundState();
110 void SetNoSuchNameState(); 100 void SetNoSuchNameState();
111 // The actual browsing resolution lifecycle.
112 void SetStartedState();
113 void SetFinishedState(bool was_resolved);
114 101
115 // Finish initialization. Must only be called once. 102 // Finish initialization. Must only be called once.
116 void SetUrl(const GURL& url); 103 void SetUrl(const GURL& url);
117 104
118 bool was_linked() const { return was_linked_; } 105 bool was_linked() const { return was_linked_; }
119 106
120 GURL referring_url() const { return referring_url_; } 107 GURL referring_url() const { return referring_url_; }
121 void SetReferringHostname(const GURL& url) { 108 void SetReferringHostname(const GURL& url) {
122 referring_url_ = url; 109 referring_url_ = url;
123 } 110 }
124 111
125 bool was_found() const { return FOUND == state_; } 112 bool was_found() const { return FOUND == state_; }
126 bool was_nonexistant() const { return NO_SUCH_NAME == state_; } 113 bool was_nonexistant() const { return NO_SUCH_NAME == state_; }
127 bool is_assigned() const { 114 bool is_assigned() const {
128 return ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_; 115 return ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_;
129 } 116 }
130 bool is_marked_to_delete() const { return ASSIGNED_BUT_MARKED == state_; } 117 bool is_marked_to_delete() const { return ASSIGNED_BUT_MARKED == state_; }
131 const GURL url() const { return url_; } 118 const GURL url() const { return url_; }
132 119
133 bool HasUrl(const GURL& url) const { 120 bool HasUrl(const GURL& url) const {
134 return url_ == url; 121 return url_ == url;
135 } 122 }
136 123
137 base::TimeDelta resolve_duration() const { return resolve_duration_;} 124 base::TimeDelta resolve_duration() const { return resolve_duration_;}
138 base::TimeDelta queue_duration() const { return queue_duration_;} 125 base::TimeDelta queue_duration() const { return queue_duration_;}
139 base::TimeDelta benefits_remaining() const { return benefits_remaining_; }
140
141 DnsBenefit AccruePrefetchBenefits(UrlInfo* navigation_info);
142 126
143 void DLogResultsStats(const char* message) const; 127 void DLogResultsStats(const char* message) const;
144 128
145 static void GetHtmlTable(const DnsInfoTable host_infos, 129 static void GetHtmlTable(const UrlInfoTable host_infos,
146 const char* description, 130 const char* description,
147 const bool brief, 131 const bool brief,
148 std::string* output); 132 std::string* output);
149 133
150 private: 134 private:
151 base::TimeDelta GetDuration() { 135 base::TimeDelta GetDuration() {
152 base::TimeTicks old_time = time_; 136 base::TimeTicks old_time = time_;
153 time_ = base::TimeTicks::Now(); 137 time_ = base::TimeTicks::Now();
154 return time_ - old_time; 138 return time_ - old_time;
155 } 139 }
(...skipping 19 matching lines...) Expand all
175 DnsProcessingState old_prequeue_state_; 159 DnsProcessingState old_prequeue_state_;
176 160
177 GURL url_; // Host, port and scheme for this info. 161 GURL url_; // Host, port and scheme for this info.
178 162
179 // When was last state changed (usually lookup completed). 163 // When was last state changed (usually lookup completed).
180 base::TimeTicks time_; 164 base::TimeTicks time_;
181 // Time needed for DNS to resolve. 165 // Time needed for DNS to resolve.
182 base::TimeDelta resolve_duration_; 166 base::TimeDelta resolve_duration_;
183 // Time spent in queue. 167 // Time spent in queue.
184 base::TimeDelta queue_duration_; 168 base::TimeDelta queue_duration_;
185 // Unused potential benefits of a prefetch.
186 base::TimeDelta benefits_remaining_;
187 169
188 int sequence_number_; // Used to calculate potential of cache eviction. 170 int sequence_number_; // Used to calculate potential of cache eviction.
189 static int sequence_counter; // Used to allocate sequence_number_'s. 171 static int sequence_counter; // Used to allocate sequence_number_'s.
190 172
191 // Motivation for creation of this instance. 173 // Motivation for creation of this instance.
192 ResolutionMotivation motivation_; 174 ResolutionMotivation motivation_;
193 175
194 // Record if the motivation for prefetching was ever a page-link-scan. 176 // Record if the motivation for prefetching was ever a page-link-scan.
195 bool was_linked_; 177 bool was_linked_;
196 178
197 // If this instance holds data about a navigation, we store the referrer. 179 // If this instance holds data about a navigation, we store the referrer.
198 // If this instance hold data about a prefetch, and the prefetch was 180 // If this instance hold data about a prefetch, and the prefetch was
199 // instigated by a referrer, we store it here (for use in about:dns). 181 // instigated by a referrer, we store it here (for use in about:dns).
200 GURL referring_url_; 182 GURL referring_url_;
201 183
202 // We put these objects into a std::map, and hence we 184 // We put these objects into a std::map, and hence we
203 // need some "evil" constructors. 185 // need some "evil" constructors.
204 // DISALLOW_COPY_AND_ASSIGN(UrlInfo); 186 // DISALLOW_COPY_AND_ASSIGN(UrlInfo);
205 }; 187 };
206 188
207 } // namespace chrome_browser_net 189 } // namespace chrome_browser_net
208 190
209 #endif // CHROME_BROWSER_NET_URL_INFO_H_ 191 #endif // CHROME_BROWSER_NET_URL_INFO_H_
OLDNEW
« no previous file with comments | « chrome/browser/net/referrer.cc ('k') | chrome/browser/net/url_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698