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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 123 |
124 // static | 124 // static |
125 bool PrerenderManager::IsPrerenderingPossible() { | 125 bool PrerenderManager::IsPrerenderingPossible() { |
126 return GetMode() == PRERENDER_MODE_ENABLED || | 126 return GetMode() == PRERENDER_MODE_ENABLED || |
127 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP || | 127 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP || |
128 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || | 128 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || |
129 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 129 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
130 } | 130 } |
131 | 131 |
132 // static | 132 // static |
133 bool PrerenderManager::ActuallyPrerendering() { | |
134 return IsPrerenderingPossible() && !IsControlGroup(); | |
135 } | |
136 | |
137 // static | |
133 bool PrerenderManager::IsControlGroup() { | 138 bool PrerenderManager::IsControlGroup() { |
134 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; | 139 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; |
135 } | 140 } |
136 | 141 |
137 // static | 142 // static |
138 bool PrerenderManager::IsValidHttpMethod(const std::string& method) { | 143 bool PrerenderManager::IsValidHttpMethod(const std::string& method) { |
139 // method has been canonicalized to upper case at this point so we can just | 144 // method has been canonicalized to upper case at this point so we can just |
140 // compare them. | 145 // compare them. |
141 DCHECK_EQ(method, StringToUpperASCII(method)); | 146 DCHECK_EQ(method, StringToUpperASCII(method)); |
142 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { | 147 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 // No unload handler to run, so delete asap. | 645 // No unload handler to run, so delete asap. |
641 ScheduleDeleteOldTabContents(old_tab_contents, NULL); | 646 ScheduleDeleteOldTabContents(old_tab_contents, NULL); |
642 } | 647 } |
643 | 648 |
644 // TODO(cbentzel): Should prerender_contents move to the pending delete | 649 // TODO(cbentzel): Should prerender_contents move to the pending delete |
645 // list, instead of deleting directly here? | 650 // list, instead of deleting directly here? |
646 AddToHistory(prerender_contents.get()); | 651 AddToHistory(prerender_contents.get()); |
647 return true; | 652 return true; |
648 } | 653 } |
649 | 654 |
650 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry) { | 655 bool PrerenderManager::NeedMatchCompleteDummyForFinalStatus( |
dominich
2011/11/11 20:53:46
This doesn't need to be a member of a PrerenderMan
tburkard
2011/11/11 21:50:07
Done.
| |
656 FinalStatus final_status) const { | |
657 return final_status != FINAL_STATUS_USED && | |
658 final_status != FINAL_STATUS_TIMED_OUT && | |
659 final_status != FINAL_STATUS_EVICTED && | |
660 final_status != FINAL_STATUS_MANAGER_SHUTDOWN && | |
661 final_status != FINAL_STATUS_WINDOW_OPENER && | |
662 final_status != FINAL_STATUS_FRAGMENT_MISMATCH && | |
663 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED && | |
664 final_status != FINAL_STATUS_CANCELLED && | |
665 final_status != FINAL_STATUS_MATCH_COMPLETE_DUMMY; | |
666 } | |
667 | |
668 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry, | |
669 FinalStatus final_status) { | |
651 DCHECK(CalledOnValidThread()); | 670 DCHECK(CalledOnValidThread()); |
671 DCHECK(entry); | |
652 DCHECK(!IsPendingDelete(entry)); | 672 DCHECK(!IsPendingDelete(entry)); |
673 | |
653 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); | 674 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); |
654 it != prerender_list_.end(); | 675 it != prerender_list_.end(); |
655 ++it) { | 676 ++it) { |
656 if (it->contents_ == entry) { | 677 if (it->contents_ == entry) { |
657 prerender_list_.erase(it); | 678 bool swapped_in_dummy_replacement = false; |
679 | |
680 // If this PrerenderContents is being deleted due to a cancellation, | |
681 // we need to create a dummy replacement for PPLT accounting purposes | |
682 // for the Match Complete group. | |
683 // This is the case if the cancellation is for any reason that would not | |
684 // occur in the control group case. | |
685 if (NeedMatchCompleteDummyForFinalStatus(final_status)) { | |
686 // TODO(tburkard): I'd like to DCHECK that we are actually prerendering. | |
687 // However, what if new conditions are added and | |
688 // NeedMatchCompleteDummyForFinalStatus, is not being updated. Not sure | |
689 // what's the best thing to do here. For now, I will just check whether | |
690 // we are actually prerendering. | |
691 if (ActuallyPrerendering()) { | |
692 PrerenderContents* dummy_replacement_prerender_contents = | |
693 CreatePrerenderContents( | |
dominich
2011/11/11 20:53:46
Instead of exposing these internals (referrer, exp
tburkard
2011/11/11 21:50:07
Since we will likely remove this again, I will lea
| |
694 entry->prerender_url(), | |
695 entry->referrer(), | |
696 entry->origin(), | |
697 entry->experiment_id()); | |
698 if (dummy_replacement_prerender_contents && | |
699 dummy_replacement_prerender_contents->Init()) { | |
dominich
2011/11/11 20:53:46
If Init fails here you should delete dummy_replace
tburkard
2011/11/11 21:50:07
Didn't we talk about this in the previous iteratio
| |
700 it->contents_ = dummy_replacement_prerender_contents; | |
701 it->contents_->set_final_status(FINAL_STATUS_MATCH_COMPLETE_DUMMY); | |
702 swapped_in_dummy_replacement = true; | |
703 } | |
704 } | |
705 } | |
706 if (!swapped_in_dummy_replacement) | |
707 prerender_list_.erase(it); | |
658 break; | 708 break; |
659 } | 709 } |
660 } | 710 } |
661 AddToHistory(entry); | 711 AddToHistory(entry); |
662 pending_delete_list_.push_back(entry); | 712 pending_delete_list_.push_back(entry); |
663 | 713 |
664 // Destroy the old TabContents relatively promptly to reduce resource usage, | 714 // Destroy the old TabContents relatively promptly to reduce resource usage, |
665 // and in the case of HTML5 media, reduce the change of playing any sound. | 715 // and in the case of HTML5 media, reduce the change of playing any sound. |
666 PostCleanupTask(); | 716 PostCleanupTask(); |
667 } | 717 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 const GURL& url) { | 769 const GURL& url) { |
720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
721 PrerenderManager* prerender_manager = | 771 PrerenderManager* prerender_manager = |
722 PrerenderManagerFactory::GetForProfile( | 772 PrerenderManagerFactory::GetForProfile( |
723 Profile::FromBrowserContext(tab_contents->browser_context())); | 773 Profile::FromBrowserContext(tab_contents->browser_context())); |
724 if (!prerender_manager) | 774 if (!prerender_manager) |
725 return; | 775 return; |
726 if (!prerender_manager->is_enabled()) | 776 if (!prerender_manager->is_enabled()) |
727 return; | 777 return; |
728 bool was_prerender = | 778 bool was_prerender = |
729 ((mode_ == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP && | 779 prerender_manager->IsTabContentsPrerendered(tab_contents); |
730 prerender_manager->WouldTabContentsBePrerendered(tab_contents)) || | 780 bool was_complete_prerender = was_prerender || |
731 (mode_ == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP && | 781 prerender_manager->WouldTabContentsBePrerendered(tab_contents); |
732 prerender_manager->IsTabContentsPrerendered(tab_contents))); | |
733 prerender_manager->histograms_->RecordPerceivedPageLoadTime( | 782 prerender_manager->histograms_->RecordPerceivedPageLoadTime( |
734 perceived_page_load_time, was_prerender, url); | 783 perceived_page_load_time, was_prerender, was_complete_prerender, url); |
735 } | 784 } |
736 | 785 |
737 bool PrerenderManager::is_enabled() const { | 786 bool PrerenderManager::is_enabled() const { |
738 DCHECK(CalledOnValidThread()); | 787 DCHECK(CalledOnValidThread()); |
739 if (!enabled_) | 788 if (!enabled_) |
740 return false; | 789 return false; |
741 for (std::list<const PrerenderCondition*>::const_iterator it = | 790 for (std::list<const PrerenderCondition*>::const_iterator it = |
742 prerender_conditions_.begin(); | 791 prerender_conditions_.begin(); |
743 it != prerender_conditions_.end(); | 792 it != prerender_conditions_.end(); |
744 ++it) { | 793 ++it) { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1045 if (!render_process_host || !render_process_host->browser_context()) | 1094 if (!render_process_host || !render_process_host->browser_context()) |
1046 return NULL; | 1095 return NULL; |
1047 Profile* profile = Profile::FromBrowserContext( | 1096 Profile* profile = Profile::FromBrowserContext( |
1048 render_process_host->browser_context()); | 1097 render_process_host->browser_context()); |
1049 if (!profile) | 1098 if (!profile) |
1050 return NULL; | 1099 return NULL; |
1051 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1100 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1052 } | 1101 } |
1053 | 1102 |
1054 } // namespace prerender | 1103 } // namespace prerender |
OLD | NEW |