| 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 14 matching lines...) Expand all Loading... |
| 25 #include "base/timer.h" | 25 #include "base/timer.h" |
| 26 #include "content/browser/download/download_resource_handler.h" | 26 #include "content/browser/download/download_resource_handler.h" |
| 27 #include "content/common/content_export.h" | 27 #include "content/common/content_export.h" |
| 28 #include "content/public/browser/child_process_data.h" | 28 #include "content/public/browser/child_process_data.h" |
| 29 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| 30 #include "ipc/ipc_message.h" | 30 #include "ipc/ipc_message.h" |
| 31 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
| 32 #include "webkit/glue/resource_type.h" | 32 #include "webkit/glue/resource_type.h" |
| 33 | 33 |
| 34 class DownloadFileManager; | 34 class DownloadFileManager; |
| 35 class ResourceDispatcherHostRequestInfo; | |
| 36 class ResourceHandler; | 35 class ResourceHandler; |
| 37 class ResourceMessageFilter; | 36 class ResourceMessageFilter; |
| 38 class SaveFileManager; | 37 class SaveFileManager; |
| 39 class TabContents; | 38 class TabContents; |
| 40 struct DownloadSaveInfo; | 39 struct DownloadSaveInfo; |
| 41 struct ResourceHostMsg_Request; | 40 struct ResourceHostMsg_Request; |
| 42 struct ViewMsg_SwapOut_Params; | 41 struct ViewMsg_SwapOut_Params; |
| 43 | 42 |
| 44 namespace content { | 43 namespace content { |
| 45 class ResourceContext; | 44 class ResourceContext; |
| 46 class ResourceDispatcherHostDelegate; | 45 class ResourceDispatcherHostDelegate; |
| 46 class ResourceRequestInfoImpl; |
| 47 struct GlobalRequestID; | 47 struct GlobalRequestID; |
| 48 } | 48 } |
| 49 | 49 |
| 50 namespace net { | 50 namespace net { |
| 51 class CookieList; | 51 class CookieList; |
| 52 class URLRequestJobFactory; | 52 class URLRequestJobFactory; |
| 53 } // namespace net | 53 } // namespace net |
| 54 | 54 |
| 55 namespace webkit_blob { | 55 namespace webkit_blob { |
| 56 class ShareableFileReference; | 56 class ShareableFileReference; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 const std::string& cookie_line, | 190 const std::string& cookie_line, |
| 191 net::CookieOptions* options) const OVERRIDE; | 191 net::CookieOptions* options) const OVERRIDE; |
| 192 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | 192 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 193 virtual void OnReadCompleted(net::URLRequest* request, | 193 virtual void OnReadCompleted(net::URLRequest* request, |
| 194 int bytes_read) OVERRIDE; | 194 int bytes_read) OVERRIDE; |
| 195 | 195 |
| 196 void OnUserGesture(TabContents* tab); | 196 void OnUserGesture(TabContents* tab); |
| 197 | 197 |
| 198 // Helper functions to get the dispatcher's request info for the request. | 198 // Helper functions to get the dispatcher's request info for the request. |
| 199 // If the dispatcher didn't create the request then NULL is returned. | 199 // If the dispatcher didn't create the request then NULL is returned. |
| 200 static ResourceDispatcherHostRequestInfo* InfoForRequest( | 200 static content::ResourceRequestInfoImpl* InfoForRequest( |
| 201 net::URLRequest* request); | 201 net::URLRequest* request); |
| 202 static const ResourceDispatcherHostRequestInfo* InfoForRequest( | 202 static const content::ResourceRequestInfoImpl* InfoForRequest( |
| 203 const net::URLRequest* request); | 203 const net::URLRequest* request); |
| 204 | 204 |
| 205 // Extracts the render view/process host's identifiers from the given request | 205 // Extracts the render view/process host's identifiers from the given request |
| 206 // and places them in the given out params (both required). If there are no | 206 // and places them in the given out params (both required). If there are no |
| 207 // such IDs associated with the request (such as non-page-related requests), | 207 // such IDs associated with the request (such as non-page-related requests), |
| 208 // this function will return false and both out params will be -1. | 208 // this function will return false and both out params will be -1. |
| 209 static bool RenderViewForRequest(const net::URLRequest* request, | 209 static bool RenderViewForRequest(const net::URLRequest* request, |
| 210 int* render_process_host_id, | 210 int* render_process_host_id, |
| 211 int* render_view_host_id); | 211 int* render_view_host_id); |
| 212 | 212 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 272 |
| 273 scoped_refptr<ResourceHandler> CreateResourceHandlerForDownload( | 273 scoped_refptr<ResourceHandler> CreateResourceHandlerForDownload( |
| 274 net::URLRequest* request, | 274 net::URLRequest* request, |
| 275 content::ResourceContext* context, | 275 content::ResourceContext* context, |
| 276 int child_id, | 276 int child_id, |
| 277 int route_id, | 277 int route_id, |
| 278 int request_id, | 278 int request_id, |
| 279 const DownloadSaveInfo& save_info, | 279 const DownloadSaveInfo& save_info, |
| 280 const DownloadResourceHandler::OnStartedCallback& started_cb); | 280 const DownloadResourceHandler::OnStartedCallback& started_cb); |
| 281 | 281 |
| 282 static void ClearLoginDelegate(net::URLRequest* request); |
| 283 |
| 282 private: | 284 private: |
| 283 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 285 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 284 TestBlockedRequestsProcessDies); | 286 TestBlockedRequestsProcessDies); |
| 285 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 287 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 286 IncrementOutstandingRequestsMemoryCost); | 288 IncrementOutstandingRequestsMemoryCost); |
| 287 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 289 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 288 CalculateApproximateMemoryCost); | 290 CalculateApproximateMemoryCost); |
| 289 | 291 |
| 290 class ShutdownTask; | 292 class ShutdownTask; |
| 291 | 293 |
| 292 friend class ShutdownTask; | 294 friend class ShutdownTask; |
| 293 | 295 |
| 294 // Associates the given info with the given request. The info will then be | |
| 295 // owned by the request. | |
| 296 void SetRequestInfo(net::URLRequest* request, | |
| 297 ResourceDispatcherHostRequestInfo* info); | |
| 298 | |
| 299 // A shutdown helper that runs on the IO thread. | 296 // A shutdown helper that runs on the IO thread. |
| 300 void OnShutdown(); | 297 void OnShutdown(); |
| 301 | 298 |
| 302 void StartRequest(net::URLRequest* request); | 299 void StartRequest(net::URLRequest* request); |
| 303 | 300 |
| 304 // Returns true if the request is paused. | 301 // Returns true if the request is paused. |
| 305 bool PauseRequestIfNeeded(ResourceDispatcherHostRequestInfo* info); | 302 bool PauseRequestIfNeeded(content::ResourceRequestInfoImpl* info); |
| 306 | 303 |
| 307 // Resumes the given request by calling OnResponseStarted or OnReadCompleted. | 304 // Resumes the given request by calling OnResponseStarted or OnReadCompleted. |
| 308 void ResumeRequest(const content::GlobalRequestID& request_id); | 305 void ResumeRequest(const content::GlobalRequestID& request_id); |
| 309 | 306 |
| 310 // Internal function to start reading for the first time. | 307 // Internal function to start reading for the first time. |
| 311 void StartReading(net::URLRequest* request); | 308 void StartReading(net::URLRequest* request); |
| 312 | 309 |
| 313 // Reads data from the response using our internal buffer as async IO. | 310 // Reads data from the response using our internal buffer as async IO. |
| 314 // Returns true if data is available immediately, false otherwise. If the | 311 // Returns true if data is available immediately, false otherwise. If the |
| 315 // return value is false, we will receive a OnReadComplete() callback later. | 312 // return value is false, we will receive a OnReadComplete() callback later. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 const GURL& url, | 375 const GURL& url, |
| 379 ResourceType::Type resource_type, | 376 ResourceType::Type resource_type, |
| 380 const net::URLRequestJobFactory& job_factory, | 377 const net::URLRequestJobFactory& job_factory, |
| 381 ResourceHandler* handler); | 378 ResourceHandler* handler); |
| 382 | 379 |
| 383 // Checks all pending requests and updates the load states and upload | 380 // Checks all pending requests and updates the load states and upload |
| 384 // progress if necessary. | 381 // progress if necessary. |
| 385 void UpdateLoadStates(); | 382 void UpdateLoadStates(); |
| 386 | 383 |
| 387 // Checks the upload state and sends an update if one is necessary. | 384 // Checks the upload state and sends an update if one is necessary. |
| 388 void MaybeUpdateUploadProgress(ResourceDispatcherHostRequestInfo *info, | 385 void MaybeUpdateUploadProgress(content::ResourceRequestInfoImpl *info, |
| 389 net::URLRequest *request); | 386 net::URLRequest *request); |
| 390 | 387 |
| 391 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 388 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
| 392 void ProcessBlockedRequestsForRoute(int child_id, | 389 void ProcessBlockedRequestsForRoute(int child_id, |
| 393 int route_id, | 390 int route_id, |
| 394 bool cancel_requests); | 391 bool cancel_requests); |
| 395 | 392 |
| 396 void OnRequestResource(const IPC::Message& msg, | 393 void OnRequestResource(const IPC::Message& msg, |
| 397 int request_id, | 394 int request_id, |
| 398 const ResourceHostMsg_Request& request_data); | 395 const ResourceHostMsg_Request& request_data); |
| 399 void OnSyncLoad(int request_id, | 396 void OnSyncLoad(int request_id, |
| 400 const ResourceHostMsg_Request& request_data, | 397 const ResourceHostMsg_Request& request_data, |
| 401 IPC::Message* sync_result); | 398 IPC::Message* sync_result); |
| 402 void BeginRequest(int request_id, | 399 void BeginRequest(int request_id, |
| 403 const ResourceHostMsg_Request& request_data, | 400 const ResourceHostMsg_Request& request_data, |
| 404 IPC::Message* sync_result, // only valid for sync | 401 IPC::Message* sync_result, // only valid for sync |
| 405 int route_id); // only valid for async | 402 int route_id); // only valid for async |
| 406 void OnDataReceivedACK(int request_id); | 403 void OnDataReceivedACK(int request_id); |
| 407 void OnDataDownloadedACK(int request_id); | 404 void OnDataDownloadedACK(int request_id); |
| 408 void OnUploadProgressACK(int request_id); | 405 void OnUploadProgressACK(int request_id); |
| 409 void OnCancelRequest(int request_id); | 406 void OnCancelRequest(int request_id); |
| 410 void OnTransferRequestToNewPage(int new_routing_id, int request_id); | 407 void OnTransferRequestToNewPage(int new_routing_id, int request_id); |
| 411 void OnFollowRedirect(int request_id, | 408 void OnFollowRedirect(int request_id, |
| 412 bool has_new_first_party_for_cookies, | 409 bool has_new_first_party_for_cookies, |
| 413 const GURL& new_first_party_for_cookies); | 410 const GURL& new_first_party_for_cookies); |
| 414 void OnReleaseDownloadedFile(int request_id); | 411 void OnReleaseDownloadedFile(int request_id); |
| 415 | 412 |
| 416 // Creates ResourceDispatcherHostRequestInfo for a download or page save. | 413 // Creates ResourceRequestInfoImpl for a download or page save. |
| 417 // |download| should be true if the request is a file download. | 414 // |download| should be true if the request is a file download. |
| 418 ResourceDispatcherHostRequestInfo* CreateRequestInfo( | 415 content::ResourceRequestInfoImpl* CreateRequestInfo( |
| 419 ResourceHandler* handler, | 416 ResourceHandler* handler, |
| 420 int child_id, | 417 int child_id, |
| 421 int route_id, | 418 int route_id, |
| 422 bool download, | 419 bool download, |
| 423 content::ResourceContext* context); | 420 content::ResourceContext* context); |
| 424 | 421 |
| 425 // Returns true if |request| is in |pending_requests_|. | 422 // Returns true if |request| is in |pending_requests_|. |
| 426 bool IsValidRequest(net::URLRequest* request); | 423 bool IsValidRequest(net::URLRequest* request); |
| 427 | 424 |
| 428 // Sends the given notification on the UI thread. The RenderViewHost's | 425 // Sends the given notification on the UI thread. The RenderViewHost's |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 // Maps the request ID of request that is being transferred to a new RVH | 520 // Maps the request ID of request that is being transferred to a new RVH |
| 524 // to the respective request. | 521 // to the respective request. |
| 525 typedef std::map<content::GlobalRequestID, net::URLRequest*> | 522 typedef std::map<content::GlobalRequestID, net::URLRequest*> |
| 526 TransferredNavigations; | 523 TransferredNavigations; |
| 527 TransferredNavigations transferred_navigations_; | 524 TransferredNavigations transferred_navigations_; |
| 528 | 525 |
| 529 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); | 526 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); |
| 530 }; | 527 }; |
| 531 | 528 |
| 532 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ | 529 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ |
| OLD | NEW |