| 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/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 Loading... |
| 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 // Render Process ID and Route ID of the page causing the prerender to be |
| 100 // issued. Needed so that we can cause its renderer to issue prefetches within |
| 101 // its context. |
| 102 int render_process_id_; |
| 103 int render_frame_id_; |
| 93 scoped_ptr<gfx::Size> size_; | 104 scoped_ptr<gfx::Size> size_; |
| 94 base::Time start_time_; // used for various time measurements | 105 base::Time start_time_; // used for various time measurements |
| 95 explicit CandidatePrerenderInfo(URLID source_id) { | 106 explicit CandidatePrerenderInfo(URLID source_id) |
| 107 : render_process_id_(kInvalidProcessId), |
| 108 render_frame_id_(kInvalidFrameId) { |
| 96 source_url_.id = source_id; | 109 source_url_.id = source_id; |
| 97 } | 110 } |
| 98 void MaybeAddCandidateURLFromLocalData(URLID id, double priority) { | 111 void MaybeAddCandidateURLFromLocalData(URLID id, double priority) { |
| 99 LocalPredictorURLInfo info; | 112 LocalPredictorURLInfo info; |
| 100 info.id = id; | 113 info.id = id; |
| 101 info.local_history_based = true; | 114 info.local_history_based = true; |
| 102 info.service_whitelist = false; | 115 info.service_whitelist = false; |
| 103 info.service_whitelist_lookup_ok = false; | 116 info.service_whitelist_lookup_ok = false; |
| 104 info.service_whitelist_reported = false; | 117 info.service_whitelist_reported = false; |
| 105 info.priority = priority; | 118 info.priority = priority; |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 if (!source_web_contents) { | 604 if (!source_web_contents) { |
| 592 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_SOURCE_WEBCONTENTS_FOUND); | 605 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_SOURCE_WEBCONTENTS_FOUND); |
| 593 return; | 606 return; |
| 594 } | 607 } |
| 595 | 608 |
| 596 if (multiple_source_web_contents_candidates) | 609 if (multiple_source_web_contents_candidates) |
| 597 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_MULTIPLE_SOURCE_WEBCONTENTS_FOUND); | 610 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_MULTIPLE_SOURCE_WEBCONTENTS_FOUND); |
| 598 | 611 |
| 599 info->session_storage_namespace_ = | 612 info->session_storage_namespace_ = |
| 600 source_web_contents->GetController().GetDefaultSessionStorageNamespace(); | 613 source_web_contents->GetController().GetDefaultSessionStorageNamespace(); |
| 614 RenderFrameHost* rfh = source_web_contents->GetMainFrame(); |
| 615 info->render_process_id_ = rfh->GetProcess()->GetID(); |
| 616 info->render_frame_id_ = rfh->GetRoutingID(); |
| 601 | 617 |
| 602 gfx::Rect container_bounds = source_web_contents->GetContainerBounds(); | 618 gfx::Rect container_bounds = source_web_contents->GetContainerBounds(); |
| 603 info->size_.reset(new gfx::Size(container_bounds.size())); | 619 info->size_.reset(new gfx::Size(container_bounds.size())); |
| 604 | 620 |
| 605 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_SUCCESS); | 621 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_SUCCESS); |
| 606 | 622 |
| 607 DoPrerenderServiceCheck(info.Pass()); | 623 DoPrerenderServiceCheck(info.Pass()); |
| 608 } | 624 } |
| 609 | 625 |
| 610 void PrerenderLocalPredictor::DoPrerenderServiceCheck( | 626 void PrerenderLocalPredictor::DoPrerenderServiceCheck( |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 if (prerender && prerender->start_time < GetCurrentTime() - plt) { | 1062 if (prerender && prerender->start_time < GetCurrentTime() - plt) { |
| 1047 if (prerender->url.is_empty()) | 1063 if (prerender->url.is_empty()) |
| 1048 RecordEvent(EVENT_ERROR_NO_PRERENDER_URL_FOR_PLT); | 1064 RecordEvent(EVENT_ERROR_NO_PRERENDER_URL_FOR_PLT); |
| 1049 return (prerender->url == url); | 1065 return (prerender->url == url); |
| 1050 } else { | 1066 } else { |
| 1051 return false; | 1067 return false; |
| 1052 } | 1068 } |
| 1053 } | 1069 } |
| 1054 | 1070 |
| 1055 PrerenderLocalPredictor::PrerenderProperties* | 1071 PrerenderLocalPredictor::PrerenderProperties* |
| 1056 PrerenderLocalPredictor::GetIssuedPrerenderSlotForPriority(double priority) { | 1072 PrerenderLocalPredictor::GetIssuedPrerenderSlotForPriority(const GURL& url, |
| 1073 double priority) { |
| 1057 int num_prerenders = GetLocalPredictorMaxConcurrentPrerenders(); | 1074 int num_prerenders = GetLocalPredictorMaxConcurrentPrerenders(); |
| 1058 while (static_cast<int>(issued_prerenders_.size()) < num_prerenders) | 1075 while (static_cast<int>(issued_prerenders_.size()) < num_prerenders) |
| 1059 issued_prerenders_.push_back(new PrerenderProperties()); | 1076 issued_prerenders_.push_back(new PrerenderProperties()); |
| 1077 // First, check if we already have a prerender for the same URL issued. |
| 1078 // If yes, we don't want to prerender this URL again, so we return NULL |
| 1079 // (on matching slot found). |
| 1080 for (int i = 0; i < static_cast<int>(issued_prerenders_.size()); i++) { |
| 1081 PrerenderProperties* p = issued_prerenders_[i]; |
| 1082 DCHECK(p != NULL); |
| 1083 if (p->prerender_handle && p->prerender_handle->IsPrerendering() && |
| 1084 p->prerender_handle->Matches(url, NULL)) { |
| 1085 return NULL; |
| 1086 } |
| 1087 } |
| 1088 // Otherwise, let's see if there are any empty slots. If yes, return the first |
| 1089 // one we find. Otherwise, if the lowest priority prerender has a lower |
| 1090 // priority than the page we want to prerender, use its slot. |
| 1060 PrerenderProperties* lowest_priority_prerender = NULL; | 1091 PrerenderProperties* lowest_priority_prerender = NULL; |
| 1061 for (int i = 0; i < static_cast<int>(issued_prerenders_.size()); i++) { | 1092 for (int i = 0; i < static_cast<int>(issued_prerenders_.size()); i++) { |
| 1062 PrerenderProperties* p = issued_prerenders_[i]; | 1093 PrerenderProperties* p = issued_prerenders_[i]; |
| 1063 DCHECK(p != NULL); | 1094 DCHECK(p != NULL); |
| 1064 if (!p->prerender_handle || !p->prerender_handle->IsPrerendering()) | 1095 if (!p->prerender_handle || !p->prerender_handle->IsPrerendering()) |
| 1065 return p; | 1096 return p; |
| 1066 double decayed_priority = p->GetCurrentDecayedPriority(); | 1097 double decayed_priority = p->GetCurrentDecayedPriority(); |
| 1067 if (decayed_priority > priority) | 1098 if (decayed_priority > priority) |
| 1068 continue; | 1099 continue; |
| 1069 if (lowest_priority_prerender == NULL || | 1100 if (lowest_priority_prerender == NULL || |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1084 if (info->candidate_urls_.size() == 0) { | 1115 if (info->candidate_urls_.size() == 0) { |
| 1085 RecordEvent(EVENT_NO_PRERENDER_CANDIDATES); | 1116 RecordEvent(EVENT_NO_PRERENDER_CANDIDATES); |
| 1086 return; | 1117 return; |
| 1087 } | 1118 } |
| 1088 scoped_ptr<LocalPredictorURLInfo> url_info; | 1119 scoped_ptr<LocalPredictorURLInfo> url_info; |
| 1089 #if defined(FULL_SAFE_BROWSING) | 1120 #if defined(FULL_SAFE_BROWSING) |
| 1090 scoped_refptr<SafeBrowsingDatabaseManager> sb_db_manager = | 1121 scoped_refptr<SafeBrowsingDatabaseManager> sb_db_manager = |
| 1091 g_browser_process->safe_browsing_service()->database_manager(); | 1122 g_browser_process->safe_browsing_service()->database_manager(); |
| 1092 #endif | 1123 #endif |
| 1093 PrerenderProperties* prerender_properties = NULL; | 1124 PrerenderProperties* prerender_properties = NULL; |
| 1094 | 1125 int num_issued = 0; |
| 1095 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { | 1126 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { |
| 1127 if (num_issued > GetLocalPredictorMaxLaunchPrerenders()) |
| 1128 return; |
| 1096 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL); | 1129 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL); |
| 1097 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); | 1130 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); |
| 1098 if (url_info->local_history_based) { | 1131 if (url_info->local_history_based) { |
| 1099 if (SkipLocalPredictorLocalCandidates()) { | 1132 if (SkipLocalPredictorLocalCandidates()) { |
| 1100 url_info.reset(NULL); | 1133 url_info.reset(NULL); |
| 1101 continue; | 1134 continue; |
| 1102 } | 1135 } |
| 1103 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL_LOCAL); | 1136 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL_LOCAL); |
| 1104 } | 1137 } |
| 1105 if (!url_info->local_history_based) { | 1138 if (!url_info->local_history_based) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1119 // URL), or it can be sufficient to issue the prerender without any | 1152 // URL), or it can be sufficient to issue the prerender without any |
| 1120 // further checks (in which case we just break). | 1153 // further checks (in which case we just break). |
| 1121 // The order of the checks is critical, because it prescribes the logic | 1154 // The order of the checks is critical, because it prescribes the logic |
| 1122 // we use here to decide what to prerender. | 1155 // we use here to decide what to prerender. |
| 1123 if (!url_info->url_lookup_success) { | 1156 if (!url_info->url_lookup_success) { |
| 1124 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NO_URL); | 1157 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NO_URL); |
| 1125 url_info.reset(NULL); | 1158 url_info.reset(NULL); |
| 1126 continue; | 1159 continue; |
| 1127 } | 1160 } |
| 1128 prerender_properties = | 1161 prerender_properties = |
| 1129 GetIssuedPrerenderSlotForPriority(url_info->priority); | 1162 GetIssuedPrerenderSlotForPriority(url_info->url, url_info->priority); |
| 1130 if (!prerender_properties) { | 1163 if (!prerender_properties) { |
| 1131 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_PRIORITY_TOO_LOW); | 1164 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_PRIORITY_TOO_LOW); |
| 1132 url_info.reset(NULL); | 1165 url_info.reset(NULL); |
| 1133 continue; | 1166 continue; |
| 1134 } | 1167 } |
| 1135 if (!SkipLocalPredictorFragment() && | 1168 if (!SkipLocalPredictorFragment() && |
| 1136 URLsIdenticalIgnoringFragments(info->source_url_.url, | 1169 URLsIdenticalIgnoringFragments(info->source_url_.url, |
| 1137 url_info->url)) { | 1170 url_info->url)) { |
| 1138 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_URLS_IDENTICAL_BUT_FRAGMENT); | 1171 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_URLS_IDENTICAL_BUT_FRAGMENT); |
| 1139 url_info.reset(NULL); | 1172 url_info.reset(NULL); |
| 1140 continue; | 1173 continue; |
| 1141 } | 1174 } |
| 1142 if (!SkipLocalPredictorHTTPS() && url_info->url.SchemeIs("https")) { | 1175 if (!SkipLocalPredictorHTTPS() && url_info->url.SchemeIs("https")) { |
| 1143 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_HTTPS); | 1176 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_HTTPS); |
| 1144 url_info.reset(NULL); | 1177 url_info.reset(NULL); |
| 1145 continue; | 1178 continue; |
| 1146 } | 1179 } |
| 1147 if (IsRootPageURL(url_info->url)) { | 1180 if (IsRootPageURL(url_info->url)) { |
| 1148 // For root pages, we assume that they are reasonably safe, and we | 1181 // For root pages, we assume that they are reasonably safe, and we |
| 1149 // will just prerender them without any additional checks. | 1182 // will just prerender them without any additional checks. |
| 1150 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ROOT_PAGE); | 1183 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ROOT_PAGE); |
| 1151 break; | 1184 IssuePrerender(info.get(), url_info.get(), prerender_properties); |
| 1185 num_issued++; |
| 1186 continue; |
| 1152 } | 1187 } |
| 1153 if (IsLogOutURL(url_info->url)) { | 1188 if (IsLogOutURL(url_info->url)) { |
| 1154 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); | 1189 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); |
| 1155 url_info.reset(NULL); | 1190 url_info.reset(NULL); |
| 1156 continue; | 1191 continue; |
| 1157 } | 1192 } |
| 1158 if (IsLogInURL(url_info->url)) { | 1193 if (IsLogInURL(url_info->url)) { |
| 1159 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); | 1194 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); |
| 1160 url_info.reset(NULL); | 1195 url_info.reset(NULL); |
| 1161 continue; | 1196 continue; |
| 1162 } | 1197 } |
| 1163 #if defined(FULL_SAFE_BROWSING) | 1198 #if defined(FULL_SAFE_BROWSING) |
| 1164 if (!SkipLocalPredictorWhitelist() && sb_db_manager && | 1199 if (!SkipLocalPredictorWhitelist() && sb_db_manager && |
| 1165 sb_db_manager->CheckSideEffectFreeWhitelistUrl(url_info->url)) { | 1200 sb_db_manager->CheckSideEffectFreeWhitelistUrl(url_info->url)) { |
| 1166 // If a page is on the side-effect free whitelist, we will just prerender | 1201 // If a page is on the side-effect free whitelist, we will just prerender |
| 1167 // it without any additional checks. | 1202 // it without any additional checks. |
| 1168 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST); | 1203 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST); |
| 1169 break; | 1204 IssuePrerender(info.get(), url_info.get(), prerender_properties); |
| 1205 num_issued++; |
| 1206 continue; |
| 1170 } | 1207 } |
| 1171 #endif | 1208 #endif |
| 1172 if (!SkipLocalPredictorServiceWhitelist() && | 1209 if (!SkipLocalPredictorServiceWhitelist() && |
| 1173 url_info->service_whitelist && url_info->service_whitelist_lookup_ok) { | 1210 url_info->service_whitelist && url_info->service_whitelist_lookup_ok) { |
| 1174 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SERVICE_WHITELIST); | 1211 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SERVICE_WHITELIST); |
| 1175 break; | 1212 IssuePrerender(info.get(), url_info.get(), prerender_properties); |
| 1213 num_issued++; |
| 1214 continue; |
| 1176 } | 1215 } |
| 1177 if (!SkipLocalPredictorLoggedIn() && | 1216 if (!SkipLocalPredictorLoggedIn() && |
| 1178 !url_info->logged_in && url_info->logged_in_lookup_ok) { | 1217 !url_info->logged_in && url_info->logged_in_lookup_ok) { |
| 1179 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); | 1218 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); |
| 1180 break; | 1219 IssuePrerender(info.get(), url_info.get(), prerender_properties); |
| 1220 num_issued++; |
| 1221 continue; |
| 1181 } | 1222 } |
| 1182 if (!SkipLocalPredictorDefaultNoPrerender()) { | 1223 if (!SkipLocalPredictorDefaultNoPrerender()) { |
| 1183 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); | 1224 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); |
| 1184 url_info.reset(NULL); | 1225 url_info.reset(NULL); |
| 1185 } else { | 1226 } else { |
| 1186 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING); | 1227 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING); |
| 1228 IssuePrerender(info.get(), url_info.get(), prerender_properties); |
| 1229 num_issued++; |
| 1230 continue; |
| 1187 } | 1231 } |
| 1188 } | 1232 } |
| 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 } | 1233 } |
| 1197 | 1234 |
| 1198 void PrerenderLocalPredictor::IssuePrerender( | 1235 void PrerenderLocalPredictor::IssuePrerender( |
| 1199 scoped_ptr<CandidatePrerenderInfo> info, | 1236 CandidatePrerenderInfo* info, |
| 1200 scoped_ptr<LocalPredictorURLInfo> url_info, | 1237 LocalPredictorURLInfo* url_info, |
| 1201 PrerenderProperties* prerender_properties) { | 1238 PrerenderProperties* prerender_properties) { |
| 1202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1240 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER); |
| 1241 DCHECK(prerender_properties != NULL); |
| 1242 DCHECK(info != NULL); |
| 1243 DCHECK(url_info != NULL); |
| 1244 if (!IsLocalPredictorPrerenderLaunchEnabled()) |
| 1245 return; |
| 1203 URLID url_id = url_info->id; | 1246 URLID url_id = url_info->id; |
| 1204 const GURL& url = url_info->url; | 1247 const GURL& url = url_info->url; |
| 1205 double priority = url_info->priority; | 1248 double priority = url_info->priority; |
| 1206 base::Time current_time = GetCurrentTime(); | 1249 base::Time current_time = GetCurrentTime(); |
| 1207 RecordEvent(EVENT_ISSUING_PRERENDER); | 1250 RecordEvent(EVENT_ISSUING_PRERENDER); |
| 1208 | 1251 |
| 1209 // Issue the prerender and obtain a new handle. | 1252 // Issue the prerender and obtain a new handle. |
| 1210 scoped_ptr<prerender::PrerenderHandle> new_prerender_handle( | 1253 scoped_ptr<prerender::PrerenderHandle> new_prerender_handle( |
| 1211 prerender_manager_->AddPrerenderFromLocalPredictor( | 1254 prerender_manager_->AddPrerenderFromLocalPredictor( |
| 1212 url, info->session_storage_namespace_.get(), *(info->size_))); | 1255 url, info->session_storage_namespace_.get(), *(info->size_))); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1236 prerender_properties->start_time = current_time; | 1279 prerender_properties->start_time = current_time; |
| 1237 prerender_properties->actual_start_time = current_time; | 1280 prerender_properties->actual_start_time = current_time; |
| 1238 prerender_properties->would_have_matched = false; | 1281 prerender_properties->would_have_matched = false; |
| 1239 prerender_properties->prerender_handle.swap(new_prerender_handle); | 1282 prerender_properties->prerender_handle.swap(new_prerender_handle); |
| 1240 // new_prerender_handle now represents the old previou prerender that we | 1283 // new_prerender_handle now represents the old previou prerender that we |
| 1241 // are replacing. So we need to cancel it. | 1284 // are replacing. So we need to cancel it. |
| 1242 if (new_prerender_handle) { | 1285 if (new_prerender_handle) { |
| 1243 new_prerender_handle->OnCancel(); | 1286 new_prerender_handle->OnCancel(); |
| 1244 RecordEvent(EVENT_ISSUE_PRERENDER_CANCELLED_OLD_PRERENDER); | 1287 RecordEvent(EVENT_ISSUE_PRERENDER_CANCELLED_OLD_PRERENDER); |
| 1245 } | 1288 } |
| 1289 // If we are prefetching rather than prerendering, now is the time to launch |
| 1290 // the prefetch. |
| 1291 if (IsLocalPredictorPrerenderPrefetchEnabled()) { |
| 1292 // Obtain the render frame host that caused this prefetch. |
| 1293 RenderFrameHost* rfh = RenderFrameHost::FromID(info->render_process_id_, |
| 1294 info->render_frame_id_); |
| 1295 // If it is still alive, launch the prefresh. |
| 1296 if (rfh) |
| 1297 rfh->Send(new PrefetchMsg_Prefetch(rfh->GetRoutingID(), url)); |
| 1298 } |
| 1246 } | 1299 } |
| 1247 | 1300 |
| 1248 RecordEvent(EVENT_ADD_VISIT_PRERENDERING); | 1301 RecordEvent(EVENT_ADD_VISIT_PRERENDERING); |
| 1249 if (current_prerender_.get() && current_prerender_->url_id == url_id) { | 1302 if (current_prerender_.get() && current_prerender_->url_id == url_id) { |
| 1250 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED); | 1303 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED); |
| 1251 if (priority > current_prerender_->priority) | 1304 if (priority > current_prerender_->priority) |
| 1252 current_prerender_->priority = priority; | 1305 current_prerender_->priority = priority; |
| 1253 // If the prerender already existed, we want to extend it. However, | 1306 // 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 | 1307 // we do not want to set its start_time to the current time to |
| 1255 // disadvantage PLT computations when the prerender is swapped in. | 1308 // disadvantage PLT computations when the prerender is swapped in. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 break; | 1415 break; |
| 1363 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: | 1416 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: |
| 1364 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); | 1417 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); |
| 1365 break; | 1418 break; |
| 1366 default: | 1419 default: |
| 1367 NOTREACHED(); | 1420 NOTREACHED(); |
| 1368 } | 1421 } |
| 1369 } | 1422 } |
| 1370 | 1423 |
| 1371 } // namespace prerender | 1424 } // namespace prerender |
| OLD | NEW |