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

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: Manage ownership with handles Created 8 years, 1 month 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.h"
28 #include "content/browser/renderer_host/resource_loader_delegate.h" 28 #include "content/browser/renderer_host/resource_loader_delegate.h"
29 #include "content/browser/renderer_host/resource_scheduler.h"
29 #include "content/common/content_export.h" 30 #include "content/common/content_export.h"
30 #include "content/public/browser/child_process_data.h" 31 #include "content/public/browser/child_process_data.h"
31 #include "content/public/browser/notification_types.h" 32 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/resource_dispatcher_host.h" 33 #include "content/public/browser/resource_dispatcher_host.h"
33 #include "ipc/ipc_message.h" 34 #include "ipc/ipc_message.h"
34 #include "net/cookies/canonical_cookie.h" 35 #include "net/cookies/canonical_cookie.h"
35 #include "net/url_request/url_request.h" 36 #include "net/url_request/url_request.h"
36 #include "webkit/glue/resource_type.h" 37 #include "webkit/glue/resource_type.h"
37 38
38 class ResourceHandler; 39 class ResourceHandler;
(...skipping 153 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
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 scheduled. 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 // We should also consider a hashtable or binary tree if it turns out we have
283 // mechanism. We should also consider a hashtable or binary tree if it turns 288 // a lot of things here.
284 // out we have a lot of things here. 289 typedef std::map<
285 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; 290 GlobalRequestID, linked_ptr<ResourceScheduler::LoadHandle> > 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<ResourceLoader> > BlockedLoadersList;
willchan no longer on Chromium 2012/11/21 09:04:30 This confuses me. Who owns the ResourceLoader? Why
James Simonsen 2012/11/27 02:20:51 Both, but only one at a time. A loader is either b
willchan no longer on Chromium 2012/12/03 02:30:16 I think we should use ScopedVector instead, and we
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_;
willchan no longer on Chromium 2012/11/21 09:04:30 Why bother with a scoped_ptr?
James Simonsen 2012/11/27 02:20:51 I thought the leak checker would complain during t
willchan no longer on Chromium 2012/11/30 10:16:20 No, I mean, why isn't the whole object just embedd
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