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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/gtest_prod_util.h" | 23 #include "base/gtest_prod_util.h" |
24 #include "base/macros.h" | 24 #include "base/macros.h" |
25 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
27 #include "base/timer/timer.h" | 27 #include "base/timer/timer.h" |
28 #include "content/browser/download/download_resource_handler.h" | 28 #include "content/browser/download/download_resource_handler.h" |
29 #include "content/browser/download/save_types.h" | 29 #include "content/browser/download/save_types.h" |
30 #include "content/browser/loader/global_routing_id.h" | 30 #include "content/browser/loader/global_routing_id.h" |
31 #include "content/browser/loader/resource_loader.h" | 31 #include "content/browser/loader/resource_loader.h" |
32 #include "content/browser/loader/resource_loader_delegate.h" | 32 #include "content/browser/loader/resource_loader_delegate.h" |
| 33 #include "content/browser/loader/resource_request_info_impl.h" |
33 #include "content/browser/loader/resource_scheduler.h" | 34 #include "content/browser/loader/resource_scheduler.h" |
34 #include "content/common/content_export.h" | 35 #include "content/common/content_export.h" |
35 #include "content/common/resource_request_body.h" | 36 #include "content/common/resource_request_body.h" |
36 #include "content/public/browser/child_process_data.h" | 37 #include "content/public/browser/child_process_data.h" |
37 #include "content/public/browser/download_item.h" | 38 #include "content/public/browser/download_item.h" |
38 #include "content/public/browser/download_url_parameters.h" | 39 #include "content/public/browser/download_url_parameters.h" |
39 #include "content/public/browser/global_request_id.h" | 40 #include "content/public/browser/global_request_id.h" |
40 #include "content/public/browser/notification_types.h" | 41 #include "content/public/browser/notification_types.h" |
41 #include "content/public/browser/resource_dispatcher_host.h" | 42 #include "content/public/browser/resource_dispatcher_host.h" |
42 #include "content/public/browser/web_contents_observer.h" | 43 #include "content/public/browser/web_contents_observer.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 336 |
336 struct OustandingRequestsStats { | 337 struct OustandingRequestsStats { |
337 int memory_cost; | 338 int memory_cost; |
338 int num_requests; | 339 int num_requests; |
339 }; | 340 }; |
340 | 341 |
341 friend class ShutdownTask; | 342 friend class ShutdownTask; |
342 friend class ResourceMessageDelegate; | 343 friend class ResourceMessageDelegate; |
343 | 344 |
344 // Information about status of a ResourceLoader. | 345 // Information about status of a ResourceLoader. |
345 struct LoadInfo { | 346 struct CONTENT_EXPORT LoadInfo { |
| 347 LoadInfo(); |
| 348 LoadInfo(const LoadInfo& info); |
| 349 ~LoadInfo(); |
| 350 |
| 351 bool IsUploading() const; |
| 352 |
| 353 // This function returns true if the LoadInfo of |a| is "more interesting" |
| 354 // than the LoadInfo of |b|. The load that is currently sending the larger |
| 355 // request body is considered more interesting. If neither request is |
| 356 // sending a body (Neither request has a body, or any request that has a |
| 357 // body is not currently sending the body), the request that is further |
| 358 // along is considered more interesting. |
| 359 // |
| 360 // This takes advantage of the fact that the load states are an enumeration |
| 361 // listed in the order in which they usually occur during the lifetime of a |
| 362 // request, so states with larger numeric values are generally further along |
| 363 // toward completion. |
| 364 // |
| 365 // For example, by this measure "tranferring data" is a more interesting |
| 366 // state than "resolving host" because when transferring data something is |
| 367 // being done that corresponds to changes that the user might observe, |
| 368 // whereas waiting for a host name to resolve implies being stuck. |
| 369 bool IsMoreInteresting(const LoadInfo& other) const; |
| 370 |
346 GURL url; | 371 GURL url; |
347 net::LoadStateWithParam load_state; | 372 net::LoadStateWithParam load_state; |
348 uint64_t upload_position; | 373 uint64_t upload_position; |
349 uint64_t upload_size; | 374 uint64_t upload_size; |
| 375 |
| 376 // Associates the load with a web contents. |
| 377 ResourceRequestInfo::WebContentsGetter web_contents_getter; |
350 }; | 378 }; |
351 | 379 |
352 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. | 380 // Map from ProcessID+FrameRouteID pair to the "most interesting" LoadState. |
353 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; | 381 typedef std::map<GlobalFrameRoutingId, LoadInfo> LoadInfoMap; |
354 | 382 |
355 // ResourceLoaderDelegate implementation: | 383 // ResourceLoaderDelegate implementation: |
356 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( | 384 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( |
357 ResourceLoader* loader, | 385 ResourceLoader* loader, |
358 net::AuthChallengeInfo* auth_info) override; | 386 net::AuthChallengeInfo* auth_info) override; |
359 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; | 387 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; |
360 void DidStartRequest(ResourceLoader* loader) override; | 388 void DidStartRequest(ResourceLoader* loader) override; |
361 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; | 389 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; |
362 void DidReceiveResponse(ResourceLoader* loader) override; | 390 void DidReceiveResponse(ResourceLoader* loader) override; |
363 void DidFinishLoading(ResourceLoader* loader) override; | 391 void DidFinishLoading(ResourceLoader* loader) override; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 // It may be enhanced in the future to provide some kind of prioritization | 451 // It may be enhanced in the future to provide some kind of prioritization |
424 // mechanism. We should also consider a hashtable or binary tree if it turns | 452 // mechanism. We should also consider a hashtable or binary tree if it turns |
425 // out we have a lot of things here. | 453 // out we have a lot of things here. |
426 using LoaderMap = std::map<GlobalRequestID, std::unique_ptr<ResourceLoader>>; | 454 using LoaderMap = std::map<GlobalRequestID, std::unique_ptr<ResourceLoader>>; |
427 | 455 |
428 // Deletes the pending request identified by the iterator passed in. | 456 // Deletes the pending request identified by the iterator passed in. |
429 // This function will invalidate the iterator passed in. Callers should | 457 // This function will invalidate the iterator passed in. Callers should |
430 // not rely on this iterator being valid on return. | 458 // not rely on this iterator being valid on return. |
431 void RemovePendingLoader(const LoaderMap::iterator& iter); | 459 void RemovePendingLoader(const LoaderMap::iterator& iter); |
432 | 460 |
433 // This function returns true if the LoadInfo of |a| is "more interesting" | |
434 // than the LoadInfo of |b|. The load that is currently sending the larger | |
435 // request body is considered more interesting. If neither request is | |
436 // sending a body (Neither request has a body, or any request that has a body | |
437 // is not currently sending the body), the request that is further along is | |
438 // considered more interesting. | |
439 // | |
440 // This takes advantage of the fact that the load states are an enumeration | |
441 // listed in the order in which they usually occur during the lifetime of a | |
442 // request, so states with larger numeric values are generally further along | |
443 // toward completion. | |
444 // | |
445 // For example, by this measure "tranferring data" is a more interesting state | |
446 // than "resolving host" because when transferring data something is being | |
447 // done that corresponds to changes that the user might observe, whereas | |
448 // waiting for a host name to resolve implies being stuck. | |
449 static bool LoadInfoIsMoreInteresting(const LoadInfo& a, const LoadInfo& b); | |
450 | |
451 // Used to marshal calls to LoadStateChanged from the IO to UI threads. All | 461 // Used to marshal calls to LoadStateChanged from the IO to UI threads. All |
452 // are done as a single callback to avoid spamming the UI thread. | 462 // are done as a single callback to avoid spamming the UI thread. Note that |
| 463 // GetLoadInfoForAllRoutes de-dupes based on frame, but not based on tab. |
| 464 // Thus, logic here also constructs a map and finds the most interesting load |
| 465 // state per WebContents. |
453 static void UpdateLoadInfoOnUIThread(std::unique_ptr<LoadInfoMap> info_map); | 466 static void UpdateLoadInfoOnUIThread(std::unique_ptr<LoadInfoMap> info_map); |
454 | 467 |
455 // Gets the most interesting LoadInfo for each GlobalRoutingID. | 468 // Gets the most interesting LoadInfo for each GlobalFrameRoutingID. |
456 std::unique_ptr<LoadInfoMap> GetLoadInfoForAllRoutes(); | 469 std::unique_ptr<LoadInfoMap> GetLoadInfoForAllRoutes(); |
457 | 470 |
458 // Checks all pending requests and updates the load info if necessary. | 471 // Checks all pending requests and updates the load info if necessary. |
459 void UpdateLoadInfo(); | 472 void UpdateLoadInfo(); |
460 | 473 |
461 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 474 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
462 void ProcessBlockedRequestsForRoute( | 475 void ProcessBlockedRequestsForRoute( |
463 const GlobalFrameRoutingId& global_routing_id, | 476 const GlobalFrameRoutingId& global_routing_id, |
464 bool cancel_requests); | 477 bool cancel_requests); |
465 | 478 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 // Allows tests to use a mock CertStore. If set, the CertStore must | 675 // Allows tests to use a mock CertStore. If set, the CertStore must |
663 // outlive this ResourceDispatcherHostImpl. | 676 // outlive this ResourceDispatcherHostImpl. |
664 CertStore* cert_store_for_testing_; | 677 CertStore* cert_store_for_testing_; |
665 | 678 |
666 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 679 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
667 }; | 680 }; |
668 | 681 |
669 } // namespace content | 682 } // namespace content |
670 | 683 |
671 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 684 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |