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

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

Issue 8539027: Add SwappedOut to TabContentsDelegate to allow us to correctly delete TabContents. (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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/favicon/favicon_tab_helper.h" 18 #include "chrome/browser/favicon/favicon_tab_helper.h"
18 #include "chrome/browser/history/top_sites.h" 19 #include "chrome/browser/history/top_sites.h"
19 #include "chrome/browser/prerender/prerender_condition.h" 20 #include "chrome/browser/prerender/prerender_condition.h"
20 #include "chrome/browser/prerender/prerender_contents.h" 21 #include "chrome/browser/prerender/prerender_contents.h"
21 #include "chrome/browser/prerender/prerender_field_trial.h" 22 #include "chrome/browser/prerender/prerender_field_trial.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 "OPTIONS", 73 "OPTIONS",
73 "POST", 74 "POST",
74 "TRACE", 75 "TRACE",
75 }; 76 };
76 77
77 // Length of prerender history, for display in chrome://net-internals 78 // Length of prerender history, for display in chrome://net-internals
78 const int kHistoryLength = 100; 79 const int kHistoryLength = 100;
79 80
80 } // namespace 81 } // namespace
81 82
82 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate { 83 class PrerenderManager::OnCloseTabContentsDeleter
84 : public TabContentsDelegate,
85 public SupportsWeakPtr<PrerenderManager::OnCloseTabContentsDeleter> {
83 public: 86 public:
84 OnCloseTabContentsDeleter(PrerenderManager* manager, 87 OnCloseTabContentsDeleter(PrerenderManager* manager,
85 TabContentsWrapper* tab) 88 TabContentsWrapper* tab)
86 : manager_(manager), 89 : manager_(manager),
87 tab_(tab) { 90 tab_(tab) {
88 tab_->tab_contents()->set_delegate(this); 91 tab_->tab_contents()->set_delegate(this);
92 MessageLoop::current()->PostDelayedTask(FROM_HERE,
93 base::Bind(&OnCloseTabContentsDeleter::ScheduleTabContentsForDeletion,
94 this->AsWeakPtr(), true), kDeleteWithExtremePrejudiceTimeMs);
89 } 95 }
90 96
91 virtual void CloseContents(TabContents* source) OVERRIDE { 97 virtual void CloseContents(TabContents* source) OVERRIDE {
92 tab_->tab_contents()->set_delegate(NULL); 98 DCHECK_EQ(tab_->tab_contents(), source);
93 manager_->ScheduleDeleteOldTabContents(tab_.release(), this); 99 ScheduleTabContentsForDeletion(false);
100 }
101
102 virtual void SwappedOut(TabContents* source) OVERRIDE {
103 DCHECK_EQ(tab_->tab_contents(), source);
104 ScheduleTabContentsForDeletion(false);
94 } 105 }
95 106
96 virtual bool ShouldSuppressDialogs() OVERRIDE { 107 virtual bool ShouldSuppressDialogs() OVERRIDE {
97 return true; 108 return true;
98 } 109 }
99 110
100 private: 111 private:
112 static const int kDeleteWithExtremePrejudiceTimeMs = 3000;
113
114 void ScheduleTabContentsForDeletion(bool timeout) {
115 tab_->tab_contents()->set_delegate(NULL);
116 manager_->ScheduleDeleteOldTabContents(tab_.release(), this);
117 UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterTimeout", timeout);
118 }
119
101 PrerenderManager* manager_; 120 PrerenderManager* manager_;
102 scoped_ptr<TabContentsWrapper> tab_; 121 scoped_ptr<TabContentsWrapper> tab_;
103 122
104 DISALLOW_COPY_AND_ASSIGN(OnCloseTabContentsDeleter); 123 DISALLOW_COPY_AND_ASSIGN(OnCloseTabContentsDeleter);
105 }; 124 };
106 125
107 // static 126 // static
108 int PrerenderManager::prerenders_per_session_count_ = 0; 127 int PrerenderManager::prerenders_per_session_count_ = 0;
109 128
110 // static 129 // static
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 if (!render_process_host || !render_process_host->browser_context()) 1078 if (!render_process_host || !render_process_host->browser_context())
1060 return NULL; 1079 return NULL;
1061 Profile* profile = Profile::FromBrowserContext( 1080 Profile* profile = Profile::FromBrowserContext(
1062 render_process_host->browser_context()); 1081 render_process_host->browser_context());
1063 if (!profile) 1082 if (!profile)
1064 return NULL; 1083 return NULL;
1065 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); 1084 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile);
1066 } 1085 }
1067 1086
1068 } // namespace prerender 1087 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_view_host.cc » ('j') | content/browser/tab_contents/tab_contents.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698