| 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 // 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 "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 const linked_ptr<ResourceLoader>& loader) { | 997 const linked_ptr<ResourceLoader>& loader) { |
| 998 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 998 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
| 999 GlobalRoutingID old_routing_id( | 999 GlobalRoutingID old_routing_id( |
| 1000 request_data.transferred_request_child_id, info->GetRouteID()); | 1000 request_data.transferred_request_child_id, info->GetRouteID()); |
| 1001 GlobalRequestID old_request_id(request_data.transferred_request_child_id, | 1001 GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
| 1002 request_data.transferred_request_request_id); | 1002 request_data.transferred_request_request_id); |
| 1003 GlobalRoutingID new_routing_id(child_id, route_id); | 1003 GlobalRoutingID new_routing_id(child_id, route_id); |
| 1004 GlobalRequestID new_request_id(child_id, request_id); | 1004 GlobalRequestID new_request_id(child_id, request_id); |
| 1005 | 1005 |
| 1006 // Clear out data that depends on |info| before updating it. | 1006 // Clear out data that depends on |info| before updating it. |
| 1007 // We always need to move the memory stats to the new process. In contrast, |
| 1008 // stats.num_requests is only tracked for some requests (those that require |
| 1009 // file descriptors for their shared memory buffer). |
| 1007 IncrementOutstandingRequestsMemory(-1, *info); | 1010 IncrementOutstandingRequestsMemory(-1, *info); |
| 1008 OustandingRequestsStats empty_stats = { 0, 0 }; | 1011 bool should_update_count = info->counted_as_in_flight_request(); |
| 1009 OustandingRequestsStats old_stats = GetOutstandingRequestsStats(*info); | 1012 if (should_update_count) |
| 1010 UpdateOutstandingRequestsStats(*info, empty_stats); | 1013 IncrementOutstandingRequestsCount(-1, info); |
| 1011 pending_loaders_.erase(old_request_id); | 1014 pending_loaders_.erase(old_request_id); |
| 1012 | 1015 |
| 1013 // ResourceHandlers should always get state related to the request from the | 1016 // ResourceHandlers should always get state related to the request from the |
| 1014 // ResourceRequestInfo rather than caching it locally. This lets us update | 1017 // ResourceRequestInfo rather than caching it locally. This lets us update |
| 1015 // the info object when a transfer occurs. | 1018 // the info object when a transfer occurs. |
| 1016 info->UpdateForTransfer(child_id, route_id, request_data.origin_pid, | 1019 info->UpdateForTransfer(child_id, route_id, request_data.origin_pid, |
| 1017 request_id, request_data.parent_render_frame_id, | 1020 request_id, request_data.parent_render_frame_id, |
| 1018 filter_->GetWeakPtr()); | 1021 filter_->GetWeakPtr()); |
| 1019 | 1022 |
| 1020 // Update maps that used the old IDs, if necessary. Some transfers in tests | 1023 // Update maps that used the old IDs, if necessary. Some transfers in tests |
| 1021 // do not actually use a different ID, so not all maps need to be updated. | 1024 // do not actually use a different ID, so not all maps need to be updated. |
| 1022 pending_loaders_[new_request_id] = loader; | 1025 pending_loaders_[new_request_id] = loader; |
| 1023 UpdateOutstandingRequestsStats(*info, old_stats); | |
| 1024 IncrementOutstandingRequestsMemory(1, *info); | 1026 IncrementOutstandingRequestsMemory(1, *info); |
| 1027 if (should_update_count) |
| 1028 IncrementOutstandingRequestsCount(1, info); |
| 1025 if (old_routing_id != new_routing_id) { | 1029 if (old_routing_id != new_routing_id) { |
| 1026 if (blocked_loaders_map_.find(old_routing_id) != | 1030 if (blocked_loaders_map_.find(old_routing_id) != |
| 1027 blocked_loaders_map_.end()) { | 1031 blocked_loaders_map_.end()) { |
| 1028 blocked_loaders_map_[new_routing_id] = | 1032 blocked_loaders_map_[new_routing_id] = |
| 1029 blocked_loaders_map_[old_routing_id]; | 1033 blocked_loaders_map_[old_routing_id]; |
| 1030 blocked_loaders_map_.erase(old_routing_id); | 1034 blocked_loaders_map_.erase(old_routing_id); |
| 1031 } | 1035 } |
| 1032 } | 1036 } |
| 1033 if (old_request_id != new_request_id) { | 1037 if (old_request_id != new_request_id) { |
| 1034 DelegateMap::iterator it = delegate_map_.find(old_request_id); | 1038 DelegateMap::iterator it = delegate_map_.find(old_request_id); |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 stats.memory_cost += count * info.memory_cost(); | 1724 stats.memory_cost += count * info.memory_cost(); |
| 1721 DCHECK_GE(stats.memory_cost, 0); | 1725 DCHECK_GE(stats.memory_cost, 0); |
| 1722 UpdateOutstandingRequestsStats(info, stats); | 1726 UpdateOutstandingRequestsStats(info, stats); |
| 1723 | 1727 |
| 1724 return stats; | 1728 return stats; |
| 1725 } | 1729 } |
| 1726 | 1730 |
| 1727 ResourceDispatcherHostImpl::OustandingRequestsStats | 1731 ResourceDispatcherHostImpl::OustandingRequestsStats |
| 1728 ResourceDispatcherHostImpl::IncrementOutstandingRequestsCount( | 1732 ResourceDispatcherHostImpl::IncrementOutstandingRequestsCount( |
| 1729 int count, | 1733 int count, |
| 1730 const ResourceRequestInfoImpl& info) { | 1734 ResourceRequestInfoImpl* info) { |
| 1731 DCHECK_EQ(1, abs(count)); | 1735 DCHECK_EQ(1, abs(count)); |
| 1732 num_in_flight_requests_ += count; | 1736 num_in_flight_requests_ += count; |
| 1733 | 1737 |
| 1734 OustandingRequestsStats stats = GetOutstandingRequestsStats(info); | 1738 // Keep track of whether this request is counting toward the number of |
| 1739 // in-flight requests for this process, in case we need to transfer it to |
| 1740 // another process. This should be a toggle. |
| 1741 DCHECK_NE(info->counted_as_in_flight_request(), count > 0); |
| 1742 info->set_counted_as_in_flight_request(count > 0); |
| 1743 |
| 1744 OustandingRequestsStats stats = GetOutstandingRequestsStats(*info); |
| 1735 stats.num_requests += count; | 1745 stats.num_requests += count; |
| 1736 DCHECK_GE(stats.num_requests, 0); | 1746 DCHECK_GE(stats.num_requests, 0); |
| 1737 UpdateOutstandingRequestsStats(info, stats); | 1747 UpdateOutstandingRequestsStats(*info, stats); |
| 1738 | 1748 |
| 1739 return stats; | 1749 return stats; |
| 1740 } | 1750 } |
| 1741 | 1751 |
| 1742 bool ResourceDispatcherHostImpl::HasSufficientResourcesForRequest( | 1752 bool ResourceDispatcherHostImpl::HasSufficientResourcesForRequest( |
| 1743 const net::URLRequest* request_) { | 1753 net::URLRequest* request) { |
| 1744 const ResourceRequestInfoImpl* info = | 1754 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
| 1745 ResourceRequestInfoImpl::ForRequest(request_); | 1755 OustandingRequestsStats stats = IncrementOutstandingRequestsCount(1, info); |
| 1746 OustandingRequestsStats stats = IncrementOutstandingRequestsCount(1, *info); | |
| 1747 | 1756 |
| 1748 if (stats.num_requests > max_num_in_flight_requests_per_process_) | 1757 if (stats.num_requests > max_num_in_flight_requests_per_process_) |
| 1749 return false; | 1758 return false; |
| 1750 if (num_in_flight_requests_ > max_num_in_flight_requests_) | 1759 if (num_in_flight_requests_ > max_num_in_flight_requests_) |
| 1751 return false; | 1760 return false; |
| 1752 | 1761 |
| 1753 return true; | 1762 return true; |
| 1754 } | 1763 } |
| 1755 | 1764 |
| 1756 void ResourceDispatcherHostImpl::FinishedWithResourcesForRequest( | 1765 void ResourceDispatcherHostImpl::FinishedWithResourcesForRequest( |
| 1757 const net::URLRequest* request_) { | 1766 net::URLRequest* request) { |
| 1758 const ResourceRequestInfoImpl* info = | 1767 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
| 1759 ResourceRequestInfoImpl::ForRequest(request_); | 1768 IncrementOutstandingRequestsCount(-1, info); |
| 1760 IncrementOutstandingRequestsCount(-1, *info); | |
| 1761 } | 1769 } |
| 1762 | 1770 |
| 1763 void ResourceDispatcherHostImpl::StartNavigationRequest( | 1771 void ResourceDispatcherHostImpl::StartNavigationRequest( |
| 1764 const CommonNavigationParams& params, | 1772 const CommonNavigationParams& params, |
| 1765 const NavigationRequestInfo& info, | 1773 const NavigationRequestInfo& info, |
| 1766 scoped_refptr<ResourceRequestBody> request_body, | 1774 scoped_refptr<ResourceRequestBody> request_body, |
| 1767 int64 navigation_request_id, | 1775 int64 navigation_request_id, |
| 1768 int64 frame_node_id) { | 1776 int64 frame_node_id) { |
| 1769 NOTIMPLEMENTED(); | 1777 NOTIMPLEMENTED(); |
| 1770 } | 1778 } |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2149 | 2157 |
| 2150 // Add a flag to selectively bypass the data reduction proxy if the resource | 2158 // Add a flag to selectively bypass the data reduction proxy if the resource |
| 2151 // type is not an image. | 2159 // type is not an image. |
| 2152 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) | 2160 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) |
| 2153 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 2161 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 2154 | 2162 |
| 2155 return load_flags; | 2163 return load_flags; |
| 2156 } | 2164 } |
| 2157 | 2165 |
| 2158 } // namespace content | 2166 } // namespace content |
| OLD | NEW |