Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: chrome/browser/prerender/prerender_manager.cc

Issue 8503040: Prerendering: Add MatchComplete PPLT (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_WINDOW_OPENER &&
90 final_status != FINAL_STATUS_FRAGMENT_MISMATCH &&
91 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED &&
92 final_status != FINAL_STATUS_CANCELLED &&
93 final_status != FINAL_STATUS_MATCH_COMPLETE_DUMMY;
94 }
95
80 } // namespace 96 } // namespace
81 97
82 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate { 98 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate {
83 public: 99 public:
84 OnCloseTabContentsDeleter(PrerenderManager* manager, 100 OnCloseTabContentsDeleter(PrerenderManager* manager,
85 TabContentsWrapper* tab) 101 TabContentsWrapper* tab)
86 : manager_(manager), 102 : manager_(manager),
87 tab_(tab) { 103 tab_(tab) {
88 tab_->tab_contents()->set_delegate(this); 104 tab_->tab_contents()->set_delegate(this);
89 } 105 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 139
124 // static 140 // static
125 bool PrerenderManager::IsPrerenderingPossible() { 141 bool PrerenderManager::IsPrerenderingPossible() {
126 return GetMode() == PRERENDER_MODE_ENABLED || 142 return GetMode() == PRERENDER_MODE_ENABLED ||
127 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP || 143 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP ||
128 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || 144 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP ||
129 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; 145 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP;
130 } 146 }
131 147
132 // static 148 // static
149 bool PrerenderManager::ActuallyPrerendering() {
150 return IsPrerenderingPossible() && !IsControlGroup();
151 }
152
153 // static
133 bool PrerenderManager::IsControlGroup() { 154 bool PrerenderManager::IsControlGroup() {
134 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; 155 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP;
135 } 156 }
136 157
137 // static 158 // static
138 bool PrerenderManager::IsValidHttpMethod(const std::string& method) { 159 bool PrerenderManager::IsValidHttpMethod(const std::string& method) {
139 // method has been canonicalized to upper case at this point so we can just 160 // method has been canonicalized to upper case at this point so we can just
140 // compare them. 161 // compare them.
141 DCHECK_EQ(method, StringToUpperASCII(method)); 162 DCHECK_EQ(method, StringToUpperASCII(method));
142 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { 163 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) {
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 // No unload handler to run, so delete asap. 661 // No unload handler to run, so delete asap.
641 ScheduleDeleteOldTabContents(old_tab_contents, NULL); 662 ScheduleDeleteOldTabContents(old_tab_contents, NULL);
642 } 663 }
643 664
644 // TODO(cbentzel): Should prerender_contents move to the pending delete 665 // TODO(cbentzel): Should prerender_contents move to the pending delete
645 // list, instead of deleting directly here? 666 // list, instead of deleting directly here?
646 AddToHistory(prerender_contents.get()); 667 AddToHistory(prerender_contents.get());
647 return true; 668 return true;
648 } 669 }
649 670
650 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry) { 671 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry,
672 FinalStatus final_status) {
651 DCHECK(CalledOnValidThread()); 673 DCHECK(CalledOnValidThread());
674 DCHECK(entry);
652 DCHECK(!IsPendingDelete(entry)); 675 DCHECK(!IsPendingDelete(entry));
676
653 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); 677 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin();
654 it != prerender_list_.end(); 678 it != prerender_list_.end();
655 ++it) { 679 ++it) {
656 if (it->contents_ == entry) { 680 if (it->contents_ == entry) {
657 prerender_list_.erase(it); 681 bool swapped_in_dummy_replacement = false;
682
683 // If this PrerenderContents is being deleted due to a cancellation,
684 // we need to create a dummy replacement for PPLT accounting purposes
685 // for the Match Complete group.
686 // This is the case if the cancellation is for any reason that would not
687 // occur in the control group case.
688 if (NeedMatchCompleteDummyForFinalStatus(final_status)) {
689 // TODO(tburkard): I'd like to DCHECK that we are actually prerendering.
690 // However, what if new conditions are added and
691 // NeedMatchCompleteDummyForFinalStatus, is not being updated. Not sure
692 // what's the best thing to do here. For now, I will just check whether
693 // we are actually prerendering.
694 if (ActuallyPrerendering()) {
695 PrerenderContents* dummy_replacement_prerender_contents =
696 CreatePrerenderContents(
697 entry->prerender_url(),
698 entry->referrer(),
699 entry->origin(),
700 entry->experiment_id());
701 if (dummy_replacement_prerender_contents &&
702 dummy_replacement_prerender_contents->Init()) {
703 it->contents_ = dummy_replacement_prerender_contents;
704 it->contents_->set_final_status(FINAL_STATUS_MATCH_COMPLETE_DUMMY);
705 swapped_in_dummy_replacement = true;
706 }
707 }
708 }
709 if (!swapped_in_dummy_replacement)
710 prerender_list_.erase(it);
658 break; 711 break;
659 } 712 }
660 } 713 }
661 AddToHistory(entry); 714 AddToHistory(entry);
662 pending_delete_list_.push_back(entry); 715 pending_delete_list_.push_back(entry);
663 716
664 // Destroy the old TabContents relatively promptly to reduce resource usage, 717 // 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. 718 // and in the case of HTML5 media, reduce the change of playing any sound.
666 PostCleanupTask(); 719 PostCleanupTask();
667 } 720 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 const GURL& url) { 772 const GURL& url) {
720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
721 PrerenderManager* prerender_manager = 774 PrerenderManager* prerender_manager =
722 PrerenderManagerFactory::GetForProfile( 775 PrerenderManagerFactory::GetForProfile(
723 Profile::FromBrowserContext(tab_contents->browser_context())); 776 Profile::FromBrowserContext(tab_contents->browser_context()));
724 if (!prerender_manager) 777 if (!prerender_manager)
725 return; 778 return;
726 if (!prerender_manager->is_enabled()) 779 if (!prerender_manager->is_enabled())
727 return; 780 return;
728 bool was_prerender = 781 bool was_prerender =
729 ((mode_ == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP && 782 prerender_manager->IsTabContentsPrerendered(tab_contents);
730 prerender_manager->WouldTabContentsBePrerendered(tab_contents)) || 783 bool was_complete_prerender = was_prerender ||
731 (mode_ == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP && 784 prerender_manager->WouldTabContentsBePrerendered(tab_contents);
732 prerender_manager->IsTabContentsPrerendered(tab_contents)));
733 prerender_manager->histograms_->RecordPerceivedPageLoadTime( 785 prerender_manager->histograms_->RecordPerceivedPageLoadTime(
734 perceived_page_load_time, was_prerender, url); 786 perceived_page_load_time, was_prerender, was_complete_prerender, url);
735 } 787 }
736 788
737 bool PrerenderManager::is_enabled() const { 789 bool PrerenderManager::is_enabled() const {
738 DCHECK(CalledOnValidThread()); 790 DCHECK(CalledOnValidThread());
739 if (!enabled_) 791 if (!enabled_)
740 return false; 792 return false;
741 for (std::list<const PrerenderCondition*>::const_iterator it = 793 for (std::list<const PrerenderCondition*>::const_iterator it =
742 prerender_conditions_.begin(); 794 prerender_conditions_.begin();
743 it != prerender_conditions_.end(); 795 it != prerender_conditions_.end();
744 ++it) { 796 ++it) {
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 if (!render_process_host || !render_process_host->browser_context()) 1097 if (!render_process_host || !render_process_host->browser_context())
1046 return NULL; 1098 return NULL;
1047 Profile* profile = Profile::FromBrowserContext( 1099 Profile* profile = Profile::FromBrowserContext(
1048 render_process_host->browser_context()); 1100 render_process_host->browser_context());
1049 if (!profile) 1101 if (!profile)
1050 return NULL; 1102 return NULL;
1051 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); 1103 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile);
1052 } 1104 }
1053 1105
1054 } // namespace prerender 1106 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698