Chromium Code Reviews| 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 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry, |
| 656 FinalStatus final_status) { | |
| 651 DCHECK(CalledOnValidThread()); | 657 DCHECK(CalledOnValidThread()); |
| 658 DCHECK(entry); | |
| 652 DCHECK(!IsPendingDelete(entry)); | 659 DCHECK(!IsPendingDelete(entry)); |
| 660 | |
| 661 // If this PrerenderContents is being deleted due to a cancellation, we need | |
| 662 // to create a dummy replacement for PPLT accounting purposes for the | |
| 663 // Match Complete group. | |
| 664 // This is the case if the cancellation is for any reason that would not occur | |
| 665 // in the control group case. | |
| 666 PrerenderContents* dummy_replacement_prerender_contents = NULL; | |
| 667 if (final_status != FINAL_STATUS_USED && | |
|
dominich
2011/11/09 20:48:16
Move this to a utility function IsCancellationStat
tburkard
2011/11/10 18:36:55
Done.
| |
| 668 final_status != FINAL_STATUS_TIMED_OUT && | |
| 669 final_status != FINAL_STATUS_EVICTED && | |
| 670 final_status != FINAL_STATUS_MANAGER_SHUTDOWN && | |
| 671 final_status != FINAL_STATUS_WINDOW_OPENER && | |
| 672 final_status != FINAL_STATUS_FRAGMENT_MISMATCH && | |
| 673 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED && | |
| 674 final_status != FINAL_STATUS_CANCELLED && | |
| 675 final_status != FINAL_STATUS_MATCH_COMPLETE_DUMMY) { | |
| 676 // TODO(tburkard): I'd like to DCHECK that we are actually prerendering. | |
| 677 // However, what if new conditions are added and this list is not being | |
| 678 // updated. Not sure what's the best thing to do here. For now, I will | |
| 679 // just check whether we are actually prerendering. | |
| 680 if (ActuallyPrerendering()) { | |
| 681 dummy_replacement_prerender_contents = CreatePrerenderContents( | |
| 682 entry->prerender_url(), | |
| 683 entry->referrer(), | |
| 684 entry->origin(), | |
| 685 entry->experiment_id()); | |
| 686 } | |
| 687 } | |
| 688 | |
| 653 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); | 689 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); |
| 654 it != prerender_list_.end(); | 690 it != prerender_list_.end(); |
| 655 ++it) { | 691 ++it) { |
| 656 if (it->contents_ == entry) { | 692 if (it->contents_ == entry) { |
| 657 prerender_list_.erase(it); | 693 if (dummy_replacement_prerender_contents) { |
| 694 it->contents_ = dummy_replacement_prerender_contents; | |
| 695 it->contents_->set_final_status(FINAL_STATUS_MATCH_COMPLETE_DUMMY); | |
| 696 } else { | |
| 697 prerender_list_.erase(it); | |
| 698 } | |
| 658 break; | 699 break; |
| 659 } | 700 } |
| 660 } | 701 } |
| 661 AddToHistory(entry); | 702 AddToHistory(entry); |
| 662 pending_delete_list_.push_back(entry); | 703 pending_delete_list_.push_back(entry); |
| 663 | 704 |
| 664 // Destroy the old TabContents relatively promptly to reduce resource usage, | 705 // 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. | 706 // and in the case of HTML5 media, reduce the change of playing any sound. |
| 666 PostCleanupTask(); | 707 PostCleanupTask(); |
| 667 } | 708 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 const GURL& url) { | 760 const GURL& url) { |
| 720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 721 PrerenderManager* prerender_manager = | 762 PrerenderManager* prerender_manager = |
| 722 PrerenderManagerFactory::GetForProfile( | 763 PrerenderManagerFactory::GetForProfile( |
| 723 Profile::FromBrowserContext(tab_contents->browser_context())); | 764 Profile::FromBrowserContext(tab_contents->browser_context())); |
| 724 if (!prerender_manager) | 765 if (!prerender_manager) |
| 725 return; | 766 return; |
| 726 if (!prerender_manager->is_enabled()) | 767 if (!prerender_manager->is_enabled()) |
| 727 return; | 768 return; |
| 728 bool was_prerender = | 769 bool was_prerender = |
| 729 ((mode_ == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP && | 770 prerender_manager->IsTabContentsPrerendered(tab_contents); |
| 730 prerender_manager->WouldTabContentsBePrerendered(tab_contents)) || | 771 bool was_complete_prerender = was_prerender || |
| 731 (mode_ == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP && | 772 prerender_manager->WouldTabContentsBePrerendered(tab_contents); |
| 732 prerender_manager->IsTabContentsPrerendered(tab_contents))); | |
| 733 prerender_manager->histograms_->RecordPerceivedPageLoadTime( | 773 prerender_manager->histograms_->RecordPerceivedPageLoadTime( |
| 734 perceived_page_load_time, was_prerender, url); | 774 perceived_page_load_time, was_prerender, was_complete_prerender, url); |
| 735 } | 775 } |
| 736 | 776 |
| 737 bool PrerenderManager::is_enabled() const { | 777 bool PrerenderManager::is_enabled() const { |
| 738 DCHECK(CalledOnValidThread()); | 778 DCHECK(CalledOnValidThread()); |
| 739 if (!enabled_) | 779 if (!enabled_) |
| 740 return false; | 780 return false; |
| 741 for (std::list<const PrerenderCondition*>::const_iterator it = | 781 for (std::list<const PrerenderCondition*>::const_iterator it = |
| 742 prerender_conditions_.begin(); | 782 prerender_conditions_.begin(); |
| 743 it != prerender_conditions_.end(); | 783 it != prerender_conditions_.end(); |
| 744 ++it) { | 784 ++it) { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 if (!render_process_host || !render_process_host->browser_context()) | 1085 if (!render_process_host || !render_process_host->browser_context()) |
| 1046 return NULL; | 1086 return NULL; |
| 1047 Profile* profile = Profile::FromBrowserContext( | 1087 Profile* profile = Profile::FromBrowserContext( |
| 1048 render_process_host->browser_context()); | 1088 render_process_host->browser_context()); |
| 1049 if (!profile) | 1089 if (!profile) |
| 1050 return NULL; | 1090 return NULL; |
| 1051 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1091 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
| 1052 } | 1092 } |
| 1053 | 1093 |
| 1054 } // namespace prerender | 1094 } // namespace prerender |
| OLD | NEW |