| 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_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 if (!prerender_data->contents()->prerendering_has_started()) { | 405 if (!prerender_data->contents()->prerendering_has_started()) { |
| 406 target_tab_helper->WouldHavePrerenderedNextLoad( | 406 target_tab_helper->WouldHavePrerenderedNextLoad( |
| 407 prerender_data->contents()->origin()); | 407 prerender_data->contents()->origin()); |
| 408 prerender_data->contents()->Destroy(FINAL_STATUS_WOULD_HAVE_BEEN_USED); | 408 prerender_data->contents()->Destroy(FINAL_STATUS_WOULD_HAVE_BEEN_USED); |
| 409 return NULL; | 409 return NULL; |
| 410 } | 410 } |
| 411 | 411 |
| 412 // Don't use prerendered pages if debugger is attached to the tab. | 412 // Don't use prerendered pages if debugger is attached to the tab. |
| 413 // See http://crbug.com/98541 | 413 // See http://crbug.com/98541 |
| 414 if (content::DevToolsAgentHost::IsDebuggerAttached(web_contents)) { | 414 if (content::DevToolsAgentHost::IsDebuggerAttached(web_contents)) { |
| 415 DestroyAndMarkMatchCompleteAsUsed(prerender_data->contents(), | 415 histograms_->RecordFinalStatus(prerender_data->contents()->origin(), |
| 416 FINAL_STATUS_DEVTOOLS_ATTACHED); | 416 FINAL_STATUS_DEVTOOLS_ATTACHED); |
| 417 prerender_data->contents()->Destroy(FINAL_STATUS_DEVTOOLS_ATTACHED); |
| 417 return NULL; | 418 return NULL; |
| 418 } | 419 } |
| 419 | 420 |
| 420 // If the prerendered page is in the middle of a cross-site navigation, | 421 // If the prerendered page is in the middle of a cross-site navigation, |
| 421 // don't swap it in because there isn't a good way to merge histories. | 422 // don't swap it in because there isn't a good way to merge histories. |
| 422 if (prerender_data->contents()->IsCrossSiteNavigationPending()) { | 423 if (prerender_data->contents()->IsCrossSiteNavigationPending()) { |
| 423 DestroyAndMarkMatchCompleteAsUsed( | 424 histograms_->RecordFinalStatus(prerender_data->contents()->origin(), |
| 424 prerender_data->contents(), | 425 FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING); |
| 426 prerender_data->contents()->Destroy( |
| 425 FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING); | 427 FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING); |
| 426 return NULL; | 428 return NULL; |
| 427 } | 429 } |
| 428 | 430 |
| 429 // For bookkeeping purposes, we need to mark this WebContents to | 431 // For bookkeeping purposes, we need to mark this WebContents to |
| 430 // reflect that it would have been prerendered. | 432 // reflect that it would have been prerendered. |
| 431 if (GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP) { | 433 if (GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP) { |
| 432 target_tab_helper->WouldHavePrerenderedNextLoad( | 434 target_tab_helper->WouldHavePrerenderedNextLoad( |
| 433 prerender_data->contents()->origin()); | 435 prerender_data->contents()->origin()); |
| 434 prerender_data->contents()->Destroy(FINAL_STATUS_WOULD_HAVE_BEEN_USED); | 436 prerender_data->contents()->Destroy(FINAL_STATUS_WOULD_HAVE_BEEN_USED); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 void PrerenderManager::ClearData(int clear_flags) { | 777 void PrerenderManager::ClearData(int clear_flags) { |
| 776 DCHECK_GE(clear_flags, 0); | 778 DCHECK_GE(clear_flags, 0); |
| 777 DCHECK_LT(clear_flags, CLEAR_MAX); | 779 DCHECK_LT(clear_flags, CLEAR_MAX); |
| 778 if (clear_flags & CLEAR_PRERENDER_CONTENTS) | 780 if (clear_flags & CLEAR_PRERENDER_CONTENTS) |
| 779 DestroyAllContents(FINAL_STATUS_CACHE_OR_HISTORY_CLEARED); | 781 DestroyAllContents(FINAL_STATUS_CACHE_OR_HISTORY_CLEARED); |
| 780 // This has to be second, since destroying prerenders can add to the history. | 782 // This has to be second, since destroying prerenders can add to the history. |
| 781 if (clear_flags & CLEAR_PRERENDER_HISTORY) | 783 if (clear_flags & CLEAR_PRERENDER_HISTORY) |
| 782 prerender_history_->Clear(); | 784 prerender_history_->Clear(); |
| 783 } | 785 } |
| 784 | 786 |
| 785 void PrerenderManager::RecordFinalStatusWithMatchCompleteStatus( | 787 void PrerenderManager::RecordFinalStatus(Origin origin, |
| 786 Origin origin, | 788 FinalStatus final_status) const { |
| 787 PrerenderContents::MatchCompleteStatus mc_status, | 789 histograms_->RecordFinalStatus(origin, final_status); |
| 788 FinalStatus final_status) const { | |
| 789 histograms_->RecordFinalStatus(origin, mc_status, final_status); | |
| 790 } | 790 } |
| 791 | 791 |
| 792 void PrerenderManager::RecordNavigation(const GURL& url) { | 792 void PrerenderManager::RecordNavigation(const GURL& url) { |
| 793 DCHECK(CalledOnValidThread()); | 793 DCHECK(CalledOnValidThread()); |
| 794 | 794 |
| 795 navigations_.push_back(NavigationRecord(url, GetCurrentTimeTicks())); | 795 navigations_.push_back(NavigationRecord(url, GetCurrentTimeTicks())); |
| 796 CleanUpOldNavigations(); | 796 CleanUpOldNavigations(); |
| 797 } | 797 } |
| 798 | 798 |
| 799 // protected | 799 // protected |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 | 1186 |
| 1187 void PrerenderManager::DestroyAllContents(FinalStatus final_status) { | 1187 void PrerenderManager::DestroyAllContents(FinalStatus final_status) { |
| 1188 DeleteOldWebContents(); | 1188 DeleteOldWebContents(); |
| 1189 while (!active_prerenders_.empty()) { | 1189 while (!active_prerenders_.empty()) { |
| 1190 PrerenderContents* contents = active_prerenders_.front()->contents(); | 1190 PrerenderContents* contents = active_prerenders_.front()->contents(); |
| 1191 contents->Destroy(final_status); | 1191 contents->Destroy(final_status); |
| 1192 } | 1192 } |
| 1193 to_delete_prerenders_.clear(); | 1193 to_delete_prerenders_.clear(); |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 void PrerenderManager::DestroyAndMarkMatchCompleteAsUsed( | |
| 1197 PrerenderContents* prerender_contents, | |
| 1198 FinalStatus final_status) { | |
| 1199 prerender_contents->set_match_complete_status( | |
| 1200 PrerenderContents::MATCH_COMPLETE_REPLACED); | |
| 1201 histograms_->RecordFinalStatus(prerender_contents->origin(), | |
| 1202 PrerenderContents::MATCH_COMPLETE_REPLACEMENT, | |
| 1203 FINAL_STATUS_WOULD_HAVE_BEEN_USED); | |
| 1204 prerender_contents->Destroy(final_status); | |
| 1205 } | |
| 1206 | |
| 1207 void PrerenderManager::RecordFinalStatusWithoutCreatingPrerenderContents( | 1196 void PrerenderManager::RecordFinalStatusWithoutCreatingPrerenderContents( |
| 1208 const GURL& url, Origin origin, FinalStatus final_status) const { | 1197 const GURL& url, Origin origin, FinalStatus final_status) const { |
| 1209 PrerenderHistory::Entry entry(url, final_status, origin, base::Time::Now()); | 1198 PrerenderHistory::Entry entry(url, final_status, origin, base::Time::Now()); |
| 1210 prerender_history_->AddEntry(entry); | 1199 prerender_history_->AddEntry(entry); |
| 1211 RecordFinalStatusWithMatchCompleteStatus( | 1200 histograms_->RecordFinalStatus(origin, final_status); |
| 1212 origin, PrerenderContents::MATCH_COMPLETE_DEFAULT, final_status); | |
| 1213 } | 1201 } |
| 1214 | 1202 |
| 1215 void PrerenderManager::Observe(int type, | 1203 void PrerenderManager::Observe(int type, |
| 1216 const content::NotificationSource& source, | 1204 const content::NotificationSource& source, |
| 1217 const content::NotificationDetails& details) { | 1205 const content::NotificationDetails& details) { |
| 1218 switch (type) { | 1206 switch (type) { |
| 1219 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 1207 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
| 1220 DestroyAllContents(FINAL_STATUS_PROFILE_DESTROYED); | 1208 DestroyAllContents(FINAL_STATUS_PROFILE_DESTROYED); |
| 1221 on_close_web_contents_deleters_.clear(); | 1209 on_close_web_contents_deleters_.clear(); |
| 1222 break; | 1210 break; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 } | 1303 } |
| 1316 | 1304 |
| 1317 void PrerenderManager::RenderProcessHostDestroyed( | 1305 void PrerenderManager::RenderProcessHostDestroyed( |
| 1318 content::RenderProcessHost* host) { | 1306 content::RenderProcessHost* host) { |
| 1319 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1307 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1320 size_t erased = prerender_process_hosts_.erase(host); | 1308 size_t erased = prerender_process_hosts_.erase(host); |
| 1321 DCHECK_EQ(1u, erased); | 1309 DCHECK_EQ(1u, erased); |
| 1322 } | 1310 } |
| 1323 | 1311 |
| 1324 } // namespace prerender | 1312 } // namespace prerender |
| OLD | NEW |