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 20 matching lines...) Expand all Loading... | |
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_scheduler.h" | 33 #include "content/browser/loader/resource_scheduler.h" |
34 #include "content/common/content_export.h" | 34 #include "content/common/content_export.h" |
35 #include "content/common/resource_request_body.h" | 35 #include "content/common/resource_request_body.h" |
36 #include "content/public/browser/child_process_data.h" | 36 #include "content/public/browser/child_process_data.h" |
37 #include "content/public/browser/download_item.h" | 37 #include "content/public/browser/download_item.h" |
38 #include "content/public/browser/download_url_parameters.h" | 38 #include "content/public/browser/download_url_parameters.h" |
39 #include "content/public/browser/global_request_id.h" | 39 #include "content/public/browser/global_request_id.h" |
40 #include "content/public/browser/notification_types.h" | 40 #include "content/public/browser/notification_types.h" |
41 #include "content/public/browser/render_view_host.h" | |
41 #include "content/public/browser/resource_dispatcher_host.h" | 42 #include "content/public/browser/resource_dispatcher_host.h" |
42 #include "content/public/common/resource_type.h" | 43 #include "content/public/common/resource_type.h" |
43 #include "ipc/ipc_message.h" | 44 #include "ipc/ipc_message.h" |
44 #include "net/base/request_priority.h" | 45 #include "net/base/request_priority.h" |
45 #include "net/cookies/canonical_cookie.h" | 46 #include "net/cookies/canonical_cookie.h" |
46 #include "net/url_request/url_request.h" | 47 #include "net/url_request/url_request.h" |
47 | 48 |
48 class ResourceHandler; | 49 class ResourceHandler; |
49 struct ResourceHostMsg_Request; | 50 struct ResourceHostMsg_Request; |
50 | 51 |
51 namespace base { | 52 namespace base { |
52 class FilePath; | 53 class FilePath; |
53 } | 54 } |
54 | 55 |
55 namespace net { | 56 namespace net { |
56 class URLRequestJobFactory; | 57 class URLRequestJobFactory; |
57 } | 58 } |
58 | 59 |
59 namespace storage { | 60 namespace storage { |
60 class ShareableFileReference; | 61 class ShareableFileReference; |
61 } | 62 } |
62 | 63 |
63 namespace content { | 64 namespace content { |
64 class AppCacheService; | 65 class AppCacheService; |
65 class AsyncRevalidationManager; | 66 class AsyncRevalidationManager; |
67 class FrameTree; | |
66 class NavigationURLLoaderImplCore; | 68 class NavigationURLLoaderImplCore; |
67 class ResourceContext; | 69 class ResourceContext; |
68 class ResourceDispatcherHostDelegate; | 70 class ResourceDispatcherHostDelegate; |
69 class ResourceMessageDelegate; | 71 class ResourceMessageDelegate; |
70 class ResourceMessageFilter; | 72 class ResourceMessageFilter; |
71 class ResourceRequestInfoImpl; | 73 class ResourceRequestInfoImpl; |
72 class SaveFileManager; | 74 class SaveFileManager; |
73 class ServiceWorkerNavigationHandleCore; | 75 class ServiceWorkerNavigationHandleCore; |
74 class WebContentsImpl; | 76 class WebContentsImpl; |
75 struct CommonNavigationParams; | 77 struct CommonNavigationParams; |
(...skipping 22 matching lines...) Expand all Loading... | |
98 ResourceContext* context, | 100 ResourceContext* context, |
99 int child_id, | 101 int child_id, |
100 int render_view_route_id, | 102 int render_view_route_id, |
101 int render_frame_route_id, | 103 int render_frame_route_id, |
102 bool prefer_cache, | 104 bool prefer_cache, |
103 bool do_not_prompt_for_login, | 105 bool do_not_prompt_for_login, |
104 scoped_ptr<DownloadSaveInfo> save_info, | 106 scoped_ptr<DownloadSaveInfo> save_info, |
105 uint32_t download_id, | 107 uint32_t download_id, |
106 const DownloadStartedCallback& started_callback) override; | 108 const DownloadStartedCallback& started_callback) override; |
107 void ClearLoginDelegateForRequest(net::URLRequest* request) override; | 109 void ClearLoginDelegateForRequest(net::URLRequest* request) override; |
108 void BlockRequestsForRoute(int child_id, int route_id) override; | |
109 void ResumeBlockedRequestsForRoute(int child_id, int route_id) override; | |
110 | 110 |
111 // Puts the resource dispatcher host in an inactive state (unable to begin | 111 // Puts the resource dispatcher host in an inactive state (unable to begin |
112 // new requests). Cancels all pending requests. | 112 // new requests). Cancels all pending requests. |
113 void Shutdown(); | 113 void Shutdown(); |
114 | 114 |
115 // Notify the ResourceDispatcherHostImpl of a new resource context. | 115 // Notify the ResourceDispatcherHostImpl of a new resource context. |
116 void AddResourceContext(ResourceContext* context); | 116 void AddResourceContext(ResourceContext* context); |
117 | 117 |
118 // Notify the ResourceDispatcherHostImpl of a resource context destruction. | 118 // Notify the ResourceDispatcherHostImpl of a resource context destruction. |
119 void RemoveResourceContext(ResourceContext* context); | 119 void RemoveResourceContext(ResourceContext* context); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 } | 169 } |
170 | 170 |
171 // The average private bytes increase of the browser for each new pending | 171 // The average private bytes increase of the browser for each new pending |
172 // request. Experimentally obtained. | 172 // request. Experimentally obtained. |
173 static const int kAvgBytesPerOutstandingRequest = 4400; | 173 static const int kAvgBytesPerOutstandingRequest = 4400; |
174 | 174 |
175 SaveFileManager* save_file_manager() const { | 175 SaveFileManager* save_file_manager() const { |
176 return save_file_manager_.get(); | 176 return save_file_manager_.get(); |
177 } | 177 } |
178 | 178 |
179 void OnRenderFrameHostDeleted(const GlobalFrameRoutingId& routing_id); | |
180 | |
179 // Called when a RenderViewHost is created. | 181 // Called when a RenderViewHost is created. |
180 void OnRenderViewHostCreated(int child_id, | 182 void OnRenderViewHostCreated(int child_id, |
181 int route_id, | 183 int route_id, |
182 bool is_visible, | 184 bool is_visible, |
183 bool is_audible); | 185 bool is_audible); |
184 | 186 |
185 // Called when a RenderViewHost is deleted. | 187 // Called when a RenderViewHost is deleted. |
186 void OnRenderViewHostDeleted(int child_id, int route_id); | 188 void OnRenderViewHostDeleted(int child_id, int route_id); |
187 | 189 |
188 // Called when a RenderViewHost starts or stops loading. | 190 // Called when a RenderViewHost starts or stops loading. |
(...skipping 15 matching lines...) Expand all Loading... | |
204 // Force cancels any pending requests for the given process. | 206 // Force cancels any pending requests for the given process. |
205 void CancelRequestsForProcess(int child_id); | 207 void CancelRequestsForProcess(int child_id); |
206 | 208 |
207 void OnUserGesture(WebContentsImpl* contents); | 209 void OnUserGesture(WebContentsImpl* contents); |
208 | 210 |
209 // Retrieves a net::URLRequest. Must be called from the IO thread. | 211 // Retrieves a net::URLRequest. Must be called from the IO thread. |
210 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id); | 212 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id); |
211 | 213 |
212 void RemovePendingRequest(int child_id, int request_id); | 214 void RemovePendingRequest(int child_id, int request_id); |
213 | 215 |
216 // Causes all new requests for the route identified by |child_id| and | |
Charlie Harrison
2016/01/04 22:07:43
Will fix this comment in next patch.
Charlie Harrison
2016/01/07 22:47:05
Done.
| |
217 // |route_id| to be blocked (not being started) until | |
218 // ResumeBlockedRequestsForRoute is called. | |
219 void BlockRequestsForFrame(const GlobalFrameRoutingId& routing_id); | |
220 | |
221 // Resumes any blocked request for the specified route id. | |
222 void ResumeBlockedRequestsForFrame(const GlobalFrameRoutingId& routing_id); | |
223 | |
214 // Cancels any blocked request for the specified route id. | 224 // Cancels any blocked request for the specified route id. |
215 void CancelBlockedRequestsForRoute(int child_id, int route_id); | 225 void CancelBlockedRequestsForFrame(const GlobalFrameRoutingId& routing_id); |
216 | 226 |
217 // Maintains a collection of temp files created in support of | 227 // Maintains a collection of temp files created in support of |
218 // the download_to_file capability. Used to grant access to the | 228 // the download_to_file capability. Used to grant access to the |
219 // child process and to defer deletion of the file until it's | 229 // child process and to defer deletion of the file until it's |
220 // no longer needed. | 230 // no longer needed. |
221 void RegisterDownloadedTempFile( | 231 void RegisterDownloadedTempFile( |
222 int child_id, int request_id, | 232 int child_id, int request_id, |
223 const base::FilePath& file_path); | 233 const base::FilePath& file_path); |
224 void UnregisterDownloadedTempFile(int child_id, int request_id); | 234 void UnregisterDownloadedTempFile(int child_id, int request_id); |
225 | 235 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 // buffer. |count| indicates whether the request is issuing or finishing. | 381 // buffer. |count| indicates whether the request is issuing or finishing. |
372 // |count| must be 1 or -1. | 382 // |count| must be 1 or -1. |
373 OustandingRequestsStats IncrementOutstandingRequestsCount( | 383 OustandingRequestsStats IncrementOutstandingRequestsCount( |
374 int count, | 384 int count, |
375 ResourceRequestInfoImpl* info); | 385 ResourceRequestInfoImpl* info); |
376 | 386 |
377 // Estimate how much heap space |request| will consume to run. | 387 // Estimate how much heap space |request| will consume to run. |
378 static int CalculateApproximateMemoryCost(net::URLRequest* request); | 388 static int CalculateApproximateMemoryCost(net::URLRequest* request); |
379 | 389 |
380 // Force cancels any pending requests for the given route id. This method | 390 // Force cancels any pending requests for the given route id. This method |
381 // acts like CancelRequestsForProcess when route_id is -1. | 391 // acts like CancelRequestsForProcess when route_id is -1. |
Charlie Harrison
2016/01/04 22:07:43
Will fix this comment in the next patch.
Charlie Harrison
2016/01/07 22:47:05
Done.
| |
382 void CancelRequestsForRoute(int child_id, int route_id); | 392 void CancelRequestsForFrame(const GlobalFrameRoutingId& routing_id); |
383 | 393 |
384 // The list of all requests that we have pending. This list is not really | 394 // The list of all requests that we have pending. This list is not really |
385 // optimized, and assumes that we have relatively few requests pending at once | 395 // optimized, and assumes that we have relatively few requests pending at once |
386 // since some operations require brute-force searching of the list. | 396 // since some operations require brute-force searching of the list. |
387 // | 397 // |
388 // It may be enhanced in the future to provide some kind of prioritization | 398 // It may be enhanced in the future to provide some kind of prioritization |
389 // mechanism. We should also consider a hashtable or binary tree if it turns | 399 // mechanism. We should also consider a hashtable or binary tree if it turns |
390 // out we have a lot of things here. | 400 // out we have a lot of things here. |
391 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; | 401 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; |
392 | 402 |
(...skipping 24 matching lines...) Expand all Loading... | |
417 // are done as a single callback to avoid spamming the UI thread. | 427 // are done as a single callback to avoid spamming the UI thread. |
418 static void UpdateLoadInfoOnUIThread(scoped_ptr<LoadInfoMap> info_map); | 428 static void UpdateLoadInfoOnUIThread(scoped_ptr<LoadInfoMap> info_map); |
419 | 429 |
420 // Gets the most interesting LoadInfo for each GlobalRoutingID. | 430 // Gets the most interesting LoadInfo for each GlobalRoutingID. |
421 scoped_ptr<LoadInfoMap> GetLoadInfoForAllRoutes(); | 431 scoped_ptr<LoadInfoMap> GetLoadInfoForAllRoutes(); |
422 | 432 |
423 // Checks all pending requests and updates the load info if necessary. | 433 // Checks all pending requests and updates the load info if necessary. |
424 void UpdateLoadInfo(); | 434 void UpdateLoadInfo(); |
425 | 435 |
426 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 436 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
427 void ProcessBlockedRequestsForRoute(int child_id, | 437 void ProcessBlockedRequestsForFrame(const GlobalFrameRoutingId& routing_id, |
428 int route_id, | |
429 bool cancel_requests); | 438 bool cancel_requests); |
430 | 439 |
431 void OnRequestResource(int routing_id, | 440 void OnRequestResource(int routing_id, |
432 int request_id, | 441 int request_id, |
433 const ResourceHostMsg_Request& request_data); | 442 const ResourceHostMsg_Request& request_data); |
434 void OnSyncLoad(int request_id, | 443 void OnSyncLoad(int request_id, |
435 const ResourceHostMsg_Request& request_data, | 444 const ResourceHostMsg_Request& request_data, |
436 IPC::Message* sync_result); | 445 IPC::Message* sync_result); |
437 | 446 |
438 // Update the ResourceRequestInfo and internal maps when a request is | 447 // Update the ResourceRequestInfo and internal maps when a request is |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 // used as a special value all over the resource_dispatcher_host for | 553 // used as a special value all over the resource_dispatcher_host for |
545 // uninitialized variables.) This way, we no longer have the unlikely (but | 554 // uninitialized variables.) This way, we no longer have the unlikely (but |
546 // observed in the real world!) event where we have two requests with the same | 555 // observed in the real world!) event where we have two requests with the same |
547 // request_id_. | 556 // request_id_. |
548 int request_id_; | 557 int request_id_; |
549 | 558 |
550 // True if the resource dispatcher host has been shut down. | 559 // True if the resource dispatcher host has been shut down. |
551 bool is_shutdown_; | 560 bool is_shutdown_; |
552 | 561 |
553 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList; | 562 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList; |
554 typedef std::map<GlobalRoutingID, BlockedLoadersList*> BlockedLoadersMap; | 563 typedef std::map<GlobalFrameRoutingId, BlockedLoadersList*> BlockedLoadersMap; |
555 BlockedLoadersMap blocked_loaders_map_; | 564 BlockedLoadersMap blocked_loaders_map_; |
556 | 565 |
557 // Maps the child_ids to the approximate number of bytes | 566 // Maps the child_ids to the approximate number of bytes |
558 // being used to service its resource requests. No entry implies 0 cost. | 567 // being used to service its resource requests. No entry implies 0 cost. |
559 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; | 568 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; |
560 OutstandingRequestsStatsMap outstanding_requests_stats_map_; | 569 OutstandingRequestsStatsMap outstanding_requests_stats_map_; |
561 | 570 |
562 // |num_in_flight_requests_| is the total number of requests currently issued | 571 // |num_in_flight_requests_| is the total number of requests currently issued |
563 // summed across all renderers. | 572 // summed across all renderers. |
564 int num_in_flight_requests_; | 573 int num_in_flight_requests_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 DelegateMap delegate_map_; | 619 DelegateMap delegate_map_; |
611 | 620 |
612 scoped_ptr<ResourceScheduler> scheduler_; | 621 scoped_ptr<ResourceScheduler> scheduler_; |
613 | 622 |
614 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 623 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
615 }; | 624 }; |
616 | 625 |
617 } // namespace content | 626 } // namespace content |
618 | 627 |
619 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 628 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |