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

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

Issue 8540025: 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
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_APP_TERMINATING &&
90 final_status != FINAL_STATUS_WINDOW_OPENER &&
91 final_status != FINAL_STATUS_FRAGMENT_MISMATCH &&
92 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED &&
93 final_status != FINAL_STATUS_CANCELLED &&
94 final_status != FINAL_STATUS_MATCH_COMPLETE_DUMMY;
95 }
96
80 } // namespace 97 } // namespace
81 98
82 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate { 99 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate {
83 public: 100 public:
84 OnCloseTabContentsDeleter(PrerenderManager* manager, 101 OnCloseTabContentsDeleter(PrerenderManager* manager,
85 TabContentsWrapper* tab) 102 TabContentsWrapper* tab)
86 : manager_(manager), 103 : manager_(manager),
87 tab_(tab) { 104 tab_(tab) {
88 tab_->tab_contents()->set_delegate(this); 105 tab_->tab_contents()->set_delegate(this);
89 } 106 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 140
124 // static 141 // static
125 bool PrerenderManager::IsPrerenderingPossible() { 142 bool PrerenderManager::IsPrerenderingPossible() {
126 return GetMode() == PRERENDER_MODE_ENABLED || 143 return GetMode() == PRERENDER_MODE_ENABLED ||
127 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP || 144 GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP ||
128 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || 145 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP ||
129 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; 146 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP;
130 } 147 }
131 148
132 // static 149 // static
150 bool PrerenderManager::ActuallyPrerendering() {
151 return IsPrerenderingPossible() && !IsControlGroup();
152 }
153
154 // static
133 bool PrerenderManager::IsControlGroup() { 155 bool PrerenderManager::IsControlGroup() {
134 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; 156 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP;
135 } 157 }
136 158
137 // static 159 // static
138 bool PrerenderManager::IsValidHttpMethod(const std::string& method) { 160 bool PrerenderManager::IsValidHttpMethod(const std::string& method) {
139 // method has been canonicalized to upper case at this point so we can just 161 // method has been canonicalized to upper case at this point so we can just
140 // compare them. 162 // compare them.
141 DCHECK_EQ(method, StringToUpperASCII(method)); 163 DCHECK_EQ(method, StringToUpperASCII(method));
142 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { 164 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) {
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // No unload handler to run, so delete asap. 665 // No unload handler to run, so delete asap.
644 ScheduleDeleteOldTabContents(old_tab_contents, NULL); 666 ScheduleDeleteOldTabContents(old_tab_contents, NULL);
645 } 667 }
646 668
647 // TODO(cbentzel): Should prerender_contents move to the pending delete 669 // TODO(cbentzel): Should prerender_contents move to the pending delete
648 // list, instead of deleting directly here? 670 // list, instead of deleting directly here?
649 AddToHistory(prerender_contents.get()); 671 AddToHistory(prerender_contents.get());
650 return true; 672 return true;
651 } 673 }
652 674
653 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry) { 675 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry,
676 FinalStatus final_status) {
654 DCHECK(CalledOnValidThread()); 677 DCHECK(CalledOnValidThread());
678 DCHECK(entry);
655 DCHECK(!IsPendingDelete(entry)); 679 DCHECK(!IsPendingDelete(entry));
680
656 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); 681 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin();
657 it != prerender_list_.end(); 682 it != prerender_list_.end();
658 ++it) { 683 ++it) {
659 if (it->contents_ == entry) { 684 if (it->contents_ == entry) {
660 prerender_list_.erase(it); 685 bool swapped_in_dummy_replacement = false;
686
687 // If this PrerenderContents is being deleted due to a cancellation,
688 // we need to create a dummy replacement for PPLT accounting purposes
689 // for the Match Complete group.
690 // This is the case if the cancellation is for any reason that would not
691 // occur in the control group case.
692 if (NeedMatchCompleteDummyForFinalStatus(final_status)) {
693 // TODO(tburkard): I'd like to DCHECK that we are actually prerendering.
694 // However, what if new conditions are added and
695 // NeedMatchCompleteDummyForFinalStatus, is not being updated. Not sure
dominich 2011/11/12 00:02:49 You could change NeedMatchCompleteDummyForFinalSta
696 // what's the best thing to do here. For now, I will just check whether
697 // we are actually prerendering.
698 if (ActuallyPrerendering()) {
699 PrerenderContents* dummy_replacement_prerender_contents =
700 CreatePrerenderContents(
701 entry->prerender_url(),
702 entry->referrer(),
703 entry->origin(),
704 entry->experiment_id());
705 if (dummy_replacement_prerender_contents &&
706 dummy_replacement_prerender_contents->Init()) {
707 it->contents_ = dummy_replacement_prerender_contents;
708 it->contents_->set_final_status(FINAL_STATUS_MATCH_COMPLETE_DUMMY);
709 swapped_in_dummy_replacement = true;
710 }
711 }
712 }
713 if (!swapped_in_dummy_replacement)
714 prerender_list_.erase(it);
661 break; 715 break;
662 } 716 }
663 } 717 }
664 AddToHistory(entry); 718 AddToHistory(entry);
665 pending_delete_list_.push_back(entry); 719 pending_delete_list_.push_back(entry);
666 720
667 // Destroy the old TabContents relatively promptly to reduce resource usage, 721 // Destroy the old TabContents relatively promptly to reduce resource usage,
668 // and in the case of HTML5 media, reduce the change of playing any sound. 722 // and in the case of HTML5 media, reduce the change of playing any sound.
669 PostCleanupTask(); 723 PostCleanupTask();
670 } 724 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 const GURL& url) { 776 const GURL& url) {
723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
724 PrerenderManager* prerender_manager = 778 PrerenderManager* prerender_manager =
725 PrerenderManagerFactory::GetForProfile( 779 PrerenderManagerFactory::GetForProfile(
726 Profile::FromBrowserContext(tab_contents->browser_context())); 780 Profile::FromBrowserContext(tab_contents->browser_context()));
727 if (!prerender_manager) 781 if (!prerender_manager)
728 return; 782 return;
729 if (!prerender_manager->is_enabled()) 783 if (!prerender_manager->is_enabled())
730 return; 784 return;
731 bool was_prerender = 785 bool was_prerender =
732 ((mode_ == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP && 786 prerender_manager->IsTabContentsPrerendered(tab_contents);
733 prerender_manager->WouldTabContentsBePrerendered(tab_contents)) || 787 bool was_complete_prerender = was_prerender ||
734 (mode_ == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP && 788 prerender_manager->WouldTabContentsBePrerendered(tab_contents);
735 prerender_manager->IsTabContentsPrerendered(tab_contents)));
736 prerender_manager->histograms_->RecordPerceivedPageLoadTime( 789 prerender_manager->histograms_->RecordPerceivedPageLoadTime(
737 perceived_page_load_time, was_prerender, url); 790 perceived_page_load_time, was_prerender, was_complete_prerender, url);
738 } 791 }
739 792
740 bool PrerenderManager::is_enabled() const { 793 bool PrerenderManager::is_enabled() const {
741 DCHECK(CalledOnValidThread()); 794 DCHECK(CalledOnValidThread());
742 if (!enabled_) 795 if (!enabled_)
743 return false; 796 return false;
744 for (std::list<const PrerenderCondition*>::const_iterator it = 797 for (std::list<const PrerenderCondition*>::const_iterator it =
745 prerender_conditions_.begin(); 798 prerender_conditions_.begin();
746 it != prerender_conditions_.end(); 799 it != prerender_conditions_.end();
747 ++it) { 800 ++it) {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 if (!render_process_host || !render_process_host->browser_context()) 1112 if (!render_process_host || !render_process_host->browser_context())
1060 return NULL; 1113 return NULL;
1061 Profile* profile = Profile::FromBrowserContext( 1114 Profile* profile = Profile::FromBrowserContext(
1062 render_process_host->browser_context()); 1115 render_process_host->browser_context());
1063 if (!profile) 1116 if (!profile)
1064 return NULL; 1117 return NULL;
1065 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); 1118 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile);
1066 } 1119 }
1067 1120
1068 } // namespace prerender 1121 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698