| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } // namespace | 153 } // namespace |
| 154 | 154 |
| 155 class PrerenderManager::OnCloseWebContentsDeleter | 155 class PrerenderManager::OnCloseWebContentsDeleter |
| 156 : public content::WebContentsDelegate, | 156 : public content::WebContentsDelegate, |
| 157 public base::SupportsWeakPtr< | 157 public base::SupportsWeakPtr< |
| 158 PrerenderManager::OnCloseWebContentsDeleter> { | 158 PrerenderManager::OnCloseWebContentsDeleter> { |
| 159 public: | 159 public: |
| 160 OnCloseWebContentsDeleter(PrerenderManager* manager, | 160 OnCloseWebContentsDeleter(PrerenderManager* manager, |
| 161 WebContents* tab) | 161 WebContents* tab) |
| 162 : manager_(manager), | 162 : manager_(manager), |
| 163 tab_(tab) { | 163 tab_(tab), |
| 164 suppressed_dialog_(false) { |
| 164 tab_->SetDelegate(this); | 165 tab_->SetDelegate(this); |
| 165 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 166 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 166 base::Bind(&OnCloseWebContentsDeleter::ScheduleWebContentsForDeletion, | 167 base::Bind(&OnCloseWebContentsDeleter::ScheduleWebContentsForDeletion, |
| 167 AsWeakPtr(), true), | 168 AsWeakPtr(), true), |
| 168 base::TimeDelta::FromSeconds(kDeleteWithExtremePrejudiceSeconds)); | 169 base::TimeDelta::FromSeconds(kDeleteWithExtremePrejudiceSeconds)); |
| 169 } | 170 } |
| 170 | 171 |
| 171 virtual void CloseContents(WebContents* source) OVERRIDE { | 172 virtual void CloseContents(WebContents* source) OVERRIDE { |
| 172 DCHECK_EQ(tab_, source); | 173 DCHECK_EQ(tab_, source); |
| 173 ScheduleWebContentsForDeletion(false); | 174 ScheduleWebContentsForDeletion(false); |
| 174 } | 175 } |
| 175 | 176 |
| 176 virtual void SwappedOut(WebContents* source) OVERRIDE { | 177 virtual void SwappedOut(WebContents* source) OVERRIDE { |
| 177 DCHECK_EQ(tab_, source); | 178 DCHECK_EQ(tab_, source); |
| 178 ScheduleWebContentsForDeletion(false); | 179 ScheduleWebContentsForDeletion(false); |
| 179 } | 180 } |
| 180 | 181 |
| 181 virtual bool ShouldSuppressDialogs() OVERRIDE { | 182 virtual bool ShouldSuppressDialogs() OVERRIDE { |
| 183 // Use this as a proxy for getting statistics on how often we fail to honor |
| 184 // the beforeunload event. |
| 185 suppressed_dialog_ = true; |
| 182 return true; | 186 return true; |
| 183 } | 187 } |
| 184 | 188 |
| 185 private: | 189 private: |
| 186 static const int kDeleteWithExtremePrejudiceSeconds = 3; | 190 static const int kDeleteWithExtremePrejudiceSeconds = 3; |
| 187 | 191 |
| 188 void ScheduleWebContentsForDeletion(bool timeout) { | 192 void ScheduleWebContentsForDeletion(bool timeout) { |
| 193 UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterTimeout", timeout); |
| 194 UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterSuppressedDialog", |
| 195 suppressed_dialog_); |
| 189 tab_->SetDelegate(NULL); | 196 tab_->SetDelegate(NULL); |
| 190 manager_->ScheduleDeleteOldWebContents(tab_.release(), this); | 197 manager_->ScheduleDeleteOldWebContents(tab_.release(), this); |
| 191 UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterTimeout", timeout); | 198 // |this| is deleted at this point. |
| 192 } | 199 } |
| 193 | 200 |
| 194 PrerenderManager* manager_; | 201 PrerenderManager* manager_; |
| 195 scoped_ptr<WebContents> tab_; | 202 scoped_ptr<WebContents> tab_; |
| 203 bool suppressed_dialog_; |
| 196 | 204 |
| 197 DISALLOW_COPY_AND_ASSIGN(OnCloseWebContentsDeleter); | 205 DISALLOW_COPY_AND_ASSIGN(OnCloseWebContentsDeleter); |
| 198 }; | 206 }; |
| 199 | 207 |
| 200 // static | 208 // static |
| 201 bool PrerenderManager::is_prefetch_enabled_ = false; | 209 bool PrerenderManager::is_prefetch_enabled_ = false; |
| 202 | 210 |
| 203 // static | 211 // static |
| 204 int PrerenderManager::prerenders_per_session_count_ = 0; | 212 int PrerenderManager::prerenders_per_session_count_ = 0; |
| 205 | 213 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 // Update PPLT metrics: | 585 // Update PPLT metrics: |
| 578 // If the tab has finished loading, record a PPLT of 0. | 586 // If the tab has finished loading, record a PPLT of 0. |
| 579 // If the tab is still loading, reset its start time to the current time. | 587 // If the tab is still loading, reset its start time to the current time. |
| 580 PrerenderTabHelper* prerender_tab_helper = | 588 PrerenderTabHelper* prerender_tab_helper = |
| 581 PrerenderTabHelper::FromWebContents(new_web_contents); | 589 PrerenderTabHelper::FromWebContents(new_web_contents); |
| 582 DCHECK(prerender_tab_helper != NULL); | 590 DCHECK(prerender_tab_helper != NULL); |
| 583 prerender_tab_helper->PrerenderSwappedIn(); | 591 prerender_tab_helper->PrerenderSwappedIn(); |
| 584 | 592 |
| 585 if (old_web_contents->NeedToFireBeforeUnload()) { | 593 if (old_web_contents->NeedToFireBeforeUnload()) { |
| 586 // Schedule the delete to occur after the tab has run its unload handlers. | 594 // Schedule the delete to occur after the tab has run its unload handlers. |
| 595 // TODO(davidben): Honor the beforeunload event. http://crbug.com/304932 |
| 587 on_close_web_contents_deleters_.push_back( | 596 on_close_web_contents_deleters_.push_back( |
| 588 new OnCloseWebContentsDeleter(this, old_web_contents)); | 597 new OnCloseWebContentsDeleter(this, old_web_contents)); |
| 589 old_web_contents->GetRenderViewHost()-> | 598 old_web_contents->GetRenderViewHost()-> |
| 590 FirePageBeforeUnload(false); | 599 FirePageBeforeUnload(false); |
| 591 } else { | 600 } else { |
| 592 // No unload handler to run, so delete asap. | 601 // No unload handler to run, so delete asap. |
| 593 ScheduleDeleteOldWebContents(old_web_contents, NULL); | 602 ScheduleDeleteOldWebContents(old_web_contents, NULL); |
| 594 } | 603 } |
| 595 | 604 |
| 596 // TODO(cbentzel): Should prerender_contents move to the pending delete | 605 // TODO(cbentzel): Should prerender_contents move to the pending delete |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 logged_in_state_->erase(domain_key); | 1588 logged_in_state_->erase(domain_key); |
| 1580 } | 1589 } |
| 1581 | 1590 |
| 1582 void PrerenderManager::LoggedInPredictorDataReceived( | 1591 void PrerenderManager::LoggedInPredictorDataReceived( |
| 1583 scoped_ptr<LoggedInStateMap> new_map) { | 1592 scoped_ptr<LoggedInStateMap> new_map) { |
| 1584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1585 logged_in_state_.swap(new_map); | 1594 logged_in_state_.swap(new_map); |
| 1586 } | 1595 } |
| 1587 | 1596 |
| 1588 } // namespace prerender | 1597 } // namespace prerender |
| OLD | NEW |