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

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

Issue 10540078: TabContentsWrapper -> TabContents, part 23. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/prerender/prerender_histograms.h" 27 #include "chrome/browser/prerender/prerender_histograms.h"
28 #include "chrome/browser/prerender/prerender_history.h" 28 #include "chrome/browser/prerender/prerender_history.h"
29 #include "chrome/browser/prerender/prerender_local_predictor.h" 29 #include "chrome/browser/prerender/prerender_local_predictor.h"
30 #include "chrome/browser/prerender/prerender_manager_factory.h" 30 #include "chrome/browser/prerender/prerender_manager_factory.h"
31 #include "chrome/browser/prerender/prerender_tab_helper.h" 31 #include "chrome/browser/prerender/prerender_tab_helper.h"
32 #include "chrome/browser/prerender/prerender_tracker.h" 32 #include "chrome/browser/prerender/prerender_tracker.h"
33 #include "chrome/browser/prerender/prerender_util.h" 33 #include "chrome/browser/prerender/prerender_util.h"
34 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 35 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
36 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" 36 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 37 #include "chrome/browser/ui/tab_contents/tab_contents.h"
38 #include "chrome/common/chrome_notification_types.h" 38 #include "chrome/common/chrome_notification_types.h"
39 #include "chrome/common/chrome_switches.h" 39 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/prerender_messages.h" 40 #include "chrome/common/prerender_messages.h"
41 #include "content/public/browser/browser_thread.h" 41 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/devtools_agent_host_registry.h" 42 #include "content/public/browser/devtools_agent_host_registry.h"
43 #include "content/public/browser/navigation_controller.h" 43 #include "content/public/browser/navigation_controller.h"
44 #include "content/public/browser/notification_observer.h" 44 #include "content/public/browser/notification_observer.h"
45 #include "content/public/browser/notification_registrar.h" 45 #include "content/public/browser/notification_registrar.h"
46 #include "content/public/browser/notification_source.h" 46 #include "content/public/browser/notification_source.h"
47 #include "content/public/browser/render_process_host.h" 47 #include "content/public/browser/render_process_host.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 118
119 } // namespace 119 } // namespace
120 120
121 class PrerenderManager::OnCloseTabContentsDeleter 121 class PrerenderManager::OnCloseTabContentsDeleter
122 : public content::WebContentsDelegate, 122 : public content::WebContentsDelegate,
123 public base::SupportsWeakPtr< 123 public base::SupportsWeakPtr<
124 PrerenderManager::OnCloseTabContentsDeleter> { 124 PrerenderManager::OnCloseTabContentsDeleter> {
125 public: 125 public:
126 OnCloseTabContentsDeleter(PrerenderManager* manager, 126 OnCloseTabContentsDeleter(PrerenderManager* manager,
127 TabContentsWrapper* tab) 127 TabContents* tab)
128 : manager_(manager), 128 : manager_(manager),
129 tab_(tab) { 129 tab_(tab) {
130 tab_->web_contents()->SetDelegate(this); 130 tab_->web_contents()->SetDelegate(this);
131 MessageLoop::current()->PostDelayedTask(FROM_HERE, 131 MessageLoop::current()->PostDelayedTask(FROM_HERE,
132 base::Bind(&OnCloseTabContentsDeleter::ScheduleTabContentsForDeletion, 132 base::Bind(&OnCloseTabContentsDeleter::ScheduleTabContentsForDeletion,
133 this->AsWeakPtr(), true), 133 this->AsWeakPtr(), true),
134 base::TimeDelta::FromSeconds(kDeleteWithExtremePrejudiceSeconds)); 134 base::TimeDelta::FromSeconds(kDeleteWithExtremePrejudiceSeconds));
135 } 135 }
136 136
137 virtual void CloseContents(WebContents* source) OVERRIDE { 137 virtual void CloseContents(WebContents* source) OVERRIDE {
(...skipping 13 matching lines...) Expand all
151 private: 151 private:
152 static const int kDeleteWithExtremePrejudiceSeconds = 3; 152 static const int kDeleteWithExtremePrejudiceSeconds = 3;
153 153
154 void ScheduleTabContentsForDeletion(bool timeout) { 154 void ScheduleTabContentsForDeletion(bool timeout) {
155 tab_->web_contents()->SetDelegate(NULL); 155 tab_->web_contents()->SetDelegate(NULL);
156 manager_->ScheduleDeleteOldTabContents(tab_.release(), this); 156 manager_->ScheduleDeleteOldTabContents(tab_.release(), this);
157 UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterTimeout", timeout); 157 UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterTimeout", timeout);
158 } 158 }
159 159
160 PrerenderManager* manager_; 160 PrerenderManager* manager_;
161 scoped_ptr<TabContentsWrapper> tab_; 161 scoped_ptr<TabContents> tab_;
162 162
163 DISALLOW_COPY_AND_ASSIGN(OnCloseTabContentsDeleter); 163 DISALLOW_COPY_AND_ASSIGN(OnCloseTabContentsDeleter);
164 }; 164 };
165 165
166 // static 166 // static
167 bool PrerenderManager::is_prefetch_enabled_ = false; 167 bool PrerenderManager::is_prefetch_enabled_ = false;
168 168
169 // static 169 // static
170 int PrerenderManager::prerenders_per_session_count_ = 0; 170 int PrerenderManager::prerenders_per_session_count_ = 0;
171 171
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 401 }
402 402
403 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); 403 histograms_->RecordPerSessionCount(++prerenders_per_session_count_);
404 histograms_->RecordUsedPrerender(prerender_contents->origin()); 404 histograms_->RecordUsedPrerender(prerender_contents->origin());
405 prerender_contents->set_final_status(FINAL_STATUS_USED); 405 prerender_contents->set_final_status(FINAL_STATUS_USED);
406 406
407 new_render_view_host->Send( 407 new_render_view_host->Send(
408 new PrerenderMsg_SetIsPrerendering(new_render_view_host->GetRoutingID(), 408 new PrerenderMsg_SetIsPrerendering(new_render_view_host->GetRoutingID(),
409 false)); 409 false));
410 410
411 TabContentsWrapper* new_tab_contents = 411 TabContents* new_tab_contents =
412 prerender_contents->ReleasePrerenderContents(); 412 prerender_contents->ReleasePrerenderContents();
413 TabContentsWrapper* old_tab_contents = 413 TabContents* old_tab_contents = TabContents::FromWebContents(web_contents);
414 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
415 DCHECK(new_tab_contents); 414 DCHECK(new_tab_contents);
416 DCHECK(old_tab_contents); 415 DCHECK(old_tab_contents);
417 416
418 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); 417 MarkWebContentsAsPrerendered(new_tab_contents->web_contents());
419 418
420 // Merge the browsing history. 419 // Merge the browsing history.
421 new_tab_contents->web_contents()->GetController().CopyStateFromAndPrune( 420 new_tab_contents->web_contents()->GetController().CopyStateFromAndPrune(
422 &old_tab_contents->web_contents()->GetController()); 421 &old_tab_contents->web_contents()->GetController());
423 old_tab_contents->core_tab_helper()->delegate()-> 422 old_tab_contents->core_tab_helper()->delegate()->
424 SwapTabContents(old_tab_contents, new_tab_contents); 423 SwapTabContents(old_tab_contents, new_tab_contents);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 bool PrerenderManager::IsNoUseGroup() { 618 bool PrerenderManager::IsNoUseGroup() {
620 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; 619 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP;
621 } 620 }
622 621
623 bool PrerenderManager::IsWebContentsPrerendering( 622 bool PrerenderManager::IsWebContentsPrerendering(
624 WebContents* web_contents) const { 623 WebContents* web_contents) const {
625 DCHECK(CalledOnValidThread()); 624 DCHECK(CalledOnValidThread());
626 for (PrerenderContentsDataList::const_iterator it = prerender_list_.begin(); 625 for (PrerenderContentsDataList::const_iterator it = prerender_list_.begin();
627 it != prerender_list_.end(); 626 it != prerender_list_.end();
628 ++it) { 627 ++it) {
629 TabContentsWrapper* prerender_tab_contents_wrapper = 628 TabContents* prerender_tab_contents = it->contents_->prerender_contents();
630 it->contents_->prerender_contents(); 629 if (prerender_tab_contents &&
631 if (prerender_tab_contents_wrapper && 630 prerender_tab_contents->web_contents() == web_contents) {
632 prerender_tab_contents_wrapper->web_contents() == web_contents) {
633 return true; 631 return true;
634 } 632 }
635 } 633 }
636 634
637 // Also look through the pending-deletion list. 635 // Also look through the pending-deletion list.
638 for (std::list<PrerenderContents*>::const_iterator it = 636 for (std::list<PrerenderContents*>::const_iterator it =
639 pending_delete_list_.begin(); 637 pending_delete_list_.begin();
640 it != pending_delete_list_.end(); 638 it != pending_delete_list_.end();
641 ++it) { 639 ++it) {
642 TabContentsWrapper* prerender_tab_contents_wrapper = 640 TabContents* prerender_tab_contents = (*it)->prerender_contents();
643 (*it)->prerender_contents(); 641 if (prerender_tab_contents &&
644 if (prerender_tab_contents_wrapper && 642 prerender_tab_contents->web_contents() == web_contents)
645 prerender_tab_contents_wrapper->web_contents() == web_contents)
646 return true; 643 return true;
647 } 644 }
648 645
649 return false; 646 return false;
650 } 647 }
651 648
652 bool PrerenderManager::DidPrerenderFinishLoading(const GURL& url) const { 649 bool PrerenderManager::DidPrerenderFinishLoading(const GURL& url) const {
653 DCHECK(CalledOnValidThread()); 650 DCHECK(CalledOnValidThread());
654 PrerenderContents* contents = FindEntry(url); 651 PrerenderContents* contents = FindEntry(url);
655 return contents ? contents->has_finished_loading() : false; 652 return contents ? contents->has_finished_loading() : false;
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 GetCurrentTimeTicks() - last_prerender_start_time_; 1086 GetCurrentTimeTicks() - last_prerender_start_time_;
1090 histograms_->RecordTimeBetweenPrerenderRequests(elapsed_time); 1087 histograms_->RecordTimeBetweenPrerenderRequests(elapsed_time);
1091 if (!config_.rate_limit_enabled) 1088 if (!config_.rate_limit_enabled)
1092 return true; 1089 return true;
1093 return elapsed_time > 1090 return elapsed_time >
1094 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs); 1091 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs);
1095 } 1092 }
1096 1093
1097 void PrerenderManager::DeleteOldTabContents() { 1094 void PrerenderManager::DeleteOldTabContents() {
1098 while (!old_tab_contents_list_.empty()) { 1095 while (!old_tab_contents_list_.empty()) {
1099 TabContentsWrapper* tab_contents = old_tab_contents_list_.front(); 1096 TabContents* tab_contents = old_tab_contents_list_.front();
1100 old_tab_contents_list_.pop_front(); 1097 old_tab_contents_list_.pop_front();
1101 // TODO(dominich): should we use Instant Unload Handler here? 1098 // TODO(dominich): should we use Instant Unload Handler here?
1102 delete tab_contents; 1099 delete tab_contents;
1103 } 1100 }
1104 } 1101 }
1105 1102
1106 void PrerenderManager::CleanUpOldNavigations() { 1103 void PrerenderManager::CleanUpOldNavigations() {
1107 DCHECK(CalledOnValidThread()); 1104 DCHECK(CalledOnValidThread());
1108 1105
1109 // Cutoff. Navigations before this cutoff can be discarded. 1106 // Cutoff. Navigations before this cutoff can be discarded.
1110 base::TimeTicks cutoff = GetCurrentTimeTicks() - 1107 base::TimeTicks cutoff = GetCurrentTimeTicks() -
1111 base::TimeDelta::FromMilliseconds(kNavigationRecordWindowMs); 1108 base::TimeDelta::FromMilliseconds(kNavigationRecordWindowMs);
1112 while (!navigations_.empty()) { 1109 while (!navigations_.empty()) {
1113 if (navigations_.front().time_ > cutoff) 1110 if (navigations_.front().time_ > cutoff)
1114 break; 1111 break;
1115 navigations_.pop_front(); 1112 navigations_.pop_front();
1116 } 1113 }
1117 } 1114 }
1118 1115
1119 void PrerenderManager::ScheduleDeleteOldTabContents( 1116 void PrerenderManager::ScheduleDeleteOldTabContents(
1120 TabContentsWrapper* tab, 1117 TabContents* tab,
1121 OnCloseTabContentsDeleter* deleter) { 1118 OnCloseTabContentsDeleter* deleter) {
1122 old_tab_contents_list_.push_back(tab); 1119 old_tab_contents_list_.push_back(tab);
1123 PostCleanupTask(); 1120 PostCleanupTask();
1124 1121
1125 if (deleter) { 1122 if (deleter) {
1126 ScopedVector<OnCloseTabContentsDeleter>::iterator i = std::find( 1123 ScopedVector<OnCloseTabContentsDeleter>::iterator i = std::find(
1127 on_close_tab_contents_deleters_.begin(), 1124 on_close_tab_contents_deleters_.begin(),
1128 on_close_tab_contents_deleters_.end(), 1125 on_close_tab_contents_deleters_.end(),
1129 deleter); 1126 deleter);
1130 DCHECK(i != on_close_tab_contents_deleters_.end()); 1127 DCHECK(i != on_close_tab_contents_deleters_.end());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 if (!render_process_host || !render_process_host->GetBrowserContext()) 1207 if (!render_process_host || !render_process_host->GetBrowserContext())
1211 return NULL; 1208 return NULL;
1212 Profile* profile = Profile::FromBrowserContext( 1209 Profile* profile = Profile::FromBrowserContext(
1213 render_process_host->GetBrowserContext()); 1210 render_process_host->GetBrowserContext());
1214 if (!profile) 1211 if (!profile)
1215 return NULL; 1212 return NULL;
1216 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); 1213 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile);
1217 } 1214 }
1218 1215
1219 } // namespace prerender 1216 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | chrome/browser/prerender/prerender_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698