Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
| 34 #include "content/public/browser/resource_request_info.h" | 34 #include "content/public/browser/resource_request_info.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
| 37 #include "net/base/network_change_notifier.h" | |
| 37 #include "net/http/http_response_headers.h" | 38 #include "net/http/http_response_headers.h" |
| 38 #include "net/url_request/url_request.h" | 39 #include "net/url_request/url_request.h" |
| 39 #include "net/url_request/url_request_context_getter.h" | 40 #include "net/url_request/url_request_context_getter.h" |
| 40 | 41 |
| 41 using content::BrowserThread; | 42 using content::BrowserThread; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 // For reporting whether a subresource is handled or not, and for what reasons. | 46 // For reporting whether a subresource is handled or not, and for what reasons. |
| 46 enum ResourceStatus { | 47 enum ResourceStatus { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1, | 84 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1, |
| 84 REPORTING_EVENT_COUNT = 2 | 85 REPORTING_EVENT_COUNT = 2 |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 void RecordNavigationEvent(NavigationEvent event) { | 88 void RecordNavigationEvent(NavigationEvent event) { |
| 88 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationEvent", | 89 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationEvent", |
| 89 event, | 90 event, |
| 90 NAVIGATION_EVENT_COUNT); | 91 NAVIGATION_EVENT_COUNT); |
| 91 } | 92 } |
| 92 | 93 |
| 94 enum PagePrefetchedNetworkType { | |
| 95 PAGE_PREFETCHED_NETWORK_TYPE_ALL = 0, | |
| 96 PAGE_PREFETCHED_NETWORK_TYPE_NETWORK_UNKNOWN = 1, | |
| 97 PAGE_PREFETCHED_NETWORK_TYPE_ETHERNET = 2, | |
| 98 PAGE_PREFETCHED_NETWORK_TYPE_WIFI = 3, | |
| 99 PAGE_PREFETCHED_NETWORK_TYPE_2G = 4, | |
| 100 PAGE_PREFETCHED_NETWORK_TYPE_3G = 5, | |
| 101 PAGE_PREFETCHED_NETWORK_TYPE_4G = 6, | |
| 102 PAGE_PREFETCHED_NETWORK_TYPE_NETWORK_NONE = 7, | |
| 103 PAGE_PREFETCHED_NETWORK_TYPE_BLUETOOTH = 8, | |
| 104 PAGE_PREFETCHED_NETWORK_TYPE_CELLULAR = 9, | |
| 105 PAGE_PREFETCHED_NETWORK_TYPE_COUNT = 10 | |
| 106 }; | |
| 107 | |
| 108 enum PageNotPrefetchedNetworkType { | |
|
tburkard
2014/10/08 07:58:29
can't these be combined into a single enum, or, be
Zhen Wang
2014/10/14 04:12:12
Reusing enum types from net now.
| |
| 109 PAGE_NOT_PREFETCHED_NETWORK_TYPE_ALL = 0, | |
| 110 PAGE_NOT_PREFETCHED_NETWORK_TYPE_NETWORK_UNKNOWN = 1, | |
| 111 PAGE_NOT_PREFETCHED_NETWORK_TYPE_ETHERNET = 2, | |
| 112 PAGE_NOT_PREFETCHED_NETWORK_TYPE_WIFI = 3, | |
| 113 PAGE_NOT_PREFETCHED_NETWORK_TYPE_2G = 4, | |
| 114 PAGE_NOT_PREFETCHED_NETWORK_TYPE_3G = 5, | |
| 115 PAGE_NOT_PREFETCHED_NETWORK_TYPE_4G = 6, | |
| 116 PAGE_NOT_PREFETCHED_NETWORK_TYPE_NETWORK_NONE = 7, | |
| 117 PAGE_NOT_PREFETCHED_NETWORK_TYPE_BLUETOOTH = 8, | |
| 118 PAGE_NOT_PREFETCHED_NETWORK_TYPE_CELLULAR = 9, | |
| 119 PAGE_NOT_PREFETCHED_NETWORK_TYPE_COUNT = 10 | |
| 120 }; | |
| 121 | |
| 122 std::string GetNetworkTypeString() { | |
| 123 switch (net::NetworkChangeNotifier::GetConnectionType()) { | |
| 124 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | |
| 125 return "Ethernet"; | |
| 126 case net::NetworkChangeNotifier::CONNECTION_WIFI: | |
| 127 return "WiFi"; | |
| 128 case net::NetworkChangeNotifier::CONNECTION_2G: | |
| 129 return "2G"; | |
| 130 case net::NetworkChangeNotifier::CONNECTION_3G: | |
| 131 return "3G"; | |
| 132 case net::NetworkChangeNotifier::CONNECTION_4G: | |
| 133 return "4G"; | |
| 134 case net::NetworkChangeNotifier::CONNECTION_NONE: | |
| 135 return "NetworkNone"; | |
| 136 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: | |
| 137 return "Bluetooth"; | |
| 138 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | |
| 139 default: | |
| 140 break; | |
| 141 } | |
| 142 return "NetworkUnknown"; | |
| 143 } | |
| 144 | |
| 145 PagePrefetchedNetworkType GetPagePrefetchedNetworkType() { | |
| 146 switch (net::NetworkChangeNotifier::GetConnectionType()) { | |
| 147 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | |
| 148 return PAGE_PREFETCHED_NETWORK_TYPE_ETHERNET; | |
| 149 case net::NetworkChangeNotifier::CONNECTION_WIFI: | |
| 150 return PAGE_PREFETCHED_NETWORK_TYPE_WIFI; | |
| 151 case net::NetworkChangeNotifier::CONNECTION_2G: | |
| 152 return PAGE_PREFETCHED_NETWORK_TYPE_2G; | |
| 153 case net::NetworkChangeNotifier::CONNECTION_3G: | |
| 154 return PAGE_PREFETCHED_NETWORK_TYPE_3G; | |
| 155 case net::NetworkChangeNotifier::CONNECTION_4G: | |
| 156 return PAGE_PREFETCHED_NETWORK_TYPE_4G; | |
| 157 case net::NetworkChangeNotifier::CONNECTION_NONE: | |
| 158 return PAGE_PREFETCHED_NETWORK_TYPE_NETWORK_NONE; | |
| 159 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: | |
| 160 return PAGE_PREFETCHED_NETWORK_TYPE_BLUETOOTH; | |
| 161 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | |
| 162 default: | |
| 163 break; | |
| 164 } | |
| 165 return PAGE_PREFETCHED_NETWORK_TYPE_NETWORK_UNKNOWN; | |
| 166 } | |
| 167 | |
| 168 PageNotPrefetchedNetworkType GetPageNotPrefetchedNetworkType() { | |
| 169 switch (net::NetworkChangeNotifier::GetConnectionType()) { | |
| 170 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | |
| 171 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_ETHERNET; | |
| 172 case net::NetworkChangeNotifier::CONNECTION_WIFI: | |
| 173 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_WIFI; | |
| 174 case net::NetworkChangeNotifier::CONNECTION_2G: | |
| 175 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_2G; | |
| 176 case net::NetworkChangeNotifier::CONNECTION_3G: | |
| 177 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_3G; | |
| 178 case net::NetworkChangeNotifier::CONNECTION_4G: | |
| 179 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_4G; | |
| 180 case net::NetworkChangeNotifier::CONNECTION_NONE: | |
| 181 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_NETWORK_NONE; | |
| 182 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: | |
| 183 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_BLUETOOTH; | |
| 184 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | |
| 185 default: | |
| 186 break; | |
| 187 } | |
| 188 return PAGE_NOT_PREFETCHED_NETWORK_TYPE_NETWORK_UNKNOWN; | |
| 189 } | |
| 190 | |
| 93 } // namespace | 191 } // namespace |
| 94 | 192 |
| 95 namespace predictors { | 193 namespace predictors { |
| 96 | 194 |
| 97 //////////////////////////////////////////////////////////////////////////////// | 195 //////////////////////////////////////////////////////////////////////////////// |
| 98 // History lookup task. | 196 // History lookup task. |
| 99 | 197 |
| 100 // Used to fetch the visit count for a URL from the History database. | 198 // Used to fetch the visit count for a URL from the History database. |
| 101 class GetUrlVisitCountTask : public history::HistoryDBTask { | 199 class GetUrlVisitCountTask : public history::HistoryDBTask { |
| 102 public: | 200 public: |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 | 616 |
| 519 NavigationMap::iterator nav_it = | 617 NavigationMap::iterator nav_it = |
| 520 inflight_navigations_.find(navigation_id); | 618 inflight_navigations_.find(navigation_id); |
| 521 if (nav_it == inflight_navigations_.end()) { | 619 if (nav_it == inflight_navigations_.end()) { |
| 522 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_UNTRACKED_URL); | 620 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_UNTRACKED_URL); |
| 523 return; | 621 return; |
| 524 } | 622 } |
| 525 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_TRACKED_URL); | 623 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_TRACKED_URL); |
| 526 | 624 |
| 527 // Report any stats. | 625 // Report any stats. |
| 626 base::TimeDelta plt = base::TimeTicks::Now() - navigation_id.creation_time; | |
| 627 ReportPageLoadTimeStats(plt); | |
| 528 if (prefetch_manager_.get()) { | 628 if (prefetch_manager_.get()) { |
| 529 ResultsMap::iterator results_it = results_map_.find(navigation_id); | 629 ResultsMap::iterator results_it = results_map_.find(navigation_id); |
| 530 bool have_prefetch_results = results_it != results_map_.end(); | 630 bool have_prefetch_results = results_it != results_map_.end(); |
| 531 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePrefetchResults", | 631 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePrefetchResults", |
| 532 have_prefetch_results); | 632 have_prefetch_results); |
| 533 if (have_prefetch_results) { | 633 if (have_prefetch_results) { |
| 534 ReportAccuracyStats(results_it->second->key_type, | 634 ReportAccuracyStats(results_it->second->key_type, |
| 535 *(nav_it->second), | 635 *(nav_it->second), |
| 536 results_it->second->requests.get()); | 636 results_it->second->requests.get()); |
| 637 ReportPageLoadTimePrefetchedStats(results_it->second->key_type, plt); | |
| 638 } else { | |
| 639 ReportPageLoadTimeNotPrefetchedStats(plt); | |
| 537 } | 640 } |
| 538 } else { | 641 } else { |
| 539 scoped_ptr<ResourcePrefetcher::RequestVector> requests( | 642 scoped_ptr<ResourcePrefetcher::RequestVector> requests( |
| 540 new ResourcePrefetcher::RequestVector); | 643 new ResourcePrefetcher::RequestVector); |
| 541 PrefetchKeyType key_type; | 644 PrefetchKeyType key_type; |
| 542 if (GetPrefetchData(navigation_id, requests.get(), &key_type)) { | 645 if (GetPrefetchData(navigation_id, requests.get(), &key_type)) { |
| 543 RecordNavigationEvent(NAVIGATION_EVENT_HAVE_PREDICTIONS_FOR_URL); | 646 RecordNavigationEvent(NAVIGATION_EVENT_HAVE_PREDICTIONS_FOR_URL); |
| 544 ReportPredictedAccuracyStats(key_type, | 647 ReportPredictedAccuracyStats(key_type, |
| 545 *(nav_it->second), | 648 *(nav_it->second), |
| 546 *requests); | 649 *requests); |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 BrowserThread::PostTask( | 1097 BrowserThread::PostTask( |
| 995 BrowserThread::DB, FROM_HERE, | 1098 BrowserThread::DB, FROM_HERE, |
| 996 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, | 1099 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, |
| 997 tables_, | 1100 tables_, |
| 998 url_data, | 1101 url_data, |
| 999 host_data)); | 1102 host_data)); |
| 1000 } | 1103 } |
| 1001 } | 1104 } |
| 1002 | 1105 |
| 1003 //////////////////////////////////////////////////////////////////////////////// | 1106 //////////////////////////////////////////////////////////////////////////////// |
| 1004 // Accuracy measurement. | 1107 // Page load time and accuracy measurement. |
| 1108 | |
| 1109 #define REPORT_PLT(name, page_load_time) \ | |
| 1110 UMA_HISTOGRAM_CUSTOM_TIMES( \ | |
| 1111 name, \ | |
| 1112 page_load_time, \ | |
| 1113 base::TimeDelta::FromMilliseconds(10), \ | |
| 1114 base::TimeDelta::FromSeconds(60), \ | |
| 1115 100) | |
| 1116 | |
| 1117 | |
| 1118 void ResourcePrefetchPredictor::ReportPageLoadTimeStats( | |
| 1119 base::TimeDelta plt) const { | |
| 1120 bool on_cellular = | |
| 1121 net::NetworkChangeNotifier::IsConnectionCellular( | |
| 1122 net::NetworkChangeNotifier::GetConnectionType()); | |
| 1123 | |
| 1124 REPORT_PLT("ResourcePrefetchPredictor.PLT", plt); | |
| 1125 REPORT_PLT("ResourcePrefetchPredictor.PLT." + GetNetworkTypeString(), plt); | |
| 1126 if (on_cellular) | |
| 1127 REPORT_PLT("ResourcePrefetchPredictor.PLT.Cellular", plt); | |
| 1128 } | |
| 1129 | |
| 1130 void ResourcePrefetchPredictor::ReportPageLoadTimePrefetchedStats( | |
| 1131 PrefetchKeyType key_type, | |
| 1132 base::TimeDelta plt) const { | |
| 1133 bool on_cellular = | |
| 1134 net::NetworkChangeNotifier::IsConnectionCellular( | |
| 1135 net::NetworkChangeNotifier::GetConnectionType()); | |
| 1136 | |
| 1137 UMA_HISTOGRAM_ENUMERATION( | |
| 1138 "ResourcePrefetchPredictor.PagePrefetchedNetworkType", | |
| 1139 PAGE_PREFETCHED_NETWORK_TYPE_ALL, | |
| 1140 PAGE_PREFETCHED_NETWORK_TYPE_COUNT); | |
| 1141 UMA_HISTOGRAM_ENUMERATION( | |
| 1142 "ResourcePrefetchPredictor.PagePrefetchedNetworkType", | |
| 1143 GetPagePrefetchedNetworkType(), | |
| 1144 PAGE_PREFETCHED_NETWORK_TYPE_COUNT); | |
| 1145 if (on_cellular) { | |
| 1146 UMA_HISTOGRAM_ENUMERATION( | |
| 1147 "ResourcePrefetchPredictor.PagePrefetchedNetworkType", | |
| 1148 PAGE_PREFETCHED_NETWORK_TYPE_CELLULAR, | |
| 1149 PAGE_PREFETCHED_NETWORK_TYPE_COUNT); | |
| 1150 } | |
| 1151 | |
| 1152 REPORT_PLT("ResourcePrefetchPredictor.PLT.PagePrefetched", plt); | |
| 1153 REPORT_PLT("ResourcePrefetchPredictor.PLT.PagePrefetched." | |
| 1154 + GetNetworkTypeString(), plt); | |
| 1155 if (on_cellular) | |
| 1156 REPORT_PLT("ResourcePrefetchPredictor.PLT.PagePrefetched.Cellular", plt); | |
| 1157 | |
| 1158 std::string histogram_type = key_type == PREFETCH_KEY_TYPE_HOST ? "Host" : | |
| 1159 "Url"; | |
| 1160 REPORT_PLT("ResourcePrefetchPredictor.PLT.PagePrefetched." + histogram_type, | |
|
tburkard
2014/10/08 07:58:29
see comment below, this shouldn't work.
Zhen Wang
2014/10/14 04:12:12
Done.
| |
| 1161 plt); | |
| 1162 REPORT_PLT("ResourcePrefetchPredictor.PLT.PagePrefetched." + histogram_type | |
|
tburkard
2014/10/08 07:58:29
ditto
Zhen Wang
2014/10/14 04:12:12
Done.
| |
| 1163 + "." + GetNetworkTypeString(), plt); | |
| 1164 if (on_cellular) { | |
| 1165 REPORT_PLT("ResourcePrefetchPredictor.PLT.PagePrefetched." + histogram_type | |
| 1166 + ".Cellular", plt); | |
| 1167 } | |
| 1168 } | |
| 1169 | |
| 1170 void ResourcePrefetchPredictor::ReportPageLoadTimeNotPrefetchedStats( | |
| 1171 base::TimeDelta plt) const { | |
| 1172 bool on_cellular = | |
| 1173 net::NetworkChangeNotifier::IsConnectionCellular( | |
| 1174 net::NetworkChangeNotifier::GetConnectionType()); | |
| 1175 | |
| 1176 UMA_HISTOGRAM_ENUMERATION( | |
| 1177 "ResourcePrefetchPredictor.PageNotPrefetchedNetworkType", | |
| 1178 PAGE_NOT_PREFETCHED_NETWORK_TYPE_ALL, | |
| 1179 PAGE_NOT_PREFETCHED_NETWORK_TYPE_COUNT); | |
| 1180 UMA_HISTOGRAM_ENUMERATION( | |
| 1181 "ResourcePrefetchPredictor.PageNotPrefetchedNetworkType", | |
| 1182 GetPageNotPrefetchedNetworkType(), | |
| 1183 PAGE_PREFETCHED_NETWORK_TYPE_COUNT); | |
| 1184 if (on_cellular) { | |
| 1185 UMA_HISTOGRAM_ENUMERATION( | |
| 1186 "ResourcePrefetchPredictor.PagePrefetchedNetworkType", | |
| 1187 PAGE_PREFETCHED_NETWORK_TYPE_CELLULAR, | |
| 1188 PAGE_PREFETCHED_NETWORK_TYPE_COUNT); | |
| 1189 } | |
| 1190 | |
| 1191 REPORT_PLT("ResourcePrefetchPredictor.PLT.PageNotPrefetched", plt); | |
| 1192 REPORT_PLT("ResourcePrefetchPredictor.PLT.PageNotPrefetched." | |
| 1193 + GetNetworkTypeString(), plt); | |
|
tburkard
2014/10/08 07:58:29
This should not work, if the user switches network
Zhen Wang
2014/10/14 04:12:12
I see. I duplicate the UMA calls now.
| |
| 1194 if (on_cellular) | |
| 1195 REPORT_PLT("ResourcePrefetchPredictor.PLT.PageNotPrefetched.Cellular", plt); | |
| 1196 } | |
| 1005 | 1197 |
| 1006 void ResourcePrefetchPredictor::ReportAccuracyStats( | 1198 void ResourcePrefetchPredictor::ReportAccuracyStats( |
| 1007 PrefetchKeyType key_type, | 1199 PrefetchKeyType key_type, |
| 1008 const std::vector<URLRequestSummary>& actual, | 1200 const std::vector<URLRequestSummary>& actual, |
| 1009 ResourcePrefetcher::RequestVector* prefetched) const { | 1201 ResourcePrefetcher::RequestVector* prefetched) const { |
| 1010 // Annotate the results. | 1202 // Annotate the results. |
| 1011 std::map<GURL, bool> actual_resources; | 1203 std::map<GURL, bool> actual_resources; |
| 1012 for (std::vector<URLRequestSummary>::const_iterator it = actual.begin(); | 1204 for (std::vector<URLRequestSummary>::const_iterator it = actual.begin(); |
| 1013 it != actual.end(); ++it) { | 1205 it != actual.end(); ++it) { |
| 1014 actual_resources[it->resource_url] = it->was_cached; | 1206 actual_resources[it->resource_url] = it->was_cached; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( | 1405 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( |
| 1214 "PrefetchFromNetworkPercentOfTotalFromNetwork", | 1406 "PrefetchFromNetworkPercentOfTotalFromNetwork", |
| 1215 prefetch_network * 100.0 / total_resources_fetched_from_network); | 1407 prefetch_network * 100.0 / total_resources_fetched_from_network); |
| 1216 } | 1408 } |
| 1217 | 1409 |
| 1218 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE | 1410 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE |
| 1219 #undef RPP_PREDICTED_HISTOGRAM_COUNTS | 1411 #undef RPP_PREDICTED_HISTOGRAM_COUNTS |
| 1220 } | 1412 } |
| 1221 | 1413 |
| 1222 } // namespace predictors | 1414 } // namespace predictors |
| OLD | NEW |