Chromium Code Reviews| 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 <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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 for (std::list<PrerenderContentsData>::const_iterator it = | 283 for (std::list<PrerenderContentsData>::const_iterator it = |
| 284 prerender_list_.begin(); | 284 prerender_list_.begin(); |
| 285 it != prerender_list_.end(); | 285 it != prerender_list_.end(); |
| 286 ++it) { | 286 ++it) { |
| 287 if (it->contents_->IsPendingEntry(url)) | 287 if (it->contents_->IsPendingEntry(url)) |
| 288 return true; | 288 return true; |
| 289 } | 289 } |
| 290 return false; | 290 return false; |
| 291 } | 291 } |
| 292 | 292 |
| 293 bool PrerenderManager::IsPrerendering(const GURL& url) { | |
|
Peter Kasting
2012/01/21 00:22:52
Nit: Can you make this file's definition order mat
dominich
2012/01/23 22:50:07
Done.
| |
| 294 DCHECK(CalledOnValidThread()); | |
| 295 return (FindEntry(url) != NULL); | |
| 296 } | |
| 297 | |
| 293 PrerenderManager::PrerenderManager(Profile* profile, | 298 PrerenderManager::PrerenderManager(Profile* profile, |
| 294 PrerenderTracker* prerender_tracker) | 299 PrerenderTracker* prerender_tracker) |
| 295 : enabled_(true), | 300 : enabled_(true), |
| 296 profile_(profile), | 301 profile_(profile), |
| 297 prerender_tracker_(prerender_tracker), | 302 prerender_tracker_(prerender_tracker), |
| 298 prerender_contents_factory_(PrerenderContents::CreateFactory()), | 303 prerender_contents_factory_(PrerenderContents::CreateFactory()), |
| 299 last_prerender_start_time_(GetCurrentTimeTicks() - | 304 last_prerender_start_time_(GetCurrentTimeTicks() - |
| 300 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), | 305 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), |
| 301 weak_factory_(this), | 306 weak_factory_(this), |
| 302 prerender_history_(new PrerenderHistory(kHistoryLength)), | 307 prerender_history_(new PrerenderHistory(kHistoryLength)), |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 | 494 |
| 490 void PrerenderManager::CancelAllPrerenders() { | 495 void PrerenderManager::CancelAllPrerenders() { |
| 491 DCHECK(CalledOnValidThread()); | 496 DCHECK(CalledOnValidThread()); |
| 492 while (!prerender_list_.empty()) { | 497 while (!prerender_list_.empty()) { |
| 493 PrerenderContentsData data = prerender_list_.front(); | 498 PrerenderContentsData data = prerender_list_.front(); |
| 494 DCHECK(data.contents_); | 499 DCHECK(data.contents_); |
| 495 data.contents_->Destroy(FINAL_STATUS_CANCELLED); | 500 data.contents_->Destroy(FINAL_STATUS_CANCELLED); |
| 496 } | 501 } |
| 497 } | 502 } |
| 498 | 503 |
| 504 void PrerenderManager::CancelOmniboxPrerenders() { | |
| 505 DCHECK(CalledOnValidThread()); | |
| 506 // Calling Destroy will invalidate iterators as it erases the entry from | |
| 507 // |prerender_list_| so we must first gather those contents to destroy and | |
| 508 // then destroy them. | |
|
Peter Kasting
2012/01/21 00:22:52
Nit: Our normal practice for this would be to do o
dominich
2012/01/23 22:50:07
Done.
| |
| 509 std::vector<PrerenderContents*> destroy_contents; | |
| 510 for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); | |
| 511 it != prerender_list_.end(); | |
| 512 ++it) { | |
| 513 if (it->contents_->origin() == ORIGIN_OMNIBOX) | |
| 514 destroy_contents.push_back(it->contents_); | |
| 515 } | |
| 516 | |
| 517 for (std::vector<PrerenderContents*>::iterator it = destroy_contents.begin(); | |
| 518 it != destroy_contents.end(); | |
| 519 ++it) { | |
| 520 (*it)->Destroy(FINAL_STATUS_CANCELLED); | |
| 521 } | |
| 522 } | |
| 523 | |
| 499 void PrerenderManager::DeleteOldEntries() { | 524 void PrerenderManager::DeleteOldEntries() { |
| 500 DCHECK(CalledOnValidThread()); | 525 DCHECK(CalledOnValidThread()); |
| 501 while (!prerender_list_.empty()) { | 526 while (!prerender_list_.empty()) { |
| 502 PrerenderContentsData data = prerender_list_.front(); | 527 PrerenderContentsData data = prerender_list_.front(); |
| 503 if (IsPrerenderElementFresh(data.start_time_)) | 528 if (IsPrerenderElementFresh(data.start_time_)) |
| 504 return; | 529 return; |
| 505 data.contents_->Destroy(FINAL_STATUS_TIMED_OUT); | 530 data.contents_->Destroy(FINAL_STATUS_TIMED_OUT); |
| 506 } | 531 } |
| 507 MaybeStopSchedulingPeriodicCleanups(); | 532 MaybeStopSchedulingPeriodicCleanups(); |
| 508 } | 533 } |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1141 if (!render_process_host || !render_process_host->GetBrowserContext()) |
| 1117 return NULL; | 1142 return NULL; |
| 1118 Profile* profile = Profile::FromBrowserContext( | 1143 Profile* profile = Profile::FromBrowserContext( |
| 1119 render_process_host->GetBrowserContext()); | 1144 render_process_host->GetBrowserContext()); |
| 1120 if (!profile) | 1145 if (!profile) |
| 1121 return NULL; | 1146 return NULL; |
| 1122 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1147 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
| 1123 } | 1148 } |
| 1124 | 1149 |
| 1125 } // namespace prerender | 1150 } // namespace prerender |
| OLD | NEW |