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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 2625063002: predictors: Add ResourcePrefetchPredictor database readiness histogram. (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
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
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
16 #include "base/rand_util.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "base/trace_event/trace_event.h" 19 #include "base/trace_event/trace_event.h"
19 #include "chrome/browser/history/history_service_factory.h" 20 #include "chrome/browser/history/history_service_factory.h"
20 #include "chrome/browser/predictors/predictor_database.h" 21 #include "chrome/browser/predictors/predictor_database.h"
21 #include "chrome/browser/predictors/predictor_database_factory.h" 22 #include "chrome/browser/predictors/predictor_database_factory.h"
22 #include "chrome/browser/predictors/resource_prefetcher_manager.h" 23 #include "chrome/browser/predictors/resource_prefetcher_manager.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
(...skipping 23 matching lines...) Expand all
49 "application/font-woff2", 50 "application/font-woff2",
50 "font/x-woff", 51 "font/x-woff",
51 "application/x-font-ttf", 52 "application/x-font-ttf",
52 "font/woff", 53 "font/woff",
53 "font/ttf", 54 "font/ttf",
54 "application/x-font-otf", 55 "application/x-font-otf",
55 "x-font/woff", 56 "x-font/woff",
56 "application/font-sfnt", 57 "application/font-sfnt",
57 "application/font-ttf"}; 58 "application/font-ttf"};
58 59
60 const size_t kNumSampleHosts = 50;
61
59 // For reporting events of interest that are not tied to any navigation. 62 // For reporting events of interest that are not tied to any navigation.
60 enum ReportingEvent { 63 enum ReportingEvent {
61 REPORTING_EVENT_ALL_HISTORY_CLEARED = 0, 64 REPORTING_EVENT_ALL_HISTORY_CLEARED = 0,
62 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1, 65 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1,
63 REPORTING_EVENT_COUNT = 2 66 REPORTING_EVENT_COUNT = 2
64 }; 67 };
65 68
66 float ComputeRedirectConfidence(const predictors::RedirectStat& redirect) { 69 float ComputeRedirectConfidence(const predictors::RedirectStat& redirect) {
67 return (redirect.number_of_hits() + 0.0) / 70 return (redirect.number_of_hits() + 0.0) /
68 (redirect.number_of_hits() + redirect.number_of_misses()); 71 (redirect.number_of_hits() + redirect.number_of_misses());
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 history::HistoryService* history_service = 605 history::HistoryService* history_service =
603 HistoryServiceFactory::GetForProfile(profile_, 606 HistoryServiceFactory::GetForProfile(profile_,
604 ServiceAccessType::EXPLICIT_ACCESS); 607 ServiceAccessType::EXPLICIT_ACCESS);
605 DCHECK(history_service); 608 DCHECK(history_service);
606 history_service->ScheduleDBTask( 609 history_service->ScheduleDBTask(
607 std::unique_ptr<history::HistoryDBTask>(new GetUrlVisitCountTask( 610 std::unique_ptr<history::HistoryDBTask>(new GetUrlVisitCountTask(
608 std::move(summary), 611 std::move(summary),
609 base::Bind(&ResourcePrefetchPredictor::OnVisitCountLookup, 612 base::Bind(&ResourcePrefetchPredictor::OnVisitCountLookup,
610 AsWeakPtr()))), 613 AsWeakPtr()))),
611 &history_lookup_consumer_); 614 &history_lookup_consumer_);
615
616 // Report readiness metric with 20% probability.
617 if (base::RandInt(1, 5) == 5) {
618 history_service->TopHosts(
619 kNumSampleHosts,
620 base::Bind(&ResourcePrefetchPredictor::ReportDatabaseReadiness,
621 AsWeakPtr()));
622 }
612 } 623 }
613 624
614 bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url, 625 bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url,
615 std::vector<GURL>* urls) { 626 std::vector<GURL>* urls) {
616 DCHECK(urls); 627 DCHECK(urls);
617 DCHECK(urls->empty()); 628 DCHECK(urls->empty());
618 629
619 // Fetch URLs based on a redirect endpoint for URL/host first. 630 // Fetch URLs based on a redirect endpoint for URL/host first.
620 std::string redirect_endpoint; 631 std::string redirect_endpoint;
621 if (GetRedirectEndpoint(main_frame_url.spec(), *url_redirect_table_cache_, 632 if (GetRedirectEndpoint(main_frame_url.spec(), *url_redirect_table_cache_,
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 const RedirectData& url_redirect_data = 1109 const RedirectData& url_redirect_data =
1099 is_host ? empty_redirect_data : data; 1110 is_host ? empty_redirect_data : data;
1100 BrowserThread::PostTask( 1111 BrowserThread::PostTask(
1101 BrowserThread::DB, FROM_HERE, 1112 BrowserThread::DB, FROM_HERE,
1102 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, tables_, 1113 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, tables_,
1103 empty_data, empty_data, url_redirect_data, 1114 empty_data, empty_data, url_redirect_data,
1104 host_redirect_data)); 1115 host_redirect_data));
1105 } 1116 }
1106 } 1117 }
1107 1118
1119 void ResourcePrefetchPredictor::ReportDatabaseReadiness(
1120 const history::TopHostsList& top_hosts) {
1121 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1122 if (top_hosts.size() == 0)
1123 return;
1124
1125 int count_in_cache = 0;
1126 for (const std::pair<std::string, int>& top_host : top_hosts) {
1127 const std::string& host = top_host.first;
1128 if (host_table_cache_->find(host) != host_table_cache_->end()) {
1129 ++count_in_cache;
1130 } else {
1131 // Hostnames in TopHostsLists are stripped of their 'www.' prefix. We
1132 // assume that www.foo.com entry from |host_table_cache_| is also suitable
1133 // for foo.com.
1134 if (!base::StartsWith(host, "www.", base::CompareCase::SENSITIVE) &&
1135 host_table_cache_->find("www." + host) != host_table_cache_->end()) {
1136 ++count_in_cache;
1137 }
1138 }
1139 }
1140 UMA_HISTOGRAM_PERCENTAGE("ResourcePrefetchPredictor.DatabaseReadiness",
1141 100 * count_in_cache / top_hosts.size());
1142 }
1143
1108 void ResourcePrefetchPredictor::OnURLsDeleted( 1144 void ResourcePrefetchPredictor::OnURLsDeleted(
1109 history::HistoryService* history_service, 1145 history::HistoryService* history_service,
1110 bool all_history, 1146 bool all_history,
1111 bool expired, 1147 bool expired,
1112 const history::URLRows& deleted_rows, 1148 const history::URLRows& deleted_rows,
1113 const std::set<GURL>& favicon_urls) { 1149 const std::set<GURL>& favicon_urls) {
1114 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1150 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1115 DCHECK(initialization_state_ == INITIALIZED); 1151 DCHECK(initialization_state_ == INITIALIZED);
1116 1152
1117 if (all_history) { 1153 if (all_history) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 TestObserver::~TestObserver() { 1191 TestObserver::~TestObserver() {
1156 predictor_->SetObserverForTesting(nullptr); 1192 predictor_->SetObserverForTesting(nullptr);
1157 } 1193 }
1158 1194
1159 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) 1195 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor)
1160 : predictor_(predictor) { 1196 : predictor_(predictor) {
1161 predictor_->SetObserverForTesting(this); 1197 predictor_->SetObserverForTesting(this);
1162 } 1198 }
1163 1199
1164 } // namespace predictors 1200 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698