| 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 <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 #if defined(OS_WIN) | 198 #if defined(OS_WIN) |
| 199 #pragma warning(disable: 4748) | 199 #pragma warning(disable: 4748) |
| 200 #pragma optimize("", off) | 200 #pragma optimize("", off) |
| 201 #endif | 201 #endif |
| 202 | 202 |
| 203 #if defined(OS_WIN) | 203 #if defined(OS_WIN) |
| 204 #pragma optimize("", on) | 204 #pragma optimize("", on) |
| 205 #pragma warning(default: 4748) | 205 #pragma warning(default: 4748) |
| 206 #endif | 206 #endif |
| 207 | 207 |
| 208 net::RequestPriority DetermineRequestPriority( | |
| 209 const ResourceHostMsg_Request& request_data) { | |
| 210 switch (request_data.priority) { | |
| 211 case WebKit::WebURLRequest::PriorityVeryHigh: | |
| 212 return net::HIGHEST; | |
| 213 | |
| 214 case WebKit::WebURLRequest::PriorityHigh: | |
| 215 return net::MEDIUM; | |
| 216 | |
| 217 case WebKit::WebURLRequest::PriorityMedium: | |
| 218 return net::LOW; | |
| 219 | |
| 220 case WebKit::WebURLRequest::PriorityLow: | |
| 221 return net::LOWEST; | |
| 222 | |
| 223 case WebKit::WebURLRequest::PriorityVeryLow: | |
| 224 return net::IDLE; | |
| 225 | |
| 226 case WebKit::WebURLRequest::PriorityUnresolved: | |
| 227 default: | |
| 228 NOTREACHED(); | |
| 229 return net::LOW; | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 void OnSwapOutACKHelper(int render_process_id, | 208 void OnSwapOutACKHelper(int render_process_id, |
| 234 int render_view_id, | 209 int render_view_id, |
| 235 bool timed_out) { | 210 bool timed_out) { |
| 236 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id, | 211 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id, |
| 237 render_view_id); | 212 render_view_id); |
| 238 if (rvh) | 213 if (rvh) |
| 239 rvh->OnSwapOutACK(timed_out); | 214 rvh->OnSwapOutACK(timed_out); |
| 240 } | 215 } |
| 241 | 216 |
| 242 net::Error CallbackAndReturn( | 217 net::Error CallbackAndReturn( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 333 DCHECK(!g_resource_dispatcher_host); | 308 DCHECK(!g_resource_dispatcher_host); |
| 334 g_resource_dispatcher_host = this; | 309 g_resource_dispatcher_host = this; |
| 335 | 310 |
| 336 GetContentClient()->browser()->ResourceDispatcherHostCreated(); | 311 GetContentClient()->browser()->ResourceDispatcherHostCreated(); |
| 337 | 312 |
| 338 ANNOTATE_BENIGN_RACE( | 313 ANNOTATE_BENIGN_RACE( |
| 339 &last_user_gesture_time_, | 314 &last_user_gesture_time_, |
| 340 "We don't care about the precise value, see http://crbug.com/92889"); | 315 "We don't care about the precise value, see http://crbug.com/92889"); |
| 341 | 316 |
| 342 BrowserThread::PostTask( | 317 BrowserThread::PostTask(BrowserThread::IO, |
| 343 BrowserThread::IO, FROM_HERE, | 318 FROM_HERE, |
| 344 base::Bind(&appcache::AppCacheInterceptor::EnsureRegistered)); | 319 base::Bind(&ResourceDispatcherHostImpl::OnInit, |
| 320 base::Unretained(this))); |
| 345 | 321 |
| 346 update_load_states_timer_.reset( | 322 update_load_states_timer_.reset( |
| 347 new base::RepeatingTimer<ResourceDispatcherHostImpl>()); | 323 new base::RepeatingTimer<ResourceDispatcherHostImpl>()); |
| 348 } | 324 } |
| 349 | 325 |
| 350 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { | 326 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
| 351 DCHECK(g_resource_dispatcher_host); | 327 DCHECK(g_resource_dispatcher_host); |
| 352 g_resource_dispatcher_host = NULL; | 328 g_resource_dispatcher_host = NULL; |
| 353 } | 329 } |
| 354 | 330 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 ResourceRequestInfoImpl::ForRequest(request); | 719 ResourceRequestInfoImpl::ForRequest(request); |
| 744 if (!info) { | 720 if (!info) { |
| 745 *render_process_id = -1; | 721 *render_process_id = -1; |
| 746 *render_view_id = -1; | 722 *render_view_id = -1; |
| 747 return false; | 723 return false; |
| 748 } | 724 } |
| 749 | 725 |
| 750 return info->GetAssociatedRenderView(render_process_id, render_view_id); | 726 return info->GetAssociatedRenderView(render_process_id, render_view_id); |
| 751 } | 727 } |
| 752 | 728 |
| 729 void ResourceDispatcherHostImpl::OnInit() { |
| 730 scheduler_.reset(new ResourceScheduler); |
| 731 appcache::AppCacheInterceptor::EnsureRegistered(); |
| 732 } |
| 733 |
| 753 void ResourceDispatcherHostImpl::OnShutdown() { | 734 void ResourceDispatcherHostImpl::OnShutdown() { |
| 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 755 | 736 |
| 756 is_shutdown_ = true; | 737 is_shutdown_ = true; |
| 757 pending_loaders_.clear(); | 738 pending_loaders_.clear(); |
| 758 | 739 |
| 759 // Make sure we shutdown the timer now, otherwise by the time our destructor | 740 // Make sure we shutdown the timer now, otherwise by the time our destructor |
| 760 // runs if the timer is still running the Task is deleted twice (once by | 741 // runs if the timer is still running the Task is deleted twice (once by |
| 761 // the MessageLoop and the second time by RepeatingTimer). | 742 // the MessageLoop and the second time by RepeatingTimer). |
| 762 update_load_states_timer_.reset(); | 743 update_load_states_timer_.reset(); |
| 763 | 744 |
| 764 // Clear blocked requests if any left. | 745 // Clear blocked requests if any left. |
| 765 // Note that we have to do this in 2 passes as we cannot call | 746 // Note that we have to do this in 2 passes as we cannot call |
| 766 // CancelBlockedRequestsForRoute while iterating over | 747 // CancelBlockedRequestsForRoute while iterating over |
| 767 // blocked_loaders_map_, as it modifies it. | 748 // blocked_loaders_map_, as it modifies it. |
| 768 std::set<ProcessRouteIDs> ids; | 749 std::set<ProcessRouteIDs> ids; |
| 769 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); | 750 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); |
| 770 iter != blocked_loaders_map_.end(); ++iter) { | 751 iter != blocked_loaders_map_.end(); ++iter) { |
| 771 std::pair<std::set<ProcessRouteIDs>::iterator, bool> result = | 752 std::pair<std::set<ProcessRouteIDs>::iterator, bool> result = |
| 772 ids.insert(iter->first); | 753 ids.insert(iter->first); |
| 773 // We should not have duplicates. | 754 // We should not have duplicates. |
| 774 DCHECK(result.second); | 755 DCHECK(result.second); |
| 775 } | 756 } |
| 776 for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); | 757 for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); |
| 777 iter != ids.end(); ++iter) { | 758 iter != ids.end(); ++iter) { |
| 778 CancelBlockedRequestsForRoute(iter->first, iter->second); | 759 CancelBlockedRequestsForRoute(iter->first, iter->second); |
| 779 } | 760 } |
| 761 |
| 762 scheduler_.reset(); |
| 780 } | 763 } |
| 781 | 764 |
| 782 bool ResourceDispatcherHostImpl::OnMessageReceived( | 765 bool ResourceDispatcherHostImpl::OnMessageReceived( |
| 783 const IPC::Message& message, | 766 const IPC::Message& message, |
| 784 ResourceMessageFilter* filter, | 767 ResourceMessageFilter* filter, |
| 785 bool* message_was_ok) { | 768 bool* message_was_ok) { |
| 786 filter_ = filter; | 769 filter_ = filter; |
| 787 bool handled = true; | 770 bool handled = true; |
| 788 IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcherHostImpl, message, *message_was_ok) | 771 IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcherHostImpl, message, *message_was_ok) |
| 789 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 772 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 referrer.policy); | 915 referrer.policy); |
| 933 net::HttpRequestHeaders headers; | 916 net::HttpRequestHeaders headers; |
| 934 headers.AddHeadersFromString(request_data.headers); | 917 headers.AddHeadersFromString(request_data.headers); |
| 935 request->SetExtraRequestHeaders(headers); | 918 request->SetExtraRequestHeaders(headers); |
| 936 } | 919 } |
| 937 | 920 |
| 938 // TODO(darin): Do we really need all of these URLRequest setters in the | 921 // TODO(darin): Do we really need all of these URLRequest setters in the |
| 939 // transferred navigation case? | 922 // transferred navigation case? |
| 940 | 923 |
| 941 request->set_load_flags(load_flags); | 924 request->set_load_flags(load_flags); |
| 942 | 925 request->set_priority(request_data.priority); |
| 943 request->set_priority(DetermineRequestPriority(request_data)); | |
| 944 | 926 |
| 945 // Resolve elements from request_body and prepare upload data. | 927 // Resolve elements from request_body and prepare upload data. |
| 946 if (request_data.request_body) { | 928 if (request_data.request_body) { |
| 947 request->set_upload(make_scoped_ptr( | 929 request->set_upload(make_scoped_ptr( |
| 948 request_data.request_body->ResolveElementsAndCreateUploadDataStream( | 930 request_data.request_body->ResolveElementsAndCreateUploadDataStream( |
| 949 filter_->blob_storage_context()->controller(), | 931 filter_->blob_storage_context()->controller(), |
| 950 filter_->file_system_context(), | 932 filter_->file_system_context(), |
| 951 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)))); | 933 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)))); |
| 952 } | 934 } |
| 953 | 935 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 // Block power save while uploading data. | 1024 // Block power save while uploading data. |
| 1043 throttles.push_back(new PowerSaveBlockResourceThrottle()); | 1025 throttles.push_back(new PowerSaveBlockResourceThrottle()); |
| 1044 } | 1026 } |
| 1045 | 1027 |
| 1046 if (request_data.resource_type == ResourceType::MAIN_FRAME) { | 1028 if (request_data.resource_type == ResourceType::MAIN_FRAME) { |
| 1047 throttles.insert( | 1029 throttles.insert( |
| 1048 throttles.begin(), | 1030 throttles.begin(), |
| 1049 new TransferNavigationResourceThrottle(request)); | 1031 new TransferNavigationResourceThrottle(request)); |
| 1050 } | 1032 } |
| 1051 | 1033 |
| 1052 if (!throttles.empty()) { | 1034 throttles.push_back( |
| 1053 handler.reset( | 1035 scheduler_->ScheduleRequest(child_id, route_id, request).release()); |
| 1054 new ThrottlingResourceHandler(handler.Pass(), child_id, request_id, | 1036 |
| 1055 throttles.Pass())); | 1037 handler.reset( |
| 1056 } | 1038 new ThrottlingResourceHandler(handler.Pass(), child_id, request_id, |
| 1039 throttles.Pass())); |
| 1057 | 1040 |
| 1058 if (deferred_loader.get()) { | 1041 if (deferred_loader.get()) { |
| 1059 pending_loaders_[extra_info->GetGlobalRequestID()] = deferred_loader; | 1042 pending_loaders_[extra_info->GetGlobalRequestID()] = deferred_loader; |
| 1060 deferred_loader->CompleteTransfer(handler.Pass()); | 1043 deferred_loader->CompleteTransfer(handler.Pass()); |
| 1061 } else { | 1044 } else { |
| 1062 BeginRequestInternal(new_request.Pass(), handler.Pass()); | 1045 BeginRequestInternal(new_request.Pass(), handler.Pass()); |
| 1063 } | 1046 } |
| 1064 } | 1047 } |
| 1065 | 1048 |
| 1066 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { | 1049 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 DelegateMap::iterator it = delegate_map_.find(id); | 1697 DelegateMap::iterator it = delegate_map_.find(id); |
| 1715 DCHECK(it->second->HasObserver(delegate)); | 1698 DCHECK(it->second->HasObserver(delegate)); |
| 1716 it->second->RemoveObserver(delegate); | 1699 it->second->RemoveObserver(delegate); |
| 1717 if (it->second->size() == 0) { | 1700 if (it->second->size() == 0) { |
| 1718 delete it->second; | 1701 delete it->second; |
| 1719 delegate_map_.erase(it); | 1702 delegate_map_.erase(it); |
| 1720 } | 1703 } |
| 1721 } | 1704 } |
| 1722 | 1705 |
| 1723 } // namespace content | 1706 } // namespace content |
| OLD | NEW |