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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host_impl.h

Issue 11270027: Add a ResourceScheduler to ResourceDispatcherHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months 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 | Annotate | Revision Log
OLDNEW
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 // This is the browser side of the resource dispatcher, it receives requests 5 // This is the browser side of the resource dispatcher, it receives requests
6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and
7 // dispatches them to URLRequests. It then forwards the messages from the 7 // dispatches them to URLRequests. It then forwards the messages from the
8 // URLRequests back to the correct process for handling. 8 // URLRequests back to the correct process for handling.
9 // 9 //
10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
11 11
12 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_ 12 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_
13 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_ 13 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_
14 14
15 #include <map> 15 #include <map>
16 #include <set> 16 #include <set>
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/gtest_prod_util.h" 21 #include "base/gtest_prod_util.h"
22 #include "base/memory/linked_ptr.h" 22 #include "base/memory/linked_ptr.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/time.h" 24 #include "base/time.h"
25 #include "base/timer.h" 25 #include "base/timer.h"
26 #include "content/browser/download/download_resource_handler.h" 26 #include "content/browser/download/download_resource_handler.h"
27 #include "content/browser/renderer_host/resource_loader.h" 27 #include "content/browser/renderer_host/resource_loader_impl.h"
28 #include "content/browser/renderer_host/resource_loader_delegate.h" 28 #include "content/browser/renderer_host/resource_loader_impl_delegate.h"
29 #include "content/common/content_export.h" 29 #include "content/common/content_export.h"
30 #include "content/public/browser/child_process_data.h" 30 #include "content/public/browser/child_process_data.h"
31 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/resource_dispatcher_host.h" 32 #include "content/public/browser/resource_dispatcher_host.h"
33 #include "ipc/ipc_message.h" 33 #include "ipc/ipc_message.h"
34 #include "net/cookies/canonical_cookie.h" 34 #include "net/cookies/canonical_cookie.h"
35 #include "net/url_request/url_request.h" 35 #include "net/url_request/url_request.h"
36 #include "webkit/glue/resource_type.h" 36 #include "webkit/glue/resource_type.h"
37 37
38 class ResourceHandler; 38 class ResourceHandler;
39 class SaveFileManager; 39 class SaveFileManager;
40 struct ResourceHostMsg_Request; 40 struct ResourceHostMsg_Request;
41 struct ViewMsg_SwapOut_Params; 41 struct ViewMsg_SwapOut_Params;
42 42
43 namespace net { 43 namespace net {
44 class URLRequestJobFactory; 44 class URLRequestJobFactory;
45 } 45 }
46 46
47 namespace webkit_blob { 47 namespace webkit_blob {
48 class ShareableFileReference; 48 class ShareableFileReference;
49 } 49 }
50 50
51 namespace content { 51 namespace content {
52 class ResourceContext; 52 class ResourceContext;
53 class ResourceDispatcherHostDelegate; 53 class ResourceDispatcherHostDelegate;
54 class ResourceMessageFilter; 54 class ResourceMessageFilter;
55 class ResourceRequestInfoImpl; 55 class ResourceRequestInfoImpl;
56 class ResourceScheduler;
56 class WebContentsImpl; 57 class WebContentsImpl;
57 struct DownloadSaveInfo; 58 struct DownloadSaveInfo;
58 struct GlobalRequestID; 59 struct GlobalRequestID;
59 struct Referrer; 60 struct Referrer;
60 61
61 class CONTENT_EXPORT ResourceDispatcherHostImpl 62 class CONTENT_EXPORT ResourceDispatcherHostImpl
62 : public ResourceDispatcherHost, 63 : public ResourceDispatcherHost,
63 public ResourceLoaderDelegate { 64 public ResourceLoaderImplDelegate {
64 public: 65 public:
65 ResourceDispatcherHostImpl(); 66 ResourceDispatcherHostImpl();
66 virtual ~ResourceDispatcherHostImpl(); 67 virtual ~ResourceDispatcherHostImpl();
67 68
68 // Returns the current ResourceDispatcherHostImpl. May return NULL if it 69 // Returns the current ResourceDispatcherHostImpl. May return NULL if it
69 // hasn't been created yet. 70 // hasn't been created yet.
70 static ResourceDispatcherHostImpl* Get(); 71 static ResourceDispatcherHostImpl* Get();
71 72
72 // ResourceDispatcherHost implementation: 73 // ResourceDispatcherHost implementation:
73 virtual void SetDelegate(ResourceDispatcherHostDelegate* delegate) OVERRIDE; 74 virtual void SetDelegate(ResourceDispatcherHostDelegate* delegate) OVERRIDE;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 bool Send(IPC::Message* message); 193 bool Send(IPC::Message* message);
193 194
194 // Indicates whether third-party sub-content can pop-up HTTP basic auth 195 // Indicates whether third-party sub-content can pop-up HTTP basic auth
195 // dialog boxes. 196 // dialog boxes.
196 bool allow_cross_origin_auth_prompt(); 197 bool allow_cross_origin_auth_prompt();
197 198
198 ResourceDispatcherHostDelegate* delegate() { 199 ResourceDispatcherHostDelegate* delegate() {
199 return delegate_; 200 return delegate_;
200 } 201 }
201 202
203 ResourceScheduler* scheduler() {
204 return resource_scheduler_.get();
205 }
206
202 // Must be called after the ResourceRequestInfo has been created 207 // Must be called after the ResourceRequestInfo has been created
203 // and associated with the request. 208 // and associated with the request.
204 scoped_ptr<ResourceHandler> CreateResourceHandlerForDownload( 209 scoped_ptr<ResourceHandler> CreateResourceHandlerForDownload(
205 net::URLRequest* request, 210 net::URLRequest* request,
206 bool is_content_initiated, 211 bool is_content_initiated,
207 scoped_ptr<DownloadSaveInfo> save_info, 212 scoped_ptr<DownloadSaveInfo> save_info,
208 const DownloadResourceHandler::OnStartedCallback& started_cb); 213 const DownloadResourceHandler::OnStartedCallback& started_cb);
209 214
210 void ClearSSLClientAuthHandlerForRequest(net::URLRequest* request); 215 void ClearSSLClientAuthHandlerForRequest(net::URLRequest* request);
211 216
212 private: 217 private:
213 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 218 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
214 TestBlockedRequestsProcessDies); 219 TestBlockedRequestsProcessDies);
215 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 220 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
216 IncrementOutstandingRequestsMemoryCost); 221 IncrementOutstandingRequestsMemoryCost);
217 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 222 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
218 CalculateApproximateMemoryCost); 223 CalculateApproximateMemoryCost);
219 224
220 class ShutdownTask; 225 class ShutdownTask;
221 226
222 friend class ShutdownTask; 227 friend class ShutdownTask;
223 228
224 // ResourceLoaderDelegate implementation: 229 // ResourceLoaderImplDelegate implementation:
225 virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 230 virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
226 ResourceLoader* loader, 231 ResourceLoaderImpl* loader,
227 net::AuthChallengeInfo* auth_info) OVERRIDE; 232 net::AuthChallengeInfo* auth_info) OVERRIDE;
228 virtual bool AcceptAuthRequest( 233 virtual bool AcceptAuthRequest(
229 ResourceLoader* loader, 234 ResourceLoaderImpl* loader,
230 net::AuthChallengeInfo* auth_info) OVERRIDE; 235 net::AuthChallengeInfo* auth_info) OVERRIDE;
231 virtual bool AcceptSSLClientCertificateRequest( 236 virtual bool AcceptSSLClientCertificateRequest(
232 ResourceLoader* loader, 237 ResourceLoaderImpl* loader,
233 net::SSLCertRequestInfo* cert_info) OVERRIDE; 238 net::SSLCertRequestInfo* cert_info) OVERRIDE;
234 virtual bool HandleExternalProtocol(ResourceLoader* loader, 239 virtual bool HandleExternalProtocol(ResourceLoaderImpl* loader,
235 const GURL& url) OVERRIDE; 240 const GURL& url) OVERRIDE;
236 virtual void DidStartRequest(ResourceLoader* loader) OVERRIDE; 241 virtual void DidStartRequest(ResourceLoaderImpl* loader) OVERRIDE;
237 virtual void DidReceiveRedirect(ResourceLoader* loader, 242 virtual void DidReceiveRedirect(ResourceLoaderImpl* loader,
238 const GURL& new_url) OVERRIDE; 243 const GURL& new_url) OVERRIDE;
239 virtual void DidReceiveResponse(ResourceLoader* loader) OVERRIDE; 244 virtual void DidReceiveResponse(ResourceLoaderImpl* loader) OVERRIDE;
240 virtual void DidFinishLoading(ResourceLoader* loader) OVERRIDE; 245 virtual void DidFinishLoading(ResourceLoaderImpl* loader) OVERRIDE;
241 246
242 // Extracts the render view/process host's identifiers from the given request 247 // Extracts the render view/process host's identifiers from the given request
243 // and places them in the given out params (both required). If there are no 248 // and places them in the given out params (both required). If there are no
244 // such IDs associated with the request (such as non-page-related requests), 249 // such IDs associated with the request (such as non-page-related requests),
245 // this function will return false and both out params will be -1. 250 // this function will return false and both out params will be -1.
246 static bool RenderViewForRequest(const net::URLRequest* request, 251 static bool RenderViewForRequest(const net::URLRequest* request,
247 int* render_process_host_id, 252 int* render_process_host_id,
248 int* render_view_host_id); 253 int* render_view_host_id);
249 254
250 // A shutdown helper that runs on the IO thread. 255 // A shutdown helper that runs on the IO thread.
251 void OnShutdown(); 256 void OnShutdown();
252 257
253 // The real implementation of the OnSwapOutACK logic. OnSwapOutACK and 258 // The real implementation of the OnSwapOutACK logic. OnSwapOutACK and
254 // OnSimulateSwapOutACK just call this method, supplying the |timed_out| 259 // OnSimulateSwapOutACK just call this method, supplying the |timed_out|
255 // parameter, which indicates whether the call is due to a timeout while 260 // parameter, which indicates whether the call is due to a timeout while
256 // waiting for SwapOut acknowledgement from the renderer process. 261 // waiting for SwapOut acknowledgement from the renderer process.
257 void HandleSwapOutACK(const ViewMsg_SwapOut_Params& params, bool timed_out); 262 void HandleSwapOutACK(const ViewMsg_SwapOut_Params& params, bool timed_out);
258 263
259 // Helper function for regular and download requests. 264 // Helper function for regular and download requests.
260 void BeginRequestInternal(scoped_ptr<net::URLRequest> request, 265 void BeginRequestInternal(scoped_ptr<net::URLRequest> request,
261 scoped_ptr<ResourceHandler> handler); 266 scoped_ptr<ResourceHandler> handler);
262 267
263 void StartLoading(ResourceRequestInfoImpl* info, 268 void StartLoading(ResourceRequestInfoImpl* info,
264 const linked_ptr<ResourceLoader>& loader); 269 const linked_ptr<ResourceLoaderImpl>& loader);
265 270
266 // Updates the "cost" of outstanding requests for |child_id|. 271 // Updates the "cost" of outstanding requests for |child_id|.
267 // The "cost" approximates how many bytes are consumed by all the in-memory 272 // The "cost" approximates how many bytes are consumed by all the in-memory
268 // data structures supporting this request (net::URLRequest object, 273 // data structures supporting this request (net::URLRequest object,
269 // HttpNetworkTransaction, etc...). 274 // HttpNetworkTransaction, etc...).
270 // The value of |cost| is added to the running total, and the resulting 275 // The value of |cost| is added to the running total, and the resulting
271 // sum is returned. 276 // sum is returned.
272 int IncrementOutstandingRequestsMemoryCost(int cost, 277 int IncrementOutstandingRequestsMemoryCost(int cost,
273 int child_id); 278 int child_id);
274 279
275 // Estimate how much heap space |request| will consume to run. 280 // Estimate how much heap space |request| will consume to run.
276 static int CalculateApproximateMemoryCost(net::URLRequest* request); 281 static int CalculateApproximateMemoryCost(net::URLRequest* request);
277 282
278 // The list of all requests that we have pending. This list is not really 283 // The list of all requests that we have pending. This list is not really
279 // optimized, and assumes that we have relatively few requests pending at once 284 // optimized, and assumes that we have relatively few requests pending at once
280 // since some operations require brute-force searching of the list. 285 // since some operations require brute-force searching of the list.
281 // 286 //
282 // It may be enhanced in the future to provide some kind of prioritization 287 // It may be enhanced in the future to provide some kind of prioritization
283 // mechanism. We should also consider a hashtable or binary tree if it turns 288 // mechanism. We should also consider a hashtable or binary tree if it turns
284 // out we have a lot of things here. 289 // out we have a lot of things here.
285 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; 290 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoaderImpl> > LoaderMap;
286 291
287 // Deletes the pending request identified by the iterator passed in. 292 // Deletes the pending request identified by the iterator passed in.
288 // This function will invalidate the iterator passed in. Callers should 293 // This function will invalidate the iterator passed in. Callers should
289 // not rely on this iterator being valid on return. 294 // not rely on this iterator being valid on return.
290 void RemovePendingLoader(const LoaderMap::iterator& iter); 295 void RemovePendingLoader(const LoaderMap::iterator& iter);
291 296
292 // Checks all pending requests and updates the load states and upload 297 // Checks all pending requests and updates the load states and upload
293 // progress if necessary. 298 // progress if necessary.
294 void UpdateLoadStates(); 299 void UpdateLoadStates();
295 300
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 341
337 HttpAuthResourceType HttpAuthResourceTypeOf(net::URLRequest* request); 342 HttpAuthResourceType HttpAuthResourceTypeOf(net::URLRequest* request);
338 343
339 // Returns whether the URLRequest identified by |transferred_request_id| is 344 // Returns whether the URLRequest identified by |transferred_request_id| is
340 // currently in the process of being transferred to a different renderer. 345 // currently in the process of being transferred to a different renderer.
341 // This happens if a request is redirected cross-site and needs to be resumed 346 // This happens if a request is redirected cross-site and needs to be resumed
342 // by a new render view. 347 // by a new render view.
343 bool IsTransferredNavigation( 348 bool IsTransferredNavigation(
344 const GlobalRequestID& transferred_request_id) const; 349 const GlobalRequestID& transferred_request_id) const;
345 350
346 ResourceLoader* GetLoader(const GlobalRequestID& id) const; 351 ResourceLoaderImpl* GetLoader(const GlobalRequestID& id) const;
347 ResourceLoader* GetLoader(int child_id, int request_id) const; 352 ResourceLoaderImpl* GetLoader(int child_id, int request_id) const;
348 353
349 LoaderMap pending_loaders_; 354 LoaderMap pending_loaders_;
350 355
351 // Collection of temp files downloaded for child processes via 356 // Collection of temp files downloaded for child processes via
352 // the download_to_file mechanism. We avoid deleting them until 357 // the download_to_file mechanism. We avoid deleting them until
353 // the client no longer needs them. 358 // the client no longer needs them.
354 typedef std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> > 359 typedef std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> >
355 DeletableFilesMap; // key is request id 360 DeletableFilesMap; // key is request id
356 typedef std::map<int, DeletableFilesMap> 361 typedef std::map<int, DeletableFilesMap>
357 RegisteredTempFiles; // key is child process id 362 RegisteredTempFiles; // key is child process id
(...skipping 12 matching lines...) Expand all
370 // start at -2 and go down from there. (We need to start at -2 because -1 is 375 // start at -2 and go down from there. (We need to start at -2 because -1 is
371 // used as a special value all over the resource_dispatcher_host for 376 // used as a special value all over the resource_dispatcher_host for
372 // uninitialized variables.) This way, we no longer have the unlikely (but 377 // uninitialized variables.) This way, we no longer have the unlikely (but
373 // observed in the real world!) event where we have two requests with the same 378 // observed in the real world!) event where we have two requests with the same
374 // request_id_. 379 // request_id_.
375 int request_id_; 380 int request_id_;
376 381
377 // True if the resource dispatcher host has been shut down. 382 // True if the resource dispatcher host has been shut down.
378 bool is_shutdown_; 383 bool is_shutdown_;
379 384
380 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList; 385 typedef std::vector<linked_ptr<ResourceLoaderImpl> > BlockedLoadersList;
381 typedef std::pair<int, int> ProcessRouteIDs; 386 typedef std::pair<int, int> ProcessRouteIDs;
382 typedef std::map<ProcessRouteIDs, BlockedLoadersList*> BlockedLoadersMap; 387 typedef std::map<ProcessRouteIDs, BlockedLoadersList*> BlockedLoadersMap;
383 BlockedLoadersMap blocked_loaders_map_; 388 BlockedLoadersMap blocked_loaders_map_;
384 389
385 // Maps the child_ids to the approximate number of bytes 390 // Maps the child_ids to the approximate number of bytes
386 // being used to service its resource requests. No entry implies 0 cost. 391 // being used to service its resource requests. No entry implies 0 cost.
387 typedef std::map<int, int> OutstandingRequestsMemoryCostMap; 392 typedef std::map<int, int> OutstandingRequestsMemoryCostMap;
388 OutstandingRequestsMemoryCostMap outstanding_requests_memory_cost_map_; 393 OutstandingRequestsMemoryCostMap outstanding_requests_memory_cost_map_;
389 394
390 // |max_outstanding_requests_cost_per_process_| is the upper bound on how 395 // |max_outstanding_requests_cost_per_process_| is the upper bound on how
(...skipping 15 matching lines...) Expand all
406 ResourceMessageFilter* filter_; 411 ResourceMessageFilter* filter_;
407 412
408 ResourceDispatcherHostDelegate* delegate_; 413 ResourceDispatcherHostDelegate* delegate_;
409 414
410 bool allow_cross_origin_auth_prompt_; 415 bool allow_cross_origin_auth_prompt_;
411 416
412 // http://crbug.com/90971 - Assists in tracking down use-after-frees on 417 // http://crbug.com/90971 - Assists in tracking down use-after-frees on
413 // shutdown. 418 // shutdown.
414 std::set<const ResourceContext*> active_resource_contexts_; 419 std::set<const ResourceContext*> active_resource_contexts_;
415 420
421 scoped_ptr<ResourceScheduler> resource_scheduler_;
422
416 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); 423 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl);
417 }; 424 };
418 425
419 } // namespace content 426 } // namespace content
420 427
421 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_ 428 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698