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

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

Issue 10501004: Refactor the guts of ResourceDispatcherHostImpl into a new class named (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
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
11 11
12 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_ 12 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_
13 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_ 13 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_
14 #pragma once 14 #pragma once
15 15
16 #include <map> 16 #include <map>
17 #include <set> 17 #include <set>
18 #include <string> 18 #include <string>
19 #include <vector> 19 #include <vector>
20 20
21 #include "base/basictypes.h" 21 #include "base/basictypes.h"
22 #include "base/gtest_prod_util.h" 22 #include "base/gtest_prod_util.h"
23 #include "base/memory/linked_ptr.h"
23 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
24 #include "base/memory/weak_ptr.h" 25 #include "base/memory/weak_ptr.h"
25 #include "base/time.h" 26 #include "base/time.h"
26 #include "base/timer.h" 27 #include "base/timer.h"
27 #include "content/browser/download/download_resource_handler.h" 28 #include "content/browser/download/download_resource_handler.h"
28 #include "content/browser/ssl/ssl_error_handler.h" 29 #include "content/browser/renderer_host/resource_loader.h"
30 #include "content/browser/renderer_host/resource_loader_delegate.h"
29 #include "content/common/content_export.h" 31 #include "content/common/content_export.h"
30 #include "content/public/browser/child_process_data.h" 32 #include "content/public/browser/child_process_data.h"
31 #include "content/public/browser/notification_types.h" 33 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/resource_dispatcher_host.h" 34 #include "content/public/browser/resource_dispatcher_host.h"
33 #include "ipc/ipc_message.h" 35 #include "ipc/ipc_message.h"
34 #include "net/url_request/url_request.h" 36 #include "net/url_request/url_request.h"
35 #include "webkit/glue/resource_type.h" 37 #include "webkit/glue/resource_type.h"
36 38
37 class DownloadFileManager; 39 class DownloadFileManager;
38 class ResourceHandler; 40 class ResourceHandler;
(...skipping 15 matching lines...) Expand all
54 class ResourceContext; 56 class ResourceContext;
55 class ResourceDispatcherHostDelegate; 57 class ResourceDispatcherHostDelegate;
56 class ResourceMessageFilter; 58 class ResourceMessageFilter;
57 class ResourceRequestInfoImpl; 59 class ResourceRequestInfoImpl;
58 struct DownloadSaveInfo; 60 struct DownloadSaveInfo;
59 struct GlobalRequestID; 61 struct GlobalRequestID;
60 struct Referrer; 62 struct Referrer;
61 63
62 class CONTENT_EXPORT ResourceDispatcherHostImpl 64 class CONTENT_EXPORT ResourceDispatcherHostImpl
63 : public ResourceDispatcherHost, 65 : public ResourceDispatcherHost,
64 public net::URLRequest::Delegate, 66 public ResourceLoaderDelegate,
65 public SSLErrorHandler::Delegate,
66 public base::SupportsWeakPtr<ResourceDispatcherHostImpl> { 67 public base::SupportsWeakPtr<ResourceDispatcherHostImpl> {
67 public: 68 public:
68 ResourceDispatcherHostImpl(); 69 ResourceDispatcherHostImpl();
69 virtual ~ResourceDispatcherHostImpl(); 70 virtual ~ResourceDispatcherHostImpl();
70 71
71 // Returns the current ResourceDispatcherHostImpl. May return NULL if it 72 // Returns the current ResourceDispatcherHostImpl. May return NULL if it
72 // hasn't been created yet. 73 // hasn't been created yet.
73 static ResourceDispatcherHostImpl* Get(); 74 static ResourceDispatcherHostImpl* Get();
74 75
75 // ResourceDispatcherHost implementation: 76 // ResourceDispatcherHost implementation:
76 virtual void SetDelegate(ResourceDispatcherHostDelegate* delegate) OVERRIDE; 77 virtual void SetDelegate(ResourceDispatcherHostDelegate* delegate) OVERRIDE;
77 virtual void SetAllowCrossOriginAuthPrompt(bool value) OVERRIDE; 78 virtual void SetAllowCrossOriginAuthPrompt(bool value) OVERRIDE;
78 virtual net::Error BeginDownload( 79 virtual net::Error BeginDownload(
79 scoped_ptr<net::URLRequest> request, 80 scoped_ptr<net::URLRequest> request,
80 bool is_content_initiated, 81 bool is_content_initiated,
81 ResourceContext* context, 82 ResourceContext* context,
82 int child_id, 83 int child_id,
83 int route_id, 84 int route_id,
84 bool prefer_cache, 85 bool prefer_cache,
85 const DownloadSaveInfo& save_info, 86 const DownloadSaveInfo& save_info,
86 const DownloadStartedCallback& started_callback) OVERRIDE; 87 const DownloadStartedCallback& started_callback) OVERRIDE;
87 virtual void ClearLoginDelegateForRequest(net::URLRequest* request) OVERRIDE; 88 virtual void ClearLoginDelegateForRequest(net::URLRequest* request) OVERRIDE;
88 89
90 // ResourceLoaderDelegate implementation:
jam 2012/06/14 01:10:22 nit: does this need to be public?
91 virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
92 ResourceLoader* loader,
93 net::AuthChallengeInfo* auth_info) OVERRIDE;
94 virtual bool AcceptAuthRequest(
95 ResourceLoader* loader,
96 net::AuthChallengeInfo* auth_info) OVERRIDE;
97 virtual bool AcceptSSLClientCertificateRequest(
98 ResourceLoader* loader,
99 net::SSLCertRequestInfo* cert_info) OVERRIDE;
100 virtual bool HandleExternalProtocol(ResourceLoader* loader,
101 const GURL& url) OVERRIDE;
102 virtual void DidStartRequest(ResourceLoader* loader) OVERRIDE;
103 virtual void DidReceiveRedirect(ResourceLoader* loader,
104 const GURL& new_url) OVERRIDE;
105 virtual void DidReceiveResponse(ResourceLoader* loader) OVERRIDE;
106 virtual void DidFinishLoading(ResourceLoader* loader) OVERRIDE;
107
89 // Puts the resource dispatcher host in an inactive state (unable to begin 108 // Puts the resource dispatcher host in an inactive state (unable to begin
90 // new requests). Cancels all pending requests. 109 // new requests). Cancels all pending requests.
91 void Shutdown(); 110 void Shutdown();
92 111
93 // Notify the ResourceDispatcherHostImpl of a new resource context. 112 // Notify the ResourceDispatcherHostImpl of a new resource context.
94 void AddResourceContext(ResourceContext* context); 113 void AddResourceContext(ResourceContext* context);
95 114
96 // Notify the ResourceDispatcherHostImpl of a resource context destruction. 115 // Notify the ResourceDispatcherHostImpl of a resource context destruction.
97 void RemoveResourceContext(ResourceContext* context); 116 void RemoveResourceContext(ResourceContext* context);
98 117
(...skipping 15 matching lines...) Expand all
114 int child_id, 133 int child_id,
115 int route_id, 134 int route_id,
116 ResourceContext* context); 135 ResourceContext* context);
117 136
118 // Cancels the given request if it still exists. We ignore cancels from the 137 // Cancels the given request if it still exists. We ignore cancels from the
119 // renderer in the event of a download. 138 // renderer in the event of a download.
120 void CancelRequest(int child_id, 139 void CancelRequest(int child_id,
121 int request_id, 140 int request_id,
122 bool from_renderer); 141 bool from_renderer);
123 142
124 // Follows a deferred redirect for the given request.
125 // new_first_party_for_cookies, if non-empty, is the new cookie policy URL
126 // for the redirected URL. If the cookie policy URL needs changing, pass
127 // true as has_new_first_party_for_cookies and the new cookie policy URL as
128 // new_first_party_for_cookies. Otherwise, pass false as
129 // has_new_first_party_for_cookies, and new_first_party_for_cookies will not
130 // be used.
131 void FollowDeferredRedirect(int child_id,
132 int request_id,
133 bool has_new_first_party_for_cookies,
134 const GURL& new_first_party_for_cookies);
135
136 // Starts a request that was deferred during ResourceHandler::OnWillStart().
137 void StartDeferredRequest(int child_id, int request_id);
138
139 // Resumes network activity for a particular request.
140 void ResumeDeferredRequest(int child_id, int request_id);
141
142 // Returns true if it's ok to send the data. If there are already too many 143 // Returns true if it's ok to send the data. If there are already too many
143 // data messages pending, it pauses the request and returns false. In this 144 // data messages pending, it pauses the request and returns false. In this
144 // case the caller should not send the data. 145 // case the caller should not send the data.
145 bool WillSendData(int child_id, int request_id); 146 bool WillSendData(int child_id, int request_id, bool* defer);
146 147
147 // Marks the request as "parked". This happens if a request is 148 // Marks the request as "parked". This happens if a request is
148 // redirected cross-site and needs to be resumed by a new render view. 149 // redirected cross-site and needs to be resumed by a new render view.
149 void MarkAsTransferredNavigation(net::URLRequest* request); 150 void MarkAsTransferredNavigation(const GlobalRequestID& id);
150 151
151 // Returns the number of pending requests. This is designed for the unittests 152 // Returns the number of pending requests. This is designed for the unittests
152 int pending_requests() const { 153 int pending_requests() const {
153 return static_cast<int>(pending_requests_.size()); 154 return static_cast<int>(pending_loaders_.size());
154 } 155 }
155 156
156 // Intended for unit-tests only. Returns the memory cost of all the 157 // Intended for unit-tests only. Returns the memory cost of all the
157 // outstanding requests (pending and blocked) for |child_id|. 158 // outstanding requests (pending and blocked) for |child_id|.
158 int GetOutstandingRequestsMemoryCost(int child_id) const; 159 int GetOutstandingRequestsMemoryCost(int child_id) const;
159 160
160 // Intended for unit-tests only. Overrides the outstanding requests bound. 161 // Intended for unit-tests only. Overrides the outstanding requests bound.
161 void set_max_outstanding_requests_cost_per_process(int limit) { 162 void set_max_outstanding_requests_cost_per_process(int limit) {
162 max_outstanding_requests_cost_per_process_ = limit; 163 max_outstanding_requests_cost_per_process_ = limit;
163 } 164 }
(...skipping 20 matching lines...) Expand all
184 const std::string& mime_type, 185 const std::string& mime_type,
185 ResourceType::Type resource_type); 186 ResourceType::Type resource_type);
186 187
187 // Force cancels any pending requests for the given process. 188 // Force cancels any pending requests for the given process.
188 void CancelRequestsForProcess(int child_id); 189 void CancelRequestsForProcess(int child_id);
189 190
190 // Force cancels any pending requests for the given route id. This method 191 // Force cancels any pending requests for the given route id. This method
191 // acts like CancelRequestsForProcess when route_id is -1. 192 // acts like CancelRequestsForProcess when route_id is -1.
192 void CancelRequestsForRoute(int child_id, int route_id); 193 void CancelRequestsForRoute(int child_id, int route_id);
193 194
194 // net::URLRequest::Delegate:
195 virtual void OnReceivedRedirect(net::URLRequest* request,
196 const GURL& new_url,
197 bool* defer_redirect) OVERRIDE;
198 virtual void OnAuthRequired(net::URLRequest* request,
199 net::AuthChallengeInfo* auth_info) OVERRIDE;
200 virtual void OnCertificateRequested(
201 net::URLRequest* request,
202 net::SSLCertRequestInfo* cert_request_info) OVERRIDE;
203 virtual void OnSSLCertificateError(net::URLRequest* request,
204 const net::SSLInfo& ssl_info,
205 bool fatal) OVERRIDE;
206 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
207 virtual void OnReadCompleted(net::URLRequest* request,
208 int bytes_read) OVERRIDE;
209
210 // SSLErrorHandler::Delegate:
211 virtual void CancelSSLRequest(const GlobalRequestID& id,
212 int error,
213 const net::SSLInfo* ssl_info) OVERRIDE;
214 virtual void ContinueSSLRequest(const GlobalRequestID& id) OVERRIDE;
215
216 void OnUserGesture(WebContentsImpl* contents); 195 void OnUserGesture(WebContentsImpl* contents);
217 196
218 // Retrieves a net::URLRequest. Must be called from the IO thread. 197 // Retrieves a net::URLRequest. Must be called from the IO thread.
219 net::URLRequest* GetURLRequest( 198 net::URLRequest* GetURLRequest(const GlobalRequestID& request_id);
220 const GlobalRequestID& request_id) const;
221 199
222 void RemovePendingRequest(int child_id, int request_id); 200 void RemovePendingRequest(int child_id, int request_id);
223 201
224 // Causes all new requests for the route identified by 202 // Causes all new requests for the route identified by
225 // |child_id| and |route_id| to be blocked (not being 203 // |child_id| and |route_id| to be blocked (not being
226 // started) until ResumeBlockedRequestsForRoute or 204 // started) until ResumeBlockedRequestsForRoute or
227 // CancelBlockedRequestsForRoute is called. 205 // CancelBlockedRequestsForRoute is called.
228 void BlockRequestsForRoute(int child_id, int route_id); 206 void BlockRequestsForRoute(int child_id, int route_id);
229 207
230 // Resumes any blocked request for the specified route id. 208 // Resumes any blocked request for the specified route id.
(...skipping 30 matching lines...) Expand all
261 scoped_ptr<ResourceHandler> CreateResourceHandlerForDownload( 239 scoped_ptr<ResourceHandler> CreateResourceHandlerForDownload(
262 net::URLRequest* request, 240 net::URLRequest* request,
263 ResourceContext* context, 241 ResourceContext* context,
264 int child_id, 242 int child_id,
265 int route_id, 243 int route_id,
266 int request_id, 244 int request_id,
267 bool is_content_initiated, 245 bool is_content_initiated,
268 const DownloadSaveInfo& save_info, 246 const DownloadSaveInfo& save_info,
269 const DownloadResourceHandler::OnStartedCallback& started_cb); 247 const DownloadResourceHandler::OnStartedCallback& started_cb);
270 248
249 void ClearSSLClientAuthHandlerForRequest(net::URLRequest* request);
250
271 private: 251 private:
272 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 252 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
273 TestBlockedRequestsProcessDies); 253 TestBlockedRequestsProcessDies);
274 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 254 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
275 IncrementOutstandingRequestsMemoryCost); 255 IncrementOutstandingRequestsMemoryCost);
276 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 256 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
277 CalculateApproximateMemoryCost); 257 CalculateApproximateMemoryCost);
278 258
279 class ShutdownTask; 259 class ShutdownTask;
280 260
281 friend class ShutdownTask; 261 friend class ShutdownTask;
282 262
283 // Extracts the render view/process host's identifiers from the given request 263 // Extracts the render view/process host's identifiers from the given request
284 // and places them in the given out params (both required). If there are no 264 // and places them in the given out params (both required). If there are no
285 // such IDs associated with the request (such as non-page-related requests), 265 // such IDs associated with the request (such as non-page-related requests),
286 // this function will return false and both out params will be -1. 266 // this function will return false and both out params will be -1.
287 static bool RenderViewForRequest(const net::URLRequest* request, 267 static bool RenderViewForRequest(const net::URLRequest* request,
288 int* render_process_host_id, 268 int* render_process_host_id,
289 int* render_view_host_id); 269 int* render_view_host_id);
290 270
291 // A shutdown helper that runs on the IO thread. 271 // A shutdown helper that runs on the IO thread.
292 void OnShutdown(); 272 void OnShutdown();
293 273
294 void StartRequest(net::URLRequest* request); 274 // Helper function for regular and download requests.
275 void BeginRequestInternal(scoped_ptr<net::URLRequest> request,
276 scoped_ptr<ResourceHandler> handler);
295 277
296 // Returns true if the request is paused. 278 void StartLoading(ResourceRequestInfoImpl* info,
297 bool PauseRequestIfNeeded(ResourceRequestInfoImpl* info); 279 const linked_ptr<ResourceLoader>& loader);
298
299 // Pause or resume network activity for a particular request.
300 void PauseRequest(int child_id, int request_id, bool pause);
301
302 // Resumes the given request by calling OnResponseStarted or OnReadCompleted.
303 void ResumeRequest(const GlobalRequestID& request_id);
304
305 // Internal function to start reading for the first time.
306 void StartReading(net::URLRequest* request);
307
308 // Reads data from the response using our internal buffer as async IO.
309 // Returns true if data is available immediately, false otherwise. If the
310 // return value is false, we will receive a OnReadComplete() callback later.
311 bool Read(net::URLRequest* request, int* bytes_read);
312
313 // Internal function to finish an async IO which has completed. Returns
314 // true if there is more data to read (e.g. we haven't read EOF yet and
315 // no errors have occurred).
316 bool CompleteRead(net::URLRequest*, int* bytes_read);
317
318 // Internal function to finish handling the ResponseStarted message. Returns
319 // true on success.
320 bool CompleteResponseStarted(net::URLRequest* request);
321
322 void ResponseCompleted(net::URLRequest* request);
323 void CallResponseCompleted(int child_id, int request_id);
324
325 // Helper function for regular and download requests.
326 void BeginRequestInternal(net::URLRequest* request);
327
328 // Helper function that cancels |request|. Returns whether the
329 // request was actually cancelled. If a renderer cancels a request
330 // for a download, we ignore the cancellation.
331 bool CancelRequestInternal(net::URLRequest* request, bool from_renderer);
332 280
333 // Updates the "cost" of outstanding requests for |child_id|. 281 // Updates the "cost" of outstanding requests for |child_id|.
334 // The "cost" approximates how many bytes are consumed by all the in-memory 282 // The "cost" approximates how many bytes are consumed by all the in-memory
335 // data structures supporting this request (net::URLRequest object, 283 // data structures supporting this request (net::URLRequest object,
336 // HttpNetworkTransaction, etc...). 284 // HttpNetworkTransaction, etc...).
337 // The value of |cost| is added to the running total, and the resulting 285 // The value of |cost| is added to the running total, and the resulting
338 // sum is returned. 286 // sum is returned.
339 int IncrementOutstandingRequestsMemoryCost(int cost, 287 int IncrementOutstandingRequestsMemoryCost(int cost,
340 int child_id); 288 int child_id);
341 289
342 // Estimate how much heap space |request| will consume to run. 290 // Estimate how much heap space |request| will consume to run.
343 static int CalculateApproximateMemoryCost(net::URLRequest* request); 291 static int CalculateApproximateMemoryCost(net::URLRequest* request);
344 292
345 // The list of all requests that we have pending. This list is not really 293 // The list of all requests that we have pending. This list is not really
346 // optimized, and assumes that we have relatively few requests pending at once 294 // optimized, and assumes that we have relatively few requests pending at once
347 // since some operations require brute-force searching of the list. 295 // since some operations require brute-force searching of the list.
348 // 296 //
349 // It may be enhanced in the future to provide some kind of prioritization 297 // It may be enhanced in the future to provide some kind of prioritization
350 // mechanism. We should also consider a hashtable or binary tree if it turns 298 // mechanism. We should also consider a hashtable or binary tree if it turns
351 // out we have a lot of things here. 299 // out we have a lot of things here.
352 typedef std::map<GlobalRequestID, net::URLRequest*> 300 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap;
353 PendingRequestList;
354 301
355 // Deletes the pending request identified by the iterator passed in. 302 // Deletes the pending request identified by the iterator passed in.
356 // This function will invalidate the iterator passed in. Callers should 303 // This function will invalidate the iterator passed in. Callers should
357 // not rely on this iterator being valid on return. 304 // not rely on this iterator being valid on return.
358 void RemovePendingRequest(const PendingRequestList::iterator& iter); 305 void RemovePendingLoader(const LoaderMap::iterator& iter);
359
360 // Notify our observers that we started receiving a response for a request.
361 void NotifyResponseStarted(net::URLRequest* request, int child_id);
362
363 // Notify our observers that a request has been redirected.
364 void NotifyReceivedRedirect(net::URLRequest* request,
365 int child_id,
366 const GURL& new_url);
367
368 // Tries to handle the url with an external protocol. If the request is
369 // handled, the function returns true. False otherwise.
370 bool HandleExternalProtocol(int request_id,
371 int child_id,
372 int route_id,
373 const GURL& url,
374 ResourceType::Type resource_type,
375 const net::URLRequestJobFactory& job_factory,
376 ResourceHandler* handler);
377 306
378 // Checks all pending requests and updates the load states and upload 307 // Checks all pending requests and updates the load states and upload
379 // progress if necessary. 308 // progress if necessary.
380 void UpdateLoadStates(); 309 void UpdateLoadStates();
381 310
382 // Checks the upload state and sends an update if one is necessary.
383 void MaybeUpdateUploadProgress(ResourceRequestInfoImpl *info,
384 net::URLRequest *request);
385
386 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. 311 // Resumes or cancels (if |cancel_requests| is true) any blocked requests.
387 void ProcessBlockedRequestsForRoute(int child_id, 312 void ProcessBlockedRequestsForRoute(int child_id,
388 int route_id, 313 int route_id,
389 bool cancel_requests); 314 bool cancel_requests);
390 315
391 void OnRequestResource(const IPC::Message& msg, 316 void OnRequestResource(const IPC::Message& msg,
392 int request_id, 317 int request_id,
393 const ResourceHostMsg_Request& request_data); 318 const ResourceHostMsg_Request& request_data);
394 void OnSyncLoad(int request_id, 319 void OnSyncLoad(int request_id,
395 const ResourceHostMsg_Request& request_data, 320 const ResourceHostMsg_Request& request_data,
396 IPC::Message* sync_result); 321 IPC::Message* sync_result);
397 void BeginRequest(int request_id, 322 void BeginRequest(int request_id,
398 const ResourceHostMsg_Request& request_data, 323 const ResourceHostMsg_Request& request_data,
399 IPC::Message* sync_result, // only valid for sync 324 IPC::Message* sync_result, // only valid for sync
400 int route_id); // only valid for async 325 int route_id); // only valid for async
401 void OnDataReceivedACK(int request_id); 326 void OnDataReceivedACK(int request_id);
402 void OnDataDownloadedACK(int request_id); 327 void OnDataDownloadedACK(int request_id);
403 void OnUploadProgressACK(int request_id); 328 void OnUploadProgressACK(int request_id);
404 void OnCancelRequest(int request_id); 329 void OnCancelRequest(int request_id);
405 void OnFollowRedirect(int request_id, 330 void OnFollowRedirect(int request_id,
406 bool has_new_first_party_for_cookies, 331 bool has_new_first_party_for_cookies,
407 const GURL& new_first_party_for_cookies); 332 const GURL& new_first_party_for_cookies);
408 void OnReleaseDownloadedFile(int request_id); 333 void OnReleaseDownloadedFile(int request_id);
409 334
410 // Creates ResourceRequestInfoImpl for a download or page save. 335 // Creates ResourceRequestInfoImpl for a download or page save.
411 // |download| should be true if the request is a file download. 336 // |download| should be true if the request is a file download.
412 ResourceRequestInfoImpl* CreateRequestInfo( 337 ResourceRequestInfoImpl* CreateRequestInfo(
413 scoped_ptr<ResourceHandler> handler,
414 int child_id, 338 int child_id,
415 int route_id, 339 int route_id,
416 bool download, 340 bool download,
417 ResourceContext* context); 341 ResourceContext* context);
418 342
419 // Returns true if |request| is in |pending_requests_|.
420 bool IsValidRequest(net::URLRequest* request);
421
422 // Sends the given notification on the UI thread. The RenderViewHost's
423 // controller is used as the source.
424 template <class T>
425 static void NotifyOnUI(int type,
426 int render_process_id,
427 int render_view_id,
428 T* detail);
429
430 // Relationship of resource being authenticated with the top level page. 343 // Relationship of resource being authenticated with the top level page.
431 enum HttpAuthResourceType { 344 enum HttpAuthResourceType {
432 HTTP_AUTH_RESOURCE_TOP, // Top-level page itself 345 HTTP_AUTH_RESOURCE_TOP, // Top-level page itself
433 HTTP_AUTH_RESOURCE_SAME_DOMAIN, // Sub-content from same domain 346 HTTP_AUTH_RESOURCE_SAME_DOMAIN, // Sub-content from same domain
434 HTTP_AUTH_RESOURCE_BLOCKED_CROSS, // Blocked Sub-content from cross domain 347 HTTP_AUTH_RESOURCE_BLOCKED_CROSS, // Blocked Sub-content from cross domain
435 HTTP_AUTH_RESOURCE_ALLOWED_CROSS, // Allowed Sub-content per command line 348 HTTP_AUTH_RESOURCE_ALLOWED_CROSS, // Allowed Sub-content per command line
436 HTTP_AUTH_RESOURCE_LAST 349 HTTP_AUTH_RESOURCE_LAST
437 }; 350 };
438 351
439 HttpAuthResourceType HttpAuthResourceTypeOf(net::URLRequest* request); 352 HttpAuthResourceType HttpAuthResourceTypeOf(net::URLRequest* request);
440 353
441 // Returns whether the URLRequest identified by |transferred_request_id| is 354 // Returns whether the URLRequest identified by |transferred_request_id| is
442 // currently in the process of being transferred to a different renderer. 355 // currently in the process of being transferred to a different renderer.
443 // This happens if a request is redirected cross-site and needs to be resumed 356 // This happens if a request is redirected cross-site and needs to be resumed
444 // by a new render view. 357 // by a new render view.
445 bool IsTransferredNavigation( 358 bool IsTransferredNavigation(
446 const GlobalRequestID& transferred_request_id) const; 359 const GlobalRequestID& transferred_request_id) const;
447 360
448 PendingRequestList pending_requests_; 361 ResourceLoader* GetLoader(const GlobalRequestID& id) const;
362 ResourceLoader* GetLoader(int child_id, int request_id) const;
363
364 LoaderMap pending_loaders_;
449 365
450 // Collection of temp files downloaded for child processes via 366 // Collection of temp files downloaded for child processes via
451 // the download_to_file mechanism. We avoid deleting them until 367 // the download_to_file mechanism. We avoid deleting them until
452 // the client no longer needs them. 368 // the client no longer needs them.
453 typedef std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> > 369 typedef std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> >
454 DeletableFilesMap; // key is request id 370 DeletableFilesMap; // key is request id
455 typedef std::map<int, DeletableFilesMap> 371 typedef std::map<int, DeletableFilesMap>
456 RegisteredTempFiles; // key is child process id 372 RegisteredTempFiles; // key is child process id
457 RegisteredTempFiles registered_temp_files_; 373 RegisteredTempFiles registered_temp_files_;
458 374
(...skipping 13 matching lines...) Expand all
472 // start at -2 and go down from there. (We need to start at -2 because -1 is 388 // start at -2 and go down from there. (We need to start at -2 because -1 is
473 // used as a special value all over the resource_dispatcher_host for 389 // used as a special value all over the resource_dispatcher_host for
474 // uninitialized variables.) This way, we no longer have the unlikely (but 390 // uninitialized variables.) This way, we no longer have the unlikely (but
475 // observed in the real world!) event where we have two requests with the same 391 // observed in the real world!) event where we have two requests with the same
476 // request_id_. 392 // request_id_.
477 int request_id_; 393 int request_id_;
478 394
479 // True if the resource dispatcher host has been shut down. 395 // True if the resource dispatcher host has been shut down.
480 bool is_shutdown_; 396 bool is_shutdown_;
481 397
482 typedef std::vector<net::URLRequest*> BlockedRequestsList; 398 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList;
483 typedef std::pair<int, int> ProcessRouteIDs; 399 typedef std::pair<int, int> ProcessRouteIDs;
484 typedef std::map<ProcessRouteIDs, BlockedRequestsList*> BlockedRequestMap; 400 typedef std::map<ProcessRouteIDs, BlockedLoadersList*> BlockedLoadersMap;
485 BlockedRequestMap blocked_requests_map_; 401 BlockedLoadersMap blocked_loaders_map_;
486 402
487 // Maps the child_ids to the approximate number of bytes 403 // Maps the child_ids to the approximate number of bytes
488 // being used to service its resource requests. No entry implies 0 cost. 404 // being used to service its resource requests. No entry implies 0 cost.
489 typedef std::map<int, int> OutstandingRequestsMemoryCostMap; 405 typedef std::map<int, int> OutstandingRequestsMemoryCostMap;
490 OutstandingRequestsMemoryCostMap outstanding_requests_memory_cost_map_; 406 OutstandingRequestsMemoryCostMap outstanding_requests_memory_cost_map_;
491 407
492 // |max_outstanding_requests_cost_per_process_| is the upper bound on how 408 // |max_outstanding_requests_cost_per_process_| is the upper bound on how
493 // many outstanding requests can be issued per child process host. 409 // many outstanding requests can be issued per child process host.
494 // The constraint is expressed in terms of bytes (where the cost of 410 // The constraint is expressed in terms of bytes (where the cost of
495 // individual requests is given by CalculateApproximateMemoryCost). 411 // individual requests is given by CalculateApproximateMemoryCost).
496 // The total number of outstanding requests is roughly: 412 // The total number of outstanding requests is roughly:
497 // (max_outstanding_requests_cost_per_process_ / 413 // (max_outstanding_requests_cost_per_process_ /
498 // kAvgBytesPerOutstandingRequest) 414 // kAvgBytesPerOutstandingRequest)
499 int max_outstanding_requests_cost_per_process_; 415 int max_outstanding_requests_cost_per_process_;
500 416
501 // Time of the last user gesture. Stored so that we can add a load 417 // Time of the last user gesture. Stored so that we can add a load
502 // flag to requests occurring soon after a gesture to indicate they 418 // flag to requests occurring soon after a gesture to indicate they
503 // may be because of explicit user action. 419 // may be because of explicit user action.
504 base::TimeTicks last_user_gesture_time_; 420 base::TimeTicks last_user_gesture_time_;
505 421
506 // Used during IPC message dispatching so that the handlers can get a pointer 422 // Used during IPC message dispatching so that the handlers can get a pointer
507 // to the source of the message. 423 // to the source of the message.
508 ResourceMessageFilter* filter_; 424 ResourceMessageFilter* filter_;
509 425
510 ResourceDispatcherHostDelegate* delegate_; 426 ResourceDispatcherHostDelegate* delegate_;
511 427
512 bool allow_cross_origin_auth_prompt_; 428 bool allow_cross_origin_auth_prompt_;
513 429
514 // Maps the request ID of request that is being transferred to a new RVH
515 // to the respective request.
516 typedef std::map<GlobalRequestID, net::URLRequest*> TransferredNavigations;
517 TransferredNavigations transferred_navigations_;
518
519 // http://crbug.com/90971 - Assists in tracking down use-after-frees on 430 // http://crbug.com/90971 - Assists in tracking down use-after-frees on
520 // shutdown. 431 // shutdown.
521 std::set<const ResourceContext*> active_resource_contexts_; 432 std::set<const ResourceContext*> active_resource_contexts_;
522 433
523 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); 434 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl);
524 }; 435 };
525 436
526 } // namespace content 437 } // namespace content
527 438
528 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_ 439 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698