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/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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 using std::vector; | 63 using std::vector; |
| 64 | 64 |
| 65 namespace prerender { | 65 namespace prerender { |
| 66 | 66 |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 static const size_t kURLHashSize = 5; | 69 static const size_t kURLHashSize = 5; |
| 70 static const int kNumPrerenderCandidates = 5; | 70 static const int kNumPrerenderCandidates = 5; |
| 71 static const int kInvalidProcessId = -1; | 71 static const int kInvalidProcessId = -1; |
| 72 static const int kInvalidFrameId = -1; | 72 static const int kInvalidFrameId = -1; |
| 73 static const int kMaxPrefetchItems = 100; | |
| 73 | 74 |
| 74 } // namespace | 75 } // namespace |
| 75 | 76 |
| 76 // When considering a candidate URL to be prerendered, we need to collect the | 77 // When considering a candidate URL to be prerendered, we need to collect the |
| 77 // data in this struct to make the determination whether we should issue the | 78 // data in this struct to make the determination whether we should issue the |
| 78 // prerender or not. | 79 // prerender or not. |
| 79 struct PrerenderLocalPredictor::LocalPredictorURLInfo { | 80 struct PrerenderLocalPredictor::LocalPredictorURLInfo { |
| 80 URLID id; | 81 URLID id; |
| 81 GURL url; | 82 GURL url; |
| 82 bool url_lookup_success; | 83 bool url_lookup_success; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 // time after the actual prerender being kept around. | 392 // time after the actual prerender being kept around. |
| 392 base::Time start_time; | 393 base::Time start_time; |
| 393 // The actual time this page was last requested for prerendering. | 394 // The actual time this page was last requested for prerendering. |
| 394 base::Time actual_start_time; | 395 base::Time actual_start_time; |
| 395 scoped_ptr<PrerenderHandle> prerender_handle; | 396 scoped_ptr<PrerenderHandle> prerender_handle; |
| 396 // Indicates whether this prerender would have matched a URL navigated to, | 397 // Indicates whether this prerender would have matched a URL navigated to, |
| 397 // but was not swapped in for some reason. | 398 // but was not swapped in for some reason. |
| 398 bool would_have_matched; | 399 bool would_have_matched; |
| 399 }; | 400 }; |
| 400 | 401 |
| 402 // A class simulating a set of URLs prefetched, for statistical purposes. | |
| 403 class PrerenderLocalPredictor::PrefetchList { | |
| 404 public: | |
| 405 enum SeenType { | |
| 406 SEEN_TABCONTENTS_OBSERVER, | |
| 407 SEEN_HISTORY, | |
| 408 SEEN_MAX_VALUE | |
| 409 }; | |
|
davidben
2014/08/05 18:51:12
Nit: newline here
tburkard
2014/08/05 20:05:54
Done.
| |
| 410 PrefetchList() {} | |
| 411 ~PrefetchList() { | |
| 412 STLDeleteValues(&entries_); | |
| 413 } | |
|
davidben
2014/08/05 18:51:12
Nit: newline here
tburkard
2014/08/05 20:05:54
Done.
| |
| 414 // Adds a new URL being prefetched. If the URL is already in the list, | |
| 415 // nothing will happen. Returns whether a new prefetch was added. | |
| 416 bool AddURL(const GURL& url) { | |
| 417 ExpireOldItems(); | |
| 418 string url_string = url.spec().c_str(); | |
| 419 base::hash_map<string, ListEntry*>::iterator it = entries_.find(url_string); | |
| 420 if (it != entries_.end()) { | |
| 421 // If a prefetch previously existed, and has not been seen yet in either | |
| 422 // a tab contents or a history, we will not re-issue it. Otherwise, if it | |
| 423 // may have been consumed by either tab contents or history, we will | |
| 424 // permit re-issuing another one. | |
| 425 if (!it->second->seen_history_ && | |
| 426 !it->second->seen_tabcontents_) { | |
| 427 return false; | |
| 428 } | |
| 429 } | |
| 430 ListEntry* entry = new ListEntry(url_string); | |
| 431 entries_[entry->url_] = entry; | |
| 432 entry_list_.push_back(entry); | |
| 433 ExpireOldItems(); | |
| 434 return true; | |
| 435 } | |
|
davidben
2014/08/05 18:51:12
Nit: newline here
tburkard
2014/08/05 20:05:54
Done.
| |
| 436 // Marks the URL provided as seen in the context specified. Returns true | |
| 437 // iff the item is currently in the list and had not been seen before in | |
| 438 // the context specified, i.e. the marking was successful. | |
| 439 bool MarkURLSeen(const GURL& url, SeenType type) { | |
| 440 ExpireOldItems(); | |
| 441 bool return_value = false; | |
| 442 base::hash_map<string, ListEntry*>::iterator it = | |
| 443 entries_.find(url.spec().c_str()); | |
| 444 if (it == entries_.end()) | |
| 445 return return_value; | |
| 446 if (type == SEEN_TABCONTENTS_OBSERVER && !it->second->seen_tabcontents_) { | |
| 447 it->second->seen_tabcontents_ = true; | |
| 448 return_value = true; | |
| 449 } | |
| 450 if (type == SEEN_HISTORY && !it->second->seen_history_) { | |
| 451 it->second->seen_history_ = true; | |
| 452 return_value = true; | |
| 453 } | |
| 454 // If the item has been seen in both the history and in tab contents, | |
| 455 // erase it from the map to make room for new prefetches. | |
| 456 if (it->second->seen_tabcontents_ && it->second->seen_history_) | |
| 457 entries_.erase(url.spec().c_str()); | |
| 458 return return_value; | |
| 459 } | |
| 460 | |
| 461 private: | |
| 462 struct ListEntry { | |
| 463 std::string url_; | |
| 464 base::Time add_time_; | |
| 465 bool seen_tabcontents_; | |
| 466 bool seen_history_; | |
| 467 explicit ListEntry(string url) | |
|
davidben
2014/08/05 18:51:12
Nit: I think we usually put methods before members
Alexei Svitkine (slow)
2014/08/05 19:20:22
Pass the param by const ref.
tburkard
2014/08/05 20:05:54
Done.
tburkard
2014/08/05 20:05:54
Done.
| |
| 468 : url_(url), | |
| 469 add_time_(GetCurrentTime()), | |
| 470 seen_tabcontents_(false), | |
| 471 seen_history_(false) { | |
| 472 } | |
| 473 }; | |
|
davidben
2014/08/05 18:51:12
Nit: newline here
tburkard
2014/08/05 20:05:54
Done.
| |
| 474 void ExpireOldItems() { | |
| 475 base::Time expiry_cutoff = GetCurrentTime() - | |
| 476 base::TimeDelta::FromSeconds(GetPrerenderPrefetchListTimeoutSeconds()); | |
| 477 while (!entry_list_.empty() && | |
| 478 (entry_list_.front()->add_time_ < expiry_cutoff || | |
| 479 entries_.size() > kMaxPrefetchItems)) { | |
| 480 ListEntry* entry = entry_list_.front(); | |
| 481 entry_list_.pop_front(); | |
| 482 // If the entry to be deleted is still the one active in entries_, | |
| 483 // we must erase it from entries_. | |
| 484 base::hash_map<string, ListEntry*>::iterator it = | |
| 485 entries_.find(entry->url_); | |
| 486 if (it != entries_.end() && it->second == entry) | |
| 487 entries_.erase(entry->url_); | |
| 488 delete entry; | |
|
Alexei Svitkine (slow)
2014/08/05 19:20:22
Can you use a scoped_ptr instead?
tburkard
2014/08/05 20:05:54
Not obvious to me how this would work well here.
C
Alexei Svitkine (slow)
2014/08/05 20:16:22
Sorry, I meant in the body of the loop, not in the
| |
| 489 } | |
| 490 } | |
|
davidben
2014/08/05 18:51:12
Nit: newline here
tburkard
2014/08/05 20:05:54
Done.
| |
| 491 base::hash_map<string, ListEntry*> entries_; | |
| 492 std::list<ListEntry*> entry_list_; | |
| 493 DISALLOW_COPY_AND_ASSIGN(PrefetchList); | |
| 494 }; | |
| 495 | |
| 401 PrerenderLocalPredictor::PrerenderLocalPredictor( | 496 PrerenderLocalPredictor::PrerenderLocalPredictor( |
| 402 PrerenderManager* prerender_manager) | 497 PrerenderManager* prerender_manager) |
| 403 : prerender_manager_(prerender_manager), | 498 : prerender_manager_(prerender_manager), |
| 404 is_visit_database_observer_(false), | 499 is_visit_database_observer_(false), |
| 405 weak_factory_(this) { | 500 weak_factory_(this), |
| 501 prefetch_list_(new PrefetchList()) { | |
| 406 RecordEvent(EVENT_CONSTRUCTED); | 502 RecordEvent(EVENT_CONSTRUCTED); |
| 407 if (base::MessageLoop::current()) { | 503 if (base::MessageLoop::current()) { |
| 408 timer_.Start(FROM_HERE, | 504 timer_.Start(FROM_HERE, |
| 409 base::TimeDelta::FromMilliseconds(kInitDelayMs), | 505 base::TimeDelta::FromMilliseconds(kInitDelayMs), |
| 410 this, | 506 this, |
| 411 &PrerenderLocalPredictor::Init); | 507 &PrerenderLocalPredictor::Init); |
| 412 RecordEvent(EVENT_INIT_SCHEDULED); | 508 RecordEvent(EVENT_INIT_SCHEDULED); |
| 413 } | 509 } |
| 414 | 510 |
| 415 static const size_t kChecksumHashSize = 32; | 511 static const size_t kChecksumHashSize = 32; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 scoped_ptr<CandidatePrerenderInfo> info) { | 665 scoped_ptr<CandidatePrerenderInfo> info) { |
| 570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 571 | 667 |
| 572 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT); | 668 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT); |
| 573 | 669 |
| 574 if (!info->source_url_.url_lookup_success) { | 670 if (!info->source_url_.url_lookup_success) { |
| 575 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_FAILED); | 671 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_FAILED); |
| 576 return; | 672 return; |
| 577 } | 673 } |
| 578 | 674 |
| 675 if (prefetch_list_->MarkURLSeen(info->source_url_.url, | |
| 676 PrefetchList::SEEN_HISTORY)) { | |
| 677 RecordEvent(EVENT_PREFETCH_LIST_SEEN_HISTORY); | |
| 678 } | |
| 679 | |
| 579 if (info->candidate_urls_.size() > 0 && | 680 if (info->candidate_urls_.size() > 0 && |
| 580 info->candidate_urls_[0].url_lookup_success) { | 681 info->candidate_urls_[0].url_lookup_success) { |
| 581 LogCandidateURLStats(info->candidate_urls_[0].url); | 682 LogCandidateURLStats(info->candidate_urls_[0].url); |
| 582 } | 683 } |
| 583 | 684 |
| 584 WebContents* source_web_contents = NULL; | 685 WebContents* source_web_contents = NULL; |
| 585 bool multiple_source_web_contents_candidates = false; | 686 bool multiple_source_web_contents_candidates = false; |
| 586 | 687 |
| 587 #if !defined(OS_ANDROID) | 688 #if !defined(OS_ANDROID) |
| 588 // We need to figure out what tab launched the prerender. We do this by | 689 // We need to figure out what tab launched the prerender. We do this by |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_STARTED); | 1219 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_STARTED); |
| 1119 if (info->candidate_urls_.size() == 0) { | 1220 if (info->candidate_urls_.size() == 0) { |
| 1120 RecordEvent(EVENT_NO_PRERENDER_CANDIDATES); | 1221 RecordEvent(EVENT_NO_PRERENDER_CANDIDATES); |
| 1121 return; | 1222 return; |
| 1122 } | 1223 } |
| 1123 scoped_ptr<LocalPredictorURLInfo> url_info; | 1224 scoped_ptr<LocalPredictorURLInfo> url_info; |
| 1124 #if defined(FULL_SAFE_BROWSING) | 1225 #if defined(FULL_SAFE_BROWSING) |
| 1125 scoped_refptr<SafeBrowsingDatabaseManager> sb_db_manager = | 1226 scoped_refptr<SafeBrowsingDatabaseManager> sb_db_manager = |
| 1126 g_browser_process->safe_browsing_service()->database_manager(); | 1227 g_browser_process->safe_browsing_service()->database_manager(); |
| 1127 #endif | 1228 #endif |
| 1128 PrerenderProperties* prerender_properties = NULL; | |
| 1129 int num_issued = 0; | 1229 int num_issued = 0; |
| 1130 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { | 1230 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { |
| 1131 if (num_issued > GetLocalPredictorMaxLaunchPrerenders()) | 1231 if (num_issued >= GetLocalPredictorMaxLaunchPrerenders()) |
| 1132 return; | 1232 return; |
| 1133 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL); | 1233 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL); |
| 1134 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); | 1234 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); |
| 1135 if (url_info->local_history_based) { | 1235 if (url_info->local_history_based) { |
| 1136 if (SkipLocalPredictorLocalCandidates()) { | 1236 if (SkipLocalPredictorLocalCandidates()) { |
| 1137 url_info.reset(NULL); | 1237 url_info.reset(NULL); |
| 1138 continue; | 1238 continue; |
| 1139 } | 1239 } |
| 1140 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL_LOCAL); | 1240 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL_LOCAL); |
| 1141 } | 1241 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1155 // be prerendered, and we continue, which means try the next candidate | 1255 // be prerendered, and we continue, which means try the next candidate |
| 1156 // URL), or it can be sufficient to issue the prerender without any | 1256 // URL), or it can be sufficient to issue the prerender without any |
| 1157 // further checks (in which case we just break). | 1257 // further checks (in which case we just break). |
| 1158 // The order of the checks is critical, because it prescribes the logic | 1258 // The order of the checks is critical, because it prescribes the logic |
| 1159 // we use here to decide what to prerender. | 1259 // we use here to decide what to prerender. |
| 1160 if (!url_info->url_lookup_success) { | 1260 if (!url_info->url_lookup_success) { |
| 1161 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NO_URL); | 1261 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NO_URL); |
| 1162 url_info.reset(NULL); | 1262 url_info.reset(NULL); |
| 1163 continue; | 1263 continue; |
| 1164 } | 1264 } |
| 1165 prerender_properties = | |
| 1166 GetIssuedPrerenderSlotForPriority(url_info->url, url_info->priority); | |
| 1167 if (!prerender_properties) { | |
| 1168 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_PRIORITY_TOO_LOW); | |
| 1169 url_info.reset(NULL); | |
| 1170 continue; | |
| 1171 } | |
|
davidben
2014/08/05 18:51:12
This will count candidate URLs toward num_issued e
tburkard
2014/08/05 20:05:54
Yes, that's fine, because they are ordered in desc
| |
| 1172 if (!SkipLocalPredictorFragment() && | 1265 if (!SkipLocalPredictorFragment() && |
| 1173 URLsIdenticalIgnoringFragments(info->source_url_.url, | 1266 URLsIdenticalIgnoringFragments(info->source_url_.url, |
| 1174 url_info->url)) { | 1267 url_info->url)) { |
| 1175 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_URLS_IDENTICAL_BUT_FRAGMENT); | 1268 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_URLS_IDENTICAL_BUT_FRAGMENT); |
| 1176 url_info.reset(NULL); | 1269 url_info.reset(NULL); |
| 1177 continue; | 1270 continue; |
| 1178 } | 1271 } |
| 1179 if (!SkipLocalPredictorHTTPS() && url_info->url.SchemeIs("https")) { | 1272 if (!SkipLocalPredictorHTTPS() && url_info->url.SchemeIs("https")) { |
| 1180 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_HTTPS); | 1273 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_HTTPS); |
| 1181 url_info.reset(NULL); | 1274 url_info.reset(NULL); |
| 1182 continue; | 1275 continue; |
| 1183 } | 1276 } |
| 1184 if (IsRootPageURL(url_info->url)) { | 1277 if (IsRootPageURL(url_info->url)) { |
| 1185 // For root pages, we assume that they are reasonably safe, and we | 1278 // For root pages, we assume that they are reasonably safe, and we |
| 1186 // will just prerender them without any additional checks. | 1279 // will just prerender them without any additional checks. |
| 1187 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ROOT_PAGE); | 1280 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ROOT_PAGE); |
| 1188 IssuePrerender(info.get(), url_info.get(), prerender_properties); | 1281 IssuePrerender(info.get(), url_info.get()); |
| 1189 num_issued++; | 1282 num_issued++; |
| 1190 continue; | 1283 continue; |
| 1191 } | 1284 } |
| 1192 if (IsLogOutURL(url_info->url)) { | 1285 if (IsLogOutURL(url_info->url)) { |
| 1193 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); | 1286 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); |
| 1194 url_info.reset(NULL); | 1287 url_info.reset(NULL); |
| 1195 continue; | 1288 continue; |
| 1196 } | 1289 } |
| 1197 if (IsLogInURL(url_info->url)) { | 1290 if (IsLogInURL(url_info->url)) { |
| 1198 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); | 1291 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); |
| 1199 url_info.reset(NULL); | 1292 url_info.reset(NULL); |
| 1200 continue; | 1293 continue; |
| 1201 } | 1294 } |
| 1202 #if defined(FULL_SAFE_BROWSING) | 1295 #if defined(FULL_SAFE_BROWSING) |
| 1203 if (!SkipLocalPredictorWhitelist() && sb_db_manager && | 1296 if (!SkipLocalPredictorWhitelist() && sb_db_manager && |
| 1204 sb_db_manager->CheckSideEffectFreeWhitelistUrl(url_info->url)) { | 1297 sb_db_manager->CheckSideEffectFreeWhitelistUrl(url_info->url)) { |
| 1205 // If a page is on the side-effect free whitelist, we will just prerender | 1298 // If a page is on the side-effect free whitelist, we will just prerender |
| 1206 // it without any additional checks. | 1299 // it without any additional checks. |
| 1207 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST); | 1300 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST); |
| 1208 IssuePrerender(info.get(), url_info.get(), prerender_properties); | 1301 IssuePrerender(info.get(), url_info.get()); |
| 1209 num_issued++; | 1302 num_issued++; |
| 1210 continue; | 1303 continue; |
| 1211 } | 1304 } |
| 1212 #endif | 1305 #endif |
| 1213 if (!SkipLocalPredictorServiceWhitelist() && | 1306 if (!SkipLocalPredictorServiceWhitelist() && |
| 1214 url_info->service_whitelist && url_info->service_whitelist_lookup_ok) { | 1307 url_info->service_whitelist && url_info->service_whitelist_lookup_ok) { |
| 1215 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SERVICE_WHITELIST); | 1308 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SERVICE_WHITELIST); |
| 1216 IssuePrerender(info.get(), url_info.get(), prerender_properties); | 1309 IssuePrerender(info.get(), url_info.get()); |
| 1217 num_issued++; | 1310 num_issued++; |
| 1218 continue; | 1311 continue; |
| 1219 } | 1312 } |
| 1220 if (!SkipLocalPredictorLoggedIn() && | 1313 if (!SkipLocalPredictorLoggedIn() && |
| 1221 !url_info->logged_in && url_info->logged_in_lookup_ok) { | 1314 !url_info->logged_in && url_info->logged_in_lookup_ok) { |
| 1222 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); | 1315 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); |
| 1223 IssuePrerender(info.get(), url_info.get(), prerender_properties); | 1316 IssuePrerender(info.get(), url_info.get()); |
| 1224 num_issued++; | 1317 num_issued++; |
| 1225 continue; | 1318 continue; |
| 1226 } | 1319 } |
| 1227 if (!SkipLocalPredictorDefaultNoPrerender()) { | 1320 if (!SkipLocalPredictorDefaultNoPrerender()) { |
| 1228 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); | 1321 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); |
| 1229 url_info.reset(NULL); | 1322 url_info.reset(NULL); |
| 1230 } else { | 1323 } else { |
| 1231 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING); | 1324 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING); |
| 1232 IssuePrerender(info.get(), url_info.get(), prerender_properties); | 1325 IssuePrerender(info.get(), url_info.get()); |
| 1233 num_issued++; | 1326 num_issued++; |
| 1234 continue; | 1327 continue; |
| 1235 } | 1328 } |
| 1236 } | 1329 } |
| 1237 } | 1330 } |
| 1238 | 1331 |
| 1239 void PrerenderLocalPredictor::IssuePrerender( | 1332 void PrerenderLocalPredictor::IssuePrerender( |
| 1240 CandidatePrerenderInfo* info, | 1333 CandidatePrerenderInfo* info, |
| 1241 LocalPredictorURLInfo* url_info, | 1334 LocalPredictorURLInfo* url_info) { |
| 1242 PrerenderProperties* prerender_properties) { | |
| 1243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1336 if (prefetch_list_->AddURL(url_info->url)) | |
| 1337 RecordEvent(EVENT_PREFETCH_LIST_ADDED); | |
| 1338 PrerenderProperties* prerender_properties = | |
| 1339 GetIssuedPrerenderSlotForPriority(url_info->url, url_info->priority); | |
| 1340 if (!prerender_properties) { | |
| 1341 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_PRIORITY_TOO_LOW); | |
| 1342 return; | |
| 1343 } | |
| 1244 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER); | 1344 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER); |
| 1245 DCHECK(prerender_properties != NULL); | 1345 DCHECK(prerender_properties != NULL); |
| 1246 DCHECK(info != NULL); | 1346 DCHECK(info != NULL); |
| 1247 DCHECK(url_info != NULL); | 1347 DCHECK(url_info != NULL); |
| 1248 if (!IsLocalPredictorPrerenderLaunchEnabled()) | 1348 if (!IsLocalPredictorPrerenderLaunchEnabled()) |
| 1249 return; | 1349 return; |
| 1250 URLID url_id = url_info->id; | 1350 URLID url_id = url_info->id; |
| 1251 const GURL& url = url_info->url; | 1351 const GURL& url = url_info->url; |
| 1252 double priority = url_info->priority; | 1352 double priority = url_info->priority; |
| 1253 base::Time current_time = GetCurrentTime(); | 1353 base::Time current_time = GetCurrentTime(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 current_prerender_.reset( | 1422 current_prerender_.reset( |
| 1323 new PrerenderProperties(url_id, url, priority, current_time)); | 1423 new PrerenderProperties(url_id, url, priority, current_time)); |
| 1324 } | 1424 } |
| 1325 current_prerender_->actual_start_time = current_time; | 1425 current_prerender_->actual_start_time = current_time; |
| 1326 } | 1426 } |
| 1327 | 1427 |
| 1328 void PrerenderLocalPredictor::OnTabHelperURLSeen( | 1428 void PrerenderLocalPredictor::OnTabHelperURLSeen( |
| 1329 const GURL& url, WebContents* web_contents) { | 1429 const GURL& url, WebContents* web_contents) { |
| 1330 RecordEvent(EVENT_TAB_HELPER_URL_SEEN); | 1430 RecordEvent(EVENT_TAB_HELPER_URL_SEEN); |
| 1331 | 1431 |
| 1432 if (prefetch_list_->MarkURLSeen(url, PrefetchList::SEEN_TABCONTENTS_OBSERVER)) | |
| 1433 RecordEvent(EVENT_PREFETCH_LIST_SEEN_TABCONTENTS); | |
| 1332 bool browser_navigate_initiated = false; | 1434 bool browser_navigate_initiated = false; |
| 1333 const content::NavigationEntry* entry = | 1435 const content::NavigationEntry* entry = |
| 1334 web_contents->GetController().GetPendingEntry(); | 1436 web_contents->GetController().GetPendingEntry(); |
| 1335 if (entry) { | 1437 if (entry) { |
| 1336 base::string16 result; | 1438 base::string16 result; |
| 1337 browser_navigate_initiated = | 1439 browser_navigate_initiated = |
| 1338 entry->GetExtraData(kChromeNavigateExtraDataKey, &result); | 1440 entry->GetExtraData(kChromeNavigateExtraDataKey, &result); |
| 1339 } | 1441 } |
| 1340 | 1442 |
| 1341 // If the namespace matches and the URL matches, we might be able to swap | 1443 // If the namespace matches and the URL matches, we might be able to swap |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1419 break; | 1521 break; |
| 1420 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: | 1522 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: |
| 1421 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); | 1523 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); |
| 1422 break; | 1524 break; |
| 1423 default: | 1525 default: |
| 1424 NOTREACHED(); | 1526 NOTREACHED(); |
| 1425 } | 1527 } |
| 1426 } | 1528 } |
| 1427 | 1529 |
| 1428 } // namespace prerender | 1530 } // namespace prerender |
| OLD | NEW |