| 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 398 } |
| 399 | 399 |
| 400 // PlzNavigate | 400 // PlzNavigate |
| 401 // This method is called in the UI thread to send the timestamp of a resource | 401 // This method is called in the UI thread to send the timestamp of a resource |
| 402 // request to the respective Navigator (for an UMA histogram). | 402 // request to the respective Navigator (for an UMA histogram). |
| 403 void LogResourceRequestTimeOnUI( | 403 void LogResourceRequestTimeOnUI( |
| 404 base::TimeTicks timestamp, | 404 base::TimeTicks timestamp, |
| 405 int render_process_id, | 405 int render_process_id, |
| 406 int render_frame_id, | 406 int render_frame_id, |
| 407 const GURL& url) { | 407 const GURL& url) { |
| 408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 408 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 409 RenderFrameHostImpl* host = | 409 RenderFrameHostImpl* host = |
| 410 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 410 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
| 411 if (host != NULL) { | 411 if (host != NULL) { |
| 412 DCHECK(host->frame_tree_node()->IsMainFrame()); | 412 DCHECK(host->frame_tree_node()->IsMainFrame()); |
| 413 host->frame_tree_node()->navigator()->LogResourceRequestTime( | 413 host->frame_tree_node()->navigator()->LogResourceRequestTime( |
| 414 timestamp, url); | 414 timestamp, url); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 | 417 |
| 418 } // namespace | 418 } // namespace |
| (...skipping 10 matching lines...) Expand all Loading... |
| 429 num_in_flight_requests_(0), | 429 num_in_flight_requests_(0), |
| 430 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), | 430 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), |
| 431 max_num_in_flight_requests_per_process_( | 431 max_num_in_flight_requests_per_process_( |
| 432 static_cast<int>( | 432 static_cast<int>( |
| 433 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), | 433 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), |
| 434 max_outstanding_requests_cost_per_process_( | 434 max_outstanding_requests_cost_per_process_( |
| 435 kMaxOutstandingRequestsCostPerProcess), | 435 kMaxOutstandingRequestsCostPerProcess), |
| 436 filter_(NULL), | 436 filter_(NULL), |
| 437 delegate_(NULL), | 437 delegate_(NULL), |
| 438 allow_cross_origin_auth_prompt_(false) { | 438 allow_cross_origin_auth_prompt_(false) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 439 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 440 DCHECK(!g_resource_dispatcher_host); | 440 DCHECK(!g_resource_dispatcher_host); |
| 441 g_resource_dispatcher_host = this; | 441 g_resource_dispatcher_host = this; |
| 442 | 442 |
| 443 GetContentClient()->browser()->ResourceDispatcherHostCreated(); | 443 GetContentClient()->browser()->ResourceDispatcherHostCreated(); |
| 444 | 444 |
| 445 ANNOTATE_BENIGN_RACE( | 445 ANNOTATE_BENIGN_RACE( |
| 446 &last_user_gesture_time_, | 446 &last_user_gesture_time_, |
| 447 "We don't care about the precise value, see http://crbug.com/92889"); | 447 "We don't care about the precise value, see http://crbug.com/92889"); |
| 448 | 448 |
| 449 BrowserThread::PostTask(BrowserThread::IO, | 449 BrowserThread::PostTask(BrowserThread::IO, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 if (loader) { | 491 if (loader) { |
| 492 // The response we were meant to resume could have already been canceled. | 492 // The response we were meant to resume could have already been canceled. |
| 493 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 493 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
| 494 if (info->cross_site_handler()) | 494 if (info->cross_site_handler()) |
| 495 info->cross_site_handler()->ResumeResponseDeferredAtStart(id.request_id); | 495 info->cross_site_handler()->ResumeResponseDeferredAtStart(id.request_id); |
| 496 } | 496 } |
| 497 } | 497 } |
| 498 | 498 |
| 499 void ResourceDispatcherHostImpl::CancelRequestsForContext( | 499 void ResourceDispatcherHostImpl::CancelRequestsForContext( |
| 500 ResourceContext* context) { | 500 ResourceContext* context) { |
| 501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 501 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 502 DCHECK(context); | 502 DCHECK(context); |
| 503 | 503 |
| 504 CHECK(ContainsKey(active_resource_contexts_, context)); | 504 CHECK(ContainsKey(active_resource_contexts_, context)); |
| 505 | 505 |
| 506 // Note that request cancellation has side effects. Therefore, we gather all | 506 // Note that request cancellation has side effects. Therefore, we gather all |
| 507 // the requests to cancel first, and then we start cancelling. We assert at | 507 // the requests to cancel first, and then we start cancelling. We assert at |
| 508 // the end that there are no more to cancel since the context is about to go | 508 // the end that there are no more to cancel since the context is about to go |
| 509 // away. | 509 // away. |
| 510 typedef std::vector<linked_ptr<ResourceLoader>> LoaderList; | 510 typedef std::vector<linked_ptr<ResourceLoader>> LoaderList; |
| 511 LoaderList loaders_to_cancel; | 511 LoaderList loaders_to_cancel; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 net::URLRequest* request) { | 685 net::URLRequest* request) { |
| 686 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 686 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
| 687 if (info) { | 687 if (info) { |
| 688 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); | 688 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); |
| 689 if (loader) | 689 if (loader) |
| 690 loader->ClearLoginDelegate(); | 690 loader->ClearLoginDelegate(); |
| 691 } | 691 } |
| 692 } | 692 } |
| 693 | 693 |
| 694 void ResourceDispatcherHostImpl::Shutdown() { | 694 void ResourceDispatcherHostImpl::Shutdown() { |
| 695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 695 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 696 BrowserThread::PostTask(BrowserThread::IO, | 696 BrowserThread::PostTask(BrowserThread::IO, |
| 697 FROM_HERE, | 697 FROM_HERE, |
| 698 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, | 698 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, |
| 699 base::Unretained(this))); | 699 base::Unretained(this))); |
| 700 } | 700 } |
| 701 | 701 |
| 702 scoped_ptr<ResourceHandler> | 702 scoped_ptr<ResourceHandler> |
| 703 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( | 703 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( |
| 704 net::URLRequest* request, | 704 net::URLRequest* request, |
| 705 bool is_content_initiated, | 705 bool is_content_initiated, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 | 896 |
| 897 // Destroy the ResourceLoader. | 897 // Destroy the ResourceLoader. |
| 898 RemovePendingRequest(info->GetChildID(), info->GetRequestID()); | 898 RemovePendingRequest(info->GetChildID(), info->GetRequestID()); |
| 899 } | 899 } |
| 900 | 900 |
| 901 void ResourceDispatcherHostImpl::OnInit() { | 901 void ResourceDispatcherHostImpl::OnInit() { |
| 902 scheduler_.reset(new ResourceScheduler); | 902 scheduler_.reset(new ResourceScheduler); |
| 903 } | 903 } |
| 904 | 904 |
| 905 void ResourceDispatcherHostImpl::OnShutdown() { | 905 void ResourceDispatcherHostImpl::OnShutdown() { |
| 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 906 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 907 | 907 |
| 908 is_shutdown_ = true; | 908 is_shutdown_ = true; |
| 909 pending_loaders_.clear(); | 909 pending_loaders_.clear(); |
| 910 | 910 |
| 911 // Make sure we shutdown the timer now, otherwise by the time our destructor | 911 // Make sure we shutdown the timer now, otherwise by the time our destructor |
| 912 // runs if the timer is still running the Task is deleted twice (once by | 912 // runs if the timer is still running the Task is deleted twice (once by |
| 913 // the MessageLoop and the second time by RepeatingTimer). | 913 // the MessageLoop and the second time by RepeatingTimer). |
| 914 update_load_states_timer_.reset(); | 914 update_load_states_timer_.reset(); |
| 915 | 915 |
| 916 // Clear blocked requests if any left. | 916 // Clear blocked requests if any left. |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2128 } | 2128 } |
| 2129 | 2129 |
| 2130 // static | 2130 // static |
| 2131 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( | 2131 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( |
| 2132 scoped_ptr<LoadInfoMap> info_map) { | 2132 scoped_ptr<LoadInfoMap> info_map) { |
| 2133 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | 2133 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 2134 // is fixed. | 2134 // is fixed. |
| 2135 tracked_objects::ScopedTracker tracking_profile( | 2135 tracked_objects::ScopedTracker tracking_profile( |
| 2136 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 2136 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2137 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); | 2137 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); |
| 2138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2139 for (const auto& load_info : *info_map) { | 2139 for (const auto& load_info : *info_map) { |
| 2140 RenderViewHostImpl* view = RenderViewHostImpl::FromID( | 2140 RenderViewHostImpl* view = RenderViewHostImpl::FromID( |
| 2141 load_info.first.child_id, load_info.first.route_id); | 2141 load_info.first.child_id, load_info.first.route_id); |
| 2142 // The view could be gone at this point. | 2142 // The view could be gone at this point. |
| 2143 if (view) { | 2143 if (view) { |
| 2144 view->LoadStateChanged(load_info.second.url, load_info.second.load_state, | 2144 view->LoadStateChanged(load_info.second.url, load_info.second.load_state, |
| 2145 load_info.second.upload_position, | 2145 load_info.second.upload_position, |
| 2146 load_info.second.upload_size); | 2146 load_info.second.upload_size); |
| 2147 } | 2147 } |
| 2148 } | 2148 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2196 "455952 ResourceDispatcherHostImpl::UpdateLoadInfo2")); | 2196 "455952 ResourceDispatcherHostImpl::UpdateLoadInfo2")); |
| 2197 | 2197 |
| 2198 BrowserThread::PostTask( | 2198 BrowserThread::PostTask( |
| 2199 BrowserThread::UI, FROM_HERE, | 2199 BrowserThread::UI, FROM_HERE, |
| 2200 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, | 2200 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, |
| 2201 base::Passed(&info_map))); | 2201 base::Passed(&info_map))); |
| 2202 } | 2202 } |
| 2203 | 2203 |
| 2204 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, | 2204 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, |
| 2205 int route_id) { | 2205 int route_id) { |
| 2206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2206 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 2207 GlobalRoutingID key(child_id, route_id); | 2207 GlobalRoutingID key(child_id, route_id); |
| 2208 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << | 2208 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << |
| 2209 "BlockRequestsForRoute called multiple time for the same RVH"; | 2209 "BlockRequestsForRoute called multiple time for the same RVH"; |
| 2210 blocked_loaders_map_[key] = new BlockedLoadersList(); | 2210 blocked_loaders_map_[key] = new BlockedLoadersList(); |
| 2211 } | 2211 } |
| 2212 | 2212 |
| 2213 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, | 2213 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, |
| 2214 int route_id) { | 2214 int route_id) { |
| 2215 ProcessBlockedRequestsForRoute(child_id, route_id, false); | 2215 ProcessBlockedRequestsForRoute(child_id, route_id, false); |
| 2216 } | 2216 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2274 } | 2274 } |
| 2275 | 2275 |
| 2276 bool ResourceDispatcherHostImpl::IsTransferredNavigation( | 2276 bool ResourceDispatcherHostImpl::IsTransferredNavigation( |
| 2277 const GlobalRequestID& id) const { | 2277 const GlobalRequestID& id) const { |
| 2278 ResourceLoader* loader = GetLoader(id); | 2278 ResourceLoader* loader = GetLoader(id); |
| 2279 return loader ? loader->is_transferring() : false; | 2279 return loader ? loader->is_transferring() : false; |
| 2280 } | 2280 } |
| 2281 | 2281 |
| 2282 ResourceLoader* ResourceDispatcherHostImpl::GetLoader( | 2282 ResourceLoader* ResourceDispatcherHostImpl::GetLoader( |
| 2283 const GlobalRequestID& id) const { | 2283 const GlobalRequestID& id) const { |
| 2284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2284 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 2285 | 2285 |
| 2286 LoaderMap::const_iterator i = pending_loaders_.find(id); | 2286 LoaderMap::const_iterator i = pending_loaders_.find(id); |
| 2287 if (i == pending_loaders_.end()) | 2287 if (i == pending_loaders_.end()) |
| 2288 return NULL; | 2288 return NULL; |
| 2289 | 2289 |
| 2290 return i->second.get(); | 2290 return i->second.get(); |
| 2291 } | 2291 } |
| 2292 | 2292 |
| 2293 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, | 2293 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, |
| 2294 int request_id) const { | 2294 int request_id) const { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2357 | 2357 |
| 2358 // Add a flag to selectively bypass the data reduction proxy if the resource | 2358 // Add a flag to selectively bypass the data reduction proxy if the resource |
| 2359 // type is not an image. | 2359 // type is not an image. |
| 2360 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) | 2360 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) |
| 2361 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 2361 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 2362 | 2362 |
| 2363 return load_flags; | 2363 return load_flags; |
| 2364 } | 2364 } |
| 2365 | 2365 |
| 2366 } // namespace content | 2366 } // namespace content |
| OLD | NEW |