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 <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 | 62 |
| 63 namespace { | 63 namespace { |
| 64 | 64 |
| 65 // Time window for which we will record windowed PLT's from the last | 65 // Time window for which we will record windowed PLT's from the last |
| 66 // observed link rel=prefetch tag. | 66 // observed link rel=prefetch tag. |
| 67 const int kWindowDurationSeconds = 30; | 67 const int kWindowDurationSeconds = 30; |
| 68 | 68 |
| 69 // Time interval at which periodic cleanups are performed. | 69 // Time interval at which periodic cleanups are performed. |
| 70 const int kPeriodicCleanupIntervalMs = 1000; | 70 const int kPeriodicCleanupIntervalMs = 1000; |
| 71 | 71 |
| 72 // Time interval before a new prerender is allowed. | |
| 73 const int kMinTimeBetweenPrerendersMs = 500; | |
| 74 | |
| 75 // Valid HTTP methods for prerendering. | 72 // Valid HTTP methods for prerendering. |
| 76 const char* const kValidHttpMethods[] = { | 73 const char* const kValidHttpMethods[] = { |
| 77 "GET", | 74 "GET", |
| 78 "HEAD", | 75 "HEAD", |
| 79 "OPTIONS", | 76 "OPTIONS", |
| 80 "POST", | 77 "POST", |
| 81 "TRACE", | 78 "TRACE", |
| 82 }; | 79 }; |
| 83 | 80 |
| 84 // Length of prerender history, for display in chrome://net-internals | 81 // Length of prerender history, for display in chrome://net-internals |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 last_prerender_start_time_(GetCurrentTimeTicks() - | 186 last_prerender_start_time_(GetCurrentTimeTicks() - |
| 190 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), | 187 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), |
| 191 weak_factory_(this), | 188 weak_factory_(this), |
| 192 prerender_history_(new PrerenderHistory(kHistoryLength)), | 189 prerender_history_(new PrerenderHistory(kHistoryLength)), |
| 193 histograms_(new PrerenderHistograms()), | 190 histograms_(new PrerenderHistograms()), |
| 194 local_predictor_(new PrerenderLocalPredictor(this)) { | 191 local_predictor_(new PrerenderLocalPredictor(this)) { |
| 195 // There are some assumptions that the PrerenderManager is on the UI thread. | 192 // There are some assumptions that the PrerenderManager is on the UI thread. |
| 196 // Any other checks simply make sure that the PrerenderManager is accessed on | 193 // Any other checks simply make sure that the PrerenderManager is accessed on |
| 197 // the same thread that it was created on. | 194 // the same thread that it was created on. |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 196 config_.max_concurrency = GetMaxConcurrency(); | |
| 199 } | 197 } |
| 200 | 198 |
| 201 PrerenderManager::~PrerenderManager() { | 199 PrerenderManager::~PrerenderManager() { |
| 202 } | 200 } |
| 203 | 201 |
| 204 void PrerenderManager::Shutdown() { | 202 void PrerenderManager::Shutdown() { |
| 205 DoShutdown(); | 203 DoShutdown(); |
| 206 } | 204 } |
| 207 | 205 |
| 208 PrerenderHandle* PrerenderManager::AddPrerenderFromLinkRelPrerender( | 206 PrerenderHandle* PrerenderManager::AddPrerenderFromLinkRelPrerender( |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 // static | 546 // static |
| 549 const char* PrerenderManager::GetModeString() { | 547 const char* PrerenderManager::GetModeString() { |
| 550 switch (mode_) { | 548 switch (mode_) { |
| 551 case PRERENDER_MODE_DISABLED: | 549 case PRERENDER_MODE_DISABLED: |
| 552 return "_Disabled"; | 550 return "_Disabled"; |
| 553 case PRERENDER_MODE_ENABLED: | 551 case PRERENDER_MODE_ENABLED: |
| 554 case PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP: | 552 case PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP: |
| 555 return "_Enabled"; | 553 return "_Enabled"; |
| 556 case PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP: | 554 case PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP: |
| 557 return "_Control"; | 555 return "_Control"; |
| 556 case PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: | |
| 557 return "_Multi"; | |
| 558 case PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP: | 558 case PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP: |
| 559 return "_5MinTTL"; | 559 return "_5MinTTL"; |
| 560 case PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP: | 560 case PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP: |
| 561 return "_NoUse"; | 561 return "_NoUse"; |
| 562 case PRERENDER_MODE_MAX: | 562 case PRERENDER_MODE_MAX: |
| 563 NOTREACHED() << "Invalid PrerenderManager mode."; | 563 NOTREACHED() << "Invalid PrerenderManager mode."; |
| 564 break; | 564 break; |
| 565 }; | 565 }; |
| 566 return ""; | 566 return ""; |
| 567 } | 567 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 579 // static | 579 // static |
| 580 bool PrerenderManager::IsControlGroup() { | 580 bool PrerenderManager::IsControlGroup() { |
| 581 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; | 581 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; |
| 582 } | 582 } |
| 583 | 583 |
| 584 // static | 584 // static |
| 585 bool PrerenderManager::IsNoUseGroup() { | 585 bool PrerenderManager::IsNoUseGroup() { |
| 586 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 586 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 587 } | 587 } |
| 588 | 588 |
| 589 // static | |
| 590 size_t PrerenderManager::GetMaxConcurrency() { | |
| 591 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) | |
| 592 return 3; | |
| 593 return 1; | |
| 594 } | |
| 595 | |
| 589 bool PrerenderManager::IsWebContentsPrerendering( | 596 bool PrerenderManager::IsWebContentsPrerendering( |
| 590 WebContents* web_contents) const { | 597 WebContents* web_contents) const { |
| 591 DCHECK(CalledOnValidThread()); | 598 DCHECK(CalledOnValidThread()); |
| 592 for (std::list<linked_ptr<PrerenderData> >::const_iterator it = | 599 for (std::list<linked_ptr<PrerenderData> >::const_iterator it = |
| 593 active_prerender_list_.begin(); | 600 active_prerender_list_.begin(); |
| 594 it != active_prerender_list_.end(); | 601 it != active_prerender_list_.end(); |
| 595 ++it) { | 602 ++it) { |
| 596 TabContents* prerender_tab_contents = | 603 TabContents* prerender_tab_contents = |
| 597 it->get()->contents_->prerender_contents(); | 604 it->get()->contents_->prerender_contents(); |
| 598 if (prerender_tab_contents && | 605 if (prerender_tab_contents && |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 | 945 |
| 939 last_prerender_start_time_ = GetCurrentTimeTicks(); | 946 last_prerender_start_time_ = GetCurrentTimeTicks(); |
| 940 | 947 |
| 941 gfx::Size contents_size = | 948 gfx::Size contents_size = |
| 942 size.IsEmpty() ? config_.default_tab_bounds.size() : size; | 949 size.IsEmpty() ? config_.default_tab_bounds.size() : size; |
| 943 | 950 |
| 944 prerender_contents->StartPrerendering(process_id, contents_size, | 951 prerender_contents->StartPrerendering(process_id, contents_size, |
| 945 session_storage_namespace, | 952 session_storage_namespace, |
| 946 control_group_behavior); | 953 control_group_behavior); |
| 947 | 954 |
| 948 while (active_prerender_list_.size() > config_.max_elements) { | 955 DCHECK(Config::kMaximumMaxConcurrency >= config_.max_concurrency); |
|
dominich
2012/07/23 18:45:56
why is this important? if we want to experiment wi
mmenke
2012/07/23 18:48:49
Drive by nit: DCHECK_GE
gavinp
2012/07/23 18:51:55
This test guards the histograms sizing; the altern
gavinp
2012/07/23 18:51:55
DCHECK_GE won't work, as it takes a pointer to its
dominich
2012/07/23 18:57:14
in logging.h it uses const T& or int - I don't see
gavinp
2012/07/23 19:06:10
Sorry, takes a reference.
| |
| 956 while (active_prerender_list_.size() > config_.max_concurrency) { | |
| 949 prerender_contents = active_prerender_list_.front()->contents_; | 957 prerender_contents = active_prerender_list_.front()->contents_; |
| 950 DCHECK(prerender_contents); | 958 DCHECK(prerender_contents); |
| 951 prerender_contents->Destroy(FINAL_STATUS_EVICTED); | 959 prerender_contents->Destroy(FINAL_STATUS_EVICTED); |
| 952 } | 960 } |
| 953 | 961 |
| 962 histograms_->RecordConcurrency(active_prerender_list_.size()); | |
| 963 | |
| 954 StartSchedulingPeriodicCleanups(); | 964 StartSchedulingPeriodicCleanups(); |
| 955 return prerender_handle; | 965 return prerender_handle; |
| 956 } | 966 } |
| 957 | 967 |
| 958 void PrerenderManager::StartSchedulingPeriodicCleanups() { | 968 void PrerenderManager::StartSchedulingPeriodicCleanups() { |
| 959 DCHECK(CalledOnValidThread()); | 969 DCHECK(CalledOnValidThread()); |
| 960 if (repeating_timer_.IsRunning()) | 970 if (repeating_timer_.IsRunning()) |
| 961 return; | 971 return; |
| 962 repeating_timer_.Start(FROM_HERE, | 972 repeating_timer_.Start(FROM_HERE, |
| 963 base::TimeDelta::FromMilliseconds(kPeriodicCleanupIntervalMs), | 973 base::TimeDelta::FromMilliseconds(kPeriodicCleanupIntervalMs), |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1234 if (!render_process_host || !render_process_host->GetBrowserContext()) |
| 1225 return NULL; | 1235 return NULL; |
| 1226 Profile* profile = Profile::FromBrowserContext( | 1236 Profile* profile = Profile::FromBrowserContext( |
| 1227 render_process_host->GetBrowserContext()); | 1237 render_process_host->GetBrowserContext()); |
| 1228 if (!profile) | 1238 if (!profile) |
| 1229 return NULL; | 1239 return NULL; |
| 1230 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1240 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
| 1231 } | 1241 } |
| 1232 | 1242 |
| 1233 } // namespace prerender | 1243 } // namespace prerender |
| OLD | NEW |