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

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

Issue 2180933002: Add experimental code behind a flag for Content Size Policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: while -> for Created 4 years, 4 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
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/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 29 matching lines...) Expand all
40 #include "content/browser/cert_store_impl.h" 40 #include "content/browser/cert_store_impl.h"
41 #include "content/browser/child_process_security_policy_impl.h" 41 #include "content/browser/child_process_security_policy_impl.h"
42 #include "content/browser/download/download_resource_handler.h" 42 #include "content/browser/download/download_resource_handler.h"
43 #include "content/browser/download/save_file_manager.h" 43 #include "content/browser/download/save_file_manager.h"
44 #include "content/browser/download/save_file_resource_handler.h" 44 #include "content/browser/download/save_file_resource_handler.h"
45 #include "content/browser/frame_host/frame_tree.h" 45 #include "content/browser/frame_host/frame_tree.h"
46 #include "content/browser/frame_host/navigation_request_info.h" 46 #include "content/browser/frame_host/navigation_request_info.h"
47 #include "content/browser/frame_host/navigator.h" 47 #include "content/browser/frame_host/navigator.h"
48 #include "content/browser/loader/async_resource_handler.h" 48 #include "content/browser/loader/async_resource_handler.h"
49 #include "content/browser/loader/async_revalidation_manager.h" 49 #include "content/browser/loader/async_revalidation_manager.h"
50 #include "content/browser/loader/content_size_resource_handler_manager.h"
50 #include "content/browser/loader/cross_site_resource_handler.h" 51 #include "content/browser/loader/cross_site_resource_handler.h"
51 #include "content/browser/loader/detachable_resource_handler.h" 52 #include "content/browser/loader/detachable_resource_handler.h"
52 #include "content/browser/loader/loader_delegate.h" 53 #include "content/browser/loader/loader_delegate.h"
53 #include "content/browser/loader/mime_type_resource_handler.h" 54 #include "content/browser/loader/mime_type_resource_handler.h"
54 #include "content/browser/loader/navigation_resource_handler.h" 55 #include "content/browser/loader/navigation_resource_handler.h"
55 #include "content/browser/loader/navigation_resource_throttle.h" 56 #include "content/browser/loader/navigation_resource_throttle.h"
56 #include "content/browser/loader/navigation_url_loader_impl_core.h" 57 #include "content/browser/loader/navigation_url_loader_impl_core.h"
57 #include "content/browser/loader/power_save_block_resource_throttle.h" 58 #include "content/browser/loader/power_save_block_resource_throttle.h"
58 #include "content/browser/loader/redirect_to_file_resource_handler.h" 59 #include "content/browser/loader/redirect_to_file_resource_handler.h"
59 #include "content/browser/loader/resource_message_filter.h" 60 #include "content/browser/loader/resource_message_filter.h"
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 } 1064 }
1064 1065
1065 std::unique_ptr<net::ClientCertStore> 1066 std::unique_ptr<net::ClientCertStore>
1066 ResourceDispatcherHostImpl::CreateClientCertStore(ResourceLoader* loader) { 1067 ResourceDispatcherHostImpl::CreateClientCertStore(ResourceLoader* loader) {
1067 return delegate_->CreateClientCertStore( 1068 return delegate_->CreateClientCertStore(
1068 loader->GetRequestInfo()->GetContext()); 1069 loader->GetRequestInfo()->GetContext());
1069 } 1070 }
1070 1071
1071 void ResourceDispatcherHostImpl::OnInit() { 1072 void ResourceDispatcherHostImpl::OnInit() {
1072 scheduler_.reset(new ResourceScheduler); 1073 scheduler_.reset(new ResourceScheduler);
1074 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1075 switches::kContentSizePolicy)) {
1076 content_size_manager_.reset(new ContentSizeResourceHandlerManager());
1077 }
1073 } 1078 }
1074 1079
1075 void ResourceDispatcherHostImpl::OnShutdown() { 1080 void ResourceDispatcherHostImpl::OnShutdown() {
1076 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1081 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1077 1082
1078 is_shutdown_ = true; 1083 is_shutdown_ = true;
1079 pending_loaders_.clear(); 1084 pending_loaders_.clear();
1080 1085
1081 // Make sure we shutdown the timer now, otherwise by the time our destructor 1086 // Make sure we shutdown the timer now, otherwise by the time our destructor
1082 // runs if the timer is still running the Task is deleted twice (once by 1087 // runs if the timer is still running the Task is deleted twice (once by
1083 // the MessageLoop and the second time by RepeatingTimer). 1088 // the MessageLoop and the second time by RepeatingTimer).
1084 update_load_states_timer_.reset(); 1089 update_load_states_timer_.reset();
1085 1090
1086 // Clear blocked requests if any left. 1091 // Clear blocked requests if any left.
1087 // Note that we have to do this in 2 passes as we cannot call 1092 // Note that we have to do this in 2 passes as we cannot call
1088 // CancelBlockedRequestsForRoute while iterating over 1093 // CancelBlockedRequestsForRoute while iterating over
1089 // blocked_loaders_map_, as it modifies it. 1094 // blocked_loaders_map_, as it modifies it.
1090 std::set<GlobalFrameRoutingId> ids; 1095 std::set<GlobalFrameRoutingId> ids;
1091 for (const auto& blocked_loaders : blocked_loaders_map_) { 1096 for (const auto& blocked_loaders : blocked_loaders_map_) {
1092 std::pair<std::set<GlobalFrameRoutingId>::iterator, bool> result = 1097 std::pair<std::set<GlobalFrameRoutingId>::iterator, bool> result =
1093 ids.insert(blocked_loaders.first); 1098 ids.insert(blocked_loaders.first);
1094 // We should not have duplicates. 1099 // We should not have duplicates.
1095 DCHECK(result.second); 1100 DCHECK(result.second);
1096 } 1101 }
1097 for (const auto& routing_id : ids) { 1102 for (const auto& routing_id : ids) {
1098 CancelBlockedRequestsForRoute(routing_id); 1103 CancelBlockedRequestsForRoute(routing_id);
1099 } 1104 }
1100 1105
1101 scheduler_.reset(); 1106 scheduler_.reset();
1107 content_size_manager_.reset();
1102 } 1108 }
1103 1109
1104 bool ResourceDispatcherHostImpl::OnMessageReceived( 1110 bool ResourceDispatcherHostImpl::OnMessageReceived(
1105 const IPC::Message& message, 1111 const IPC::Message& message,
1106 ResourceMessageFilter* filter) { 1112 ResourceMessageFilter* filter) {
1107 filter_ = filter; 1113 filter_ = filter;
1108 bool handled = true; 1114 bool handled = true;
1109 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) 1115 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
1110 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) 1116 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource)
1111 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) 1117 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad)
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 } 1678 }
1673 1679
1674 if (request->has_upload()) { 1680 if (request->has_upload()) {
1675 // Block power save while uploading data. 1681 // Block power save while uploading data.
1676 throttles.push_back(new PowerSaveBlockResourceThrottle( 1682 throttles.push_back(new PowerSaveBlockResourceThrottle(
1677 request->url().host(), 1683 request->url().host(),
1678 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), 1684 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
1679 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); 1685 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)));
1680 } 1686 }
1681 1687
1688 // Insert a handler for inspecting content sizes as they come in. Note that
1689 // this handler can cancel requests if they are associated with frames that go
1690 // over a prescribed limit.
1691 if (content_size_manager_) {
1692 handler =
1693 content_size_manager_->MaybeAddHandler(std::move(handler), request);
1694 }
1695
1682 // TODO(ricea): Stop looking this up so much. 1696 // TODO(ricea): Stop looking this up so much.
1683 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 1697 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
1684 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, 1698 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id,
1685 info->IsAsync(), request)); 1699 info->IsAsync(), request));
1686 1700
1687 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, 1701 handler.reset(new ThrottlingResourceHandler(std::move(handler), request,
1688 std::move(throttles))); 1702 std::move(throttles)));
1689 1703
1690 return handler; 1704 return handler;
1691 } 1705 }
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 } 2286 }
2273 2287
2274 void ResourceDispatcherHostImpl::SetLoaderDelegate( 2288 void ResourceDispatcherHostImpl::SetLoaderDelegate(
2275 LoaderDelegate* loader_delegate) { 2289 LoaderDelegate* loader_delegate) {
2276 loader_delegate_ = loader_delegate; 2290 loader_delegate_ = loader_delegate;
2277 } 2291 }
2278 2292
2279 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( 2293 void ResourceDispatcherHostImpl::OnRenderFrameDeleted(
2280 const GlobalFrameRoutingId& global_routing_id) { 2294 const GlobalFrameRoutingId& global_routing_id) {
2281 CancelRequestsForRoute(global_routing_id); 2295 CancelRequestsForRoute(global_routing_id);
2296 if (content_size_manager_)
2297 content_size_manager_->FrameDeleted(global_routing_id);
2282 } 2298 }
2283 2299
2284 // static 2300 // static
2285 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( 2301 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2286 net::URLRequest* request) { 2302 net::URLRequest* request) {
2287 // The following fields should be a minor size contribution (experimentally 2303 // The following fields should be a minor size contribution (experimentally
2288 // on the order of 100). However since they are variable length, it could 2304 // on the order of 100). However since they are variable length, it could
2289 // in theory be a sizeable contribution. 2305 // in theory be a sizeable contribution.
2290 int strings_cost = request->extra_request_headers().ToString().size() + 2306 int strings_cost = request->extra_request_headers().ToString().size() +
2291 request->original_url().spec().size() + 2307 request->original_url().spec().size() +
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2617 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2602 response->head.security_info = SerializeSecurityInfo(ssl); 2618 response->head.security_info = SerializeSecurityInfo(ssl);
2603 } 2619 }
2604 2620
2605 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2621 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2606 return cert_store_for_testing_ ? cert_store_for_testing_ 2622 return cert_store_for_testing_ ? cert_store_for_testing_
2607 : CertStore::GetInstance(); 2623 : CertStore::GetInstance();
2608 } 2624 }
2609 2625
2610 } // namespace content 2626 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/resource_request_info_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698