Chromium Code Reviews| Index: content/browser/loader/resource_scheduler.cc |
| diff --git a/content/browser/loader/resource_scheduler.cc b/content/browser/loader/resource_scheduler.cc |
| index f21dd4badfadafc10f5b15e2dce73e9e003200d3..38593580a4930691d078abdef79148a8251c1025 100644 |
| --- a/content/browser/loader/resource_scheduler.cc |
| +++ b/content/browser/loader/resource_scheduler.cc |
| @@ -22,6 +22,7 @@ |
| namespace content { |
| +static const size_t kCoalescedTimerPeriod = 5000; |
| static const size_t kMaxNumDelayableRequestsPerClient = 10; |
| static const size_t kMaxNumDelayableRequestsPerHost = 6; |
| static const size_t kMaxNumThrottledRequestsPerClient = 1; |
| @@ -315,6 +316,7 @@ class ResourceScheduler::Client { |
| } else if (!is_active()) { |
| SetThrottleState(UNTHROTTLED); |
| } |
| + |
| if (throttle_state_ == old_throttle_state) { |
| return; |
| } |
| @@ -323,6 +325,11 @@ class ResourceScheduler::Client { |
| } else if (old_throttle_state == ACTIVE_AND_LOADING) { |
| scheduler_->DecrementActiveClientsLoading(); |
| } |
| + if (throttle_state_ == COALESCED) { |
| + scheduler_->IncrementCoalescedClients(); |
| + } else if (old_throttle_state == COALESCED) { |
| + scheduler_->DecrementCoalescedClients(); |
| + } |
|
aiolos (Not reviewing)
2014/07/15 23:54:58
We don't need to have the timer running when we do
mmenke
2014/07/16 17:01:34
We could be even more careful with this - if no co
|
| } |
| void OnNavigate() { |
| @@ -634,7 +641,10 @@ class ResourceScheduler::Client { |
| ResourceScheduler::ClientThrottleState throttle_state_; |
| }; |
| -ResourceScheduler::ResourceScheduler() : active_clients_loading_(0) { |
| +ResourceScheduler::ResourceScheduler() |
| + : active_clients_loading_(0), |
| + coalesced_clients_(0), |
| + coalescing_timer_(new base::Timer(true, true)) { |
|
mmenke
2014/07/16 17:01:34
Suggest labelling the two arguments, like:
new ba
|
| } |
| ResourceScheduler::~ResourceScheduler() { |
| @@ -850,6 +860,49 @@ size_t ResourceScheduler::CountActiveClientsLoading() { |
| return active_and_loading; |
| } |
| +void ResourceScheduler::IncrementCoalescedClients() { |
|
aiolos (Not reviewing)
2014/07/15 23:54:58
I wondered about adding tests to check that the ti
mmenke
2014/07/16 17:01:34
It is a bit of a transparent implementation detail
|
| + ++coalesced_clients_; |
| + DCHECK_EQ(coalesced_clients_, CountCoalescedClients()); |
| + if (coalesced_clients_ == 1) { |
| + coalescing_timer_->Start( |
| + FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kCoalescedTimerPeriod), |
| + base::Bind(&ResourceScheduler::LoadCoalescedRequests, |
| + base::Unretained(this))); |
| + } |
| +} |
| + |
| +void ResourceScheduler::DecrementCoalescedClients() { |
| + DCHECK_NE(0U, coalesced_clients_); |
| + --coalesced_clients_; |
| + DCHECK_EQ(coalesced_clients_, CountCoalescedClients()); |
| + if (coalesced_clients_ == 0) { |
| + coalescing_timer_->Stop(); |
| + } |
| +} |
| + |
| +size_t ResourceScheduler::CountCoalescedClients() { |
|
mmenke
2014/07/16 17:01:33
nit: This should be const (As should CountActiveC
|
| + size_t coalesced_clients = 0; |
| + ClientMap::iterator client_it = client_map_.begin(); |
| + while (client_it != client_map_.end()) { |
| + Client* client = client_it->second; |
| + if (client->throttle_state() == COALESCED) { |
| + ++coalesced_clients; |
| + } |
| + ++client_it; |
| + } |
| + return coalesced_clients_; |
| +} |
| + |
| +void ResourceScheduler::LoadCoalescedRequests() { |
|
mmenke
2014/07/16 17:01:34
nit: Should use a similar naming scheme here as i
aiolos (Not reviewing)
2014/07/24 17:09:54
The code structures are parallel, but when/why the
|
| + ClientMap::iterator client_it = client_map_.begin(); |
| + while (client_it != client_map_.end()) { |
| + Client* client = client_it->second; |
| + client->LoadCoalescedRequests(); |
| + ++client_it; |
| + } |
| +} |
| + |
| void ResourceScheduler::ReprioritizeRequest(ScheduledResourceRequest* request, |
| net::RequestPriority new_priority, |
| int new_intra_priority_value) { |