| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
| 6 | 6 |
| 7 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 // Maximum number of pending data messages sent to the renderer at any | 103 // Maximum number of pending data messages sent to the renderer at any |
| 104 // given time for a given request. | 104 // given time for a given request. |
| 105 const int kMaxPendingDataMessages = 20; | 105 const int kMaxPendingDataMessages = 20; |
| 106 | 106 |
| 107 // Maximum byte "cost" of all the outstanding requests for a renderer. | 107 // Maximum byte "cost" of all the outstanding requests for a renderer. |
| 108 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. | 108 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. |
| 109 // This bound is 25MB, which allows for around 6000 outstanding requests. | 109 // This bound is 25MB, which allows for around 6000 outstanding requests. |
| 110 const int kMaxOutstandingRequestsCostPerProcess = 26214400; | 110 const int kMaxOutstandingRequestsCostPerProcess = 26214400; |
| 111 | 111 |
| 112 // A NotificationTask proxies a resource dispatcher notification from the IO | 112 // Calls ClosePageIgnoringUnloadEvents on the UI thread for the given |
| 113 // thread to the RenderViewHostDelegate on the UI thread. It should be | 113 // RenderView. |
| 114 // constructed on the IO thread and run in the UI thread. | 114 // |
| 115 class NotificationTask : public Task { | 115 // If there are more functions we need to call on RVH, we should generalize this |
| 116 // like the "Delegate" notification task below. |
| 117 class RVHCloseNotificationTask : public Task { |
| 118 public: |
| 119 RVHCloseNotificationTask(int render_process_host_id, |
| 120 int render_view_host_id) |
| 121 : render_process_host_id_(render_process_host_id), |
| 122 render_view_host_id_(render_view_host_id) { |
| 123 } |
| 124 |
| 125 virtual void Run() { |
| 126 RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id_, |
| 127 render_view_host_id_); |
| 128 if (rvh) |
| 129 rvh->ClosePageIgnoringUnloadEvents(); |
| 130 } |
| 131 |
| 132 private: |
| 133 int render_process_host_id_; |
| 134 int render_view_host_id_; |
| 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(RVHCloseNotificationTask); |
| 137 }; |
| 138 |
| 139 // A RVHDelegateNotificationTask proxies a resource dispatcher notification |
| 140 // from the IO thread to the RenderViewHostDelegate on the UI thread. It should |
| 141 // be constructed on the IO thread and run in the UI thread. |
| 142 class RVHDelegateNotificationTask : public Task { |
| 116 public: | 143 public: |
| 117 typedef void (RenderViewHostDelegate::Resource::* ResourceFunction) | 144 typedef void (RenderViewHostDelegate::Resource::* ResourceFunction) |
| 118 (ResourceRequestDetails*); | 145 (ResourceRequestDetails*); |
| 119 | 146 |
| 120 // Supply the originating URLRequest, a function on RenderViewHostDelegate | 147 // Supply the originating URLRequest, a function on RenderViewHostDelegate |
| 121 // to call, and the details to use as the parameter to the given function. | 148 // to call, and the details to use as the parameter to the given function. |
| 122 // | 149 // |
| 123 // This object will take ownership of the details pointer, which must be | 150 // This object will take ownership of the details pointer, which must be |
| 124 // allocated on the heap. | 151 // allocated on the heap. |
| 125 NotificationTask( | 152 RVHDelegateNotificationTask( |
| 126 URLRequest* request, | 153 URLRequest* request, |
| 127 ResourceFunction function, | 154 ResourceFunction function, |
| 128 ResourceRequestDetails* details) | 155 ResourceRequestDetails* details) |
| 129 : function_(function), | 156 : render_process_host_id_(-1), |
| 157 render_view_host_id_(-1), |
| 158 function_(function), |
| 130 details_(details) { | 159 details_(details) { |
| 131 if (!ResourceDispatcherHost::RenderViewForRequest(request, | 160 if (!ResourceDispatcherHost::RenderViewForRequest(request, |
| 132 &render_process_host_id_, | 161 &render_process_host_id_, |
| 133 &render_view_host_id_)) { | 162 &render_view_host_id_)) { |
| 134 NOTREACHED(); | 163 NOTREACHED(); |
| 135 } | 164 } |
| 136 } | 165 } |
| 137 | 166 |
| 138 virtual void Run() { | 167 virtual void Run() { |
| 139 RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id_, | 168 RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id_, |
| 140 render_view_host_id_); | 169 render_view_host_id_); |
| 141 if (rvh) { | 170 if (rvh) { |
| 142 RenderViewHostDelegate::Resource* resource_delegate = | 171 RenderViewHostDelegate::Resource* resource_delegate = |
| 143 rvh->delegate()->GetResourceDelegate(); | 172 rvh->delegate()->GetResourceDelegate(); |
| 144 if (resource_delegate) | 173 if (resource_delegate) |
| 145 (resource_delegate->*function_)(details_.get()); | 174 (resource_delegate->*function_)(details_.get()); |
| 146 } | 175 } |
| 147 } | 176 } |
| 148 | 177 |
| 149 private: | 178 private: |
| 150 int render_process_host_id_; | 179 int render_process_host_id_; |
| 151 int render_view_host_id_; | 180 int render_view_host_id_; |
| 152 | 181 |
| 153 // The function to call on RenderViewHostDelegate::Resource on the UI thread. | 182 // The function to call on RenderViewHostDelegate::Resource on the UI thread. |
| 154 ResourceFunction function_; | 183 ResourceFunction function_; |
| 155 | 184 |
| 156 // The details for the notification. | 185 // The details for the notification. |
| 157 scoped_ptr<ResourceRequestDetails> details_; | 186 scoped_ptr<ResourceRequestDetails> details_; |
| 158 | 187 |
| 159 DISALLOW_COPY_AND_ASSIGN(NotificationTask); | 188 DISALLOW_COPY_AND_ASSIGN(RVHDelegateNotificationTask); |
| 160 }; | 189 }; |
| 161 | 190 |
| 162 // Consults the RendererSecurity policy to determine whether the | 191 // Consults the RendererSecurity policy to determine whether the |
| 163 // ResourceDispatcherHost should service this request. A request might be | 192 // ResourceDispatcherHost should service this request. A request might be |
| 164 // disallowed if the renderer is not authorized to restrive the request URL or | 193 // disallowed if the renderer is not authorized to restrive the request URL or |
| 165 // if the renderer is attempting to upload an unauthorized file. | 194 // if the renderer is attempting to upload an unauthorized file. |
| 166 bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type, | 195 bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type, |
| 167 int process_id, | 196 int process_id, |
| 168 const ViewHostMsg_Resource_Request& request_data) { | 197 const ViewHostMsg_Resource_Request& request_data) { |
| 169 if (process_type == ChildProcessInfo::PLUGIN_PROCESS) | 198 if (process_type == ChildProcessInfo::PLUGIN_PROCESS) |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 return; | 544 return; |
| 516 | 545 |
| 517 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); | 546 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); |
| 518 info->waiting_for_upload_progress_ack = false; | 547 info->waiting_for_upload_progress_ack = false; |
| 519 } | 548 } |
| 520 | 549 |
| 521 void ResourceDispatcherHost::OnCancelRequest(int request_id) { | 550 void ResourceDispatcherHost::OnCancelRequest(int request_id) { |
| 522 CancelRequest(receiver_->GetProcessId(), request_id, true, true); | 551 CancelRequest(receiver_->GetProcessId(), request_id, true, true); |
| 523 } | 552 } |
| 524 | 553 |
| 525 void ResourceDispatcherHost::OnClosePageACK(int new_render_process_host_id, | 554 void ResourceDispatcherHost::OnClosePageACK( |
| 526 int new_request_id) { | 555 const ViewMsg_ClosePage_Params& params) { |
| 527 GlobalRequestID global_id(new_render_process_host_id, new_request_id); | 556 if (params.for_cross_site_transition) { |
| 528 PendingRequestList::iterator i = pending_requests_.find(global_id); | 557 // Closes for cross-site transitions are handled such that the cross-site |
| 529 if (i == pending_requests_.end()) { | 558 // transition continues. |
| 530 // If there are no matching pending requests, then this is not a | 559 GlobalRequestID global_id(params.new_render_process_host_id, |
| 531 // cross-site navigation and we are just closing the tab/browser. | 560 params.new_request_id); |
| 532 ui_loop_->PostTask(FROM_HERE, NewRunnableFunction( | 561 PendingRequestList::iterator i = pending_requests_.find(global_id); |
| 533 &RenderViewHost::ClosePageIgnoringUnloadEvents, | 562 if (i != pending_requests_.end()) { |
| 534 new_render_process_host_id, | 563 // The response we were meant to resume could have already been canceled. |
| 535 new_request_id)); | 564 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); |
| 536 return; | 565 if (info->cross_site_handler) |
| 537 } | 566 info->cross_site_handler->ResumeResponse(); |
| 538 | 567 } |
| 539 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); | 568 } else { |
| 540 if (info->cross_site_handler) { | 569 // This is a tab close, so just forward the message to close it. |
| 541 info->cross_site_handler->ResumeResponse(); | 570 DCHECK(params.new_render_process_host_id == -1); |
| 571 DCHECK(params.new_request_id == -1); |
| 572 ui_loop_->PostTask( |
| 573 FROM_HERE, |
| 574 new RVHCloseNotificationTask(params.closing_process_id, |
| 575 params.closing_route_id)); |
| 542 } | 576 } |
| 543 } | 577 } |
| 544 | 578 |
| 545 // We are explicitly forcing the download of 'url'. | 579 // We are explicitly forcing the download of 'url'. |
| 546 void ResourceDispatcherHost::BeginDownload(const GURL& url, | 580 void ResourceDispatcherHost::BeginDownload(const GURL& url, |
| 547 const GURL& referrer, | 581 const GURL& referrer, |
| 548 int process_id, | 582 int process_id, |
| 549 int route_id, | 583 int route_id, |
| 550 URLRequestContext* request_context) { | 584 URLRequestContext* request_context) { |
| 551 if (is_shutdown_) | 585 if (is_shutdown_) |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 (request->response_headers()->response_code() <= 599))); | 1427 (request->response_headers()->response_code() <= 599))); |
| 1394 return 0; | 1428 return 0; |
| 1395 } | 1429 } |
| 1396 | 1430 |
| 1397 void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request, | 1431 void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request, |
| 1398 int process_id) { | 1432 int process_id) { |
| 1399 // Notify the observers on the IO thread. | 1433 // Notify the observers on the IO thread. |
| 1400 FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request)); | 1434 FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request)); |
| 1401 | 1435 |
| 1402 // Notify the observers on the UI thread. | 1436 // Notify the observers on the UI thread. |
| 1403 ui_loop_->PostTask(FROM_HERE, new NotificationTask(request, | 1437 ui_loop_->PostTask(FROM_HERE, new RVHDelegateNotificationTask(request, |
| 1404 &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, | 1438 &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, |
| 1405 new ResourceRequestDetails(request, | 1439 new ResourceRequestDetails(request, |
| 1406 GetCertID(request, process_id)))); | 1440 GetCertID(request, process_id)))); |
| 1407 } | 1441 } |
| 1408 | 1442 |
| 1409 void ResourceDispatcherHost::NotifyResponseCompleted( | 1443 void ResourceDispatcherHost::NotifyResponseCompleted( |
| 1410 URLRequest* request, | 1444 URLRequest* request, |
| 1411 int process_id) { | 1445 int process_id) { |
| 1412 // Notify the observers on the IO thread. | 1446 // Notify the observers on the IO thread. |
| 1413 FOR_EACH_OBSERVER(Observer, observer_list_, | 1447 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 1414 OnResponseCompleted(this, request)); | 1448 OnResponseCompleted(this, request)); |
| 1415 } | 1449 } |
| 1416 | 1450 |
| 1417 void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request, | 1451 void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request, |
| 1418 int process_id, | 1452 int process_id, |
| 1419 const GURL& new_url) { | 1453 const GURL& new_url) { |
| 1420 // Notify the observers on the IO thread. | 1454 // Notify the observers on the IO thread. |
| 1421 FOR_EACH_OBSERVER(Observer, observer_list_, | 1455 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 1422 OnReceivedRedirect(this, request, new_url)); | 1456 OnReceivedRedirect(this, request, new_url)); |
| 1423 | 1457 |
| 1424 int cert_id = GetCertID(request, process_id); | 1458 int cert_id = GetCertID(request, process_id); |
| 1425 | 1459 |
| 1426 // Notify the observers on the UI thread. | 1460 // Notify the observers on the UI thread. |
| 1427 ui_loop_->PostTask(FROM_HERE, | 1461 ui_loop_->PostTask(FROM_HERE, |
| 1428 new NotificationTask(request, | 1462 new RVHDelegateNotificationTask(request, |
| 1429 &RenderViewHostDelegate::Resource::DidRedirectResource, | 1463 &RenderViewHostDelegate::Resource::DidRedirectResource, |
| 1430 new ResourceRedirectDetails(request, cert_id, new_url))); | 1464 new ResourceRedirectDetails(request, cert_id, new_url))); |
| 1431 } | 1465 } |
| 1432 | 1466 |
| 1433 namespace { | 1467 namespace { |
| 1434 | 1468 |
| 1435 // This function attempts to return the "more interesting" load state of |a| | 1469 // This function attempts to return the "more interesting" load state of |a| |
| 1436 // and |b|. We don't have temporal information about these load states | 1470 // and |b|. We don't have temporal information about these load states |
| 1437 // (meaning we don't know when we transitioned into these states), so we just | 1471 // (meaning we don't know when we transitioned into these states), so we just |
| 1438 // rank them according to how "interesting" the states are. | 1472 // rank them according to how "interesting" the states are. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 case ViewHostMsg_UploadProgress_ACK::ID: | 1651 case ViewHostMsg_UploadProgress_ACK::ID: |
| 1618 case ViewHostMsg_SyncLoad::ID: | 1652 case ViewHostMsg_SyncLoad::ID: |
| 1619 return true; | 1653 return true; |
| 1620 | 1654 |
| 1621 default: | 1655 default: |
| 1622 break; | 1656 break; |
| 1623 } | 1657 } |
| 1624 | 1658 |
| 1625 return false; | 1659 return false; |
| 1626 } | 1660 } |
| OLD | NEW |