| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_RENDERER_HOST_RESOURCE_QUEUE_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ | 6 #define CONTENT_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 #include "content/common/content_export.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 class URLRequest; | 16 class URLRequest; |
| 16 } // namespace net | 17 } // namespace net |
| 17 | 18 |
| 18 class ResourceDispatcherHostRequestInfo; | 19 class ResourceDispatcherHostRequestInfo; |
| 19 class ResourceQueue; | 20 class ResourceQueue; |
| 20 struct GlobalRequestID; | 21 struct GlobalRequestID; |
| 21 | 22 |
| 22 // Makes decisions about delaying or not each net::URLRequest in the queue. | 23 // Makes decisions about delaying or not each net::URLRequest in the queue. |
| 23 // All methods are called on the IO thread. | 24 // All methods are called on the IO thread. |
| 24 class ResourceQueueDelegate { | 25 class ResourceQueueDelegate { |
| 25 public: | 26 public: |
| 26 // Gives the delegate a pointer to the queue object. | 27 // Gives the delegate a pointer to the queue object. |
| 27 virtual void Initialize(ResourceQueue* resource_queue) = 0; | 28 virtual void Initialize(ResourceQueue* resource_queue) = 0; |
| 28 | 29 |
| 29 // Should return true if it wants the |request| to not be started at this | 30 // Should return true if it wants the |request| to not be started at this |
| 30 // point. To start the delayed request, ResourceQueue::StartDelayedRequest | 31 // point. To start the delayed request, ResourceQueue::StartDelayedRequest |
| 31 // should be used. | 32 // should be used. |
| 32 virtual bool ShouldDelayRequest( | 33 virtual bool ShouldDelayRequest( |
| 33 net::URLRequest* request, | 34 net::URLRequest* request, |
| 34 const ResourceDispatcherHostRequestInfo& request_info, | 35 const ResourceDispatcherHostRequestInfo& request_info, |
| 35 const GlobalRequestID& request_id) = 0; | 36 const GlobalRequestID& request_id) = 0; |
| 36 | 37 |
| 37 // Called just before ResourceQueue shutdown. After that, the delegate | 38 // Called just before ResourceQueue shutdown. After that, the delegate |
| 38 // should not use the ResourceQueue. | 39 // should not use the ResourceQueue. |
| 39 virtual void WillShutdownResourceQueue() = 0; | 40 virtual void WillShutdownResourceQueue() = 0; |
| 40 | 41 |
| 41 protected: | 42 protected: |
| 42 virtual ~ResourceQueueDelegate(); | 43 CONTENT_EXPORT virtual ~ResourceQueueDelegate(); |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 // Makes it easy to delay starting URL requests until specified conditions are | 46 // Makes it easy to delay starting URL requests until specified conditions are |
| 46 // met. | 47 // met. |
| 47 class ResourceQueue { | 48 class ResourceQueue { |
| 48 public: | 49 public: |
| 49 typedef std::set<ResourceQueueDelegate*> DelegateSet; | 50 typedef std::set<ResourceQueueDelegate*> DelegateSet; |
| 50 | 51 |
| 51 // UI THREAD ONLY ------------------------------------------------------------ | 52 // UI THREAD ONLY ------------------------------------------------------------ |
| 52 | 53 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 69 void AddRequest(net::URLRequest* request, | 70 void AddRequest(net::URLRequest* request, |
| 70 const ResourceDispatcherHostRequestInfo& request_info); | 71 const ResourceDispatcherHostRequestInfo& request_info); |
| 71 | 72 |
| 72 // Tells the queue that the net::URLRequest object associated with | 73 // Tells the queue that the net::URLRequest object associated with |
| 73 // |request_id| is no longer valid. | 74 // |request_id| is no longer valid. |
| 74 void RemoveRequest(const GlobalRequestID& request_id); | 75 void RemoveRequest(const GlobalRequestID& request_id); |
| 75 | 76 |
| 76 // A delegate should call StartDelayedRequest when it wants to allow the | 77 // A delegate should call StartDelayedRequest when it wants to allow the |
| 77 // request to start. If it was the last delegate that demanded the request | 78 // request to start. If it was the last delegate that demanded the request |
| 78 // to be delayed, the request will be started. | 79 // to be delayed, the request will be started. |
| 79 void StartDelayedRequest(ResourceQueueDelegate* delegate, | 80 CONTENT_EXPORT void StartDelayedRequest(ResourceQueueDelegate* delegate, |
| 80 const GlobalRequestID& request_id); | 81 const GlobalRequestID& request_id); |
| 81 | 82 |
| 82 private: | 83 private: |
| 83 typedef std::map<GlobalRequestID, net::URLRequest*> RequestMap; | 84 typedef std::map<GlobalRequestID, net::URLRequest*> RequestMap; |
| 84 typedef std::map<GlobalRequestID, DelegateSet> InterestedDelegatesMap; | 85 typedef std::map<GlobalRequestID, DelegateSet> InterestedDelegatesMap; |
| 85 | 86 |
| 86 // The registered delegates. Will not change after the queue has been | 87 // The registered delegates. Will not change after the queue has been |
| 87 // initialized. | 88 // initialized. |
| 88 DelegateSet delegates_; | 89 DelegateSet delegates_; |
| 89 | 90 |
| 90 // Stores net::URLRequest objects associated with each GlobalRequestID. This | 91 // Stores net::URLRequest objects associated with each GlobalRequestID. This |
| 91 // helps decoupling the queue from ResourceDispatcherHost. | 92 // helps decoupling the queue from ResourceDispatcherHost. |
| 92 RequestMap requests_; | 93 RequestMap requests_; |
| 93 | 94 |
| 94 // Maps a GlobalRequestID to the set of delegates that want to prevent the | 95 // Maps a GlobalRequestID to the set of delegates that want to prevent the |
| 95 // associated request from starting yet. | 96 // associated request from starting yet. |
| 96 InterestedDelegatesMap interested_delegates_; | 97 InterestedDelegatesMap interested_delegates_; |
| 97 | 98 |
| 98 // True when we are shutting down. | 99 // True when we are shutting down. |
| 99 bool shutdown_; | 100 bool shutdown_; |
| 100 | 101 |
| 101 DISALLOW_COPY_AND_ASSIGN(ResourceQueue); | 102 DISALLOW_COPY_AND_ASSIGN(ResourceQueue); |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ | 105 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_ |
| OLD | NEW |