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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 250 |
251 } // namespace | 251 } // namespace |
252 | 252 |
253 ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop) | 253 ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop) |
254 : ui_loop_(MessageLoop::current()), | 254 : ui_loop_(MessageLoop::current()), |
255 io_loop_(io_loop), | 255 io_loop_(io_loop), |
256 ALLOW_THIS_IN_INITIALIZER_LIST( | 256 ALLOW_THIS_IN_INITIALIZER_LIST( |
257 download_file_manager_(new DownloadFileManager(this))), | 257 download_file_manager_(new DownloadFileManager(this))), |
258 download_request_manager_(new DownloadRequestManager(io_loop, ui_loop_)), | 258 download_request_manager_(new DownloadRequestManager(io_loop, ui_loop_)), |
259 ALLOW_THIS_IN_INITIALIZER_LIST( | 259 ALLOW_THIS_IN_INITIALIZER_LIST( |
260 save_file_manager_(new SaveFileManager(ui_loop_, io_loop, this))), | 260 save_file_manager_(new SaveFileManager(this))), |
261 ALLOW_THIS_IN_INITIALIZER_LIST(user_script_listener_( | 261 ALLOW_THIS_IN_INITIALIZER_LIST(user_script_listener_( |
262 new UserScriptListener(this))), | 262 new UserScriptListener(this))), |
263 safe_browsing_(new SafeBrowsingService), | 263 safe_browsing_(new SafeBrowsingService), |
264 webkit_thread_(new WebKitThread), | 264 webkit_thread_(new WebKitThread), |
265 request_id_(-1), | 265 request_id_(-1), |
266 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)), | 266 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)), |
267 is_shutdown_(false), | 267 is_shutdown_(false), |
268 max_outstanding_requests_cost_per_process_( | 268 max_outstanding_requests_cost_per_process_( |
269 kMaxOutstandingRequestsCostPerProcess), | 269 kMaxOutstandingRequestsCostPerProcess), |
270 receiver_(NULL) { | 270 receiver_(NULL) { |
(...skipping 17 matching lines...) Expand all Loading... |
288 } | 288 } |
289 for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); | 289 for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); |
290 iter != ids.end(); ++iter) { | 290 iter != ids.end(); ++iter) { |
291 CancelBlockedRequestsForRoute(iter->first, iter->second); | 291 CancelBlockedRequestsForRoute(iter->first, iter->second); |
292 } | 292 } |
293 | 293 |
294 user_script_listener_->OnResourceDispatcherHostGone(); | 294 user_script_listener_->OnResourceDispatcherHostGone(); |
295 } | 295 } |
296 | 296 |
297 void ResourceDispatcherHost::Initialize() { | 297 void ResourceDispatcherHost::Initialize() { |
298 DCHECK(MessageLoop::current() == ui_loop_); | 298 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
299 safe_browsing_->Initialize(io_loop_); | 299 safe_browsing_->Initialize(); |
300 io_loop_->PostTask( | 300 ChromeThread::PostTask( |
301 FROM_HERE, | 301 ChromeThread::IO, FROM_HERE, |
302 NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); | 302 NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); |
303 } | 303 } |
304 | 304 |
305 void ResourceDispatcherHost::Shutdown() { | 305 void ResourceDispatcherHost::Shutdown() { |
306 DCHECK(MessageLoop::current() == ui_loop_); | 306 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
307 io_loop_->PostTask(FROM_HERE, new ShutdownTask(this)); | 307 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, new ShutdownTask(this)); |
308 } | 308 } |
309 | 309 |
310 void ResourceDispatcherHost::SetRequestInfo( | 310 void ResourceDispatcherHost::SetRequestInfo( |
311 URLRequest* request, | 311 URLRequest* request, |
312 ResourceDispatcherHostRequestInfo* info) { | 312 ResourceDispatcherHostRequestInfo* info) { |
313 request->SetUserData(NULL, info); | 313 request->SetUserData(NULL, info); |
314 } | 314 } |
315 | 315 |
316 void ResourceDispatcherHost::OnShutdown() { | 316 void ResourceDispatcherHost::OnShutdown() { |
317 DCHECK(MessageLoop::current() == io_loop_); | 317 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
318 is_shutdown_ = true; | 318 is_shutdown_ = true; |
319 STLDeleteValues(&pending_requests_); | 319 STLDeleteValues(&pending_requests_); |
320 // Make sure we shutdown the timer now, otherwise by the time our destructor | 320 // Make sure we shutdown the timer now, otherwise by the time our destructor |
321 // runs if the timer is still running the Task is deleted twice (once by | 321 // runs if the timer is still running the Task is deleted twice (once by |
322 // the MessageLoop and the second time by RepeatingTimer). | 322 // the MessageLoop and the second time by RepeatingTimer). |
323 update_load_states_timer_.Stop(); | 323 update_load_states_timer_.Stop(); |
324 } | 324 } |
325 | 325 |
326 bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, | 326 bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, |
327 int child_id, | 327 int child_id, |
328 int route_id, | 328 int route_id, |
329 const GURL& url, | 329 const GURL& url, |
330 ResourceType::Type type, | 330 ResourceType::Type type, |
331 ResourceHandler* handler) { | 331 ResourceHandler* handler) { |
332 if (!ResourceType::IsFrame(type) || URLRequest::IsHandledURL(url)) | 332 if (!ResourceType::IsFrame(type) || URLRequest::IsHandledURL(url)) |
333 return false; | 333 return false; |
334 | 334 |
335 ui_loop_->PostTask(FROM_HERE, NewRunnableFunction( | 335 ChromeThread::PostTask( |
336 &ExternalProtocolHandler::LaunchUrl, url, child_id, route_id)); | 336 ChromeThread::UI, FROM_HERE, |
| 337 NewRunnableFunction( |
| 338 &ExternalProtocolHandler::LaunchUrl, url, child_id, route_id)); |
337 | 339 |
338 handler->OnResponseCompleted(request_id, URLRequestStatus( | 340 handler->OnResponseCompleted(request_id, URLRequestStatus( |
339 URLRequestStatus::FAILED, | 341 URLRequestStatus::FAILED, |
340 net::ERR_ABORTED), | 342 net::ERR_ABORTED), |
341 std::string()); // No security info necessary. | 343 std::string()); // No security info necessary. |
342 return true; | 344 return true; |
343 } | 345 } |
344 | 346 |
345 bool ResourceDispatcherHost::OnMessageReceived(const IPC::Message& message, | 347 bool ResourceDispatcherHost::OnMessageReceived(const IPC::Message& message, |
346 Receiver* receiver, | 348 Receiver* receiver, |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 if (i != pending_requests_.end()) { | 672 if (i != pending_requests_.end()) { |
671 // The response we were meant to resume could have already been canceled. | 673 // The response we were meant to resume could have already been canceled. |
672 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 674 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); |
673 if (info->cross_site_handler()) | 675 if (info->cross_site_handler()) |
674 info->cross_site_handler()->ResumeResponse(); | 676 info->cross_site_handler()->ResumeResponse(); |
675 } | 677 } |
676 } else { | 678 } else { |
677 // This is a tab close, so just forward the message to close it. | 679 // This is a tab close, so just forward the message to close it. |
678 DCHECK(params.new_render_process_host_id == -1); | 680 DCHECK(params.new_render_process_host_id == -1); |
679 DCHECK(params.new_request_id == -1); | 681 DCHECK(params.new_request_id == -1); |
680 ui_loop_->PostTask( | 682 ChromeThread::PostTask( |
681 FROM_HERE, | 683 ChromeThread::UI, FROM_HERE, |
682 new RVHCloseNotificationTask(params.closing_process_id, | 684 new RVHCloseNotificationTask(params.closing_process_id, |
683 params.closing_route_id)); | 685 params.closing_route_id)); |
684 } | 686 } |
685 } | 687 } |
686 | 688 |
687 // We are explicitly forcing the download of 'url'. | 689 // We are explicitly forcing the download of 'url'. |
688 void ResourceDispatcherHost::BeginDownload(const GURL& url, | 690 void ResourceDispatcherHost::BeginDownload(const GURL& url, |
689 const GURL& referrer, | 691 const GURL& referrer, |
690 int child_id, | 692 int child_id, |
691 int route_id, | 693 int route_id, |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 void ResourceDispatcherHost::AddObserver(Observer* obs) { | 1512 void ResourceDispatcherHost::AddObserver(Observer* obs) { |
1511 observer_list_.AddObserver(obs); | 1513 observer_list_.AddObserver(obs); |
1512 } | 1514 } |
1513 | 1515 |
1514 void ResourceDispatcherHost::RemoveObserver(Observer* obs) { | 1516 void ResourceDispatcherHost::RemoveObserver(Observer* obs) { |
1515 observer_list_.RemoveObserver(obs); | 1517 observer_list_.RemoveObserver(obs); |
1516 } | 1518 } |
1517 | 1519 |
1518 URLRequest* ResourceDispatcherHost::GetURLRequest( | 1520 URLRequest* ResourceDispatcherHost::GetURLRequest( |
1519 GlobalRequestID request_id) const { | 1521 GlobalRequestID request_id) const { |
1520 // This should be running in the IO loop. io_loop_ can be NULL during the | 1522 // This should be running in the IO loop. |
1521 // unit_tests. | 1523 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
1522 DCHECK(MessageLoop::current() == io_loop_ && io_loop_); | |
1523 | 1524 |
1524 PendingRequestList::const_iterator i = pending_requests_.find(request_id); | 1525 PendingRequestList::const_iterator i = pending_requests_.find(request_id); |
1525 if (i == pending_requests_.end()) | 1526 if (i == pending_requests_.end()) |
1526 return NULL; | 1527 return NULL; |
1527 | 1528 |
1528 return i->second; | 1529 return i->second; |
1529 } | 1530 } |
1530 | 1531 |
1531 static int GetCertID(URLRequest* request, int child_id) { | 1532 static int GetCertID(URLRequest* request, int child_id) { |
1532 if (request->ssl_info().cert) { | 1533 if (request->ssl_info().cert) { |
(...skipping 11 matching lines...) Expand all Loading... |
1544 (request->response_headers()->response_code() <= 599))); | 1545 (request->response_headers()->response_code() <= 599))); |
1545 return 0; | 1546 return 0; |
1546 } | 1547 } |
1547 | 1548 |
1548 void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request, | 1549 void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request, |
1549 int child_id) { | 1550 int child_id) { |
1550 // Notify the observers on the IO thread. | 1551 // Notify the observers on the IO thread. |
1551 FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request)); | 1552 FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request)); |
1552 | 1553 |
1553 // Notify the observers on the UI thread. | 1554 // Notify the observers on the UI thread. |
1554 ui_loop_->PostTask(FROM_HERE, new RVHDelegateNotificationTask(request, | 1555 ChromeThread::PostTask( |
1555 &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, | 1556 ChromeThread::UI, FROM_HERE, |
1556 new ResourceRequestDetails(request, GetCertID(request, child_id)))); | 1557 new RVHDelegateNotificationTask( |
| 1558 request, |
| 1559 &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, |
| 1560 new ResourceRequestDetails(request, GetCertID(request, child_id)))); |
1557 } | 1561 } |
1558 | 1562 |
1559 void ResourceDispatcherHost::NotifyResponseCompleted(URLRequest* request, | 1563 void ResourceDispatcherHost::NotifyResponseCompleted(URLRequest* request, |
1560 int child_id) { | 1564 int child_id) { |
1561 // Notify the observers on the IO thread. | 1565 // Notify the observers on the IO thread. |
1562 FOR_EACH_OBSERVER(Observer, observer_list_, | 1566 FOR_EACH_OBSERVER(Observer, observer_list_, |
1563 OnResponseCompleted(this, request)); | 1567 OnResponseCompleted(this, request)); |
1564 } | 1568 } |
1565 | 1569 |
1566 void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request, | 1570 void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request, |
1567 int child_id, | 1571 int child_id, |
1568 const GURL& new_url) { | 1572 const GURL& new_url) { |
1569 // Notify the observers on the IO thread. | 1573 // Notify the observers on the IO thread. |
1570 FOR_EACH_OBSERVER(Observer, observer_list_, | 1574 FOR_EACH_OBSERVER(Observer, observer_list_, |
1571 OnReceivedRedirect(this, request, new_url)); | 1575 OnReceivedRedirect(this, request, new_url)); |
1572 | 1576 |
1573 int cert_id = GetCertID(request, child_id); | 1577 int cert_id = GetCertID(request, child_id); |
1574 | 1578 |
1575 // Notify the observers on the UI thread. | 1579 // Notify the observers on the UI thread. |
1576 ui_loop_->PostTask(FROM_HERE, | 1580 ChromeThread::PostTask( |
1577 new RVHDelegateNotificationTask(request, | 1581 ChromeThread::UI, FROM_HERE, |
1578 &RenderViewHostDelegate::Resource::DidRedirectResource, | 1582 new RVHDelegateNotificationTask( |
| 1583 request, &RenderViewHostDelegate::Resource::DidRedirectResource, |
1579 new ResourceRedirectDetails(request, cert_id, new_url))); | 1584 new ResourceRedirectDetails(request, cert_id, new_url))); |
1580 } | 1585 } |
1581 | 1586 |
1582 namespace { | 1587 namespace { |
1583 | 1588 |
1584 // This function attempts to return the "more interesting" load state of |a| | 1589 // This function attempts to return the "more interesting" load state of |a| |
1585 // and |b|. We don't have temporal information about these load states | 1590 // and |b|. We don't have temporal information about these load states |
1586 // (meaning we don't know when we transitioned into these states), so we just | 1591 // (meaning we don't know when we transitioned into these states), so we just |
1587 // rank them according to how "interesting" the states are. | 1592 // rank them according to how "interesting" the states are. |
1588 // | 1593 // |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 load_info.upload_size = info->upload_size(); | 1694 load_info.upload_size = info->upload_size(); |
1690 load_info.upload_position = request->GetUploadProgress(); | 1695 load_info.upload_position = request->GetUploadProgress(); |
1691 } | 1696 } |
1692 } | 1697 } |
1693 | 1698 |
1694 if (info_map.empty()) | 1699 if (info_map.empty()) |
1695 return; | 1700 return; |
1696 | 1701 |
1697 LoadInfoUpdateTask* task = new LoadInfoUpdateTask; | 1702 LoadInfoUpdateTask* task = new LoadInfoUpdateTask; |
1698 task->info_map.swap(info_map); | 1703 task->info_map.swap(info_map); |
1699 ui_loop_->PostTask(FROM_HERE, task); | 1704 ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, task); |
1700 } | 1705 } |
1701 | 1706 |
1702 // Calls the ResourceHandler to send upload progress messages to the renderer. | 1707 // Calls the ResourceHandler to send upload progress messages to the renderer. |
1703 // Returns true iff an upload progress message should be sent to the UI thread. | 1708 // Returns true iff an upload progress message should be sent to the UI thread. |
1704 bool ResourceDispatcherHost::MaybeUpdateUploadProgress( | 1709 bool ResourceDispatcherHost::MaybeUpdateUploadProgress( |
1705 ResourceDispatcherHostRequestInfo *info, | 1710 ResourceDispatcherHostRequestInfo *info, |
1706 URLRequest *request) { | 1711 URLRequest *request) { |
1707 | 1712 |
1708 if (!info->upload_size() || info->waiting_for_upload_progress_ack()) | 1713 if (!info->upload_size() || info->waiting_for_upload_progress_ack()) |
1709 return false; | 1714 return false; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 case ViewHostMsg_UploadProgress_ACK::ID: | 1804 case ViewHostMsg_UploadProgress_ACK::ID: |
1800 case ViewHostMsg_SyncLoad::ID: | 1805 case ViewHostMsg_SyncLoad::ID: |
1801 return true; | 1806 return true; |
1802 | 1807 |
1803 default: | 1808 default: |
1804 break; | 1809 break; |
1805 } | 1810 } |
1806 | 1811 |
1807 return false; | 1812 return false; |
1808 } | 1813 } |
OLD | NEW |