OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/shared_memory.h" | 19 #include "base/shared_memory.h" |
20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
21 #include "base/time.h" | |
22 #include "chrome/browser/download/download_file_manager.h" | 21 #include "chrome/browser/download/download_file_manager.h" |
23 #include "chrome/browser/download/download_manager.h" | 22 #include "chrome/browser/download/download_manager.h" |
24 #include "chrome/browser/download/download_request_limiter.h" | 23 #include "chrome/browser/download/download_request_limiter.h" |
25 #include "chrome/browser/download/download_util.h" | 24 #include "chrome/browser/download/download_util.h" |
26 #include "chrome/browser/renderer_host/download_resource_handler.h" | 25 #include "chrome/browser/renderer_host/download_resource_handler.h" |
27 #include "content/browser/appcache/chrome_appcache_service.h" | 26 #include "content/browser/appcache/chrome_appcache_service.h" |
28 #include "content/browser/cert_store.h" | 27 #include "content/browser/cert_store.h" |
29 #include "content/browser/child_process_security_policy.h" | 28 #include "content/browser/child_process_security_policy.h" |
30 #include "content/browser/chrome_blob_storage_context.h" | 29 #include "content/browser/chrome_blob_storage_context.h" |
31 #include "content/browser/content_browser_client.h" | 30 #include "content/browser/content_browser_client.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 108 |
110 // Maximum number of pending data messages sent to the renderer at any | 109 // Maximum number of pending data messages sent to the renderer at any |
111 // given time for a given request. | 110 // given time for a given request. |
112 const int kMaxPendingDataMessages = 20; | 111 const int kMaxPendingDataMessages = 20; |
113 | 112 |
114 // Maximum byte "cost" of all the outstanding requests for a renderer. | 113 // Maximum byte "cost" of all the outstanding requests for a renderer. |
115 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. | 114 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. |
116 // This bound is 25MB, which allows for around 6000 outstanding requests. | 115 // This bound is 25MB, which allows for around 6000 outstanding requests. |
117 const int kMaxOutstandingRequestsCostPerProcess = 26214400; | 116 const int kMaxOutstandingRequestsCostPerProcess = 26214400; |
118 | 117 |
| 118 // The number of milliseconds after noting a user gesture that we will |
| 119 // tag newly-created URLRequest objects with the |
| 120 // net::LOAD_MAYBE_USER_GESTURE load flag. This is a fairly arbitrary |
| 121 // guess at how long to expect direct impact from a user gesture, but |
| 122 // this should be OK as the load flag is a best-effort thing only, |
| 123 // rather than being intended as fully accurate. |
| 124 const int kUserGestureWindowMs = 3500; |
| 125 |
119 // All possible error codes from the network module. Note that the error codes | 126 // All possible error codes from the network module. Note that the error codes |
120 // are all positive (since histograms expect positive sample values). | 127 // are all positive (since histograms expect positive sample values). |
121 const int kAllNetErrorCodes[] = { | 128 const int kAllNetErrorCodes[] = { |
122 #define NET_ERROR(label, value) -(value), | 129 #define NET_ERROR(label, value) -(value), |
123 #include "net/base/net_error_list.h" | 130 #include "net/base/net_error_list.h" |
124 #undef NET_ERROR | 131 #undef NET_ERROR |
125 }; | 132 }; |
126 | 133 |
127 // Aborts a request before an URLRequest has actually been created. | 134 // Aborts a request before an URLRequest has actually been created. |
128 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, | 135 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, |
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 | 1409 |
1403 // Note that this expression will typically be dominated by: | 1410 // Note that this expression will typically be dominated by: |
1404 // |kAvgBytesPerOutstandingRequest|. | 1411 // |kAvgBytesPerOutstandingRequest|. |
1405 return kAvgBytesPerOutstandingRequest + strings_cost + upload_cost; | 1412 return kAvgBytesPerOutstandingRequest + strings_cost + upload_cost; |
1406 } | 1413 } |
1407 | 1414 |
1408 void ResourceDispatcherHost::BeginRequestInternal(net::URLRequest* request) { | 1415 void ResourceDispatcherHost::BeginRequestInternal(net::URLRequest* request) { |
1409 DCHECK(!request->is_pending()); | 1416 DCHECK(!request->is_pending()); |
1410 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1417 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
1411 | 1418 |
| 1419 if ((TimeTicks::Now() - last_user_gesture_time_) < |
| 1420 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { |
| 1421 request->set_load_flags( |
| 1422 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); |
| 1423 } |
| 1424 |
1412 // Add the memory estimate that starting this request will consume. | 1425 // Add the memory estimate that starting this request will consume. |
1413 info->set_memory_cost(CalculateApproximateMemoryCost(request)); | 1426 info->set_memory_cost(CalculateApproximateMemoryCost(request)); |
1414 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), | 1427 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), |
1415 info->child_id()); | 1428 info->child_id()); |
1416 | 1429 |
1417 // If enqueing/starting this request will exceed our per-process memory | 1430 // If enqueing/starting this request will exceed our per-process memory |
1418 // bound, abort it right away. | 1431 // bound, abort it right away. |
1419 if (memory_cost > max_outstanding_requests_cost_per_process_) { | 1432 if (memory_cost > max_outstanding_requests_cost_per_process_) { |
1420 // We call "SimulateError()" as a way of setting the net::URLRequest's | 1433 // We call "SimulateError()" as a way of setting the net::URLRequest's |
1421 // status -- it has no effect beyond this, since the request hasn't started. | 1434 // status -- it has no effect beyond this, since the request hasn't started. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 request->status(), | 1680 request->status(), |
1668 security_info)) { | 1681 security_info)) { |
1669 | 1682 |
1670 // The request is complete so we can remove it. | 1683 // The request is complete so we can remove it. |
1671 RemovePendingRequest(info->child_id(), info->request_id()); | 1684 RemovePendingRequest(info->child_id(), info->request_id()); |
1672 } | 1685 } |
1673 // If the handler's OnResponseCompleted returns false, we are deferring the | 1686 // If the handler's OnResponseCompleted returns false, we are deferring the |
1674 // call until later. We will notify the world and clean up when we resume. | 1687 // call until later. We will notify the world and clean up when we resume. |
1675 } | 1688 } |
1676 | 1689 |
| 1690 void ResourceDispatcherHost::OnUserGesture(TabContents* tab) { |
| 1691 download_request_limiter()->OnUserGesture(tab); |
| 1692 |
| 1693 last_user_gesture_time_ = TimeTicks::Now(); |
| 1694 } |
| 1695 |
1677 // static | 1696 // static |
1678 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( | 1697 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( |
1679 net::URLRequest* request) { | 1698 net::URLRequest* request) { |
1680 // Avoid writing this function twice by casting the const version. | 1699 // Avoid writing this function twice by casting the const version. |
1681 const net::URLRequest* const_request = request; | 1700 const net::URLRequest* const_request = request; |
1682 return const_cast<ResourceDispatcherHostRequestInfo*>( | 1701 return const_cast<ResourceDispatcherHostRequestInfo*>( |
1683 InfoForRequest(const_request)); | 1702 InfoForRequest(const_request)); |
1684 } | 1703 } |
1685 | 1704 |
1686 // static | 1705 // static |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; | 2125 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; |
2107 } | 2126 } |
2108 | 2127 |
2109 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { | 2128 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { |
2110 return allow_cross_origin_auth_prompt_; | 2129 return allow_cross_origin_auth_prompt_; |
2111 } | 2130 } |
2112 | 2131 |
2113 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { | 2132 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { |
2114 allow_cross_origin_auth_prompt_ = value; | 2133 allow_cross_origin_auth_prompt_ = value; |
2115 } | 2134 } |
OLD | NEW |