OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 | 13 |
| 14 namespace net { |
| 15 class URLRequest; |
| 16 } // namespace net |
| 17 |
14 class ResourceDispatcherHostRequestInfo; | 18 class ResourceDispatcherHostRequestInfo; |
15 class URLRequest; | |
16 struct GlobalRequestID; | 19 struct GlobalRequestID; |
17 | 20 |
18 // Makes decisions about delaying or not each URLRequest in the queue. | 21 // Makes decisions about delaying or not each URLRequest in the queue. |
19 // All methods are called on the IO thread. | 22 // All methods are called on the IO thread. |
20 class ResourceQueueDelegate { | 23 class ResourceQueueDelegate { |
21 public: | 24 public: |
22 // Should return true if it wants the |request| to not be started at this | 25 // Should return true if it wants the |request| to not be started at this |
23 // point. To start the delayed request, ResourceQueue::StartDelayedRequest | 26 // point. To start the delayed request, ResourceQueue::StartDelayedRequest |
24 // should be used. | 27 // should be used. |
25 virtual bool ShouldDelayRequest( | 28 virtual bool ShouldDelayRequest( |
26 URLRequest* request, | 29 net::URLRequest* request, |
27 const ResourceDispatcherHostRequestInfo& request_info, | 30 const ResourceDispatcherHostRequestInfo& request_info, |
28 const GlobalRequestID& request_id) = 0; | 31 const GlobalRequestID& request_id) = 0; |
29 | 32 |
30 // Called just before ResourceQueue shutdown. After that, the delegate | 33 // Called just before ResourceQueue shutdown. After that, the delegate |
31 // should not use the ResourceQueue. | 34 // should not use the ResourceQueue. |
32 virtual void WillShutdownResourceQueue() = 0; | 35 virtual void WillShutdownResourceQueue() = 0; |
33 | 36 |
34 protected: | 37 protected: |
35 virtual ~ResourceQueueDelegate(); | 38 virtual ~ResourceQueueDelegate(); |
36 }; | 39 }; |
(...skipping 15 matching lines...) Expand all Loading... |
52 void Initialize(const DelegateSet& delegates); | 55 void Initialize(const DelegateSet& delegates); |
53 | 56 |
54 // IO THREAD ONLY ------------------------------------------------------------ | 57 // IO THREAD ONLY ------------------------------------------------------------ |
55 | 58 |
56 // Must be called before destroying the queue. No other methods can be called | 59 // Must be called before destroying the queue. No other methods can be called |
57 // after that. | 60 // after that. |
58 void Shutdown(); | 61 void Shutdown(); |
59 | 62 |
60 // Takes care to start the |request| after all delegates allow that. If no | 63 // Takes care to start the |request| after all delegates allow that. If no |
61 // delegate demands delaying the request it will be started immediately. | 64 // delegate demands delaying the request it will be started immediately. |
62 void AddRequest(URLRequest* request, | 65 void AddRequest(net::URLRequest* request, |
63 const ResourceDispatcherHostRequestInfo& request_info); | 66 const ResourceDispatcherHostRequestInfo& request_info); |
64 | 67 |
65 // Tells the queue that the URLRequest object associated with |request_id| | 68 // Tells the queue that the URLRequest object associated with |request_id| |
66 // is no longer valid. | 69 // is no longer valid. |
67 void RemoveRequest(const GlobalRequestID& request_id); | 70 void RemoveRequest(const GlobalRequestID& request_id); |
68 | 71 |
69 // A delegate should call StartDelayedRequest when it wants to allow the | 72 // A delegate should call StartDelayedRequest when it wants to allow the |
70 // request to start. If it was the last delegate that demanded the request | 73 // request to start. If it was the last delegate that demanded the request |
71 // to be delayed, the request will be started. | 74 // to be delayed, the request will be started. |
72 void StartDelayedRequest(ResourceQueueDelegate* delegate, | 75 void StartDelayedRequest(ResourceQueueDelegate* delegate, |
73 const GlobalRequestID& request_id); | 76 const GlobalRequestID& request_id); |
74 | 77 |
75 private: | 78 private: |
76 typedef std::map<GlobalRequestID, URLRequest*> RequestMap; | 79 typedef std::map<GlobalRequestID, net::URLRequest*> RequestMap; |
77 typedef std::map<GlobalRequestID, DelegateSet> InterestedDelegatesMap; | 80 typedef std::map<GlobalRequestID, DelegateSet> InterestedDelegatesMap; |
78 | 81 |
79 // The registered delegates. Will not change after the queue has been | 82 // The registered delegates. Will not change after the queue has been |
80 // initialized. | 83 // initialized. |
81 DelegateSet delegates_; | 84 DelegateSet delegates_; |
82 | 85 |
83 // Stores URLRequest objects associated with each GlobalRequestID. This helps | 86 // Stores URLRequest objects associated with each GlobalRequestID. This helps |
84 // decoupling the queue from ResourceDispatcherHost. | 87 // decoupling the queue from ResourceDispatcherHost. |
85 RequestMap requests_; | 88 RequestMap requests_; |
86 | 89 |
87 // Maps a GlobalRequestID to the set of delegates that want to prevent the | 90 // Maps a GlobalRequestID to the set of delegates that want to prevent the |
88 // associated request from starting yet. | 91 // associated request from starting yet. |
89 InterestedDelegatesMap interested_delegates_; | 92 InterestedDelegatesMap interested_delegates_; |
90 | 93 |
91 // True when we are shutting down. | 94 // True when we are shutting down. |
92 bool shutdown_; | 95 bool shutdown_; |
93 | 96 |
94 DISALLOW_COPY_AND_ASSIGN(ResourceQueue); | 97 DISALLOW_COPY_AND_ASSIGN(ResourceQueue); |
95 }; | 98 }; |
96 | 99 |
97 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ | 100 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ |
OLD | NEW |