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

Side by Side Diff: chrome/browser/prerender/prerender_local_predictor.cc

Issue 330063004: Various Prerender Service / Prerender LocalPredictor related changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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/prerender/prerender_local_predictor.h" 5 #include "chrome/browser/prerender/prerender_local_predictor.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/history/history_service_factory.h" 25 #include "chrome/browser/history/history_service_factory.h"
26 #include "chrome/browser/prerender/prerender_field_trial.h" 26 #include "chrome/browser/prerender/prerender_field_trial.h"
27 #include "chrome/browser/prerender/prerender_handle.h" 27 #include "chrome/browser/prerender/prerender_handle.h"
28 #include "chrome/browser/prerender/prerender_histograms.h" 28 #include "chrome/browser/prerender/prerender_histograms.h"
29 #include "chrome/browser/prerender/prerender_manager.h" 29 #include "chrome/browser/prerender/prerender_manager.h"
30 #include "chrome/browser/prerender/prerender_util.h" 30 #include "chrome/browser/prerender/prerender_util.h"
31 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/safe_browsing/database_manager.h" 32 #include "chrome/browser/safe_browsing/database_manager.h"
33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
34 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 34 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
35 #include "chrome/common/prefetch_messages.h"
35 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/navigation_controller.h" 37 #include "content/public/browser/navigation_controller.h"
37 #include "content/public/browser/navigation_entry.h" 38 #include "content/public/browser/navigation_entry.h"
39 #include "content/public/browser/render_frame_host.h"
40 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
39 #include "content/public/common/page_transition_types.h" 42 #include "content/public/common/page_transition_types.h"
40 #include "crypto/secure_hash.h" 43 #include "crypto/secure_hash.h"
41 #include "grit/browser_resources.h" 44 #include "grit/browser_resources.h"
42 #include "net/base/escape.h" 45 #include "net/base/escape.h"
43 #include "net/base/load_flags.h" 46 #include "net/base/load_flags.h"
44 #include "net/url_request/url_fetcher.h" 47 #include "net/url_request/url_fetcher.h"
45 #include "ui/base/resource/resource_bundle.h" 48 #include "ui/base/resource/resource_bundle.h"
46 #include "url/url_canon.h" 49 #include "url/url_canon.h"
47 50
48 using base::DictionaryValue; 51 using base::DictionaryValue;
49 using base::ListValue; 52 using base::ListValue;
50 using base::Value; 53 using base::Value;
51 using content::BrowserThread; 54 using content::BrowserThread;
52 using content::PageTransition; 55 using content::PageTransition;
56 using content::RenderFrameHost;
53 using content::SessionStorageNamespace; 57 using content::SessionStorageNamespace;
54 using content::WebContents; 58 using content::WebContents;
55 using history::URLID; 59 using history::URLID;
56 using net::URLFetcher; 60 using net::URLFetcher;
57 using predictors::LoggedInPredictorTable; 61 using predictors::LoggedInPredictorTable;
58 using std::string; 62 using std::string;
59 using std::vector; 63 using std::vector;
60 64
61 namespace prerender { 65 namespace prerender {
62 66
63 namespace { 67 namespace {
64 68
65 static const size_t kURLHashSize = 5; 69 static const size_t kURLHashSize = 5;
66 static const int kNumPrerenderCandidates = 5; 70 static const int kNumPrerenderCandidates = 5;
71 static const int kInvalidProcessId = -1;
72 static const int kInvalidFrameId = -1;
67 73
68 } // namespace 74 } // namespace
69 75
70 // When considering a candidate URL to be prerendered, we need to collect the 76 // When considering a candidate URL to be prerendered, we need to collect the
71 // data in this struct to make the determination whether we should issue the 77 // data in this struct to make the determination whether we should issue the
72 // prerender or not. 78 // prerender or not.
73 struct PrerenderLocalPredictor::LocalPredictorURLInfo { 79 struct PrerenderLocalPredictor::LocalPredictorURLInfo {
74 URLID id; 80 URLID id;
75 GURL url; 81 GURL url;
76 bool url_lookup_success; 82 bool url_lookup_success;
77 bool logged_in; 83 bool logged_in;
78 bool logged_in_lookup_ok; 84 bool logged_in_lookup_ok;
79 bool local_history_based; 85 bool local_history_based;
80 bool service_whitelist; 86 bool service_whitelist;
81 bool service_whitelist_lookup_ok; 87 bool service_whitelist_lookup_ok;
82 bool service_whitelist_reported; 88 bool service_whitelist_reported;
83 double priority; 89 double priority;
84 }; 90 };
85 91
86 // A struct consisting of everything needed for launching a potential prerender 92 // A struct consisting of everything needed for launching a potential prerender
87 // on a navigation: The navigation URL (source) triggering potential prerenders, 93 // on a navigation: The navigation URL (source) triggering potential prerenders,
88 // and a set of candidate URLs. 94 // and a set of candidate URLs.
89 struct PrerenderLocalPredictor::CandidatePrerenderInfo { 95 struct PrerenderLocalPredictor::CandidatePrerenderInfo {
90 LocalPredictorURLInfo source_url_; 96 LocalPredictorURLInfo source_url_;
91 vector<LocalPredictorURLInfo> candidate_urls_; 97 vector<LocalPredictorURLInfo> candidate_urls_;
92 scoped_refptr<SessionStorageNamespace> session_storage_namespace_; 98 scoped_refptr<SessionStorageNamespace> session_storage_namespace_;
99 int render_process_id_;
100 int render_frame_id_;
davidben 2014/06/19 19:33:34 Nit: add a comment that this is the route of the s
tburkard 2014/06/19 20:01:49 Done.
93 scoped_ptr<gfx::Size> size_; 101 scoped_ptr<gfx::Size> size_;
94 base::Time start_time_; // used for various time measurements 102 base::Time start_time_; // used for various time measurements
95 explicit CandidatePrerenderInfo(URLID source_id) { 103 explicit CandidatePrerenderInfo(URLID source_id) {
96 source_url_.id = source_id; 104 source_url_.id = source_id;
105 render_process_id_ = kInvalidProcessId;
106 render_frame_id_ = kInvalidFrameId;
davidben 2014/06/19 19:33:34 Nit: these can be in an initializer list.
tburkard 2014/06/19 20:01:49 Done.
97 } 107 }
98 void MaybeAddCandidateURLFromLocalData(URLID id, double priority) { 108 void MaybeAddCandidateURLFromLocalData(URLID id, double priority) {
99 LocalPredictorURLInfo info; 109 LocalPredictorURLInfo info;
100 info.id = id; 110 info.id = id;
101 info.local_history_based = true; 111 info.local_history_based = true;
102 info.service_whitelist = false; 112 info.service_whitelist = false;
103 info.service_whitelist_lookup_ok = false; 113 info.service_whitelist_lookup_ok = false;
104 info.service_whitelist_reported = false; 114 info.service_whitelist_reported = false;
105 info.priority = priority; 115 info.priority = priority;
106 MaybeAddCandidateURLInternal(info); 116 MaybeAddCandidateURLInternal(info);
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 if (!source_web_contents) { 601 if (!source_web_contents) {
592 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_SOURCE_WEBCONTENTS_FOUND); 602 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_SOURCE_WEBCONTENTS_FOUND);
593 return; 603 return;
594 } 604 }
595 605
596 if (multiple_source_web_contents_candidates) 606 if (multiple_source_web_contents_candidates)
597 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_MULTIPLE_SOURCE_WEBCONTENTS_FOUND); 607 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_MULTIPLE_SOURCE_WEBCONTENTS_FOUND);
598 608
599 info->session_storage_namespace_ = 609 info->session_storage_namespace_ =
600 source_web_contents->GetController().GetDefaultSessionStorageNamespace(); 610 source_web_contents->GetController().GetDefaultSessionStorageNamespace();
611 RenderFrameHost* rfh = source_web_contents->GetMainFrame();
612 info->render_process_id_ = rfh->GetProcess()->GetID();
613 info->render_frame_id_ = rfh->GetRoutingID();
601 614
602 gfx::Rect container_bounds = source_web_contents->GetContainerBounds(); 615 gfx::Rect container_bounds = source_web_contents->GetContainerBounds();
603 info->size_.reset(new gfx::Size(container_bounds.size())); 616 info->size_.reset(new gfx::Size(container_bounds.size()));
604 617
605 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_SUCCESS); 618 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_SUCCESS);
606 619
607 DoPrerenderServiceCheck(info.Pass()); 620 DoPrerenderServiceCheck(info.Pass());
608 } 621 }
609 622
610 void PrerenderLocalPredictor::DoPrerenderServiceCheck( 623 void PrerenderLocalPredictor::DoPrerenderServiceCheck(
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 if (prerender && prerender->start_time < GetCurrentTime() - plt) { 1059 if (prerender && prerender->start_time < GetCurrentTime() - plt) {
1047 if (prerender->url.is_empty()) 1060 if (prerender->url.is_empty())
1048 RecordEvent(EVENT_ERROR_NO_PRERENDER_URL_FOR_PLT); 1061 RecordEvent(EVENT_ERROR_NO_PRERENDER_URL_FOR_PLT);
1049 return (prerender->url == url); 1062 return (prerender->url == url);
1050 } else { 1063 } else {
1051 return false; 1064 return false;
1052 } 1065 }
1053 } 1066 }
1054 1067
1055 PrerenderLocalPredictor::PrerenderProperties* 1068 PrerenderLocalPredictor::PrerenderProperties*
1056 PrerenderLocalPredictor::GetIssuedPrerenderSlotForPriority(double priority) { 1069 PrerenderLocalPredictor::GetIssuedPrerenderSlotForPriority(const GURL& url,
1070 double priority) {
1057 int num_prerenders = GetLocalPredictorMaxConcurrentPrerenders(); 1071 int num_prerenders = GetLocalPredictorMaxConcurrentPrerenders();
1058 while (static_cast<int>(issued_prerenders_.size()) < num_prerenders) 1072 while (static_cast<int>(issued_prerenders_.size()) < num_prerenders)
1059 issued_prerenders_.push_back(new PrerenderProperties()); 1073 issued_prerenders_.push_back(new PrerenderProperties());
1060 PrerenderProperties* lowest_priority_prerender = NULL; 1074 PrerenderProperties* lowest_priority_prerender = NULL;
1061 for (int i = 0; i < static_cast<int>(issued_prerenders_.size()); i++) { 1075 for (int i = 0; i < static_cast<int>(issued_prerenders_.size()); i++) {
1062 PrerenderProperties* p = issued_prerenders_[i]; 1076 PrerenderProperties* p = issued_prerenders_[i];
1063 DCHECK(p != NULL); 1077 DCHECK(p != NULL);
1064 if (!p->prerender_handle || !p->prerender_handle->IsPrerendering()) 1078 if (!p->prerender_handle || !p->prerender_handle->IsPrerendering())
1065 return p; 1079 return p;
1080 if (p->prerender_handle->Matches(url, NULL))
davidben 2014/06/19 19:33:34 Does this check actually do what you want? If ther
tburkard 2014/06/19 20:01:49 Done.
1081 return NULL;
1066 double decayed_priority = p->GetCurrentDecayedPriority(); 1082 double decayed_priority = p->GetCurrentDecayedPriority();
1067 if (decayed_priority > priority) 1083 if (decayed_priority > priority)
1068 continue; 1084 continue;
1069 if (lowest_priority_prerender == NULL || 1085 if (lowest_priority_prerender == NULL ||
1070 lowest_priority_prerender->GetCurrentDecayedPriority() > 1086 lowest_priority_prerender->GetCurrentDecayedPriority() >
1071 decayed_priority) { 1087 decayed_priority) {
1072 lowest_priority_prerender = p; 1088 lowest_priority_prerender = p;
1073 } 1089 }
1074 } 1090 }
1075 return lowest_priority_prerender; 1091 return lowest_priority_prerender;
1076 } 1092 }
1077 1093
1078 void PrerenderLocalPredictor::ContinuePrerenderCheck( 1094 void PrerenderLocalPredictor::ContinuePrerenderCheck(
1079 scoped_ptr<CandidatePrerenderInfo> info) { 1095 scoped_ptr<CandidatePrerenderInfo> info) {
1080 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1081 TIMING_HISTOGRAM("Prerender.LocalPredictorLoggedInLookupTime", 1097 TIMING_HISTOGRAM("Prerender.LocalPredictorLoggedInLookupTime",
1082 base::Time::Now() - info->start_time_); 1098 base::Time::Now() - info->start_time_);
1083 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_STARTED); 1099 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_STARTED);
1084 if (info->candidate_urls_.size() == 0) { 1100 if (info->candidate_urls_.size() == 0) {
1085 RecordEvent(EVENT_NO_PRERENDER_CANDIDATES); 1101 RecordEvent(EVENT_NO_PRERENDER_CANDIDATES);
1086 return; 1102 return;
1087 } 1103 }
1088 scoped_ptr<LocalPredictorURLInfo> url_info; 1104 scoped_ptr<LocalPredictorURLInfo> url_info;
1089 #if defined(FULL_SAFE_BROWSING) 1105 #if defined(FULL_SAFE_BROWSING)
1090 scoped_refptr<SafeBrowsingDatabaseManager> sb_db_manager = 1106 scoped_refptr<SafeBrowsingDatabaseManager> sb_db_manager =
1091 g_browser_process->safe_browsing_service()->database_manager(); 1107 g_browser_process->safe_browsing_service()->database_manager();
1092 #endif 1108 #endif
1093 PrerenderProperties* prerender_properties = NULL; 1109 PrerenderProperties* prerender_properties = NULL;
1094 1110 int num_issued = 0;
1095 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { 1111 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) {
1112 if (num_issued > GetLocalPredictorMaxLaunchPrerenders())
1113 return;
1096 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL); 1114 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL);
1097 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); 1115 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i]));
1098 if (url_info->local_history_based) { 1116 if (url_info->local_history_based) {
1099 if (SkipLocalPredictorLocalCandidates()) { 1117 if (SkipLocalPredictorLocalCandidates()) {
1100 url_info.reset(NULL); 1118 url_info.reset(NULL);
1101 continue; 1119 continue;
1102 } 1120 }
1103 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL_LOCAL); 1121 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL_LOCAL);
1104 } 1122 }
1105 if (!url_info->local_history_based) { 1123 if (!url_info->local_history_based) {
(...skipping 13 matching lines...) Expand all
1119 // URL), or it can be sufficient to issue the prerender without any 1137 // URL), or it can be sufficient to issue the prerender without any
1120 // further checks (in which case we just break). 1138 // further checks (in which case we just break).
1121 // The order of the checks is critical, because it prescribes the logic 1139 // The order of the checks is critical, because it prescribes the logic
1122 // we use here to decide what to prerender. 1140 // we use here to decide what to prerender.
1123 if (!url_info->url_lookup_success) { 1141 if (!url_info->url_lookup_success) {
1124 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NO_URL); 1142 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NO_URL);
1125 url_info.reset(NULL); 1143 url_info.reset(NULL);
1126 continue; 1144 continue;
1127 } 1145 }
1128 prerender_properties = 1146 prerender_properties =
1129 GetIssuedPrerenderSlotForPriority(url_info->priority); 1147 GetIssuedPrerenderSlotForPriority(url_info->url, url_info->priority);
1130 if (!prerender_properties) { 1148 if (!prerender_properties) {
1131 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_PRIORITY_TOO_LOW); 1149 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_PRIORITY_TOO_LOW);
1132 url_info.reset(NULL); 1150 url_info.reset(NULL);
1133 continue; 1151 continue;
1134 } 1152 }
1135 if (!SkipLocalPredictorFragment() && 1153 if (!SkipLocalPredictorFragment() &&
1136 URLsIdenticalIgnoringFragments(info->source_url_.url, 1154 URLsIdenticalIgnoringFragments(info->source_url_.url,
1137 url_info->url)) { 1155 url_info->url)) {
1138 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_URLS_IDENTICAL_BUT_FRAGMENT); 1156 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_URLS_IDENTICAL_BUT_FRAGMENT);
1139 url_info.reset(NULL); 1157 url_info.reset(NULL);
1140 continue; 1158 continue;
1141 } 1159 }
1142 if (!SkipLocalPredictorHTTPS() && url_info->url.SchemeIs("https")) { 1160 if (!SkipLocalPredictorHTTPS() && url_info->url.SchemeIs("https")) {
1143 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_HTTPS); 1161 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_HTTPS);
1144 url_info.reset(NULL); 1162 url_info.reset(NULL);
1145 continue; 1163 continue;
1146 } 1164 }
1147 if (IsRootPageURL(url_info->url)) { 1165 if (IsRootPageURL(url_info->url)) {
1148 // For root pages, we assume that they are reasonably safe, and we 1166 // For root pages, we assume that they are reasonably safe, and we
1149 // will just prerender them without any additional checks. 1167 // will just prerender them without any additional checks.
1150 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ROOT_PAGE); 1168 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ROOT_PAGE);
1151 break; 1169 IssuePrerender(info.get(), url_info.get(), prerender_properties);
1170 num_issued++;
1171 continue;
1152 } 1172 }
1153 if (IsLogOutURL(url_info->url)) { 1173 if (IsLogOutURL(url_info->url)) {
1154 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); 1174 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL);
1155 url_info.reset(NULL); 1175 url_info.reset(NULL);
1156 continue; 1176 continue;
1157 } 1177 }
1158 if (IsLogInURL(url_info->url)) { 1178 if (IsLogInURL(url_info->url)) {
1159 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); 1179 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL);
1160 url_info.reset(NULL); 1180 url_info.reset(NULL);
1161 continue; 1181 continue;
1162 } 1182 }
1163 #if defined(FULL_SAFE_BROWSING) 1183 #if defined(FULL_SAFE_BROWSING)
1164 if (!SkipLocalPredictorWhitelist() && sb_db_manager && 1184 if (!SkipLocalPredictorWhitelist() && sb_db_manager &&
1165 sb_db_manager->CheckSideEffectFreeWhitelistUrl(url_info->url)) { 1185 sb_db_manager->CheckSideEffectFreeWhitelistUrl(url_info->url)) {
1166 // If a page is on the side-effect free whitelist, we will just prerender 1186 // If a page is on the side-effect free whitelist, we will just prerender
1167 // it without any additional checks. 1187 // it without any additional checks.
1168 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST); 1188 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST);
1169 break; 1189 IssuePrerender(info.get(), url_info.get(), prerender_properties);
1190 num_issued++;
1191 continue;
1170 } 1192 }
1171 #endif 1193 #endif
1172 if (!SkipLocalPredictorServiceWhitelist() && 1194 if (!SkipLocalPredictorServiceWhitelist() &&
1173 url_info->service_whitelist && url_info->service_whitelist_lookup_ok) { 1195 url_info->service_whitelist && url_info->service_whitelist_lookup_ok) {
1174 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SERVICE_WHITELIST); 1196 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SERVICE_WHITELIST);
1175 break; 1197 IssuePrerender(info.get(), url_info.get(), prerender_properties);
1198 num_issued++;
1199 continue;
1176 } 1200 }
1177 if (!SkipLocalPredictorLoggedIn() && 1201 if (!SkipLocalPredictorLoggedIn() &&
1178 !url_info->logged_in && url_info->logged_in_lookup_ok) { 1202 !url_info->logged_in && url_info->logged_in_lookup_ok) {
1179 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); 1203 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN);
1180 break; 1204 IssuePrerender(info.get(), url_info.get(), prerender_properties);
1205 num_issued++;
1206 continue;
1181 } 1207 }
1182 if (!SkipLocalPredictorDefaultNoPrerender()) { 1208 if (!SkipLocalPredictorDefaultNoPrerender()) {
1183 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); 1209 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING);
1184 url_info.reset(NULL); 1210 url_info.reset(NULL);
1185 } else { 1211 } else {
1186 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING); 1212 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING);
1213 IssuePrerender(info.get(), url_info.get(), prerender_properties);
1214 num_issued++;
1215 continue;
1187 } 1216 }
1188 } 1217 }
1189 if (!url_info.get())
1190 return;
1191 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER);
1192 DCHECK(prerender_properties != NULL);
1193 if (IsLocalPredictorPrerenderLaunchEnabled()) {
1194 IssuePrerender(info.Pass(), url_info.Pass(), prerender_properties);
1195 }
1196 } 1218 }
1197 1219
1198 void PrerenderLocalPredictor::IssuePrerender( 1220 void PrerenderLocalPredictor::IssuePrerender(
1199 scoped_ptr<CandidatePrerenderInfo> info, 1221 CandidatePrerenderInfo* info,
1200 scoped_ptr<LocalPredictorURLInfo> url_info, 1222 LocalPredictorURLInfo* url_info,
1201 PrerenderProperties* prerender_properties) { 1223 PrerenderProperties* prerender_properties) {
1202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1225 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER);
1226 DCHECK(prerender_properties != NULL);
1227 DCHECK(info != NULL);
1228 DCHECK(url_info != NULL);
1229 if (!IsLocalPredictorPrerenderLaunchEnabled())
1230 return;
1203 URLID url_id = url_info->id; 1231 URLID url_id = url_info->id;
1204 const GURL& url = url_info->url; 1232 const GURL& url = url_info->url;
1205 double priority = url_info->priority; 1233 double priority = url_info->priority;
1206 base::Time current_time = GetCurrentTime(); 1234 base::Time current_time = GetCurrentTime();
1207 RecordEvent(EVENT_ISSUING_PRERENDER); 1235 RecordEvent(EVENT_ISSUING_PRERENDER);
1208 1236
1209 // Issue the prerender and obtain a new handle. 1237 // Issue the prerender and obtain a new handle.
1210 scoped_ptr<prerender::PrerenderHandle> new_prerender_handle( 1238 scoped_ptr<prerender::PrerenderHandle> new_prerender_handle(
1211 prerender_manager_->AddPrerenderFromLocalPredictor( 1239 prerender_manager_->AddPrerenderFromLocalPredictor(
1212 url, info->session_storage_namespace_.get(), *(info->size_))); 1240 url, info->session_storage_namespace_.get(), *(info->size_)));
(...skipping 23 matching lines...) Expand all
1236 prerender_properties->start_time = current_time; 1264 prerender_properties->start_time = current_time;
1237 prerender_properties->actual_start_time = current_time; 1265 prerender_properties->actual_start_time = current_time;
1238 prerender_properties->would_have_matched = false; 1266 prerender_properties->would_have_matched = false;
1239 prerender_properties->prerender_handle.swap(new_prerender_handle); 1267 prerender_properties->prerender_handle.swap(new_prerender_handle);
1240 // new_prerender_handle now represents the old previou prerender that we 1268 // new_prerender_handle now represents the old previou prerender that we
1241 // are replacing. So we need to cancel it. 1269 // are replacing. So we need to cancel it.
1242 if (new_prerender_handle) { 1270 if (new_prerender_handle) {
1243 new_prerender_handle->OnCancel(); 1271 new_prerender_handle->OnCancel();
1244 RecordEvent(EVENT_ISSUE_PRERENDER_CANCELLED_OLD_PRERENDER); 1272 RecordEvent(EVENT_ISSUE_PRERENDER_CANCELLED_OLD_PRERENDER);
1245 } 1273 }
1274 // If we are prefetching rather than prerendering, now is the time to launch
1275 // the prefetch.
1276 if (IsLocalPredictorPrerenderPrefetchEnabled()) {
1277 // Obtain the render frame host that caused this prefetch.
1278 RenderFrameHost* rfh = RenderFrameHost::FromID(info->render_process_id_,
1279 info->render_frame_id_);
1280 // If it is still alive, launch the prefresh.
1281 if (rfh)
1282 rfh->Send(new PrefetchMsg_Prefetch(rfh->GetRoutingID(), url));
1283 }
1246 } 1284 }
1247 1285
1248 RecordEvent(EVENT_ADD_VISIT_PRERENDERING); 1286 RecordEvent(EVENT_ADD_VISIT_PRERENDERING);
1249 if (current_prerender_.get() && current_prerender_->url_id == url_id) { 1287 if (current_prerender_.get() && current_prerender_->url_id == url_id) {
1250 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED); 1288 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED);
1251 if (priority > current_prerender_->priority) 1289 if (priority > current_prerender_->priority)
1252 current_prerender_->priority = priority; 1290 current_prerender_->priority = priority;
1253 // If the prerender already existed, we want to extend it. However, 1291 // If the prerender already existed, we want to extend it. However,
1254 // we do not want to set its start_time to the current time to 1292 // we do not want to set its start_time to the current time to
1255 // disadvantage PLT computations when the prerender is swapped in. 1293 // disadvantage PLT computations when the prerender is swapped in.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 break; 1400 break;
1363 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: 1401 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE:
1364 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); 1402 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE);
1365 break; 1403 break;
1366 default: 1404 default:
1367 NOTREACHED(); 1405 NOTREACHED();
1368 } 1406 }
1369 } 1407 }
1370 1408
1371 } // namespace prerender 1409 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698