| 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 21 matching lines...) Expand all  Loading... | 
| 46 // Users should call ScheduleRequest() to notify this ResourceScheduler of a | 47 // Users should call ScheduleRequest() to notify this ResourceScheduler of a | 
| 47 // new request. The returned ResourceThrottle should be destroyed when the load | 48 // new request. The returned ResourceThrottle should be destroyed when the load | 
| 48 // finishes or is canceled. | 49 // finishes or is canceled. | 
| 49 // | 50 // | 
| 50 // The scheduler may defer issuing the request via the ResourceThrottle | 51 // The scheduler may defer issuing the request via the ResourceThrottle | 
| 51 // interface or it may alter the request's priority by calling set_priority() on | 52 // interface or it may alter the request's priority by calling set_priority() on | 
| 52 // the URLRequest. | 53 // the URLRequest. | 
| 53 class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { | 54 class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { | 
| 54  public: | 55  public: | 
| 55   enum ClientThrottleState { | 56   enum ClientThrottleState { | 
|  | 57     // Currently being deleted client. | 
|  | 58     PAUSED, | 
| 56     // Loaded background client, all observable clients loaded. | 59     // Loaded background client, all observable clients loaded. | 
| 57     COALESCED, | 60     COALESCED, | 
| 58     // Background client, an observable client is loading. | 61     // Background client, an observable client is loading. | 
| 59     THROTTLED, | 62     THROTTLED, | 
| 60     // Observable (active) loaded client or | 63     // Observable (active) loaded client or | 
| 61     // Loading background client, all observable clients loaded. | 64     // Loading background client, all observable clients loaded. | 
| 62     // Note that clients which would be COALESCED are UNTHROTTLED until | 65     // Note that clients which would be COALESCED are UNTHROTTLED until | 
| 63     // coalescing is turned on. | 66     // coalescing is turned on. | 
| 64     UNTHROTTLED, | 67     UNTHROTTLED, | 
| 65     // Observable (active) loading client. | 68     // Observable (active) loading client. | 
| 66     ACTIVE_AND_LOADING, | 69     ACTIVE_AND_LOADING, | 
| 67   }; | 70   }; | 
| 68 | 71 | 
| 69   ResourceScheduler(); | 72   ResourceScheduler(); | 
| 70   ~ResourceScheduler(); | 73   ~ResourceScheduler(); | 
| 71 | 74 | 
|  | 75   // Use a mock timer when testing. | 
|  | 76   void set_timer_for_testing(scoped_ptr<base::Timer> timer) { | 
|  | 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 129   }; | 137   }; | 
| 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-entrant. | 
| 141   // Called when a Client newly becomes active loading. | 149   // Called when a Client newly becomes active loading. | 
|  | 150   void IncrementActiveClientsLoading(); | 
|  | 151   // Called when an active and loading Client either completes loading or | 
|  | 152   // becomes inactive. | 
| 142   void DecrementActiveClientsLoading(); | 153   void DecrementActiveClientsLoading(); | 
| 143   // Caled when a Client stops being active loading. |  | 
| 144   void IncrementActiveClientsLoading(); |  | 
| 145 | 154 | 
| 146   void OnLoadingActiveClientsStateChanged(); | 155   void OnLoadingActiveClientsStateChangedForAllClients(); | 
| 147 | 156 | 
| 148   size_t CountActiveClientsLoading(); | 157   size_t CountActiveClientsLoading() const; | 
|  | 158 | 
|  | 159   // Called when a Client becomes coalesced. | 
|  | 160   void IncrementCoalescedClients(); | 
|  | 161   // Called when a client stops being coalesced. | 
|  | 162   void DecrementCoalescedClients(); | 
|  | 163 | 
|  | 164   void LoadCoalescedRequests(); | 
|  | 165 | 
|  | 166   size_t CountCoalescedClients() const; | 
| 149 | 167 | 
| 150   // Update the queue position for |request|, possibly causing it to start | 168   // Update the queue position for |request|, possibly causing it to start | 
| 151   // loading. | 169   // loading. | 
| 152   // | 170   // | 
| 153   // Queues are maintained for each priority level. When |request| is | 171   // Queues are maintained for each priority level. When |request| is | 
| 154   // reprioritized, it will move to the end of the queue for that priority | 172   // reprioritized, it will move to the end of the queue for that priority | 
| 155   // level. | 173   // level. | 
| 156   void ReprioritizeRequest(ScheduledResourceRequest* request, | 174   void ReprioritizeRequest(ScheduledResourceRequest* request, | 
| 157                            net::RequestPriority new_priority, | 175                            net::RequestPriority new_priority, | 
| 158                            int intra_priority_value); | 176                            int intra_priority_value); | 
| 159 | 177 | 
| 160   // Returns the client ID for the given |child_id| and |route_id| combo. | 178   // Returns the client ID for the given |child_id| and |route_id| combo. | 
| 161   ClientId MakeClientId(int child_id, int route_id); | 179   ClientId MakeClientId(int child_id, int route_id); | 
| 162 | 180 | 
| 163   // Returns the client for the given |child_id| and |route_id| combo. | 181   // Returns the client for the given |child_id| and |route_id| combo. | 
| 164   Client* GetClient(int child_id, int route_id); | 182   Client* GetClient(int child_id, int route_id); | 
| 165 | 183 | 
| 166   bool should_coalesce_; | 184   bool should_coalesce_; | 
| 167   bool should_throttle_; | 185   bool should_throttle_; | 
| 168   ClientMap client_map_; | 186   ClientMap client_map_; | 
| 169   size_t active_clients_loading_; | 187   size_t active_clients_loading_; | 
|  | 188   size_t coalesced_clients_; | 
|  | 189   // This is a repeating timer to initiate requests on COALESCED Clients. | 
|  | 190   scoped_ptr<base::Timer> coalescing_timer_; | 
| 170   RequestSet unowned_requests_; | 191   RequestSet unowned_requests_; | 
| 171 }; | 192 }; | 
| 172 | 193 | 
| 173 }  // namespace content | 194 }  // namespace content | 
| 174 | 195 | 
| 175 #endif  // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ | 196 #endif  // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ | 
| OLD | NEW | 
|---|