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 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ | 6 #define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "base/timer/timer.h" | |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 16 #include "net/base/priority_queue.h" | 17 #include "net/base/priority_queue.h" |
| 17 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 class HostPortPair; | 21 class HostPortPair; |
| 21 class URLRequest; | 22 class URLRequest; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 // Note that clients which would be COALESCED are UNTHROTTLED until | 63 // Note that clients which would be COALESCED are UNTHROTTLED until |
| 63 // coalescing is turned on. | 64 // coalescing is turned on. |
| 64 UNTHROTTLED, | 65 UNTHROTTLED, |
| 65 // Observable (active) loading client. | 66 // Observable (active) loading client. |
| 66 ACTIVE_AND_LOADING, | 67 ACTIVE_AND_LOADING, |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 ResourceScheduler(); | 70 ResourceScheduler(); |
| 70 ~ResourceScheduler(); | 71 ~ResourceScheduler(); |
| 71 | 72 |
| 73 // Use a mock timer when testing. | |
| 74 void set_timer_for_testing(scoped_ptr<base::Timer> timer) { | |
| 75 DCHECK(timer); | |
| 76 coalescing_timer_.reset(); | |
| 77 coalescing_timer_.reset(timer.release()); | |
| 78 } | |
| 79 | |
| 72 // TODO(aiolos): Remove when throttling and coalescing have landed | 80 // TODO(aiolos): Remove when throttling and coalescing have landed |
| 73 void SetThrottleOptionsForTesting(bool should_throttle, bool should_coalesce); | 81 void SetThrottleOptionsForTesting(bool should_throttle, bool should_coalesce); |
| 74 | 82 |
| 75 bool should_coalesce() const { return should_coalesce_; } | 83 bool should_coalesce() const { return should_coalesce_; } |
| 76 bool should_throttle() const { return should_throttle_; } | 84 bool should_throttle() const { return should_throttle_; } |
| 77 | 85 |
| 78 ClientThrottleState GetClientStateForTesting(int child_id, int route_id); | 86 ClientThrottleState GetClientStateForTesting(int child_id, int route_id); |
| 79 | 87 |
| 80 // Requests that this ResourceScheduler schedule, and eventually loads, the | 88 // Requests that this ResourceScheduler schedule, and eventually loads, the |
| 81 // specified |url_request|. Caller should delete the returned ResourceThrottle | 89 // specified |url_request|. Caller should delete the returned ResourceThrottle |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 class Client; | 138 class Client; |
| 131 | 139 |
| 132 typedef int64 ClientId; | 140 typedef int64 ClientId; |
| 133 typedef std::map<ClientId, Client*> ClientMap; | 141 typedef std::map<ClientId, Client*> ClientMap; |
| 134 typedef std::set<ScheduledResourceRequest*> RequestSet; | 142 typedef std::set<ScheduledResourceRequest*> RequestSet; |
| 135 | 143 |
| 136 // Called when a ScheduledResourceRequest is destroyed. | 144 // Called when a ScheduledResourceRequest is destroyed. |
| 137 void RemoveRequest(ScheduledResourceRequest* request); | 145 void RemoveRequest(ScheduledResourceRequest* request); |
| 138 | 146 |
| 139 // These Calls may update the ThrottleState of all clients, and have the | 147 // These Calls may update the ThrottleState of all clients, and have the |
| 140 // potential to be re-entarant. | 148 // potential to be re-entarant. |
|
mmenke
2014/07/16 17:01:34
nit: While you're here, this should be "re-entran
| |
| 141 // Called when a Client newly becomes active loading. | 149 // Called when a Client newly becomes active loading. |
| 150 void IncrementActiveClientsLoading(); | |
| 151 // Caled when a Client stops being active loading. | |
|
mmenke
2014/07/16 17:01:34
nit: "Called". Also, grammar isn't quite right.
| |
| 142 void DecrementActiveClientsLoading(); | 152 void DecrementActiveClientsLoading(); |
|
aiolos (Not reviewing)
2014/07/15 23:54:58
The comments were in the wrong order. If you want
mmenke
2014/07/16 17:01:34
I'm fine with the change in this CL.
| |
| 143 // Caled when a Client stops being active loading. | |
| 144 void IncrementActiveClientsLoading(); | |
| 145 | 153 |
| 146 void OnLoadingActiveClientsStateChanged(); | 154 void OnLoadingActiveClientsStateChanged(); |
| 147 | 155 |
| 148 size_t CountActiveClientsLoading(); | 156 size_t CountActiveClientsLoading(); |
| 149 | 157 |
| 158 // Called when a Client becomes coalesced. | |
| 159 void IncrementCoalescedClients(); | |
| 160 // Called when a client stops being coalesced. | |
| 161 void DecrementCoalescedClients(); | |
| 162 | |
| 163 size_t CountCoalescedClients(); | |
| 164 | |
| 165 void LoadCoalescedRequests(); | |
| 166 | |
| 150 // Update the queue position for |request|, possibly causing it to start | 167 // Update the queue position for |request|, possibly causing it to start |
| 151 // loading. | 168 // loading. |
| 152 // | 169 // |
| 153 // Queues are maintained for each priority level. When |request| is | 170 // Queues are maintained for each priority level. When |request| is |
| 154 // reprioritized, it will move to the end of the queue for that priority | 171 // reprioritized, it will move to the end of the queue for that priority |
| 155 // level. | 172 // level. |
| 156 void ReprioritizeRequest(ScheduledResourceRequest* request, | 173 void ReprioritizeRequest(ScheduledResourceRequest* request, |
| 157 net::RequestPriority new_priority, | 174 net::RequestPriority new_priority, |
| 158 int intra_priority_value); | 175 int intra_priority_value); |
| 159 | 176 |
| 160 // Returns the client ID for the given |child_id| and |route_id| combo. | 177 // Returns the client ID for the given |child_id| and |route_id| combo. |
| 161 ClientId MakeClientId(int child_id, int route_id); | 178 ClientId MakeClientId(int child_id, int route_id); |
| 162 | 179 |
| 163 // Returns the client for the given |child_id| and |route_id| combo. | 180 // Returns the client for the given |child_id| and |route_id| combo. |
| 164 Client* GetClient(int child_id, int route_id); | 181 Client* GetClient(int child_id, int route_id); |
| 165 | 182 |
| 166 bool should_coalesce_; | 183 bool should_coalesce_; |
| 167 bool should_throttle_; | 184 bool should_throttle_; |
| 168 ClientMap client_map_; | 185 ClientMap client_map_; |
| 169 size_t active_clients_loading_; | 186 size_t active_clients_loading_; |
| 187 size_t coalesced_clients_; | |
| 188 scoped_ptr<base::Timer> coalescing_timer_; | |
| 170 RequestSet unowned_requests_; | 189 RequestSet unowned_requests_; |
| 171 }; | 190 }; |
| 172 | 191 |
| 173 } // namespace content | 192 } // namespace content |
| 174 | 193 |
| 175 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ | 194 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |
| OLD | NEW |