Chromium Code Reviews| 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> |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 // on the same thread. The predictor lives on the IO thread and will die | 665 // on the same thread. The predictor lives on the IO thread and will die |
| 666 // from there so now that we're on the IO thread we need to properly | 666 // from there so now that we're on the IO thread we need to properly |
| 667 // initialize the base::WeakPtrFactory. | 667 // initialize the base::WeakPtrFactory. |
| 668 // TODO(groby): Check if WeakPtrFactory has the same constraint. | 668 // TODO(groby): Check if WeakPtrFactory has the same constraint. |
| 669 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this)); | 669 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this)); |
| 670 | 670 |
| 671 // Prefetch these hostnames on startup. | 671 // Prefetch these hostnames on startup. |
| 672 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); | 672 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); |
| 673 | 673 |
| 674 DeserializeReferrersThenDelete(referral_list); | 674 DeserializeReferrersThenDelete(referral_list); |
| 675 | |
| 676 LogStartupMetrics(); | |
| 675 } | 677 } |
| 676 | 678 |
| 677 //----------------------------------------------------------------------------- | 679 //----------------------------------------------------------------------------- |
| 678 // This section intermingles prefetch results with actual browser HTTP | 680 // This section intermingles prefetch results with actual browser HTTP |
| 679 // network activity. It supports calculating of the benefit of a prefetch, as | 681 // network activity. It supports calculating of the benefit of a prefetch, as |
| 680 // well as recording what prefetched hostname resolutions might be potentially | 682 // well as recording what prefetched hostname resolutions might be potentially |
| 681 // helpful during the next chrome-startup. | 683 // helpful during the next chrome-startup. |
| 682 //----------------------------------------------------------------------------- | 684 //----------------------------------------------------------------------------- |
| 683 | 685 |
| 684 void Predictor::LearnAboutInitialNavigation(const GURL& url) { | 686 void Predictor::LearnAboutInitialNavigation(const GURL& url) { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1165 return url; | 1167 return url; |
| 1166 if (!transport_security_state_->ShouldUpgradeToSSL(url.host())) | 1168 if (!transport_security_state_->ShouldUpgradeToSSL(url.host())) |
| 1167 return url; | 1169 return url; |
| 1168 | 1170 |
| 1169 url::Replacements<char> replacements; | 1171 url::Replacements<char> replacements; |
| 1170 const char kNewScheme[] = "https"; | 1172 const char kNewScheme[] = "https"; |
| 1171 replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme))); | 1173 replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme))); |
| 1172 return url.ReplaceComponents(replacements); | 1174 return url.ReplaceComponents(replacements); |
| 1173 } | 1175 } |
| 1174 | 1176 |
| 1177 void Predictor::LogStartupMetrics() { | |
| 1178 size_t total_bytes = 0; | |
| 1179 for (const auto& referrer : referrers_) { | |
| 1180 total_bytes += referrer.first.spec().size(); | |
|
mmenke
2016/06/20 17:01:24
Could optionally add in in sizeof(ReferrerValue) h
Charlie Harrison
2016/06/20 17:26:37
Isn't that what sizeof(subresource.second) is doin
mmenke
2016/06/20 17:33:52
Sorry, I meant sizeof(Referrer). I find the objec
Charlie Harrison
2016/06/20 17:35:13
Agreed. Hoping to clean this up once we stop using
| |
| 1181 for (const auto& subresource: referrer.second) { | |
|
mmenke
2016/06/20 17:01:24
nit: Space before colon
Charlie Harrison
2016/06/20 17:26:37
Done.
| |
| 1182 total_bytes += subresource.first.spec().size(); | |
| 1183 total_bytes += sizeof(subresource.second); | |
| 1184 } | |
| 1185 } | |
| 1186 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.Predictor.Startup.DBSize", total_bytes, 1, | |
| 1187 1000000000, 50); | |
|
mmenke
2016/06/20 17:01:24
Suggest reducing this to 10 MB to get a finer brea
Charlie Harrison
2016/06/20 17:26:37
Done.
| |
| 1188 } | |
| 1189 | |
| 1190 | |
| 1175 // ---------------------- End IO methods. ------------------------------------- | 1191 // ---------------------- End IO methods. ------------------------------------- |
| 1176 | 1192 |
| 1177 //----------------------------------------------------------------------------- | 1193 //----------------------------------------------------------------------------- |
| 1178 | 1194 |
| 1179 bool Predictor::PreconnectEnabled() const { | 1195 bool Predictor::PreconnectEnabled() const { |
| 1180 base::AutoLock lock(preconnect_enabled_lock_); | 1196 base::AutoLock lock(preconnect_enabled_lock_); |
| 1181 return preconnect_enabled_; | 1197 return preconnect_enabled_; |
| 1182 } | 1198 } |
| 1183 | 1199 |
| 1184 void Predictor::SetPreconnectEnabledForTest(bool preconnect_enabled) { | 1200 void Predictor::SetPreconnectEnabledForTest(bool preconnect_enabled) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 } | 1332 } |
| 1317 | 1333 |
| 1318 void SimplePredictor::ShutdownOnUIThread() { | 1334 void SimplePredictor::ShutdownOnUIThread() { |
| 1319 SetShutdown(true); | 1335 SetShutdown(true); |
| 1320 } | 1336 } |
| 1321 | 1337 |
| 1322 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1338 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
| 1323 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1339 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
| 1324 | 1340 |
| 1325 } // namespace chrome_browser_net | 1341 } // namespace chrome_browser_net |
| OLD | NEW |