Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/renderer_host/resource_queue.h

Issue 460108: Implement ResourceQueue, an object that makes it easy to delay starting (Closed)
Patch Set: nitfixing Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_
6 #define CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_
7
8 #include <map>
9 #include <set>
10
11 #include "base/basictypes.h"
12
13 class ResourceDispatcherHostRequestInfo;
14 class URLRequest;
15 struct GlobalRequestID;
16
17 // Makes decisions about delaying or not each URLRequest in the queue.
18 // All methods are called on the IO thread.
19 class ResourceQueueDelegate {
20 public:
21 // Should return true if it wants the |request| to not be started at this
22 // point. To start the delayed request, ResourceQueue::StartDelayedRequest
23 // should be used.
24 virtual bool ShouldDelayRequest(
25 URLRequest* request,
26 const ResourceDispatcherHostRequestInfo& request_info,
27 const GlobalRequestID& request_id) = 0;
28
29 // Called just before ResourceQueue shutdown. After that, the delegate
30 // should not use the ResourceQueue.
31 virtual void WillShutdownResourceQueue() = 0;
32
33 protected:
34 virtual ~ResourceQueueDelegate();
35 };
36
37 // Makes it easy to delay starting URL requests until specified conditions are
38 // met.
39 class ResourceQueue {
40 public:
41 typedef std::set<ResourceQueueDelegate*> DelegateSet;
42
43 // UI THREAD ONLY ------------------------------------------------------------
44
45 // Construct the queue. You must initialize it using Initialize.
46 ResourceQueue();
47 ~ResourceQueue();
48
49 // Initialize the queue with set of delegates it should ask for each incoming
50 // request.
51 void Initialize(const DelegateSet& delegates);
52
53 // IO THREAD ONLY ------------------------------------------------------------
54
55 // Must be called before destroying the queue. No other methods can be called
56 // after that.
57 void Shutdown();
58
59 // Takes care to start the |request| after all delegates allow that. If no
60 // delegate demands delaying the request it will be started immediately.
61 void AddRequest(URLRequest* request,
62 const ResourceDispatcherHostRequestInfo& request_info);
63
64 // Tells the queue that the URLRequest object associated with |request_id|
65 // is no longer valid.
66 void RemoveRequest(const GlobalRequestID& request_id);
67
68 // A delegate should call StartDelayedRequest when it wants to allow the
69 // request to start. If it was the last delegate that demanded the request
70 // to be delayed, the request will be started.
71 void StartDelayedRequest(ResourceQueueDelegate* delegate,
72 const GlobalRequestID& request_id);
73
74 private:
75 typedef std::map<GlobalRequestID, URLRequest*> RequestMap;
76 typedef std::map<GlobalRequestID, DelegateSet> InterestedDelegatesMap;
77
78 // The registered delegates. Will not change after the queue has been
79 // initialized.
80 DelegateSet delegates_;
81
82 // Stores URLRequest objects associated with each GlobalRequestID. This helps
83 // decoupling the queue from ResourceDispatcherHost.
84 RequestMap requests_;
85
86 // Maps a GlobalRequestID to the set of delegates that want to prevent the
87 // associated request from starting yet.
88 InterestedDelegatesMap interested_delegates_;
89
90 // True when we are shutting down.
91 bool shutdown_;
92
93 DISALLOW_COPY_AND_ASSIGN(ResourceQueue);
94 };
95
96 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_QUEUE_H_
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc ('k') | chrome/browser/renderer_host/resource_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698