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