| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/net/predictor.h" | 5 #include "chrome/browser/net/predictor.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <sstream> | 10 #include <sstream> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/containers/mru_cache.h" | 14 #include "base/containers/mru_cache.h" |
| 15 #include "base/feature_list.h" |
| 15 #include "base/location.h" | 16 #include "base/location.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 20 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 21 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/synchronization/waitable_event.h" | 25 #include "base/synchronization/waitable_event.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 49 #include "net/proxy/proxy_service.h" | 50 #include "net/proxy/proxy_service.h" |
| 50 #include "net/ssl/ssl_config_service.h" | 51 #include "net/ssl/ssl_config_service.h" |
| 51 #include "net/url_request/url_request_context.h" | 52 #include "net/url_request/url_request_context.h" |
| 52 #include "net/url_request/url_request_context_getter.h" | 53 #include "net/url_request/url_request_context_getter.h" |
| 53 | 54 |
| 54 using base::TimeDelta; | 55 using base::TimeDelta; |
| 55 using content::BrowserThread; | 56 using content::BrowserThread; |
| 56 | 57 |
| 57 namespace chrome_browser_net { | 58 namespace chrome_browser_net { |
| 58 | 59 |
| 60 namespace { |
| 61 const base::Feature kUsePredictorDNSQueue{"UsePredictorDNSQueue", |
| 62 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 63 } |
| 64 |
| 59 // static | 65 // static |
| 60 const int Predictor::kPredictorReferrerVersion = 2; | 66 const int Predictor::kPredictorReferrerVersion = 2; |
| 61 const double Predictor::kPreconnectWorthyExpectedValue = 0.8; | 67 const double Predictor::kPreconnectWorthyExpectedValue = 0.8; |
| 62 const double Predictor::kDNSPreresolutionWorthyExpectedValue = 0.1; | 68 const double Predictor::kDNSPreresolutionWorthyExpectedValue = 0.1; |
| 63 const double Predictor::kDiscardableExpectedValue = 0.05; | 69 const double Predictor::kDiscardableExpectedValue = 0.05; |
| 64 // The goal is of trimming is to to reduce the importance (number of expected | 70 // The goal is of trimming is to to reduce the importance (number of expected |
| 65 // subresources needed) by a factor of 2 after about 24 hours of uptime. We will | 71 // subresources needed) by a factor of 2 after about 24 hours of uptime. We will |
| 66 // trim roughly once-an-hour of uptime. The ratio to use in each trim operation | 72 // trim roughly once-an-hour of uptime. The ratio to use in each trim operation |
| 67 // is then the 24th root of 0.5. If a user only surfs for 4 hours a day, then | 73 // is then the 24th root of 0.5. If a user only surfs for 4 hours a day, then |
| 68 // after about 6 days they will have halved all their estimates of subresource | 74 // after about 6 days they will have halved all their estimates of subresource |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 Results assignees; | 425 Results assignees; |
| 420 for (Results::iterator it = results_.begin(); results_.end() != it; ++it) { | 426 for (Results::iterator it = results_.begin(); results_.end() != it; ++it) { |
| 421 GURL url(it->first); | 427 GURL url(it->first); |
| 422 UrlInfo* info = &it->second; | 428 UrlInfo* info = &it->second; |
| 423 DCHECK(info->HasUrl(url)); | 429 DCHECK(info->HasUrl(url)); |
| 424 if (info->is_assigned()) { | 430 if (info->is_assigned()) { |
| 425 info->SetPendingDeleteState(); | 431 info->SetPendingDeleteState(); |
| 426 assignees[url] = *info; | 432 assignees[url] = *info; |
| 427 } | 433 } |
| 428 } | 434 } |
| 429 DCHECK_LE(assignees.size(), max_concurrent_dns_lookups_); | 435 DCHECK(!base::FeatureList::IsEnabled(kUsePredictorDNSQueue) || |
| 436 assignees.size() <= max_concurrent_dns_lookups_); |
| 430 results_.clear(); | 437 results_.clear(); |
| 431 // Put back in the names being worked on. | 438 // Put back in the names being worked on. |
| 432 for (Results::iterator it = assignees.begin(); assignees.end() != it; ++it) { | 439 for (Results::iterator it = assignees.begin(); assignees.end() != it; ++it) { |
| 433 DCHECK(it->second.is_marked_to_delete()); | 440 DCHECK(it->second.is_marked_to_delete()); |
| 434 results_[it->first] = it->second; | 441 results_[it->first] = it->second; |
| 435 } | 442 } |
| 436 } | 443 } |
| 437 | 444 |
| 438 // Overloaded Resolve() to take a vector of names. | 445 // Overloaded Resolve() to take a vector of names. |
| 439 void Predictor::ResolveList(const UrlList& urls, | 446 void Predictor::ResolveList(const UrlList& urls, |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 | 1086 |
| 1080 info->SetQueuedState(motivation); | 1087 info->SetQueuedState(motivation); |
| 1081 work_queue_.Push(url, motivation); | 1088 work_queue_.Push(url, motivation); |
| 1082 | 1089 |
| 1083 StartSomeQueuedResolutions(); | 1090 StartSomeQueuedResolutions(); |
| 1084 return info; | 1091 return info; |
| 1085 } | 1092 } |
| 1086 | 1093 |
| 1087 bool Predictor::CongestionControlPerformed(UrlInfo* info) { | 1094 bool Predictor::CongestionControlPerformed(UrlInfo* info) { |
| 1088 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1095 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1096 DCHECK(base::FeatureList::IsEnabled(kUsePredictorDNSQueue)); |
| 1089 // Note: queue_duration is ONLY valid after we go to assigned state. | 1097 // Note: queue_duration is ONLY valid after we go to assigned state. |
| 1090 if (info->queue_duration() < max_dns_queue_delay_) | 1098 if (info->queue_duration() < max_dns_queue_delay_) |
| 1091 return false; | 1099 return false; |
| 1092 // We need to discard all entries in our queue, as we're keeping them waiting | 1100 // We need to discard all entries in our queue, as we're keeping them waiting |
| 1093 // too long. By doing this, we'll have a chance to quickly service urgent | 1101 // too long. By doing this, we'll have a chance to quickly service urgent |
| 1094 // resolutions, and not have a bogged down system. | 1102 // resolutions, and not have a bogged down system. |
| 1095 while (true) { | 1103 while (true) { |
| 1096 info->RemoveFromQueue(); | 1104 info->RemoveFromQueue(); |
| 1097 if (work_queue_.IsEmpty()) | 1105 if (work_queue_.IsEmpty()) |
| 1098 break; | 1106 break; |
| 1099 info = &results_[work_queue_.Pop()]; | 1107 info = &results_[work_queue_.Pop()]; |
| 1100 info->SetAssignedState(); | 1108 info->SetAssignedState(); |
| 1101 } | 1109 } |
| 1102 return true; | 1110 return true; |
| 1103 } | 1111 } |
| 1104 | 1112 |
| 1105 void Predictor::StartSomeQueuedResolutions() { | 1113 void Predictor::StartSomeQueuedResolutions() { |
| 1106 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1114 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1107 | 1115 |
| 1116 // If the queue is disabled, just make LookupRequests for all entries. |
| 1117 bool enable_queue = base::FeatureList::IsEnabled(kUsePredictorDNSQueue); |
| 1108 while (!work_queue_.IsEmpty() && | 1118 while (!work_queue_.IsEmpty() && |
| 1109 pending_lookups_.size() < max_concurrent_dns_lookups_) { | 1119 (!enable_queue || |
| 1120 pending_lookups_.size() < max_concurrent_dns_lookups_)) { |
| 1110 const GURL url(work_queue_.Pop()); | 1121 const GURL url(work_queue_.Pop()); |
| 1111 UrlInfo* info = &results_[url]; | 1122 UrlInfo* info = &results_[url]; |
| 1112 DCHECK(info->HasUrl(url)); | 1123 DCHECK(info->HasUrl(url)); |
| 1113 info->SetAssignedState(); | 1124 info->SetAssignedState(); |
| 1114 | 1125 |
| 1115 if (CongestionControlPerformed(info)) { | 1126 // Only perform congestion control if the queue is enabled. |
| 1127 if (enable_queue && CongestionControlPerformed(info)) { |
| 1116 DCHECK(work_queue_.IsEmpty()); | 1128 DCHECK(work_queue_.IsEmpty()); |
| 1117 return; | 1129 return; |
| 1118 } | 1130 } |
| 1119 | 1131 |
| 1120 LookupRequest* request = new LookupRequest(this, host_resolver_, url); | 1132 LookupRequest* request = new LookupRequest(this, host_resolver_, url); |
| 1121 | 1133 |
| 1122 int status = request->Start(); | 1134 int status = request->Start(); |
| 1123 if (status == net::ERR_IO_PENDING) { | 1135 if (status == net::ERR_IO_PENDING) { |
| 1124 // Will complete asynchronously. | 1136 // Will complete asynchronously. |
| 1125 pending_lookups_.insert(request); | 1137 pending_lookups_.insert(request); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 } | 1347 } |
| 1336 | 1348 |
| 1337 void SimplePredictor::ShutdownOnUIThread() { | 1349 void SimplePredictor::ShutdownOnUIThread() { |
| 1338 SetShutdown(true); | 1350 SetShutdown(true); |
| 1339 } | 1351 } |
| 1340 | 1352 |
| 1341 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1353 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
| 1342 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1354 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
| 1343 | 1355 |
| 1344 } // namespace chrome_browser_net | 1356 } // namespace chrome_browser_net |
| OLD | NEW |