OLD | NEW |
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_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
14 | 14 |
15 #include <stdint.h> | 15 #include <stdint.h> |
16 | 16 |
17 #include <map> | 17 #include <map> |
18 #include <set> | 18 #include <set> |
19 #include <string> | 19 #include <string> |
20 #include <vector> | 20 #include <vector> |
21 | 21 |
22 #include "base/gtest_prod_util.h" | 22 #include "base/gtest_prod_util.h" |
23 #include "base/macros.h" | 23 #include "base/macros.h" |
24 #include "base/memory/linked_ptr.h" | |
25 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
26 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
27 #include "base/time/time.h" | 26 #include "base/time/time.h" |
28 #include "base/timer/timer.h" | 27 #include "base/timer/timer.h" |
29 #include "content/browser/download/download_resource_handler.h" | 28 #include "content/browser/download/download_resource_handler.h" |
30 #include "content/browser/download/save_types.h" | 29 #include "content/browser/download/save_types.h" |
31 #include "content/browser/loader/global_routing_id.h" | 30 #include "content/browser/loader/global_routing_id.h" |
32 #include "content/browser/loader/resource_loader.h" | 31 #include "content/browser/loader/resource_loader.h" |
33 #include "content/browser/loader/resource_loader_delegate.h" | 32 #include "content/browser/loader/resource_loader_delegate.h" |
34 #include "content/browser/loader/resource_scheduler.h" | 33 #include "content/browser/loader/resource_scheduler.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 void OnInit(); | 334 void OnInit(); |
336 | 335 |
337 // A shutdown helper that runs on the IO thread. | 336 // A shutdown helper that runs on the IO thread. |
338 void OnShutdown(); | 337 void OnShutdown(); |
339 | 338 |
340 // Helper function for regular and download requests. | 339 // Helper function for regular and download requests. |
341 void BeginRequestInternal(scoped_ptr<net::URLRequest> request, | 340 void BeginRequestInternal(scoped_ptr<net::URLRequest> request, |
342 scoped_ptr<ResourceHandler> handler); | 341 scoped_ptr<ResourceHandler> handler); |
343 | 342 |
344 void StartLoading(ResourceRequestInfoImpl* info, | 343 void StartLoading(ResourceRequestInfoImpl* info, |
345 const linked_ptr<ResourceLoader>& loader); | 344 scoped_ptr<ResourceLoader> loader); |
346 | 345 |
347 // We keep track of how much memory each request needs and how many requests | 346 // We keep track of how much memory each request needs and how many requests |
348 // are issued by each renderer. These are known as OustandingRequestStats. | 347 // are issued by each renderer. These are known as OustandingRequestStats. |
349 // Memory limits apply to all requests sent to us by the renderers. There is a | 348 // Memory limits apply to all requests sent to us by the renderers. There is a |
350 // limit for each renderer. File descriptor limits apply to requests that are | 349 // limit for each renderer. File descriptor limits apply to requests that are |
351 // receiving their body. These are known as in-flight requests. There is a | 350 // receiving their body. These are known as in-flight requests. There is a |
352 // global limit that applies for the browser process. Each render is allowed | 351 // global limit that applies for the browser process. Each render is allowed |
353 // to use up to a fraction of that. | 352 // to use up to a fraction of that. |
354 | 353 |
355 // Returns the OustandingRequestsStats for |info|'s renderer, or an empty | 354 // Returns the OustandingRequestsStats for |info|'s renderer, or an empty |
(...skipping 26 matching lines...) Expand all Loading... |
382 // acts like CancelRequestsForProcess when route_id is -1. | 381 // acts like CancelRequestsForProcess when route_id is -1. |
383 void CancelRequestsForRoute(int child_id, int route_id); | 382 void CancelRequestsForRoute(int child_id, int route_id); |
384 | 383 |
385 // The list of all requests that we have pending. This list is not really | 384 // The list of all requests that we have pending. This list is not really |
386 // optimized, and assumes that we have relatively few requests pending at once | 385 // optimized, and assumes that we have relatively few requests pending at once |
387 // since some operations require brute-force searching of the list. | 386 // since some operations require brute-force searching of the list. |
388 // | 387 // |
389 // It may be enhanced in the future to provide some kind of prioritization | 388 // It may be enhanced in the future to provide some kind of prioritization |
390 // mechanism. We should also consider a hashtable or binary tree if it turns | 389 // mechanism. We should also consider a hashtable or binary tree if it turns |
391 // out we have a lot of things here. | 390 // out we have a lot of things here. |
392 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; | 391 using LoaderMap = std::map<GlobalRequestID, scoped_ptr<ResourceLoader>>; |
393 | 392 |
394 // Deletes the pending request identified by the iterator passed in. | 393 // Deletes the pending request identified by the iterator passed in. |
395 // This function will invalidate the iterator passed in. Callers should | 394 // This function will invalidate the iterator passed in. Callers should |
396 // not rely on this iterator being valid on return. | 395 // not rely on this iterator being valid on return. |
397 void RemovePendingLoader(const LoaderMap::iterator& iter); | 396 void RemovePendingLoader(const LoaderMap::iterator& iter); |
398 | 397 |
399 // This function returns true if the LoadInfo of |a| is "more interesting" | 398 // This function returns true if the LoadInfo of |a| is "more interesting" |
400 // than the LoadInfo of |b|. The load that is currently sending the larger | 399 // than the LoadInfo of |b|. The load that is currently sending the larger |
401 // request body is considered more interesting. If neither request is | 400 // request body is considered more interesting. If neither request is |
402 // sending a body (Neither request has a body, or any request that has a body | 401 // sending a body (Neither request has a body, or any request that has a body |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 void OnSyncLoad(int request_id, | 434 void OnSyncLoad(int request_id, |
436 const ResourceHostMsg_Request& request_data, | 435 const ResourceHostMsg_Request& request_data, |
437 IPC::Message* sync_result); | 436 IPC::Message* sync_result); |
438 | 437 |
439 // Update the ResourceRequestInfo and internal maps when a request is | 438 // Update the ResourceRequestInfo and internal maps when a request is |
440 // transferred from one process to another. | 439 // transferred from one process to another. |
441 void UpdateRequestForTransfer(int child_id, | 440 void UpdateRequestForTransfer(int child_id, |
442 int route_id, | 441 int route_id, |
443 int request_id, | 442 int request_id, |
444 const ResourceHostMsg_Request& request_data, | 443 const ResourceHostMsg_Request& request_data, |
445 const linked_ptr<ResourceLoader>& loader); | 444 LoaderMap::iterator iter); |
446 | 445 |
447 void BeginRequest(int request_id, | 446 void BeginRequest(int request_id, |
448 const ResourceHostMsg_Request& request_data, | 447 const ResourceHostMsg_Request& request_data, |
449 IPC::Message* sync_result, // only valid for sync | 448 IPC::Message* sync_result, // only valid for sync |
450 int route_id); // only valid for async | 449 int route_id); // only valid for async |
451 | 450 |
452 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 451 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
453 // loading. | 452 // loading. |
454 scoped_ptr<ResourceHandler> CreateResourceHandler( | 453 scoped_ptr<ResourceHandler> CreateResourceHandler( |
455 net::URLRequest* request, | 454 net::URLRequest* request, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 // start at -2 and go down from there. (We need to start at -2 because -1 is | 543 // start at -2 and go down from there. (We need to start at -2 because -1 is |
545 // used as a special value all over the resource_dispatcher_host for | 544 // used as a special value all over the resource_dispatcher_host for |
546 // uninitialized variables.) This way, we no longer have the unlikely (but | 545 // uninitialized variables.) This way, we no longer have the unlikely (but |
547 // observed in the real world!) event where we have two requests with the same | 546 // observed in the real world!) event where we have two requests with the same |
548 // request_id_. | 547 // request_id_. |
549 int request_id_; | 548 int request_id_; |
550 | 549 |
551 // True if the resource dispatcher host has been shut down. | 550 // True if the resource dispatcher host has been shut down. |
552 bool is_shutdown_; | 551 bool is_shutdown_; |
553 | 552 |
554 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList; | 553 using BlockedLoadersList = std::vector<scoped_ptr<ResourceLoader>>; |
555 typedef std::map<GlobalRoutingID, BlockedLoadersList*> BlockedLoadersMap; | 554 using BlockedLoadersMap = |
| 555 std::map<GlobalRoutingID, scoped_ptr<BlockedLoadersList>>; |
556 BlockedLoadersMap blocked_loaders_map_; | 556 BlockedLoadersMap blocked_loaders_map_; |
557 | 557 |
558 // Maps the child_ids to the approximate number of bytes | 558 // Maps the child_ids to the approximate number of bytes |
559 // being used to service its resource requests. No entry implies 0 cost. | 559 // being used to service its resource requests. No entry implies 0 cost. |
560 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; | 560 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; |
561 OutstandingRequestsStatsMap outstanding_requests_stats_map_; | 561 OutstandingRequestsStatsMap outstanding_requests_stats_map_; |
562 | 562 |
563 // |num_in_flight_requests_| is the total number of requests currently issued | 563 // |num_in_flight_requests_| is the total number of requests currently issued |
564 // summed across all renderers. | 564 // summed across all renderers. |
565 int num_in_flight_requests_; | 565 int num_in_flight_requests_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 DelegateMap delegate_map_; | 611 DelegateMap delegate_map_; |
612 | 612 |
613 scoped_ptr<ResourceScheduler> scheduler_; | 613 scoped_ptr<ResourceScheduler> scheduler_; |
614 | 614 |
615 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 615 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
616 }; | 616 }; |
617 | 617 |
618 } // namespace content | 618 } // namespace content |
619 | 619 |
620 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 620 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |