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

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

Issue 10332130: Use defer out-params instead of ResourceDispatcherHostImpl::PauseRequest(...true) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 // 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/renderer_host/resource_dispatcher_host_impl.h" 7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 << child_id << ", " << request_id << ")"; 1227 << child_id << ", " << request_id << ")";
1228 return; 1228 return;
1229 } 1229 }
1230 1230
1231 // TODO(eroman): are there other considerations for paused or blocked 1231 // TODO(eroman): are there other considerations for paused or blocked
1232 // requests? 1232 // requests?
1233 1233
1234 StartRequest(i->second); 1234 StartRequest(i->second);
1235 } 1235 }
1236 1236
1237 void ResourceDispatcherHostImpl::ResumeDeferredRequest(int child_id,
1238 int request_id) {
1239 PauseRequest(child_id, request_id, false);
1240 }
1241
1237 bool ResourceDispatcherHostImpl::WillSendData(int child_id, 1242 bool ResourceDispatcherHostImpl::WillSendData(int child_id,
1238 int request_id) { 1243 int request_id) {
1239 PendingRequestList::iterator i = pending_requests_.find( 1244 PendingRequestList::iterator i = pending_requests_.find(
1240 GlobalRequestID(child_id, request_id)); 1245 GlobalRequestID(child_id, request_id));
1241 if (i == pending_requests_.end()) { 1246 if (i == pending_requests_.end()) {
1242 NOTREACHED() << "WillSendData for invalid request"; 1247 NOTREACHED() << "WillSendData for invalid request";
1243 return false; 1248 return false;
1244 } 1249 }
1245 1250
1246 ResourceRequestInfoImpl* info = 1251 ResourceRequestInfoImpl* info =
1247 ResourceRequestInfoImpl::ForRequest(i->second); 1252 ResourceRequestInfoImpl::ForRequest(i->second);
1248 1253
1249 info->IncrementPendingDataCount(); 1254 info->IncrementPendingDataCount();
1250 if (info->pending_data_count() > kMaxPendingDataMessages) { 1255 if (info->pending_data_count() > kMaxPendingDataMessages) {
1251 // We reached the max number of data messages that can be sent to 1256 // We reached the max number of data messages that can be sent to
1252 // the renderer for a given request. Pause the request and wait for 1257 // the renderer for a given request. Pause the request and wait for
1253 // the renderer to start processing them before resuming it. 1258 // the renderer to start processing them before resuming it.
1254 PauseRequest(child_id, request_id, true); 1259 PauseRequest(child_id, request_id, true);
1255 return false; 1260 return false;
1256 } 1261 }
1257 1262
1258 return true; 1263 return true;
1259 } 1264 }
1260 1265
1261 void ResourceDispatcherHostImpl::PauseRequest(int child_id,
1262 int request_id,
1263 bool pause) {
1264 GlobalRequestID global_id(child_id, request_id);
1265 PendingRequestList::iterator i = pending_requests_.find(global_id);
1266 if (i == pending_requests_.end()) {
1267 DVLOG(1) << "Pausing a request that wasn't found";
1268 return;
1269 }
1270
1271 ResourceRequestInfoImpl* info =
1272 ResourceRequestInfoImpl::ForRequest(i->second);
1273 int pause_count = info->pause_count() + (pause ? 1 : -1);
1274 if (pause_count < 0) {
1275 NOTREACHED(); // Unbalanced call to pause.
1276 return;
1277 }
1278 info->set_pause_count(pause_count);
1279
1280 VLOG(1) << "To pause (" << pause << "): " << i->second->url().spec();
1281
1282 // If we're resuming, kick the request to start reading again. Run the read
1283 // asynchronously to avoid recursion problems.
1284 if (info->pause_count() == 0) {
1285 MessageLoop::current()->PostTask(FROM_HERE,
1286 base::Bind(
1287 &ResourceDispatcherHostImpl::ResumeRequest,
1288 weak_factory_.GetWeakPtr(),
1289 global_id));
1290 }
1291 }
1292
1293 int ResourceDispatcherHostImpl::GetOutstandingRequestsMemoryCost( 1266 int ResourceDispatcherHostImpl::GetOutstandingRequestsMemoryCost(
1294 int child_id) const { 1267 int child_id) const {
1295 OutstandingRequestsMemoryCostMap::const_iterator entry = 1268 OutstandingRequestsMemoryCostMap::const_iterator entry =
1296 outstanding_requests_memory_cost_map_.find(child_id); 1269 outstanding_requests_memory_cost_map_.find(child_id);
1297 return (entry == outstanding_requests_memory_cost_map_.end()) ? 1270 return (entry == outstanding_requests_memory_cost_map_.end()) ?
1298 0 : entry->second; 1271 0 : entry->second;
1299 } 1272 }
1300 1273
1301 // The object died, so cancel and detach all requests associated with it except 1274 // The object died, so cancel and detach all requests associated with it except
1302 // for downloads, which belong to the browser process even if initiated via a 1275 // for downloads, which belong to the browser process even if initiated via a
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 request->ssl_info().connection_status); 1563 request->ssl_info().connection_status);
1591 } else { 1564 } else {
1592 // We should not have any SSL state. 1565 // We should not have any SSL state.
1593 DCHECK(!request->ssl_info().cert_status && 1566 DCHECK(!request->ssl_info().cert_status &&
1594 request->ssl_info().security_bits == -1 && 1567 request->ssl_info().security_bits == -1 &&
1595 !request->ssl_info().connection_status); 1568 !request->ssl_info().connection_status);
1596 } 1569 }
1597 1570
1598 NotifyResponseStarted(request, info->GetChildID()); 1571 NotifyResponseStarted(request, info->GetChildID());
1599 info->set_called_on_response_started(true); 1572 info->set_called_on_response_started(true);
1600 return info->resource_handler()->OnResponseStarted(info->GetRequestID(), 1573
1601 response.get()); 1574 bool defer = false;
1575 if (!info->resource_handler()->OnResponseStarted(info->GetRequestID(),
1576 response.get(),
1577 &defer))
1578 return false;
1579
1580 if (defer)
1581 PauseRequest(info->GetChildID(), info->GetRequestID(), true);
1582
1583 return true;
1602 } 1584 }
1603 1585
1604 void ResourceDispatcherHostImpl::CancelRequest(int child_id, 1586 void ResourceDispatcherHostImpl::CancelRequest(int child_id,
1605 int request_id, 1587 int request_id,
1606 bool from_renderer) { 1588 bool from_renderer) {
1607 GlobalRequestID id(child_id, request_id); 1589 GlobalRequestID id(child_id, request_id);
1608 if (from_renderer) { 1590 if (from_renderer) {
1609 // When the old renderer dies, it sends a message to us to cancel its 1591 // When the old renderer dies, it sends a message to us to cancel its
1610 // requests. 1592 // requests.
1611 if (transferred_navigations_.find(id) != transferred_navigations_.end()) 1593 if (transferred_navigations_.find(id) != transferred_navigations_.end())
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 } 1761 }
1780 } 1762 }
1781 1763
1782 bool ResourceDispatcherHostImpl::PauseRequestIfNeeded( 1764 bool ResourceDispatcherHostImpl::PauseRequestIfNeeded(
1783 ResourceRequestInfoImpl* info) { 1765 ResourceRequestInfoImpl* info) {
1784 if (info->pause_count() > 0) 1766 if (info->pause_count() > 0)
1785 info->set_is_paused(true); 1767 info->set_is_paused(true);
1786 return info->is_paused(); 1768 return info->is_paused();
1787 } 1769 }
1788 1770
1771 void ResourceDispatcherHostImpl::PauseRequest(int child_id,
1772 int request_id,
1773 bool pause) {
1774 GlobalRequestID global_id(child_id, request_id);
1775 PendingRequestList::iterator i = pending_requests_.find(global_id);
1776 if (i == pending_requests_.end()) {
1777 DVLOG(1) << "Pausing a request that wasn't found";
1778 return;
1779 }
1780
1781 ResourceRequestInfoImpl* info =
1782 ResourceRequestInfoImpl::ForRequest(i->second);
1783 int pause_count = info->pause_count() + (pause ? 1 : -1);
1784 if (pause_count < 0) {
1785 NOTREACHED(); // Unbalanced call to pause.
1786 return;
1787 }
1788 info->set_pause_count(pause_count);
1789
1790 VLOG(1) << "To pause (" << pause << "): " << i->second->url().spec();
1791
1792 // If we're resuming, kick the request to start reading again. Run the read
1793 // asynchronously to avoid recursion problems.
1794 if (info->pause_count() == 0) {
1795 MessageLoop::current()->PostTask(FROM_HERE,
1796 base::Bind(
1797 &ResourceDispatcherHostImpl::ResumeRequest,
1798 weak_factory_.GetWeakPtr(),
1799 global_id));
1800 }
1801 }
1802
1789 void ResourceDispatcherHostImpl::ResumeRequest( 1803 void ResourceDispatcherHostImpl::ResumeRequest(
1790 const GlobalRequestID& request_id) { 1804 const GlobalRequestID& request_id) {
1791 PendingRequestList::iterator i = pending_requests_.find(request_id); 1805 PendingRequestList::iterator i = pending_requests_.find(request_id);
1792 if (i == pending_requests_.end()) // The request may have been destroyed 1806 if (i == pending_requests_.end()) // The request may have been destroyed
1793 return; 1807 return;
1794 1808
1795 net::URLRequest* request = i->second; 1809 net::URLRequest* request = i->second;
1796 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 1810 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
1797 1811
1798 // We may already be unpaused, or the pause count may have increased since we 1812 // We may already be unpaused, or the pause count may have increased since we
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 } 1934 }
1921 1935
1922 bool ResourceDispatcherHostImpl::CompleteRead(net::URLRequest* request, 1936 bool ResourceDispatcherHostImpl::CompleteRead(net::URLRequest* request,
1923 int* bytes_read) { 1937 int* bytes_read) {
1924 if (!request || !request->status().is_success()) { 1938 if (!request || !request->status().is_success()) {
1925 NOTREACHED(); 1939 NOTREACHED();
1926 return false; 1940 return false;
1927 } 1941 }
1928 1942
1929 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 1943 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
1944
1945 bool defer = false;
1930 if (!info->resource_handler()->OnReadCompleted(info->GetRequestID(), 1946 if (!info->resource_handler()->OnReadCompleted(info->GetRequestID(),
1931 bytes_read)) { 1947 bytes_read, &defer)) {
1932 CancelRequestInternal(request, false); 1948 CancelRequestInternal(request, false);
1933 return false; 1949 return false;
1934 } 1950 }
1935 1951
1952 if (defer)
1953 PauseRequest(info->GetChildID(), info->GetRequestID(), true);
1954
1936 return *bytes_read != 0; 1955 return *bytes_read != 0;
1937 } 1956 }
1938 1957
1939 void ResourceDispatcherHostImpl::ResponseCompleted(net::URLRequest* request) { 1958 void ResourceDispatcherHostImpl::ResponseCompleted(net::URLRequest* request) {
1940 VLOG(1) << "ResponseCompleted: " << request->url().spec(); 1959 VLOG(1) << "ResponseCompleted: " << request->url().spec();
1941 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 1960 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
1942 1961
1943 // Record final result of all resource loads. 1962 // Record final result of all resource loads.
1944 if (info->GetResourceType() == ResourceType::MAIN_FRAME) { 1963 if (info->GetResourceType() == ResourceType::MAIN_FRAME) {
1945 // This enumeration has "3" appended to its name to distinguish it from 1964 // This enumeration has "3" appended to its name to distinguish it from
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
2334 return allow_cross_origin_auth_prompt_; 2353 return allow_cross_origin_auth_prompt_;
2335 } 2354 }
2336 2355
2337 bool ResourceDispatcherHostImpl::IsTransferredNavigation( 2356 bool ResourceDispatcherHostImpl::IsTransferredNavigation(
2338 const GlobalRequestID& transferred_request_id) const { 2357 const GlobalRequestID& transferred_request_id) const {
2339 return transferred_navigations_.find(transferred_request_id) != 2358 return transferred_navigations_.find(transferred_request_id) !=
2340 transferred_navigations_.end(); 2359 transferred_navigations_.end();
2341 } 2360 }
2342 2361
2343 } // namespace content 2362 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698