| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 "GET", | 70 "GET", |
| 71 "HEAD", | 71 "HEAD", |
| 72 "OPTIONS", | 72 "OPTIONS", |
| 73 "POST", | 73 "POST", |
| 74 "TRACE", | 74 "TRACE", |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // Length of prerender history, for display in chrome://net-internals | 77 // Length of prerender history, for display in chrome://net-internals |
| 78 const int kHistoryLength = 100; | 78 const int kHistoryLength = 100; |
| 79 | 79 |
| 80 // Indicates whether a Prerender has been cancelled such that we need |
| 81 // a dummy replacement for the purpose of recording the correct PPLT for |
| 82 // the Match Complete case. |
| 83 |
| 84 bool NeedMatchCompleteDummyForFinalStatus(FinalStatus final_status) { |
| 85 return final_status != FINAL_STATUS_USED && |
| 86 final_status != FINAL_STATUS_TIMED_OUT && |
| 87 final_status != FINAL_STATUS_EVICTED && |
| 88 final_status != FINAL_STATUS_MANAGER_SHUTDOWN && |
| 89 final_status != FINAL_STATUS_APP_TERMINATING && |
| 90 final_status != FINAL_STATUS_RENDERER_CRASHED && |
| 91 final_status != FINAL_STATUS_WINDOW_OPENER && |
| 92 final_status != FINAL_STATUS_FRAGMENT_MISMATCH && |
| 93 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED && |
| 94 final_status != FINAL_STATUS_CANCELLED && |
| 95 final_status != FINAL_STATUS_MATCH_COMPLETE_DUMMY; |
| 96 } |
| 97 |
| 80 } // namespace | 98 } // namespace |
| 81 | 99 |
| 82 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate { | 100 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate { |
| 83 public: | 101 public: |
| 84 OnCloseTabContentsDeleter(PrerenderManager* manager, | 102 OnCloseTabContentsDeleter(PrerenderManager* manager, |
| 85 TabContentsWrapper* tab) | 103 TabContentsWrapper* tab) |
| 86 : manager_(manager), | 104 : manager_(manager), |
| 87 tab_(tab) { | 105 tab_(tab) { |
| 88 tab_->tab_contents()->set_delegate(this); | 106 tab_->tab_contents()->set_delegate(this); |
| 89 } | 107 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 141 |
| 124 // static | 142 // static |
| 125 bool PrerenderManager::IsPrerenderingPossible() { | 143 bool PrerenderManager::IsPrerenderingPossible() { |
| 126 return GetMode() == PRERENDER_MODE_ENABLED || | 144 return GetMode() == PRERENDER_MODE_ENABLED || |
| 127 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP || | 145 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP || |
| 128 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || | 146 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || |
| 129 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 147 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 130 } | 148 } |
| 131 | 149 |
| 132 // static | 150 // static |
| 151 bool PrerenderManager::ActuallyPrerendering() { |
| 152 return IsPrerenderingPossible() && !IsControlGroup(); |
| 153 } |
| 154 |
| 155 // static |
| 133 bool PrerenderManager::IsControlGroup() { | 156 bool PrerenderManager::IsControlGroup() { |
| 134 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; | 157 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; |
| 135 } | 158 } |
| 136 | 159 |
| 137 // static | 160 // static |
| 138 bool PrerenderManager::IsNoUseGroup() { | 161 bool PrerenderManager::IsNoUseGroup() { |
| 139 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 162 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 140 } | 163 } |
| 141 | 164 |
| 142 // static | 165 // static |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 // No unload handler to run, so delete asap. | 671 // No unload handler to run, so delete asap. |
| 649 ScheduleDeleteOldTabContents(old_tab_contents, NULL); | 672 ScheduleDeleteOldTabContents(old_tab_contents, NULL); |
| 650 } | 673 } |
| 651 | 674 |
| 652 // TODO(cbentzel): Should prerender_contents move to the pending delete | 675 // TODO(cbentzel): Should prerender_contents move to the pending delete |
| 653 // list, instead of deleting directly here? | 676 // list, instead of deleting directly here? |
| 654 AddToHistory(prerender_contents.get()); | 677 AddToHistory(prerender_contents.get()); |
| 655 return true; | 678 return true; |
| 656 } | 679 } |
| 657 | 680 |
| 658 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry) { | 681 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry, |
| 682 FinalStatus final_status) { |
| 659 DCHECK(CalledOnValidThread()); | 683 DCHECK(CalledOnValidThread()); |
| 684 DCHECK(entry); |
| 660 DCHECK(!IsPendingDelete(entry)); | 685 DCHECK(!IsPendingDelete(entry)); |
| 686 |
| 661 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); | 687 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); |
| 662 it != prerender_list_.end(); | 688 it != prerender_list_.end(); |
| 663 ++it) { | 689 ++it) { |
| 664 if (it->contents_ == entry) { | 690 if (it->contents_ == entry) { |
| 665 prerender_list_.erase(it); | 691 bool swapped_in_dummy_replacement = false; |
| 692 |
| 693 // If this PrerenderContents is being deleted due to a cancellation, |
| 694 // we need to create a dummy replacement for PPLT accounting purposes |
| 695 // for the Match Complete group. |
| 696 // This is the case if the cancellation is for any reason that would not |
| 697 // occur in the control group case. |
| 698 if (NeedMatchCompleteDummyForFinalStatus(final_status)) { |
| 699 // TODO(tburkard): I'd like to DCHECK that we are actually prerendering. |
| 700 // However, what if new conditions are added and |
| 701 // NeedMatchCompleteDummyForFinalStatus, is not being updated. Not sure |
| 702 // what's the best thing to do here. For now, I will just check whether |
| 703 // we are actually prerendering. |
| 704 if (ActuallyPrerendering()) { |
| 705 PrerenderContents* dummy_replacement_prerender_contents = |
| 706 CreatePrerenderContents( |
| 707 entry->prerender_url(), |
| 708 entry->referrer(), |
| 709 entry->origin(), |
| 710 entry->experiment_id()); |
| 711 if (dummy_replacement_prerender_contents && |
| 712 dummy_replacement_prerender_contents->Init()) { |
| 713 it->contents_ = dummy_replacement_prerender_contents; |
| 714 it->contents_->set_final_status(FINAL_STATUS_MATCH_COMPLETE_DUMMY); |
| 715 swapped_in_dummy_replacement = true; |
| 716 } |
| 717 } |
| 718 } |
| 719 if (!swapped_in_dummy_replacement) |
| 720 prerender_list_.erase(it); |
| 666 break; | 721 break; |
| 667 } | 722 } |
| 668 } | 723 } |
| 669 AddToHistory(entry); | 724 AddToHistory(entry); |
| 670 pending_delete_list_.push_back(entry); | 725 pending_delete_list_.push_back(entry); |
| 671 | 726 |
| 672 // Destroy the old TabContents relatively promptly to reduce resource usage, | 727 // Destroy the old TabContents relatively promptly to reduce resource usage, |
| 673 // and in the case of HTML5 media, reduce the change of playing any sound. | 728 // and in the case of HTML5 media, reduce the change of playing any sound. |
| 674 PostCleanupTask(); | 729 PostCleanupTask(); |
| 675 } | 730 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 const GURL& url) { | 782 const GURL& url) { |
| 728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 729 PrerenderManager* prerender_manager = | 784 PrerenderManager* prerender_manager = |
| 730 PrerenderManagerFactory::GetForProfile( | 785 PrerenderManagerFactory::GetForProfile( |
| 731 Profile::FromBrowserContext(tab_contents->browser_context())); | 786 Profile::FromBrowserContext(tab_contents->browser_context())); |
| 732 if (!prerender_manager) | 787 if (!prerender_manager) |
| 733 return; | 788 return; |
| 734 if (!prerender_manager->is_enabled()) | 789 if (!prerender_manager->is_enabled()) |
| 735 return; | 790 return; |
| 736 bool was_prerender = | 791 bool was_prerender = |
| 737 ((mode_ == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP && | 792 prerender_manager->IsTabContentsPrerendered(tab_contents); |
| 738 prerender_manager->WouldTabContentsBePrerendered(tab_contents)) || | 793 bool was_complete_prerender = was_prerender || |
| 739 (mode_ == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP && | 794 prerender_manager->WouldTabContentsBePrerendered(tab_contents); |
| 740 prerender_manager->IsTabContentsPrerendered(tab_contents))); | |
| 741 prerender_manager->histograms_->RecordPerceivedPageLoadTime( | 795 prerender_manager->histograms_->RecordPerceivedPageLoadTime( |
| 742 perceived_page_load_time, was_prerender, url); | 796 perceived_page_load_time, was_prerender, was_complete_prerender, url); |
| 743 } | 797 } |
| 744 | 798 |
| 745 bool PrerenderManager::is_enabled() const { | 799 bool PrerenderManager::is_enabled() const { |
| 746 DCHECK(CalledOnValidThread()); | 800 DCHECK(CalledOnValidThread()); |
| 747 if (!enabled_) | 801 if (!enabled_) |
| 748 return false; | 802 return false; |
| 749 for (std::list<const PrerenderCondition*>::const_iterator it = | 803 for (std::list<const PrerenderCondition*>::const_iterator it = |
| 750 prerender_conditions_.begin(); | 804 prerender_conditions_.begin(); |
| 751 it != prerender_conditions_.end(); | 805 it != prerender_conditions_.end(); |
| 752 ++it) { | 806 ++it) { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 if (!render_process_host || !render_process_host->browser_context()) | 1120 if (!render_process_host || !render_process_host->browser_context()) |
| 1067 return NULL; | 1121 return NULL; |
| 1068 Profile* profile = Profile::FromBrowserContext( | 1122 Profile* profile = Profile::FromBrowserContext( |
| 1069 render_process_host->browser_context()); | 1123 render_process_host->browser_context()); |
| 1070 if (!profile) | 1124 if (!profile) |
| 1071 return NULL; | 1125 return NULL; |
| 1072 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1126 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
| 1073 } | 1127 } |
| 1074 | 1128 |
| 1075 } // namespace prerender | 1129 } // namespace prerender |
| OLD | NEW |