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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.h

Issue 1542743002: [RDHI] Refactored blocked_loaders_map_ to key by render frame route id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New, simpler API (default recurses frame tree) Created 4 years, 10 months 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
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
(...skipping 21 matching lines...) Expand all
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/resource_dispatcher_host.h" 41 #include "content/public/browser/resource_dispatcher_host.h"
42 #include "content/public/browser/web_contents_observer.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;
69 class RenderFrameHostImpl;
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 thread.
88 // TODO(csharrison): Add methods tracking visibility and audio changes, to
89 // propogate to the ResourceScheduler.
90 class LoaderIOThreadNotifier : public WebContentsObserver {
91 public:
92 explicit LoaderIOThreadNotifier(WebContents* web_contents);
93 ~LoaderIOThreadNotifier() override;
94
95 // content::WebContentsObserver:
96 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
97 };
98
80 class CONTENT_EXPORT ResourceDispatcherHostImpl 99 class CONTENT_EXPORT ResourceDispatcherHostImpl
81 : public ResourceDispatcherHost, 100 : public ResourceDispatcherHost,
82 public ResourceLoaderDelegate { 101 public ResourceLoaderDelegate {
83 public: 102 public:
84 ResourceDispatcherHostImpl(); 103 ResourceDispatcherHostImpl();
85 ~ResourceDispatcherHostImpl() override; 104 ~ResourceDispatcherHostImpl() override;
86 105
87 // Returns the current ResourceDispatcherHostImpl. May return NULL if it 106 // Returns the current ResourceDispatcherHostImpl. May return NULL if it
88 // hasn't been created yet. 107 // hasn't been created yet.
89 static ResourceDispatcherHostImpl* Get(); 108 static ResourceDispatcherHostImpl* Get();
90 109
110 // The following static methods should all be called from the UI thread.
111
112 // Resumes requests for a given render frame routing id. This will only resume
113 // requests for a single frame.
114 static void ResumeBlockedRequestsForRouteOnUI(
Randy Smith (Not in Mondays) 2016/02/01 21:19:20 Nit: For consistency, I'd either name them all wit
115 const GlobalFrameRoutingId& global_routing_id);
116
117 // Blocks (and does not start) all requests for the frame tree identified by
nasko 2016/02/02 21:26:29 nit: Change "frame tree" with "frame and its subfr
Charlie Harrison 2016/02/02 21:44:22 Done.
118 // |root_frame_host|.
119 static void BlockRequestsForFrames(RenderFrameHost* root_frame_host);
120
121 // Resumes any blocked requests for the specified frame tree identified by
122 // |root_frame_host|.
123 static void ResumeBlockedRequestsForFrames(RenderFrameHost* root_frame_host);
124
125 // Cancels any blocked request for the frame tree identified by
126 // |root_frame_host|.
127 static void CancelBlockedRequestsForFrames(
128 RenderFrameHostImpl* root_frame_host);
129
91 // ResourceDispatcherHost implementation: 130 // ResourceDispatcherHost implementation:
92 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; 131 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override;
93 void SetAllowCrossOriginAuthPrompt(bool value) override; 132 void SetAllowCrossOriginAuthPrompt(bool value) override;
94 DownloadInterruptReason BeginDownload( 133 DownloadInterruptReason BeginDownload(
95 scoped_ptr<net::URLRequest> request, 134 scoped_ptr<net::URLRequest> request,
96 const Referrer& referrer, 135 const Referrer& referrer,
97 bool is_content_initiated, 136 bool is_content_initiated,
98 ResourceContext* context, 137 ResourceContext* context,
99 int child_id, 138 int child_id,
100 int render_view_route_id, 139 int render_view_route_id,
101 int render_frame_route_id, 140 int render_frame_route_id,
102 bool prefer_cache, 141 bool prefer_cache,
103 bool do_not_prompt_for_login, 142 bool do_not_prompt_for_login,
104 scoped_ptr<DownloadSaveInfo> save_info, 143 scoped_ptr<DownloadSaveInfo> save_info,
105 uint32_t download_id, 144 uint32_t download_id,
106 const DownloadStartedCallback& started_callback) override; 145 const DownloadStartedCallback& started_callback) override;
107 void ClearLoginDelegateForRequest(net::URLRequest* request) override; 146 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 147
111 // Puts the resource dispatcher host in an inactive state (unable to begin 148 // Puts the resource dispatcher host in an inactive state (unable to begin
112 // new requests). Cancels all pending requests. 149 // new requests). Cancels all pending requests.
113 void Shutdown(); 150 void Shutdown();
114 151
115 // Notify the ResourceDispatcherHostImpl of a new resource context. 152 // Notify the ResourceDispatcherHostImpl of a new resource context.
116 void AddResourceContext(ResourceContext* context); 153 void AddResourceContext(ResourceContext* context);
117 154
118 // Notify the ResourceDispatcherHostImpl of a resource context destruction. 155 // Notify the ResourceDispatcherHostImpl of a resource context destruction.
119 void RemoveResourceContext(ResourceContext* context); 156 void RemoveResourceContext(ResourceContext* context);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 206 }
170 207
171 // The average private bytes increase of the browser for each new pending 208 // The average private bytes increase of the browser for each new pending
172 // request. Experimentally obtained. 209 // request. Experimentally obtained.
173 static const int kAvgBytesPerOutstandingRequest = 4400; 210 static const int kAvgBytesPerOutstandingRequest = 4400;
174 211
175 SaveFileManager* save_file_manager() const { 212 SaveFileManager* save_file_manager() const {
176 return save_file_manager_.get(); 213 return save_file_manager_.get();
177 } 214 }
178 215
216 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id);
217
179 // Called when a RenderViewHost is created. 218 // Called when a RenderViewHost is created.
180 void OnRenderViewHostCreated(int child_id, 219 void OnRenderViewHostCreated(int child_id,
181 int route_id, 220 int route_id,
182 bool is_visible, 221 bool is_visible,
183 bool is_audible); 222 bool is_audible);
184 223
185 // Called when a RenderViewHost is deleted. 224 // Called when a RenderViewHost is deleted.
186 void OnRenderViewHostDeleted(int child_id, int route_id); 225 void OnRenderViewHostDeleted(int child_id, int route_id);
187 226
188 // Called when a RenderViewHost starts or stops loading. 227 // Called when a RenderViewHost starts or stops loading.
(...skipping 15 matching lines...) Expand all
204 // Force cancels any pending requests for the given process. 243 // Force cancels any pending requests for the given process.
205 void CancelRequestsForProcess(int child_id); 244 void CancelRequestsForProcess(int child_id);
206 245
207 void OnUserGesture(WebContentsImpl* contents); 246 void OnUserGesture(WebContentsImpl* contents);
208 247
209 // Retrieves a net::URLRequest. Must be called from the IO thread. 248 // Retrieves a net::URLRequest. Must be called from the IO thread.
210 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id); 249 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id);
211 250
212 void RemovePendingRequest(int child_id, int request_id); 251 void RemovePendingRequest(int child_id, int request_id);
213 252
253 // Causes all new requests for the route identified by |routing_id| to be
254 // blocked (not being started) until ResumeBlockedRequestsForRoute is called.
255 void BlockRequestsForRoute(const GlobalFrameRoutingId& global_routing_id);
256
257 // Resumes any blocked request for the specified route id.
258 void ResumeBlockedRequestsForRoute(
259 const GlobalFrameRoutingId& global_routing_id);
260
214 // Cancels any blocked request for the specified route id. 261 // Cancels any blocked request for the specified route id.
215 void CancelBlockedRequestsForRoute(int child_id, int route_id); 262 void CancelBlockedRequestsForRoute(
263 const GlobalFrameRoutingId& global_routing_id);
216 264
217 // Maintains a collection of temp files created in support of 265 // Maintains a collection of temp files created in support of
218 // the download_to_file capability. Used to grant access to the 266 // the download_to_file capability. Used to grant access to the
219 // child process and to defer deletion of the file until it's 267 // child process and to defer deletion of the file until it's
220 // no longer needed. 268 // no longer needed.
221 void RegisterDownloadedTempFile( 269 void RegisterDownloadedTempFile(
222 int child_id, int request_id, 270 int child_id, int request_id,
223 const base::FilePath& file_path); 271 const base::FilePath& file_path);
224 void UnregisterDownloadedTempFile(int child_id, int request_id); 272 void UnregisterDownloadedTempFile(int child_id, int request_id);
225 273
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // buffer. |count| indicates whether the request is issuing or finishing. 419 // buffer. |count| indicates whether the request is issuing or finishing.
372 // |count| must be 1 or -1. 420 // |count| must be 1 or -1.
373 OustandingRequestsStats IncrementOutstandingRequestsCount( 421 OustandingRequestsStats IncrementOutstandingRequestsCount(
374 int count, 422 int count,
375 ResourceRequestInfoImpl* info); 423 ResourceRequestInfoImpl* info);
376 424
377 // Estimate how much heap space |request| will consume to run. 425 // Estimate how much heap space |request| will consume to run.
378 static int CalculateApproximateMemoryCost(net::URLRequest* request); 426 static int CalculateApproximateMemoryCost(net::URLRequest* request);
379 427
380 // Force cancels any pending requests for the given route id. This method 428 // Force cancels any pending requests for the given route id. This method
381 // acts like CancelRequestsForProcess when route_id is -1. 429 // acts like CancelRequestsForProcess when the |route_id| member of
382 void CancelRequestsForRoute(int child_id, int route_id); 430 // |routing_id| is MSG_ROUTING_NONE.
431 void CancelRequestsForRoute(const GlobalFrameRoutingId& global_routing_id);
383 432
384 // The list of all requests that we have pending. This list is not really 433 // 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 434 // optimized, and assumes that we have relatively few requests pending at once
386 // since some operations require brute-force searching of the list. 435 // since some operations require brute-force searching of the list.
387 // 436 //
388 // It may be enhanced in the future to provide some kind of prioritization 437 // 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 438 // mechanism. We should also consider a hashtable or binary tree if it turns
390 // out we have a lot of things here. 439 // out we have a lot of things here.
391 using LoaderMap = std::map<GlobalRequestID, scoped_ptr<ResourceLoader>>; 440 using LoaderMap = std::map<GlobalRequestID, scoped_ptr<ResourceLoader>>;
392 441
(...skipping 24 matching lines...) Expand all
417 // are done as a single callback to avoid spamming the UI thread. 466 // are done as a single callback to avoid spamming the UI thread.
418 static void UpdateLoadInfoOnUIThread(scoped_ptr<LoadInfoMap> info_map); 467 static void UpdateLoadInfoOnUIThread(scoped_ptr<LoadInfoMap> info_map);
419 468
420 // Gets the most interesting LoadInfo for each GlobalRoutingID. 469 // Gets the most interesting LoadInfo for each GlobalRoutingID.
421 scoped_ptr<LoadInfoMap> GetLoadInfoForAllRoutes(); 470 scoped_ptr<LoadInfoMap> GetLoadInfoForAllRoutes();
422 471
423 // Checks all pending requests and updates the load info if necessary. 472 // Checks all pending requests and updates the load info if necessary.
424 void UpdateLoadInfo(); 473 void UpdateLoadInfo();
425 474
426 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. 475 // Resumes or cancels (if |cancel_requests| is true) any blocked requests.
427 void ProcessBlockedRequestsForRoute(int child_id, 476 void ProcessBlockedRequestsForRoute(
428 int route_id, 477 const GlobalFrameRoutingId& global_routing_id,
429 bool cancel_requests); 478 bool cancel_requests);
430 479
431 void OnRequestResource(int routing_id, 480 void OnRequestResource(int routing_id,
432 int request_id, 481 int request_id,
433 const ResourceHostMsg_Request& request_data); 482 const ResourceHostMsg_Request& request_data);
434 void OnSyncLoad(int request_id, 483 void OnSyncLoad(int request_id,
435 const ResourceHostMsg_Request& request_data, 484 const ResourceHostMsg_Request& request_data,
436 IPC::Message* sync_result); 485 IPC::Message* sync_result);
437 486
438 // Update the ResourceRequestInfo and internal maps when a request is 487 // Update the ResourceRequestInfo and internal maps when a request is
439 // transferred from one process to another. 488 // transferred from one process to another.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 // uninitialized variables.) This way, we no longer have the unlikely (but 594 // 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 595 // observed in the real world!) event where we have two requests with the same
547 // request_id_. 596 // request_id_.
548 int request_id_; 597 int request_id_;
549 598
550 // True if the resource dispatcher host has been shut down. 599 // True if the resource dispatcher host has been shut down.
551 bool is_shutdown_; 600 bool is_shutdown_;
552 601
553 using BlockedLoadersList = std::vector<scoped_ptr<ResourceLoader>>; 602 using BlockedLoadersList = std::vector<scoped_ptr<ResourceLoader>>;
554 using BlockedLoadersMap = 603 using BlockedLoadersMap =
555 std::map<GlobalRoutingID, scoped_ptr<BlockedLoadersList>>; 604 std::map<GlobalFrameRoutingId, scoped_ptr<BlockedLoadersList>>;
556 BlockedLoadersMap blocked_loaders_map_; 605 BlockedLoadersMap blocked_loaders_map_;
557 606
558 // Maps the child_ids to the approximate number of bytes 607 // Maps the child_ids to the approximate number of bytes
559 // being used to service its resource requests. No entry implies 0 cost. 608 // being used to service its resource requests. No entry implies 0 cost.
560 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; 609 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap;
561 OutstandingRequestsStatsMap outstanding_requests_stats_map_; 610 OutstandingRequestsStatsMap outstanding_requests_stats_map_;
562 611
563 // |num_in_flight_requests_| is the total number of requests currently issued 612 // |num_in_flight_requests_| is the total number of requests currently issued
564 // summed across all renderers. 613 // summed across all renderers.
565 int num_in_flight_requests_; 614 int num_in_flight_requests_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 DelegateMap delegate_map_; 660 DelegateMap delegate_map_;
612 661
613 scoped_ptr<ResourceScheduler> scheduler_; 662 scoped_ptr<ResourceScheduler> scheduler_;
614 663
615 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); 664 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl);
616 }; 665 };
617 666
618 } // namespace content 667 } // namespace content
619 668
620 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ 669 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698