| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/login_prompt.h" | 27 #include "chrome/browser/login_prompt.h" |
| 28 #include "chrome/browser/net/chrome_url_request_context.h" | 28 #include "chrome/browser/net/chrome_url_request_context.h" |
| 29 #include "chrome/browser/net/url_request_tracking.h" | 29 #include "chrome/browser/net/url_request_tracking.h" |
| 30 #include "chrome/browser/plugin_service.h" | 30 #include "chrome/browser/plugin_service.h" |
| 31 #include "chrome/browser/privacy_blacklist/blacklist.h" | 31 #include "chrome/browser/privacy_blacklist/blacklist.h" |
| 32 #include "chrome/browser/profile.h" | 32 #include "chrome/browser/profile.h" |
| 33 #include "chrome/browser/renderer_host/async_resource_handler.h" | 33 #include "chrome/browser/renderer_host/async_resource_handler.h" |
| 34 #include "chrome/browser/renderer_host/buffered_resource_handler.h" | 34 #include "chrome/browser/renderer_host/buffered_resource_handler.h" |
| 35 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" | 35 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" |
| 36 #include "chrome/browser/renderer_host/download_resource_handler.h" | 36 #include "chrome/browser/renderer_host/download_resource_handler.h" |
| 37 #include "chrome/browser/renderer_host/global_request_id.h" |
| 37 #include "chrome/browser/renderer_host/render_view_host.h" | 38 #include "chrome/browser/renderer_host/render_view_host.h" |
| 38 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 39 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 39 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" | 40 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 41 #include "chrome/browser/renderer_host/resource_queue.h" |
| 40 #include "chrome/browser/renderer_host/resource_request_details.h" | 42 #include "chrome/browser/renderer_host/resource_request_details.h" |
| 41 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" | 43 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" |
| 42 #include "chrome/browser/renderer_host/save_file_resource_handler.h" | 44 #include "chrome/browser/renderer_host/save_file_resource_handler.h" |
| 43 #include "chrome/browser/renderer_host/socket_stream_dispatcher_host.h" | 45 #include "chrome/browser/renderer_host/socket_stream_dispatcher_host.h" |
| 44 #include "chrome/browser/renderer_host/sync_resource_handler.h" | 46 #include "chrome/browser/renderer_host/sync_resource_handler.h" |
| 45 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 47 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 46 #include "chrome/browser/ssl/ssl_client_auth_handler.h" | 48 #include "chrome/browser/ssl/ssl_client_auth_handler.h" |
| 47 #include "chrome/browser/ssl/ssl_manager.h" | 49 #include "chrome/browser/ssl/ssl_manager.h" |
| 48 #include "chrome/browser/worker_host/worker_service.h" | 50 #include "chrome/browser/worker_host/worker_service.h" |
| 49 #include "chrome/common/chrome_switches.h" | 51 #include "chrome/common/chrome_switches.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 242 } |
| 241 | 243 |
| 242 } // namespace | 244 } // namespace |
| 243 | 245 |
| 244 ResourceDispatcherHost::ResourceDispatcherHost() | 246 ResourceDispatcherHost::ResourceDispatcherHost() |
| 245 : ALLOW_THIS_IN_INITIALIZER_LIST( | 247 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 246 download_file_manager_(new DownloadFileManager(this))), | 248 download_file_manager_(new DownloadFileManager(this))), |
| 247 download_request_manager_(new DownloadRequestManager()), | 249 download_request_manager_(new DownloadRequestManager()), |
| 248 ALLOW_THIS_IN_INITIALIZER_LIST( | 250 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 249 save_file_manager_(new SaveFileManager(this))), | 251 save_file_manager_(new SaveFileManager(this))), |
| 250 ALLOW_THIS_IN_INITIALIZER_LIST(user_script_listener_( | 252 user_script_listener_(new UserScriptListener(&resource_queue_)), |
| 251 new UserScriptListener(this))), | |
| 252 safe_browsing_(new SafeBrowsingService), | 253 safe_browsing_(new SafeBrowsingService), |
| 253 socket_stream_dispatcher_host_(new SocketStreamDispatcherHost), | 254 socket_stream_dispatcher_host_(new SocketStreamDispatcherHost), |
| 254 webkit_thread_(new WebKitThread), | 255 webkit_thread_(new WebKitThread), |
| 255 request_id_(-1), | 256 request_id_(-1), |
| 256 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)), | 257 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)), |
| 257 is_shutdown_(false), | 258 is_shutdown_(false), |
| 258 max_outstanding_requests_cost_per_process_( | 259 max_outstanding_requests_cost_per_process_( |
| 259 kMaxOutstandingRequestsCostPerProcess), | 260 kMaxOutstandingRequestsCostPerProcess), |
| 260 receiver_(NULL) { | 261 receiver_(NULL) { |
| 262 ResourceQueue::DelegateSet resource_queue_delegates; |
| 263 resource_queue_delegates.insert(user_script_listener_.get()); |
| 264 resource_queue_.Initialize(resource_queue_delegates); |
| 261 } | 265 } |
| 262 | 266 |
| 263 ResourceDispatcherHost::~ResourceDispatcherHost() { | 267 ResourceDispatcherHost::~ResourceDispatcherHost() { |
| 264 AsyncResourceHandler::GlobalCleanup(); | 268 AsyncResourceHandler::GlobalCleanup(); |
| 265 STLDeleteValues(&pending_requests_); | 269 STLDeleteValues(&pending_requests_); |
| 266 | 270 |
| 267 // Clear blocked requests if any left. | 271 // Clear blocked requests if any left. |
| 268 // Note that we have to do this in 2 passes as we cannot call | 272 // Note that we have to do this in 2 passes as we cannot call |
| 269 // CancelBlockedRequestsForRoute while iterating over | 273 // CancelBlockedRequestsForRoute while iterating over |
| 270 // blocked_requests_map_, as it modifies it. | 274 // blocked_requests_map_, as it modifies it. |
| 271 std::set<ProcessRouteIDs> ids; | 275 std::set<ProcessRouteIDs> ids; |
| 272 for (BlockedRequestMap::const_iterator iter = blocked_requests_map_.begin(); | 276 for (BlockedRequestMap::const_iterator iter = blocked_requests_map_.begin(); |
| 273 iter != blocked_requests_map_.end(); ++iter) { | 277 iter != blocked_requests_map_.end(); ++iter) { |
| 274 std::pair<std::set<ProcessRouteIDs>::iterator, bool> result = | 278 std::pair<std::set<ProcessRouteIDs>::iterator, bool> result = |
| 275 ids.insert(iter->first); | 279 ids.insert(iter->first); |
| 276 // We should not have duplicates. | 280 // We should not have duplicates. |
| 277 DCHECK(result.second); | 281 DCHECK(result.second); |
| 278 } | 282 } |
| 279 for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); | 283 for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); |
| 280 iter != ids.end(); ++iter) { | 284 iter != ids.end(); ++iter) { |
| 281 CancelBlockedRequestsForRoute(iter->first, iter->second); | 285 CancelBlockedRequestsForRoute(iter->first, iter->second); |
| 282 } | 286 } |
| 283 | |
| 284 user_script_listener_->OnResourceDispatcherHostGone(); | |
| 285 } | 287 } |
| 286 | 288 |
| 287 void ResourceDispatcherHost::Initialize() { | 289 void ResourceDispatcherHost::Initialize() { |
| 288 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 290 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 289 webkit_thread_->Initialize(); | 291 webkit_thread_->Initialize(); |
| 290 safe_browsing_->Initialize(); | 292 safe_browsing_->Initialize(); |
| 291 ChromeThread::PostTask( | 293 ChromeThread::PostTask( |
| 292 ChromeThread::IO, FROM_HERE, | 294 ChromeThread::IO, FROM_HERE, |
| 293 NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); | 295 NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); |
| 294 } | 296 } |
| 295 | 297 |
| 296 void ResourceDispatcherHost::Shutdown() { | 298 void ResourceDispatcherHost::Shutdown() { |
| 297 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 299 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 298 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, new ShutdownTask(this)); | 300 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, new ShutdownTask(this)); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void ResourceDispatcherHost::SetRequestInfo( | 303 void ResourceDispatcherHost::SetRequestInfo( |
| 302 URLRequest* request, | 304 URLRequest* request, |
| 303 ResourceDispatcherHostRequestInfo* info) { | 305 ResourceDispatcherHostRequestInfo* info) { |
| 304 request->SetUserData(NULL, info); | 306 request->SetUserData(NULL, info); |
| 305 } | 307 } |
| 306 | 308 |
| 307 void ResourceDispatcherHost::OnShutdown() { | 309 void ResourceDispatcherHost::OnShutdown() { |
| 308 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 310 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 309 is_shutdown_ = true; | 311 is_shutdown_ = true; |
| 312 resource_queue_.Shutdown(); |
| 310 STLDeleteValues(&pending_requests_); | 313 STLDeleteValues(&pending_requests_); |
| 311 // Make sure we shutdown the timer now, otherwise by the time our destructor | 314 // Make sure we shutdown the timer now, otherwise by the time our destructor |
| 312 // runs if the timer is still running the Task is deleted twice (once by | 315 // runs if the timer is still running the Task is deleted twice (once by |
| 313 // the MessageLoop and the second time by RepeatingTimer). | 316 // the MessageLoop and the second time by RepeatingTimer). |
| 314 update_load_states_timer_.Stop(); | 317 update_load_states_timer_.Stop(); |
| 315 } | 318 } |
| 316 | 319 |
| 317 bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, | 320 bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, |
| 318 int child_id, | 321 int child_id, |
| 319 int route_id, | 322 int route_id, |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 998 |
| 996 void ResourceDispatcherHost::RemovePendingRequest( | 999 void ResourceDispatcherHost::RemovePendingRequest( |
| 997 const PendingRequestList::iterator& iter) { | 1000 const PendingRequestList::iterator& iter) { |
| 998 ResourceDispatcherHostRequestInfo* info = InfoForRequest(iter->second); | 1001 ResourceDispatcherHostRequestInfo* info = InfoForRequest(iter->second); |
| 999 | 1002 |
| 1000 // Remove the memory credit that we added when pushing the request onto | 1003 // Remove the memory credit that we added when pushing the request onto |
| 1001 // the pending list. | 1004 // the pending list. |
| 1002 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), | 1005 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), |
| 1003 info->child_id()); | 1006 info->child_id()); |
| 1004 | 1007 |
| 1005 // Notify the login handler that this request object is going away. | 1008 // Notify interested parties that the request object is going away. |
| 1006 if (info && info->login_handler()) | 1009 if (info && info->login_handler()) |
| 1007 info->login_handler()->OnRequestCancelled(); | 1010 info->login_handler()->OnRequestCancelled(); |
| 1011 resource_queue_.RemoveRequest(iter->first); |
| 1008 | 1012 |
| 1009 delete iter->second; | 1013 delete iter->second; |
| 1010 pending_requests_.erase(iter); | 1014 pending_requests_.erase(iter); |
| 1011 | 1015 |
| 1012 // If we have no more pending requests, then stop the load state monitor | 1016 // If we have no more pending requests, then stop the load state monitor |
| 1013 if (pending_requests_.empty()) | 1017 if (pending_requests_.empty()) |
| 1014 update_load_states_timer_.Stop(); | 1018 update_load_states_timer_.Stop(); |
| 1015 } | 1019 } |
| 1016 | 1020 |
| 1017 // URLRequest::Delegate ------------------------------------------------------- | 1021 // URLRequest::Delegate ------------------------------------------------------- |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 std::pair<int, int> pair_id(info->child_id(), info->route_id()); | 1304 std::pair<int, int> pair_id(info->child_id(), info->route_id()); |
| 1301 BlockedRequestMap::const_iterator iter = blocked_requests_map_.find(pair_id); | 1305 BlockedRequestMap::const_iterator iter = blocked_requests_map_.find(pair_id); |
| 1302 if (iter != blocked_requests_map_.end()) { | 1306 if (iter != blocked_requests_map_.end()) { |
| 1303 // The request should be blocked. | 1307 // The request should be blocked. |
| 1304 iter->second->push_back(request); | 1308 iter->second->push_back(request); |
| 1305 return; | 1309 return; |
| 1306 } | 1310 } |
| 1307 | 1311 |
| 1308 GlobalRequestID global_id(info->child_id(), info->request_id()); | 1312 GlobalRequestID global_id(info->child_id(), info->request_id()); |
| 1309 pending_requests_[global_id] = request; | 1313 pending_requests_[global_id] = request; |
| 1310 if (!user_script_listener_->ShouldStartRequest(request)) { | 1314 resource_queue_.AddRequest(request, *info); |
| 1311 // This request depends on some user scripts that haven't loaded yet. The | |
| 1312 // UserScriptListener will resume the request when they're ready. | |
| 1313 return; | |
| 1314 } | |
| 1315 request->Start(); | |
| 1316 | 1315 |
| 1317 // Make sure we have the load state monitor running | 1316 // Make sure we have the load state monitor running |
| 1318 if (!update_load_states_timer_.IsRunning()) { | 1317 if (!update_load_states_timer_.IsRunning()) { |
| 1319 update_load_states_timer_.Start( | 1318 update_load_states_timer_.Start( |
| 1320 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), | 1319 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), |
| 1321 this, &ResourceDispatcherHost::UpdateLoadStates); | 1320 this, &ResourceDispatcherHost::UpdateLoadStates); |
| 1322 } | 1321 } |
| 1323 } | 1322 } |
| 1324 | 1323 |
| 1325 bool ResourceDispatcherHost::PauseRequestIfNeeded( | 1324 bool ResourceDispatcherHost::PauseRequestIfNeeded( |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 | 1527 |
| 1529 void ResourceDispatcherHost::AddObserver(Observer* obs) { | 1528 void ResourceDispatcherHost::AddObserver(Observer* obs) { |
| 1530 observer_list_.AddObserver(obs); | 1529 observer_list_.AddObserver(obs); |
| 1531 } | 1530 } |
| 1532 | 1531 |
| 1533 void ResourceDispatcherHost::RemoveObserver(Observer* obs) { | 1532 void ResourceDispatcherHost::RemoveObserver(Observer* obs) { |
| 1534 observer_list_.RemoveObserver(obs); | 1533 observer_list_.RemoveObserver(obs); |
| 1535 } | 1534 } |
| 1536 | 1535 |
| 1537 URLRequest* ResourceDispatcherHost::GetURLRequest( | 1536 URLRequest* ResourceDispatcherHost::GetURLRequest( |
| 1538 GlobalRequestID request_id) const { | 1537 const GlobalRequestID& request_id) const { |
| 1539 // This should be running in the IO loop. | 1538 // This should be running in the IO loop. |
| 1540 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 1539 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 1541 | 1540 |
| 1542 PendingRequestList::const_iterator i = pending_requests_.find(request_id); | 1541 PendingRequestList::const_iterator i = pending_requests_.find(request_id); |
| 1543 if (i == pending_requests_.end()) | 1542 if (i == pending_requests_.end()) |
| 1544 return NULL; | 1543 return NULL; |
| 1545 | 1544 |
| 1546 return i->second; | 1545 return i->second; |
| 1547 } | 1546 } |
| 1548 | 1547 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 case ViewHostMsg_UploadProgress_ACK::ID: | 1820 case ViewHostMsg_UploadProgress_ACK::ID: |
| 1822 case ViewHostMsg_SyncLoad::ID: | 1821 case ViewHostMsg_SyncLoad::ID: |
| 1823 return true; | 1822 return true; |
| 1824 | 1823 |
| 1825 default: | 1824 default: |
| 1826 break; | 1825 break; |
| 1827 } | 1826 } |
| 1828 | 1827 |
| 1829 return false; | 1828 return false; |
| 1830 } | 1829 } |
| OLD | NEW |