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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/metrics/histogram.h" | |
12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
13 #include "base/time.h" | 15 #include "base/time.h" |
14 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/favicon/favicon_tab_helper.h" | 19 #include "chrome/browser/favicon/favicon_tab_helper.h" |
18 #include "chrome/browser/history/top_sites.h" | 20 #include "chrome/browser/history/top_sites.h" |
19 #include "chrome/browser/prerender/prerender_condition.h" | 21 #include "chrome/browser/prerender/prerender_condition.h" |
20 #include "chrome/browser/prerender/prerender_contents.h" | 22 #include "chrome/browser/prerender/prerender_contents.h" |
21 #include "chrome/browser/prerender/prerender_field_trial.h" | 23 #include "chrome/browser/prerender/prerender_field_trial.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 "OPTIONS", | 74 "OPTIONS", |
73 "POST", | 75 "POST", |
74 "TRACE", | 76 "TRACE", |
75 }; | 77 }; |
76 | 78 |
77 // Length of prerender history, for display in chrome://net-internals | 79 // Length of prerender history, for display in chrome://net-internals |
78 const int kHistoryLength = 100; | 80 const int kHistoryLength = 100; |
79 | 81 |
80 } // namespace | 82 } // namespace |
81 | 83 |
82 class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate { | 84 class PrerenderManager::OnCloseTabContentsDeleter |
85 : public TabContentsDelegate, | |
86 public base::SupportsWeakPtr< | |
87 PrerenderManager::OnCloseTabContentsDeleter> { | |
83 public: | 88 public: |
84 OnCloseTabContentsDeleter(PrerenderManager* manager, | 89 OnCloseTabContentsDeleter(PrerenderManager* manager, |
85 TabContentsWrapper* tab) | 90 TabContentsWrapper* tab) |
86 : manager_(manager), | 91 : manager_(manager), |
87 tab_(tab) { | 92 tab_(tab) { |
88 tab_->tab_contents()->set_delegate(this); | 93 tab_->tab_contents()->set_delegate(this); |
94 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
cbentzel
2011/11/15 12:20:34
Why is this needed? Do the other mechanisms not gu
| |
95 base::Bind(&OnCloseTabContentsDeleter::ScheduleTabContentsForDeletion, | |
cbentzel
2011/11/15 12:20:34
There's already some hang timers in RenderViewHost
dominich
2011/11/15 15:33:28
The hang timers didn't fire in this case as the RV
| |
96 this->AsWeakPtr(), true), kDeleteWithExtremePrejudiceTimeMs); | |
89 } | 97 } |
90 | 98 |
91 virtual void CloseContents(TabContents* source) OVERRIDE { | 99 virtual void CloseContents(TabContents* source) OVERRIDE { |
92 tab_->tab_contents()->set_delegate(NULL); | 100 DCHECK_EQ(tab_->tab_contents(), source); |
93 manager_->ScheduleDeleteOldTabContents(tab_.release(), this); | 101 ScheduleTabContentsForDeletion(false); |
102 } | |
103 | |
104 virtual void SwappedOut(TabContents* source) OVERRIDE { | |
105 DCHECK_EQ(tab_->tab_contents(), source); | |
106 ScheduleTabContentsForDeletion(false); | |
94 } | 107 } |
95 | 108 |
96 virtual bool ShouldSuppressDialogs() OVERRIDE { | 109 virtual bool ShouldSuppressDialogs() OVERRIDE { |
97 return true; | 110 return true; |
98 } | 111 } |
99 | 112 |
100 private: | 113 private: |
114 static const int kDeleteWithExtremePrejudiceTimeMs = 3000; | |
115 | |
116 void ScheduleTabContentsForDeletion(bool timeout) { | |
117 tab_->tab_contents()->set_delegate(NULL); | |
118 manager_->ScheduleDeleteOldTabContents(tab_.release(), this); | |
119 UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterTimeout", timeout); | |
120 } | |
121 | |
101 PrerenderManager* manager_; | 122 PrerenderManager* manager_; |
102 scoped_ptr<TabContentsWrapper> tab_; | 123 scoped_ptr<TabContentsWrapper> tab_; |
103 | 124 |
104 DISALLOW_COPY_AND_ASSIGN(OnCloseTabContentsDeleter); | 125 DISALLOW_COPY_AND_ASSIGN(OnCloseTabContentsDeleter); |
105 }; | 126 }; |
106 | 127 |
107 // static | 128 // static |
108 int PrerenderManager::prerenders_per_session_count_ = 0; | 129 int PrerenderManager::prerenders_per_session_count_ = 0; |
109 | 130 |
110 // static | 131 // static |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 if (!render_process_host || !render_process_host->browser_context()) | 1080 if (!render_process_host || !render_process_host->browser_context()) |
1060 return NULL; | 1081 return NULL; |
1061 Profile* profile = Profile::FromBrowserContext( | 1082 Profile* profile = Profile::FromBrowserContext( |
1062 render_process_host->browser_context()); | 1083 render_process_host->browser_context()); |
1063 if (!profile) | 1084 if (!profile) |
1064 return NULL; | 1085 return NULL; |
1065 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1086 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1066 } | 1087 } |
1067 | 1088 |
1068 } // namespace prerender | 1089 } // namespace prerender |
OLD | NEW |