OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 // Don't prerender page if parent RenderViewHost no longer exists, or it has | 277 // Don't prerender page if parent RenderViewHost no longer exists, or it has |
278 // no view. The latter should only happen when the RenderView has closed. | 278 // no view. The latter should only happen when the RenderView has closed. |
279 if (!source_render_view_host || !source_render_view_host->view()) { | 279 if (!source_render_view_host || !source_render_view_host->view()) { |
280 RecordFinalStatus(FINAL_STATUS_SOURCE_RENDER_VIEW_CLOSED); | 280 RecordFinalStatus(FINAL_STATUS_SOURCE_RENDER_VIEW_CLOSED); |
281 return false; | 281 return false; |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 PrerenderContents* prerender_contents = | 285 PrerenderContents* prerender_contents = |
286 CreatePrerenderContents(url, referrer); | 286 CreatePrerenderContents(url, referrer); |
287 if (!prerender_contents || !prerender_contents->Init()) | 287 if (!prerender_contents) |
288 return false; | 288 return false; |
289 | 289 |
290 // TODO(cbentzel): Move invalid checks here instead of PrerenderContents? | 290 // TODO(cbentzel): Move invalid checks here instead of PrerenderContents? |
291 PrerenderContentsData data(prerender_contents, GetCurrentTime()); | 291 PrerenderContentsData data(prerender_contents, GetCurrentTime()); |
292 prerender_list_.push_back(data); | |
292 | 293 |
293 prerender_list_.push_back(data); | 294 if (!prerender_contents->Init()) |
295 return false; | |
296 | |
294 if (IsControlGroup()) { | 297 if (IsControlGroup()) { |
295 data.contents_->set_final_status(FINAL_STATUS_CONTROL_GROUP); | 298 data.contents_->set_final_status(FINAL_STATUS_CONTROL_GROUP); |
296 } else { | 299 } else { |
297 last_prerender_start_time_ = GetCurrentTimeTicks(); | 300 last_prerender_start_time_ = GetCurrentTimeTicks(); |
298 data.contents_->StartPrerendering(source_render_view_host); | 301 data.contents_->StartPrerendering(source_render_view_host); |
299 } | 302 } |
300 while (prerender_list_.size() > max_elements_) { | 303 while (prerender_list_.size() > max_elements_) { |
301 data = prerender_list_.front(); | 304 data = prerender_list_.front(); |
302 prerender_list_.pop_front(); | 305 prerender_list_.pop_front(); |
303 data.contents_->Destroy(FINAL_STATUS_EVICTED); | 306 data.contents_->Destroy(FINAL_STATUS_EVICTED); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 } | 570 } |
568 pending_prerender_list_.erase(pending_it); | 571 pending_prerender_list_.erase(pending_it); |
569 } | 572 } |
570 | 573 |
571 old_tab_contents_list_.push_back(old_tab_contents); | 574 old_tab_contents_list_.push_back(old_tab_contents); |
572 // Destroy the old TabContents relatively promptly to reduce resource usage. | 575 // Destroy the old TabContents relatively promptly to reduce resource usage. |
573 PostCleanupTask(); | 576 PostCleanupTask(); |
574 return true; | 577 return true; |
575 } | 578 } |
576 | 579 |
577 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry) { | 580 bool PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry) { |
578 DCHECK(CalledOnValidThread()); | 581 DCHECK(CalledOnValidThread()); |
579 DCHECK(!IsPendingDelete(entry)); | 582 DCHECK(!IsPendingDelete(entry)); |
580 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); | 583 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); |
581 it != prerender_list_.end(); | 584 it != prerender_list_.end(); |
582 ++it) { | 585 ++it) { |
583 if (it->contents_ == entry) { | 586 if (it->contents_ == entry) { |
584 RemovePendingPreload(entry); | 587 RemovePendingPreload(entry); |
585 prerender_list_.erase(it); | 588 prerender_list_.erase(it); |
586 break; | 589 pending_delete_list_.push_back(entry); |
Shishir
2011/05/18 18:34:32
I had initially pushed this outside the loop becau
mmenke
2011/05/18 18:50:37
Ok... Seems like the simplest way to do this robu
| |
590 | |
591 // Destroy the old TabContents relatively promptly to reduce resource | |
592 // usage, and in the case of HTML5 media, reduce the chance of playing | |
593 // any sound. | |
594 PostCleanupTask(); | |
595 | |
596 return true; | |
587 } | 597 } |
588 } | 598 } |
589 pending_delete_list_.push_back(entry); | 599 return false; |
590 | |
591 // Destroy the old TabContents relatively promptly to reduce resource usage, | |
592 // and in the case of HTML5 media, reduce the change of playing any sound. | |
593 PostCleanupTask(); | |
594 } | 600 } |
595 | 601 |
596 bool PrerenderManager::IsPendingDelete(PrerenderContents* entry) const { | 602 bool PrerenderManager::IsPendingDelete(PrerenderContents* entry) const { |
597 DCHECK(CalledOnValidThread()); | 603 DCHECK(CalledOnValidThread()); |
598 for (std::list<PrerenderContents*>::const_iterator it = | 604 for (std::list<PrerenderContents*>::const_iterator it = |
599 pending_delete_list_.begin(); | 605 pending_delete_list_.begin(); |
600 it != pending_delete_list_.end(); | 606 it != pending_delete_list_.end(); |
601 ++it) { | 607 ++it) { |
602 if (*it == entry) | 608 if (*it == entry) |
603 return true; | 609 return true; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 return prerendered_tab_contents_set_.count(tab_contents) > 0; | 918 return prerendered_tab_contents_set_.count(tab_contents) > 0; |
913 } | 919 } |
914 | 920 |
915 bool PrerenderManager::WouldTabContentsBePrerendered( | 921 bool PrerenderManager::WouldTabContentsBePrerendered( |
916 TabContents* tab_contents) const { | 922 TabContents* tab_contents) const { |
917 DCHECK(CalledOnValidThread()); | 923 DCHECK(CalledOnValidThread()); |
918 return would_be_prerendered_tab_contents_set_.count(tab_contents) > 0; | 924 return would_be_prerendered_tab_contents_set_.count(tab_contents) > 0; |
919 } | 925 } |
920 | 926 |
921 } // namespace prerender | 927 } // namespace prerender |
OLD | NEW |