[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 3530cd9 | 2010-06-27 06:22:01 | [diff] [blame] | 5 | #include "chrome/browser/net/predictor.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 8 | #include <set> |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 9 | #include <sstream> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/histogram.h" |
| 13 | #include "base/stats_counters.h" |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 15 | #include "base/time.h" |
[email protected] | 6fad263 | 2009-11-02 05:59:37 | [diff] [blame] | 16 | #include "chrome/browser/chrome_thread.h" |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 17 | #include "chrome/browser/net/preconnect.h" |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 18 | #include "net/base/address_list.h" |
| 19 | #include "net/base/completion_callback.h" |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 20 | #include "net/base/host_port_pair.h" |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 21 | #include "net/base/host_resolver.h" |
| 22 | #include "net/base/net_errors.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 23 | #include "net/base/net_log.h" |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 24 | |
[email protected] | 602faf3c | 2009-06-27 14:35:44 | [diff] [blame] | 25 | using base::TimeDelta; |
| 26 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | namespace chrome_browser_net { |
| 28 | |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 29 | // static |
| 30 | const double Predictor::kPreconnectWorthyExpectedValue = 0.7; |
| 31 | // static |
| 32 | const double Predictor::kDNSPreresolutionWorthyExpectedValue = 0.2; |
| 33 | // static |
| 34 | const double Predictor::kPersistWorthyExpectedValue = 0.1; |
| 35 | |
| 36 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 37 | class Predictor::LookupRequest { |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 38 | public: |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 39 | LookupRequest(Predictor* predictor, |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 40 | net::HostResolver* host_resolver, |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 41 | const GURL& url) |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 42 | : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 43 | net_callback_(this, &LookupRequest::OnLookupFinished)), |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 44 | predictor_(predictor), |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 45 | url_(url), |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 46 | resolver_(host_resolver) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | } |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 48 | |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 49 | // Return underlying network resolver status. |
| 50 | // net::OK ==> Host was found synchronously. |
| 51 | // net:ERR_IO_PENDING ==> Network will callback later with result. |
| 52 | // anything else ==> Host was not found synchronously. |
| 53 | int Start() { |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 54 | net::HostResolver::RequestInfo resolve_info(url_.host(), |
| 55 | url_.EffectiveIntPort()); |
[email protected] | 2884a46 | 2009-06-15 05:08:42 | [diff] [blame] | 56 | |
| 57 | // Make a note that this is a speculative resolve request. This allows us |
| 58 | // to separate it from real navigations in the observer's callback, and |
| 59 | // lets the HostResolver know it can de-prioritize it. |
| 60 | resolve_info.set_is_speculative(true); |
[email protected] | ec08bb2 | 2009-08-12 00:25:12 | [diff] [blame] | 61 | return resolver_.Resolve( |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 62 | resolve_info, &addresses_, &net_callback_, net::BoundNetLog()); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | private: |
| 66 | void OnLookupFinished(int result) { |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 67 | predictor_->OnLookupFinished(this, url_, result == net::OK); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | // HostResolver will call us using this callback when resolution is complete. |
| 71 | net::CompletionCallbackImpl<LookupRequest> net_callback_; |
| 72 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 73 | Predictor* predictor_; // The predictor which started us. |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 74 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 75 | const GURL url_; // Hostname to resolve. |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 76 | net::SingleRequestHostResolver resolver_; |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 77 | net::AddressList addresses_; |
| 78 | |
| 79 | DISALLOW_COPY_AND_ASSIGN(LookupRequest); |
| 80 | }; |
| 81 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 82 | Predictor::Predictor(net::HostResolver* host_resolver, |
| 83 | base::TimeDelta max_dns_queue_delay, |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 84 | size_t max_concurrent, |
| 85 | bool preconnect_enabled) |
| 86 | : peak_pending_lookups_(0), |
| 87 | shutdown_(false), |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 88 | max_concurrent_dns_lookups_(max_concurrent), |
| 89 | max_dns_queue_delay_(max_dns_queue_delay), |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 90 | host_resolver_(host_resolver), |
| 91 | preconnect_enabled_(preconnect_enabled) { |
| 92 | Referrer::SetUsePreconnectValuations(preconnect_enabled); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 93 | } |
| 94 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 95 | Predictor::~Predictor() { |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 96 | DCHECK(shutdown_); |
| 97 | } |
| 98 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 99 | void Predictor::Shutdown() { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 100 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 101 | DCHECK(!shutdown_); |
| 102 | shutdown_ = true; |
| 103 | |
| 104 | std::set<LookupRequest*>::iterator it; |
| 105 | for (it = pending_lookups_.begin(); it != pending_lookups_.end(); ++it) |
| 106 | delete *it; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // Overloaded Resolve() to take a vector of names. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 110 | void Predictor::ResolveList(const UrlList& urls, |
| 111 | UrlInfo::ResolutionMotivation motivation) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 112 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | fd2f8afe | 2009-06-11 21:53:55 | [diff] [blame] | 113 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 114 | for (UrlList::const_iterator it = urls.begin(); it < urls.end(); ++it) { |
| 115 | AppendToResolutionQueue(*it, motivation); |
| 116 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | // Basic Resolve() takes an invidual name, and adds it |
| 120 | // to the queue. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 121 | void Predictor::Resolve(const GURL& url, |
| 122 | UrlInfo::ResolutionMotivation motivation) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 123 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 124 | if (!url.has_host()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 125 | return; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 126 | AppendToResolutionQueue(url, motivation); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 127 | } |
| 128 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 129 | void Predictor::LearnFromNavigation(const GURL& referring_url, |
| 130 | const GURL& target_url) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 131 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 132 | if (referring_url.has_host() && |
| 133 | referring_url != target_url) { |
| 134 | DCHECK(referring_url == referring_url.GetWithEmptyPath()); |
| 135 | referrers_[referring_url].SuggestHost(target_url); |
| 136 | } |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 137 | } |
| 138 | |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 139 | enum SubresourceValue { |
| 140 | PRECONNECTION, |
| 141 | PRERESOLUTION, |
| 142 | TOO_NEW, |
| 143 | SUBRESOURCE_VALUE_MAX |
| 144 | }; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 145 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 146 | void Predictor::PredictFrameSubresources(const GURL& url) { |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 147 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 148 | DCHECK(url.GetWithEmptyPath() == url); |
| 149 | Referrers::iterator it = referrers_.find(url); |
| 150 | if (referrers_.end() == it) |
| 151 | return; |
[email protected] | 9008c86f | 2010-08-06 07:10:24 | [diff] [blame^] | 152 | ChromeThread::PostTask( |
| 153 | ChromeThread::IO, |
| 154 | FROM_HERE, |
| 155 | NewRunnableMethod(this, |
| 156 | &Predictor::PrepareFrameSubresources, url)); |
| 157 | } |
| 158 | |
| 159 | void Predictor::PrepareFrameSubresources(const GURL& url) { |
| 160 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 161 | DCHECK(url.GetWithEmptyPath() == url); |
| 162 | Referrers::iterator it = referrers_.find(url); |
| 163 | if (referrers_.end() == it) |
| 164 | return; |
| 165 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 166 | Referrer* referrer = &(it->second); |
| 167 | referrer->IncrementUseCount(); |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 168 | const UrlInfo::ResolutionMotivation motivation = |
| 169 | UrlInfo::LEARNED_REFERAL_MOTIVATED; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 170 | for (Referrer::iterator future_url = referrer->begin(); |
| 171 | future_url != referrer->end(); ++future_url) { |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 172 | SubresourceValue evalution(TOO_NEW); |
| 173 | double connection_expectation = future_url->second.subresource_use_rate(); |
| 174 | UMA_HISTOGRAM_CUSTOM_COUNTS("Net.PreconnectSubresourceExpectation", |
| 175 | static_cast<int>(connection_expectation * 100), |
| 176 | 10, 5000, 50); |
| 177 | future_url->second.ReferrerWasObserved(); |
| 178 | if (preconnect_enabled_ && |
| 179 | kPreconnectWorthyExpectedValue < connection_expectation) { |
| 180 | evalution = PRECONNECTION; |
| 181 | future_url->second.IncrementPreconnectionCount(); |
| 182 | Preconnect::PreconnectOnIOThread(future_url->first, motivation); |
| 183 | } else if (kDNSPreresolutionWorthyExpectedValue < connection_expectation) { |
| 184 | evalution = PRERESOLUTION; |
| 185 | future_url->second.preresolution_increment(); |
| 186 | UrlInfo* queued_info = AppendToResolutionQueue(future_url->first, |
| 187 | motivation); |
| 188 | if (queued_info) |
| 189 | queued_info->SetReferringHostname(url); |
| 190 | } |
| 191 | UMA_HISTOGRAM_ENUMERATION("Net.PreconnectSubresourceEval", evalution, |
| 192 | SUBRESOURCE_VALUE_MAX); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 196 | // Provide sort order so all .com's are together, etc. |
| 197 | struct RightToLeftStringSorter { |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 198 | bool operator()(const GURL& left, |
| 199 | const GURL& right) const { |
| 200 | return string_compare(left.host(), right.host()); |
| 201 | } |
| 202 | |
| 203 | static bool string_compare(const std::string& left_host, |
| 204 | const std::string right_host) { |
| 205 | if (left_host == right_host) return true; |
| 206 | size_t left_already_matched = left_host.size(); |
| 207 | size_t right_already_matched = right_host.size(); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 208 | |
| 209 | // Ensure both strings have characters. |
| 210 | if (!left_already_matched) return true; |
| 211 | if (!right_already_matched) return false; |
| 212 | |
| 213 | // Watch for trailing dot, so we'll always be safe to go one beyond dot. |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 214 | if ('.' == left_host[left_already_matched - 1]) { |
| 215 | if ('.' != right_host[right_already_matched - 1]) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 216 | return true; |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 217 | // Both have dots at end of string. |
| 218 | --left_already_matched; |
| 219 | --right_already_matched; |
| 220 | } else { |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 221 | if ('.' == right_host[right_already_matched - 1]) |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 222 | return false; |
| 223 | } |
| 224 | |
| 225 | while (1) { |
| 226 | if (!left_already_matched) return true; |
| 227 | if (!right_already_matched) return false; |
| 228 | |
| 229 | size_t left_length, right_length; |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 230 | size_t left_start = left_host.find_last_of('.', left_already_matched - 1); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 231 | if (std::string::npos == left_start) { |
| 232 | left_length = left_already_matched; |
| 233 | left_already_matched = left_start = 0; |
| 234 | } else { |
| 235 | left_length = left_already_matched - left_start; |
| 236 | left_already_matched = left_start; |
| 237 | ++left_start; // Don't compare the dot. |
| 238 | } |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 239 | size_t right_start = right_host.find_last_of('.', |
| 240 | right_already_matched - 1); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 241 | if (std::string::npos == right_start) { |
| 242 | right_length = right_already_matched; |
| 243 | right_already_matched = right_start = 0; |
| 244 | } else { |
| 245 | right_length = right_already_matched - right_start; |
| 246 | right_already_matched = right_start; |
| 247 | ++right_start; // Don't compare the dot. |
| 248 | } |
| 249 | |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 250 | int diff = left_host.compare(left_start, left_host.size(), |
| 251 | right_host, right_start, right_host.size()); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 252 | if (diff > 0) return false; |
| 253 | if (diff < 0) return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | }; |
| 257 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 258 | void Predictor::GetHtmlReferrerLists(std::string* output) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 259 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 260 | if (referrers_.empty()) |
| 261 | return; |
| 262 | |
| 263 | // TODO(jar): Remove any plausible JavaScript from names before displaying. |
| 264 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 265 | typedef std::set<GURL, struct RightToLeftStringSorter> |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 266 | SortedNames; |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 267 | SortedNames sorted_names; |
| 268 | |
| 269 | for (Referrers::iterator it = referrers_.begin(); |
| 270 | referrers_.end() != it; ++it) |
| 271 | sorted_names.insert(it->first); |
| 272 | |
| 273 | output->append("<br><table border>"); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 274 | output->append( |
| 275 | "<tr><th>Host for Page</th>" |
| 276 | "<th>Page Load<br>Count</th>" |
| 277 | "<th>Subresource<br>Navigations</th>" |
| 278 | "<th>Subresource<br>PreConnects</th>" |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 279 | "<th>Subresource<br>PreResolves</th>" |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 280 | "<th>Expected<br>Connects</th>" |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 281 | "<th>Subresource Spec</th></tr>"); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 282 | |
| 283 | for (SortedNames::iterator it = sorted_names.begin(); |
| 284 | sorted_names.end() != it; ++it) { |
| 285 | Referrer* referrer = &(referrers_[*it]); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 286 | bool first_set_of_futures = true; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 287 | for (Referrer::iterator future_url = referrer->begin(); |
| 288 | future_url != referrer->end(); ++future_url) { |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 289 | output->append("<tr align=right>"); |
| 290 | if (first_set_of_futures) |
| 291 | StringAppendF(output, "<td rowspan=%d>%s</td><td rowspan=%d>%d</td>", |
| 292 | static_cast<int>(referrer->size()), |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 293 | it->spec().c_str(), |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 294 | static_cast<int>(referrer->size()), |
| 295 | static_cast<int>(referrer->use_count())); |
| 296 | first_set_of_futures = false; |
| 297 | StringAppendF(output, |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 298 | "<td>%d</td><td>%d</td><td>%d</td><td>%2.3f</td><td>%s</td></tr>", |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 299 | static_cast<int>(future_url->second.navigation_count()), |
| 300 | static_cast<int>(future_url->second.preconnection_count()), |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 301 | static_cast<int>(future_url->second.preresolution_count()), |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 302 | static_cast<double>(future_url->second.subresource_use_rate()), |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 303 | future_url->first.spec().c_str()); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 304 | } |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 305 | } |
| 306 | output->append("</table>"); |
| 307 | } |
| 308 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 309 | void Predictor::GetHtmlInfo(std::string* output) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 310 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 311 | // Local lists for calling UrlInfo |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 312 | UrlInfo::UrlInfoTable name_not_found; |
| 313 | UrlInfo::UrlInfoTable name_preresolved; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 314 | |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 315 | // Get copies of all useful data. |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 316 | typedef std::map<GURL, UrlInfo, RightToLeftStringSorter> SortedUrlInfo; |
| 317 | SortedUrlInfo snapshot; |
| 318 | // UrlInfo supports value semantics, so we can do a shallow copy. |
| 319 | for (Results::iterator it(results_.begin()); it != results_.end(); it++) |
| 320 | snapshot[it->first] = it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 321 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 322 | // Partition the UrlInfo's into categories. |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 323 | for (SortedUrlInfo::iterator it(snapshot.begin()); |
| 324 | it != snapshot.end(); it++) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 325 | if (it->second.was_nonexistant()) { |
| 326 | name_not_found.push_back(it->second); |
| 327 | continue; |
| 328 | } |
| 329 | if (!it->second.was_found()) |
| 330 | continue; // Still being processed. |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 331 | name_preresolved.push_back(it->second); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | bool brief = false; |
| 335 | #ifdef NDEBUG |
| 336 | brief = true; |
| 337 | #endif // NDEBUG |
| 338 | |
| 339 | // Call for display of each table, along with title. |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 340 | UrlInfo::GetHtmlTable(name_preresolved, |
| 341 | "Preresolution DNS records performed for ", brief, output); |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 342 | UrlInfo::GetHtmlTable(name_not_found, |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 343 | "Preresolving DNS records revealed non-existance for ", brief, output); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 344 | } |
| 345 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 346 | UrlInfo* Predictor::AppendToResolutionQueue( |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 347 | const GURL& url, |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 348 | UrlInfo::ResolutionMotivation motivation) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 349 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 350 | DCHECK(url.has_host()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 352 | if (shutdown_) |
| 353 | return NULL; |
| 354 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 355 | UrlInfo* info = &results_[url]; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 356 | info->SetUrl(url); // Initialize or DCHECK. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 357 | // TODO(jar): I need to discard names that have long since expired. |
| 358 | // Currently we only add to the domain map :-/ |
| 359 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 360 | DCHECK(info->HasUrl(url)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 361 | |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 362 | if (!info->NeedsDnsUpdate()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 363 | info->DLogResultsStats("DNS PrefetchNotUpdated"); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 364 | return NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 367 | info->SetQueuedState(motivation); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 368 | work_queue_.Push(url, motivation); |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 369 | StartSomeQueuedResolutions(); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 370 | return info; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 373 | void Predictor::StartSomeQueuedResolutions() { |
[email protected] | 6fad263 | 2009-11-02 05:59:37 | [diff] [blame] | 374 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | fd2f8afe | 2009-06-11 21:53:55 | [diff] [blame] | 375 | |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 376 | while (!work_queue_.IsEmpty() && |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 377 | pending_lookups_.size() < max_concurrent_dns_lookups_) { |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 378 | const GURL url(work_queue_.Pop()); |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 379 | UrlInfo* info = &results_[url]; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 380 | DCHECK(info->HasUrl(url)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 381 | info->SetAssignedState(); |
| 382 | |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 383 | if (CongestionControlPerformed(info)) { |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 384 | DCHECK(work_queue_.IsEmpty()); |
| 385 | return; |
| 386 | } |
| 387 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 388 | LookupRequest* request = new LookupRequest(this, host_resolver_, url); |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 389 | int status = request->Start(); |
| 390 | if (status == net::ERR_IO_PENDING) { |
[email protected] | fd2f8afe | 2009-06-11 21:53:55 | [diff] [blame] | 391 | // Will complete asynchronously. |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 392 | pending_lookups_.insert(request); |
| 393 | peak_pending_lookups_ = std::max(peak_pending_lookups_, |
| 394 | pending_lookups_.size()); |
| 395 | } else { |
[email protected] | 221f3336 | 2009-06-29 20:46:48 | [diff] [blame] | 396 | // Completed synchronously (was already cached by HostResolver), or else |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 397 | // there was (equivalently) some network error that prevents us from |
| 398 | // finding the name. Status net::OK means it was "found." |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 399 | LookupFinished(request, url, status == net::OK); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 400 | delete request; |
| 401 | } |
| 402 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 403 | } |
| 404 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 405 | bool Predictor::CongestionControlPerformed(UrlInfo* info) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 406 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 407 | // Note: queue_duration is ONLY valid after we go to assigned state. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 408 | if (info->queue_duration() < max_dns_queue_delay_) |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 409 | return false; |
| 410 | // We need to discard all entries in our queue, as we're keeping them waiting |
| 411 | // too long. By doing this, we'll have a chance to quickly service urgent |
| 412 | // resolutions, and not have a bogged down system. |
| 413 | while (true) { |
| 414 | info->RemoveFromQueue(); |
| 415 | if (work_queue_.IsEmpty()) |
| 416 | break; |
| 417 | info = &results_[work_queue_.Pop()]; |
| 418 | info->SetAssignedState(); |
| 419 | } |
| 420 | return true; |
| 421 | } |
| 422 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 423 | void Predictor::OnLookupFinished(LookupRequest* request, const GURL& url, |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 424 | bool found) { |
[email protected] | 6fad263 | 2009-11-02 05:59:37 | [diff] [blame] | 425 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | fd2f8afe | 2009-06-11 21:53:55 | [diff] [blame] | 426 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 427 | LookupFinished(request, url, found); |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 428 | pending_lookups_.erase(request); |
| 429 | delete request; |
| 430 | |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 431 | StartSomeQueuedResolutions(); |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 434 | void Predictor::LookupFinished(LookupRequest* request, const GURL& url, |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 435 | bool found) { |
| 436 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 437 | UrlInfo* info = &results_[url]; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 438 | DCHECK(info->HasUrl(url)); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 439 | if (info->is_marked_to_delete()) { |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 440 | results_.erase(url); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 441 | } else { |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 442 | if (found) |
| 443 | info->SetFoundState(); |
| 444 | else |
| 445 | info->SetNoSuchNameState(); |
[email protected] | 7c19b87b0 | 2009-01-26 16:19:44 | [diff] [blame] | 446 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 447 | } |
| 448 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 449 | void Predictor::DiscardAllResults() { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 450 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 451 | // Delete anything listed so far in this session that shows in about:dns. |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 452 | referrers_.clear(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 453 | |
| 454 | |
| 455 | // Try to delete anything in our work queue. |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 456 | while (!work_queue_.IsEmpty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 457 | // Emulate processing cycle as though host was not found. |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 458 | GURL url = work_queue_.Pop(); |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 459 | UrlInfo* info = &results_[url]; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 460 | DCHECK(info->HasUrl(url)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 461 | info->SetAssignedState(); |
| 462 | info->SetNoSuchNameState(); |
| 463 | } |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 464 | // Now every result_ is either resolved, or is being resolved |
| 465 | // (see LookupRequest). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 466 | |
| 467 | // Step through result_, recording names of all hosts that can't be erased. |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 468 | // We can't erase anything being worked on. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 469 | Results assignees; |
| 470 | for (Results::iterator it = results_.begin(); results_.end() != it; ++it) { |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 471 | GURL url(it->first); |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 472 | UrlInfo* info = &it->second; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 473 | DCHECK(info->HasUrl(url)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 474 | if (info->is_assigned()) { |
| 475 | info->SetPendingDeleteState(); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 476 | assignees[url] = *info; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | } |
| 478 | } |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 479 | DCHECK(assignees.size() <= max_concurrent_dns_lookups_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 480 | results_.clear(); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 481 | // Put back in the names being worked on. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 482 | for (Results::iterator it = assignees.begin(); assignees.end() != it; ++it) { |
| 483 | DCHECK(it->second.is_marked_to_delete()); |
| 484 | results_[it->first] = it->second; |
| 485 | } |
| 486 | } |
| 487 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 488 | void Predictor::TrimReferrers() { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 489 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 490 | std::vector<GURL> urls; |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 491 | for (Referrers::const_iterator it = referrers_.begin(); |
| 492 | it != referrers_.end(); ++it) |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 493 | urls.push_back(it->first); |
| 494 | for (size_t i = 0; i < urls.size(); ++i) |
| 495 | if (!referrers_[urls[i]].Trim()) |
| 496 | referrers_.erase(urls[i]); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 497 | } |
| 498 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 499 | void Predictor::SerializeReferrers(ListValue* referral_list) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 500 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 501 | referral_list->Clear(); |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 502 | referral_list->Append(new FundamentalValue(PREDICTOR_REFERRER_VERSION)); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 503 | for (Referrers::const_iterator it = referrers_.begin(); |
| 504 | it != referrers_.end(); ++it) { |
| 505 | // Serialize the list of subresource names. |
| 506 | Value* subresource_list(it->second.Serialize()); |
| 507 | |
| 508 | // Create a list for each referer. |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 509 | ListValue* motivator(new ListValue); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 510 | motivator->Append(new StringValue(it->first.spec())); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 511 | motivator->Append(subresource_list); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 512 | |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 513 | referral_list->Append(motivator); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 517 | void Predictor::DeserializeReferrers(const ListValue& referral_list) { |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 518 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 519 | int format_version = -1; |
| 520 | if (referral_list.GetSize() > 0 && |
| 521 | referral_list.GetInteger(0, &format_version) && |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 522 | format_version == PREDICTOR_REFERRER_VERSION) { |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 523 | for (size_t i = 1; i < referral_list.GetSize(); ++i) { |
| 524 | ListValue* motivator; |
| 525 | if (!referral_list.GetList(i, &motivator)) { |
| 526 | NOTREACHED(); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 527 | return; |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 528 | } |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 529 | std::string motivating_url_spec; |
| 530 | if (!motivator->GetString(0, &motivating_url_spec)) { |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 531 | NOTREACHED(); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 532 | return; |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | Value* subresource_list; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 536 | if (!motivator->Get(1, &subresource_list)) { |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 537 | NOTREACHED(); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 538 | return; |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 539 | } |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 540 | |
| 541 | referrers_[GURL(motivating_url_spec)].Deserialize(*subresource_list); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 542 | } |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 546 | |
| 547 | //------------------------------------------------------------------------------ |
| 548 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 549 | Predictor::HostNameQueue::HostNameQueue() { |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 550 | } |
| 551 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 552 | Predictor::HostNameQueue::~HostNameQueue() { |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 553 | } |
| 554 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 555 | void Predictor::HostNameQueue::Push(const GURL& url, |
| 556 | UrlInfo::ResolutionMotivation motivation) { |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 557 | switch (motivation) { |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 558 | case UrlInfo::STATIC_REFERAL_MOTIVATED: |
| 559 | case UrlInfo::LEARNED_REFERAL_MOTIVATED: |
| 560 | case UrlInfo::MOUSE_OVER_MOTIVATED: |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 561 | rush_queue_.push(url); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 562 | break; |
| 563 | |
| 564 | default: |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 565 | background_queue_.push(url); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 570 | bool Predictor::HostNameQueue::IsEmpty() const { |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 571 | return rush_queue_.empty() && background_queue_.empty(); |
| 572 | } |
| 573 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 574 | GURL Predictor::HostNameQueue::Pop() { |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 575 | DCHECK(!IsEmpty()); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 576 | std::queue<GURL> *queue(rush_queue_.empty() ? &background_queue_ |
| 577 | : &rush_queue_); |
| 578 | GURL url(queue->front()); |
| 579 | queue->pop(); |
| 580 | return url; |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 581 | } |
| 582 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 583 | } // namespace chrome_browser_net |