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_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 | 406 |
| 407 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( | 407 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( |
| 408 const GURL& url, | 408 const GURL& url, |
| 409 content::SessionStorageNamespace* session_storage_namespace, | 409 content::SessionStorageNamespace* session_storage_namespace, |
| 410 const gfx::Size& size) { | 410 const gfx::Size& size) { |
| 411 DCHECK(chrome::ShouldPrefetchSearchResults()); | 411 DCHECK(chrome::ShouldPrefetchSearchResults()); |
| 412 return AddPrerender(ORIGIN_INSTANT, -1, url, content::Referrer(), size, | 412 return AddPrerender(ORIGIN_INSTANT, -1, url, content::Referrer(), size, |
| 413 session_storage_namespace); | 413 session_storage_namespace); |
| 414 } | 414 } |
| 415 | 415 |
| 416 void PrerenderManager::DestroyPrerenderForRenderView( | |
| 417 int process_id, int view_id, FinalStatus final_status) { | |
| 418 DCHECK(CalledOnValidThread()); | |
| 419 if (PrerenderData* prerender_data = | |
| 420 FindPrerenderDataForChildAndRoute(process_id, view_id)) { | |
| 421 prerender_data->contents()->Destroy(final_status); | |
| 422 } | |
| 423 } | |
| 424 | |
| 425 void PrerenderManager::CancelAllPrerenders() { | 416 void PrerenderManager::CancelAllPrerenders() { |
| 426 DCHECK(CalledOnValidThread()); | 417 DCHECK(CalledOnValidThread()); |
| 427 while (!active_prerenders_.empty()) { | 418 while (!active_prerenders_.empty()) { |
| 428 PrerenderContents* prerender_contents = | 419 PrerenderContents* prerender_contents = |
| 429 active_prerenders_.front()->contents(); | 420 active_prerenders_.front()->contents(); |
| 430 prerender_contents->Destroy(FINAL_STATUS_CANCELLED); | 421 prerender_contents->Destroy(FINAL_STATUS_CANCELLED); |
| 431 } | 422 } |
| 432 } | 423 } |
| 433 | 424 |
| 434 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url, | 425 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 MarkWebContentsAsWouldBePrerendered(web_contents, | 584 MarkWebContentsAsWouldBePrerendered(web_contents, |
| 594 prerender_data->contents()->origin()); | 585 prerender_data->contents()->origin()); |
| 595 prerender_data->contents()->Destroy(FINAL_STATUS_WOULD_HAVE_BEEN_USED); | 586 prerender_data->contents()->Destroy(FINAL_STATUS_WOULD_HAVE_BEEN_USED); |
| 596 return NULL; | 587 return NULL; |
| 597 } | 588 } |
| 598 | 589 |
| 599 int child_id, route_id; | 590 int child_id, route_id; |
| 600 CHECK(prerender_data->contents()->GetChildId(&child_id)); | 591 CHECK(prerender_data->contents()->GetChildId(&child_id)); |
| 601 CHECK(prerender_data->contents()->GetRouteId(&route_id)); | 592 CHECK(prerender_data->contents()->GetRouteId(&route_id)); |
| 602 | 593 |
| 603 // Try to set the prerendered page as used, so any subsequent attempts to | |
| 604 // cancel on other threads will fail. If this fails because the prerender | |
| 605 // was already cancelled, possibly on another thread, fail. | |
| 606 if (!prerender_tracker_->TryUse(child_id, route_id)) | |
| 607 return NULL; | |
| 608 | |
| 609 // At this point, we've determined that we will use the prerender. | 594 // At this point, we've determined that we will use the prerender. |
| 610 if (prerender_data->pending_swap()) | 595 if (prerender_data->pending_swap()) |
| 611 prerender_data->pending_swap()->set_swap_successful(true); | 596 prerender_data->pending_swap()->set_swap_successful(true); |
| 612 ScopedVector<PrerenderData>::iterator to_erase = | 597 ScopedVector<PrerenderData>::iterator to_erase = |
| 613 FindIteratorForPrerenderContents(prerender_data->contents()); | 598 FindIteratorForPrerenderContents(prerender_data->contents()); |
| 614 DCHECK(active_prerenders_.end() != to_erase); | 599 DCHECK(active_prerenders_.end() != to_erase); |
| 615 DCHECK_EQ(prerender_data, *to_erase); | 600 DCHECK_EQ(prerender_data, *to_erase); |
| 616 scoped_ptr<PrerenderContents> | 601 scoped_ptr<PrerenderContents> |
| 617 prerender_contents(prerender_data->ReleaseContents()); | 602 prerender_contents(prerender_data->ReleaseContents()); |
| 618 active_prerenders_.erase(to_erase); | 603 active_prerenders_.erase(to_erase); |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1274 } | 1259 } |
| 1275 | 1260 |
| 1276 if (result != SessionStorageNamespace::MERGE_RESULT_MERGEABLE && | 1261 if (result != SessionStorageNamespace::MERGE_RESULT_MERGEABLE && |
| 1277 result != SessionStorageNamespace::MERGE_RESULT_NO_TRANSACTIONS) { | 1262 result != SessionStorageNamespace::MERGE_RESULT_NO_TRANSACTIONS) { |
| 1278 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_MERGE_FAILED); | 1263 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_MERGE_FAILED); |
| 1279 prerender_data_->ClearPendingSwap(); | 1264 prerender_data_->ClearPendingSwap(); |
| 1280 return; | 1265 return; |
| 1281 } | 1266 } |
| 1282 | 1267 |
| 1283 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_SWAPPING_IN); | 1268 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_SWAPPING_IN); |
| 1284 // Note that SwapInternal, on success, will delete |prerender_data_| and | 1269 |
| 1285 // |this|. Pass in a new GURL object rather than a reference to |url_|. | 1270 WebContents* new_web_contents = NULL; |
| 1286 // | 1271 // Ensure that the prerendering hasn't been destroyed in the meantime. |
| 1287 // TODO(davidben): See about deleting PrerenderData asynchronously so this | 1272 if (prerender_data_->contents()->final_status() == FINAL_STATUS_MAX) { |
|
tburkard
2014/01/10 06:14:03
Why is this check necessary?
I assume because you
jam
2014/01/10 07:45:00
Yep
tburkard
2014/01/10 09:57:12
So, when PrerenderData is destroyed, PendingSwaped
tburkard
2014/01/10 10:06:14
sorry, in the comment above, "line 845" should be
jam
2014/01/10 15:56:08
I agree that the way you describe is easier to rea
davidben
2014/01/10 16:03:09
I think I had to remove it there because SwapInter
jam
2014/01/10 16:24:09
hmm, since I'm not familiar with this code, I will
| |
| 1288 // behavior is more reasonable. | 1273 // Note that SwapInternal, on success, will delete |prerender_data_| and |
| 1289 WebContents* new_web_contents = | 1274 // |this|. Pass in a new GURL object rather than a reference to |url_|. |
| 1290 manager_->SwapInternal(GURL(url_), target_contents_, prerender_data_, | 1275 // |
| 1291 should_replace_current_entry_); | 1276 // TODO(davidben): See about deleting PrerenderData asynchronously so this |
| 1277 // behavior is more reasonable. | |
| 1278 | |
| 1279 new_web_contents = manager_->SwapInternal( | |
| 1280 GURL(url_), target_contents_, prerender_data_, | |
| 1281 should_replace_current_entry_); | |
| 1282 } | |
| 1283 | |
| 1292 if (!new_web_contents) { | 1284 if (!new_web_contents) { |
| 1293 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_SWAPIN_FAILED); | 1285 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_SWAPIN_FAILED); |
| 1294 prerender_data_->ClearPendingSwap(); | 1286 prerender_data_->ClearPendingSwap(); |
| 1295 } | 1287 } |
| 1296 } | 1288 } |
| 1297 | 1289 |
| 1298 void PrerenderManager::PendingSwap::OnMergeTimeout() { | 1290 void PrerenderManager::PendingSwap::OnMergeTimeout() { |
| 1299 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_TIMED_OUT); | 1291 RecordEvent(PRERENDER_EVENT_MERGE_RESULT_TIMED_OUT); |
| 1300 prerender_data_->ClearPendingSwap(); | 1292 prerender_data_->ClearPendingSwap(); |
| 1301 } | 1293 } |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1867 void PrerenderManager::RecordEvent(PrerenderContents* contents, | 1859 void PrerenderManager::RecordEvent(PrerenderContents* contents, |
| 1868 PrerenderEvent event) const { | 1860 PrerenderEvent event) const { |
| 1869 if (!contents) | 1861 if (!contents) |
| 1870 histograms_->RecordEvent(ORIGIN_NONE, kNoExperiment, event); | 1862 histograms_->RecordEvent(ORIGIN_NONE, kNoExperiment, event); |
| 1871 else | 1863 else |
| 1872 histograms_->RecordEvent(contents->origin(), contents->experiment_id(), | 1864 histograms_->RecordEvent(contents->origin(), contents->experiment_id(), |
| 1873 event); | 1865 event); |
| 1874 } | 1866 } |
| 1875 | 1867 |
| 1876 } // namespace prerender | 1868 } // namespace prerender |
| OLD | NEW |