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_MAYBE_USER_GESTURE load flag. | |
yzshen1
2011/08/05 21:50:41
1) NET_MAYBE_USER_GESTURE -> LOAD_MAYBE_USER_GESTU
Jói
2011/08/08 17:09:45
1) Done.
2) See updated comment for this constant
| |
121 const int kUserGestureWindowMs = 3500; | |
122 | |
119 // All possible error codes from the network module. Note that the error codes | 123 // All possible error codes from the network module. Note that the error codes |
120 // are all positive (since histograms expect positive sample values). | 124 // are all positive (since histograms expect positive sample values). |
121 const int kAllNetErrorCodes[] = { | 125 const int kAllNetErrorCodes[] = { |
122 #define NET_ERROR(label, value) -(value), | 126 #define NET_ERROR(label, value) -(value), |
123 #include "net/base/net_error_list.h" | 127 #include "net/base/net_error_list.h" |
124 #undef NET_ERROR | 128 #undef NET_ERROR |
125 }; | 129 }; |
126 | 130 |
127 // Aborts a request before an URLRequest has actually been created. | 131 // Aborts a request before an URLRequest has actually been created. |
128 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, | 132 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, |
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1402 | 1406 |
1403 // Note that this expression will typically be dominated by: | 1407 // Note that this expression will typically be dominated by: |
1404 // |kAvgBytesPerOutstandingRequest|. | 1408 // |kAvgBytesPerOutstandingRequest|. |
1405 return kAvgBytesPerOutstandingRequest + strings_cost + upload_cost; | 1409 return kAvgBytesPerOutstandingRequest + strings_cost + upload_cost; |
1406 } | 1410 } |
1407 | 1411 |
1408 void ResourceDispatcherHost::BeginRequestInternal(net::URLRequest* request) { | 1412 void ResourceDispatcherHost::BeginRequestInternal(net::URLRequest* request) { |
1409 DCHECK(!request->is_pending()); | 1413 DCHECK(!request->is_pending()); |
1410 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1414 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
1411 | 1415 |
1416 if ((TimeTicks::Now() - last_user_gesture_time_) < | |
1417 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { | |
1418 request->set_load_flags( | |
1419 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); | |
1420 } | |
1421 | |
1412 // Add the memory estimate that starting this request will consume. | 1422 // Add the memory estimate that starting this request will consume. |
1413 info->set_memory_cost(CalculateApproximateMemoryCost(request)); | 1423 info->set_memory_cost(CalculateApproximateMemoryCost(request)); |
1414 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), | 1424 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), |
1415 info->child_id()); | 1425 info->child_id()); |
1416 | 1426 |
1417 // If enqueing/starting this request will exceed our per-process memory | 1427 // If enqueing/starting this request will exceed our per-process memory |
1418 // bound, abort it right away. | 1428 // bound, abort it right away. |
1419 if (memory_cost > max_outstanding_requests_cost_per_process_) { | 1429 if (memory_cost > max_outstanding_requests_cost_per_process_) { |
1420 // We call "SimulateError()" as a way of setting the net::URLRequest's | 1430 // 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. | 1431 // 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(), | 1677 request->status(), |
1668 security_info)) { | 1678 security_info)) { |
1669 | 1679 |
1670 // The request is complete so we can remove it. | 1680 // The request is complete so we can remove it. |
1671 RemovePendingRequest(info->child_id(), info->request_id()); | 1681 RemovePendingRequest(info->child_id(), info->request_id()); |
1672 } | 1682 } |
1673 // If the handler's OnResponseCompleted returns false, we are deferring the | 1683 // 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. | 1684 // call until later. We will notify the world and clean up when we resume. |
1675 } | 1685 } |
1676 | 1686 |
1687 void ResourceDispatcherHost::OnUserGesture(TabContents* tab) { | |
1688 download_request_limiter()->OnUserGesture(tab); | |
1689 | |
1690 last_user_gesture_time_ = TimeTicks::Now(); | |
1691 } | |
1692 | |
1677 // static | 1693 // static |
1678 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( | 1694 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( |
1679 net::URLRequest* request) { | 1695 net::URLRequest* request) { |
1680 // Avoid writing this function twice by casting the const version. | 1696 // Avoid writing this function twice by casting the const version. |
1681 const net::URLRequest* const_request = request; | 1697 const net::URLRequest* const_request = request; |
1682 return const_cast<ResourceDispatcherHostRequestInfo*>( | 1698 return const_cast<ResourceDispatcherHostRequestInfo*>( |
1683 InfoForRequest(const_request)); | 1699 InfoForRequest(const_request)); |
1684 } | 1700 } |
1685 | 1701 |
1686 // static | 1702 // static |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2106 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; | 2122 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; |
2107 } | 2123 } |
2108 | 2124 |
2109 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { | 2125 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { |
2110 return allow_cross_origin_auth_prompt_; | 2126 return allow_cross_origin_auth_prompt_; |
2111 } | 2127 } |
2112 | 2128 |
2113 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { | 2129 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { |
2114 allow_cross_origin_auth_prompt_ = value; | 2130 allow_cross_origin_auth_prompt_ = value; |
2115 } | 2131 } |
OLD | NEW |