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" | |
Randy Smith (Not in Mondays)
2016/01/20 23:23:19
Why?
Charlie Harrison
2016/01/21 18:52:55
Removed.
| |
41 #include "content/public/browser/resource_dispatcher_host.h" | 42 #include "content/public/browser/resource_dispatcher_host.h" |
43 #include "content/public/browser/web_contents_observer.h" | |
42 #include "content/public/common/resource_type.h" | 44 #include "content/public/common/resource_type.h" |
43 #include "ipc/ipc_message.h" | 45 #include "ipc/ipc_message.h" |
44 #include "net/base/request_priority.h" | 46 #include "net/base/request_priority.h" |
45 #include "net/cookies/canonical_cookie.h" | 47 #include "net/cookies/canonical_cookie.h" |
46 #include "net/url_request/url_request.h" | 48 #include "net/url_request/url_request.h" |
47 | 49 |
48 class ResourceHandler; | 50 class ResourceHandler; |
49 struct ResourceHostMsg_Request; | 51 struct ResourceHostMsg_Request; |
50 | 52 |
51 namespace base { | 53 namespace base { |
52 class FilePath; | 54 class FilePath; |
53 } | 55 } |
54 | 56 |
55 namespace net { | 57 namespace net { |
56 class URLRequestJobFactory; | 58 class URLRequestJobFactory; |
57 } | 59 } |
58 | 60 |
59 namespace storage { | 61 namespace storage { |
60 class ShareableFileReference; | 62 class ShareableFileReference; |
61 } | 63 } |
62 | 64 |
63 namespace content { | 65 namespace content { |
64 class AppCacheService; | 66 class AppCacheService; |
65 class AsyncRevalidationManager; | 67 class AsyncRevalidationManager; |
68 class FrameTree; | |
66 class NavigationURLLoaderImplCore; | 69 class NavigationURLLoaderImplCore; |
67 class ResourceContext; | 70 class ResourceContext; |
68 class ResourceDispatcherHostDelegate; | 71 class ResourceDispatcherHostDelegate; |
69 class ResourceMessageDelegate; | 72 class ResourceMessageDelegate; |
70 class ResourceMessageFilter; | 73 class ResourceMessageFilter; |
71 class ResourceRequestInfoImpl; | 74 class ResourceRequestInfoImpl; |
72 class SaveFileManager; | 75 class SaveFileManager; |
73 class ServiceWorkerNavigationHandleCore; | 76 class ServiceWorkerNavigationHandleCore; |
74 class WebContentsImpl; | 77 class WebContentsImpl; |
75 struct CommonNavigationParams; | 78 struct CommonNavigationParams; |
76 struct DownloadSaveInfo; | 79 struct DownloadSaveInfo; |
77 struct NavigationRequestInfo; | 80 struct NavigationRequestInfo; |
78 struct Referrer; | 81 struct Referrer; |
79 | 82 |
83 // This class is responsible for notifying the IO thread (specifically, the | |
84 // ResourceDispatcherHostImpl) of frame events. It has an interace for callers | |
85 // to use and also sends notifications on WebContentsObserver events. All | |
86 // methods (static or class) will be called from the UI thread and post to the | |
87 // IO | |
88 // thread. | |
nasko
2016/01/16 00:15:58
This can fit with the previous line :).
Charlie Harrison
2016/01/21 18:52:55
Done. Oops :)
| |
89 // TODO(csharrison): Add methods tracking visibility and audio changes, to | |
90 // propogate to the ResourceScheduler. | |
91 class LoaderIOThreadNotifier : public WebContentsObserver { | |
92 public: | |
93 explicit LoaderIOThreadNotifier(WebContents* web_contents); | |
94 ~LoaderIOThreadNotifier() override; | |
95 | |
96 // content::WebContentsObserver: | |
97 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | |
98 }; | |
99 | |
80 class CONTENT_EXPORT ResourceDispatcherHostImpl | 100 class CONTENT_EXPORT ResourceDispatcherHostImpl |
81 : public ResourceDispatcherHost, | 101 : public ResourceDispatcherHost, |
82 public ResourceLoaderDelegate { | 102 public ResourceLoaderDelegate { |
83 public: | 103 public: |
84 ResourceDispatcherHostImpl(); | 104 ResourceDispatcherHostImpl(); |
85 ~ResourceDispatcherHostImpl() override; | 105 ~ResourceDispatcherHostImpl() override; |
86 | 106 |
87 // Returns the current ResourceDispatcherHostImpl. May return NULL if it | 107 // Returns the current ResourceDispatcherHostImpl. May return NULL if it |
88 // hasn't been created yet. | 108 // hasn't been created yet. |
89 static ResourceDispatcherHostImpl* Get(); | 109 static ResourceDispatcherHostImpl* Get(); |
90 | 110 |
111 // This method notifies the RDHI concerning the status of an entire frame | |
112 // tree. This will correspond to page-level events affecting resource loading. | |
113 static void NotifyForEachFrame( | |
114 FrameTree* frame_tree, | |
115 base::Callback<void(ResourceDispatcherHostImpl*, | |
116 const GlobalFrameRoutingId&)> frame_callback); | |
117 | |
118 // This method notifies the RDHI concerning the status of a frame. Consumers | |
119 // should use the public ResourceDispatcherHost static methods if the | |
120 // RenderFrameHost is available. | |
121 static void NotifyForRoute(const GlobalFrameRoutingId& routing_id, | |
122 base::Callback<void(ResourceDispatcherHostImpl*, | |
123 const GlobalFrameRoutingId&)> | |
124 frame_callback); | |
125 | |
91 // ResourceDispatcherHost implementation: | 126 // ResourceDispatcherHost implementation: |
92 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; | 127 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; |
93 void SetAllowCrossOriginAuthPrompt(bool value) override; | 128 void SetAllowCrossOriginAuthPrompt(bool value) override; |
94 DownloadInterruptReason BeginDownload( | 129 DownloadInterruptReason BeginDownload( |
95 scoped_ptr<net::URLRequest> request, | 130 scoped_ptr<net::URLRequest> request, |
96 const Referrer& referrer, | 131 const Referrer& referrer, |
97 bool is_content_initiated, | 132 bool is_content_initiated, |
98 ResourceContext* context, | 133 ResourceContext* context, |
99 int child_id, | 134 int child_id, |
100 int render_view_route_id, | 135 int render_view_route_id, |
101 int render_frame_route_id, | 136 int render_frame_route_id, |
102 bool prefer_cache, | 137 bool prefer_cache, |
103 bool do_not_prompt_for_login, | 138 bool do_not_prompt_for_login, |
104 scoped_ptr<DownloadSaveInfo> save_info, | 139 scoped_ptr<DownloadSaveInfo> save_info, |
105 uint32_t download_id, | 140 uint32_t download_id, |
106 const DownloadStartedCallback& started_callback) override; | 141 const DownloadStartedCallback& started_callback) override; |
107 void ClearLoginDelegateForRequest(net::URLRequest* request) override; | 142 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 | 143 |
111 // Puts the resource dispatcher host in an inactive state (unable to begin | 144 // Puts the resource dispatcher host in an inactive state (unable to begin |
112 // new requests). Cancels all pending requests. | 145 // new requests). Cancels all pending requests. |
113 void Shutdown(); | 146 void Shutdown(); |
114 | 147 |
115 // Notify the ResourceDispatcherHostImpl of a new resource context. | 148 // Notify the ResourceDispatcherHostImpl of a new resource context. |
116 void AddResourceContext(ResourceContext* context); | 149 void AddResourceContext(ResourceContext* context); |
117 | 150 |
118 // Notify the ResourceDispatcherHostImpl of a resource context destruction. | 151 // Notify the ResourceDispatcherHostImpl of a resource context destruction. |
119 void RemoveResourceContext(ResourceContext* context); | 152 void RemoveResourceContext(ResourceContext* context); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 } | 202 } |
170 | 203 |
171 // The average private bytes increase of the browser for each new pending | 204 // The average private bytes increase of the browser for each new pending |
172 // request. Experimentally obtained. | 205 // request. Experimentally obtained. |
173 static const int kAvgBytesPerOutstandingRequest = 4400; | 206 static const int kAvgBytesPerOutstandingRequest = 4400; |
174 | 207 |
175 SaveFileManager* save_file_manager() const { | 208 SaveFileManager* save_file_manager() const { |
176 return save_file_manager_.get(); | 209 return save_file_manager_.get(); |
177 } | 210 } |
178 | 211 |
212 void OnRenderFrameDeleted(const GlobalFrameRoutingId& routing_id); | |
213 | |
179 // Called when a RenderViewHost is created. | 214 // Called when a RenderViewHost is created. |
180 void OnRenderViewHostCreated(int child_id, | 215 void OnRenderViewHostCreated(int child_id, |
181 int route_id, | 216 int route_id, |
182 bool is_visible, | 217 bool is_visible, |
183 bool is_audible); | 218 bool is_audible); |
184 | 219 |
185 // Called when a RenderViewHost is deleted. | 220 // Called when a RenderViewHost is deleted. |
186 void OnRenderViewHostDeleted(int child_id, int route_id); | 221 void OnRenderViewHostDeleted(int child_id, int route_id); |
187 | 222 |
188 // Called when a RenderViewHost starts or stops loading. | 223 // 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. | 239 // Force cancels any pending requests for the given process. |
205 void CancelRequestsForProcess(int child_id); | 240 void CancelRequestsForProcess(int child_id); |
206 | 241 |
207 void OnUserGesture(WebContentsImpl* contents); | 242 void OnUserGesture(WebContentsImpl* contents); |
208 | 243 |
209 // Retrieves a net::URLRequest. Must be called from the IO thread. | 244 // Retrieves a net::URLRequest. Must be called from the IO thread. |
210 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id); | 245 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id); |
211 | 246 |
212 void RemovePendingRequest(int child_id, int request_id); | 247 void RemovePendingRequest(int child_id, int request_id); |
213 | 248 |
249 // Causes all new requests for the route identified by |routing_id| to be | |
250 // blocked (not being started) until ResumeBlockedRequestsForRoute is called. | |
251 void BlockRequestsForRoute(const GlobalFrameRoutingId& routing_id); | |
252 | |
253 // Resumes any blocked request for the specified route id. | |
254 void ResumeBlockedRequestsForRoute(const GlobalFrameRoutingId& routing_id); | |
255 | |
214 // Cancels any blocked request for the specified route id. | 256 // Cancels any blocked request for the specified route id. |
215 void CancelBlockedRequestsForRoute(int child_id, int route_id); | 257 void CancelBlockedRequestsForRoute(const GlobalFrameRoutingId& routing_id); |
216 | 258 |
217 // Maintains a collection of temp files created in support of | 259 // Maintains a collection of temp files created in support of |
218 // the download_to_file capability. Used to grant access to the | 260 // the download_to_file capability. Used to grant access to the |
219 // child process and to defer deletion of the file until it's | 261 // child process and to defer deletion of the file until it's |
220 // no longer needed. | 262 // no longer needed. |
221 void RegisterDownloadedTempFile( | 263 void RegisterDownloadedTempFile( |
222 int child_id, int request_id, | 264 int child_id, int request_id, |
223 const base::FilePath& file_path); | 265 const base::FilePath& file_path); |
224 void UnregisterDownloadedTempFile(int child_id, int request_id); | 266 void UnregisterDownloadedTempFile(int child_id, int request_id); |
225 | 267 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 // buffer. |count| indicates whether the request is issuing or finishing. | 413 // buffer. |count| indicates whether the request is issuing or finishing. |
372 // |count| must be 1 or -1. | 414 // |count| must be 1 or -1. |
373 OustandingRequestsStats IncrementOutstandingRequestsCount( | 415 OustandingRequestsStats IncrementOutstandingRequestsCount( |
374 int count, | 416 int count, |
375 ResourceRequestInfoImpl* info); | 417 ResourceRequestInfoImpl* info); |
376 | 418 |
377 // Estimate how much heap space |request| will consume to run. | 419 // Estimate how much heap space |request| will consume to run. |
378 static int CalculateApproximateMemoryCost(net::URLRequest* request); | 420 static int CalculateApproximateMemoryCost(net::URLRequest* request); |
379 | 421 |
380 // Force cancels any pending requests for the given route id. This method | 422 // Force cancels any pending requests for the given route id. This method |
381 // acts like CancelRequestsForProcess when route_id is -1. | 423 // acts like CancelRequestsForProcess when the |route_id| member of |
382 void CancelRequestsForRoute(int child_id, int route_id); | 424 // |routing_id| is -1. |
nasko
2016/01/16 00:15:58
MSG_ROUTING_NONE
Charlie Harrison
2016/01/21 18:52:55
Done.
| |
425 void CancelRequestsForRoute(const GlobalFrameRoutingId& routing_id); | |
383 | 426 |
384 // The list of all requests that we have pending. This list is not really | 427 // 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 | 428 // optimized, and assumes that we have relatively few requests pending at once |
386 // since some operations require brute-force searching of the list. | 429 // since some operations require brute-force searching of the list. |
387 // | 430 // |
388 // It may be enhanced in the future to provide some kind of prioritization | 431 // 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 | 432 // mechanism. We should also consider a hashtable or binary tree if it turns |
390 // out we have a lot of things here. | 433 // out we have a lot of things here. |
391 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; | 434 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; |
392 | 435 |
(...skipping 24 matching lines...) Expand all Loading... | |
417 // are done as a single callback to avoid spamming the UI thread. | 460 // are done as a single callback to avoid spamming the UI thread. |
418 static void UpdateLoadInfoOnUIThread(scoped_ptr<LoadInfoMap> info_map); | 461 static void UpdateLoadInfoOnUIThread(scoped_ptr<LoadInfoMap> info_map); |
419 | 462 |
420 // Gets the most interesting LoadInfo for each GlobalRoutingID. | 463 // Gets the most interesting LoadInfo for each GlobalRoutingID. |
421 scoped_ptr<LoadInfoMap> GetLoadInfoForAllRoutes(); | 464 scoped_ptr<LoadInfoMap> GetLoadInfoForAllRoutes(); |
422 | 465 |
423 // Checks all pending requests and updates the load info if necessary. | 466 // Checks all pending requests and updates the load info if necessary. |
424 void UpdateLoadInfo(); | 467 void UpdateLoadInfo(); |
425 | 468 |
426 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 469 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
427 void ProcessBlockedRequestsForRoute(int child_id, | 470 void ProcessBlockedRequestsForRoute(const GlobalFrameRoutingId& routing_id, |
428 int route_id, | |
429 bool cancel_requests); | 471 bool cancel_requests); |
430 | 472 |
431 void OnRequestResource(int routing_id, | 473 void OnRequestResource(int routing_id, |
432 int request_id, | 474 int request_id, |
433 const ResourceHostMsg_Request& request_data); | 475 const ResourceHostMsg_Request& request_data); |
434 void OnSyncLoad(int request_id, | 476 void OnSyncLoad(int request_id, |
435 const ResourceHostMsg_Request& request_data, | 477 const ResourceHostMsg_Request& request_data, |
436 IPC::Message* sync_result); | 478 IPC::Message* sync_result); |
437 | 479 |
438 // Update the ResourceRequestInfo and internal maps when a request is | 480 // 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 | 586 // used as a special value all over the resource_dispatcher_host for |
545 // uninitialized variables.) This way, we no longer have the unlikely (but | 587 // 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 | 588 // observed in the real world!) event where we have two requests with the same |
547 // request_id_. | 589 // request_id_. |
548 int request_id_; | 590 int request_id_; |
549 | 591 |
550 // True if the resource dispatcher host has been shut down. | 592 // True if the resource dispatcher host has been shut down. |
551 bool is_shutdown_; | 593 bool is_shutdown_; |
552 | 594 |
553 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList; | 595 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList; |
554 typedef std::map<GlobalRoutingID, BlockedLoadersList*> BlockedLoadersMap; | 596 typedef std::map<GlobalFrameRoutingId, BlockedLoadersList*> BlockedLoadersMap; |
555 BlockedLoadersMap blocked_loaders_map_; | 597 BlockedLoadersMap blocked_loaders_map_; |
556 | 598 |
557 // Maps the child_ids to the approximate number of bytes | 599 // Maps the child_ids to the approximate number of bytes |
558 // being used to service its resource requests. No entry implies 0 cost. | 600 // being used to service its resource requests. No entry implies 0 cost. |
559 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; | 601 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; |
560 OutstandingRequestsStatsMap outstanding_requests_stats_map_; | 602 OutstandingRequestsStatsMap outstanding_requests_stats_map_; |
561 | 603 |
562 // |num_in_flight_requests_| is the total number of requests currently issued | 604 // |num_in_flight_requests_| is the total number of requests currently issued |
563 // summed across all renderers. | 605 // summed across all renderers. |
564 int num_in_flight_requests_; | 606 int num_in_flight_requests_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 DelegateMap delegate_map_; | 652 DelegateMap delegate_map_; |
611 | 653 |
612 scoped_ptr<ResourceScheduler> scheduler_; | 654 scoped_ptr<ResourceScheduler> scheduler_; |
613 | 655 |
614 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 656 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
615 }; | 657 }; |
616 | 658 |
617 } // namespace content | 659 } // namespace content |
618 | 660 |
619 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 661 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |