Chromium Code Reviews| Index: chrome/browser/renderer_host/download_throttling_resource_handler.cc |
| =================================================================== |
| --- chrome/browser/renderer_host/download_throttling_resource_handler.cc (revision 74377) |
| +++ chrome/browser/renderer_host/download_throttling_resource_handler.cc (working copy) |
| @@ -6,11 +6,27 @@ |
| #include "base/logging.h" |
| #include "chrome/browser/renderer_host/download_resource_handler.h" |
| +#include "chrome/browser/renderer_host/render_view_host.h" |
| #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| +#include "chrome/common/notification_service.h" |
| #include "chrome/common/resource_response.h" |
| #include "net/base/io_buffer.h" |
| #include "net/base/mime_sniffer.h" |
| +namespace { |
| +void NotifyOnUI(NotificationType::Type notification_type, |
| + int process_id, int view_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + RenderViewHost* rvh = RenderViewHost::FromID(process_id, view_id); |
| + if (!rvh) |
| + return; |
| + |
| + NotificationService::current()->Notify(notification_type, |
| + Source<RenderViewHost>(rvh), |
| + NotificationService::NoDetails()); |
| +} |
| +} // namespace |
| + |
| DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( |
| ResourceDispatcherHost* host, |
| net::URLRequest* request, |
| @@ -31,7 +47,7 @@ |
| host_->PauseRequest(render_process_host_id_, request_id_, true); |
| host_->download_request_limiter()->CanDownloadOnIOThread( |
| render_process_host_id_, render_view_id, this); |
| - } |
| +} |
| DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() { |
| } |
| @@ -49,6 +65,10 @@ |
| const GURL& url, |
| ResourceResponse* response, |
| bool* defer) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + NewRunnableFunction(&NotifyOnUI, NotificationType::DOWNLOAD_INITIATED, |
| + render_process_host_id_, render_view_id_)); |
| if (download_handler_.get()) { |
| return download_handler_->OnRequestRedirected( |
| request_id, url, response, defer); |
| @@ -60,6 +80,11 @@ |
| bool DownloadThrottlingResourceHandler::OnResponseStarted( |
| int request_id, |
| ResourceResponse* response) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + NewRunnableFunction(&NotifyOnUI, NotificationType::DOWNLOAD_INITIATED, |
| + render_process_host_id_, render_view_id_)); |
|
Randy Smith (Not in Mondays)
2011/02/11 18:44:15
Why do separate notifications for request redirect
dominich
2011/02/11 22:51:54
Done.
|
| + |
| if (download_handler_.get()) |
| return download_handler_->OnResponseStarted(request_id, response); |
| response_ = response; |
| @@ -78,6 +103,10 @@ |
| net::IOBuffer** buf, |
| int* buf_size, |
| int min_size) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + NewRunnableFunction(&NotifyOnUI, NotificationType::DOWNLOAD_INITIATED, |
|
dominich
2011/02/10 20:02:17
Moving this to OnWillStart for the same reasons as
|
| + render_process_host_id_, render_view_id_)); |
| if (download_handler_.get()) |
| return download_handler_->OnWillRead(request_id, buf, buf_size, min_size); |
| @@ -112,6 +141,10 @@ |
| CopyTmpBufferToDownloadHandler(); |
| return true; |
| } |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
|
cbentzel
2011/02/10 19:32:18
I really don't think this is what you want - it wi
dominich
2011/02/10 20:02:17
You're right - I was going from rdsmith's diagram
dominich
2011/02/10 20:02:17
Done.
Randy Smith (Not in Mondays)
2011/02/11 18:44:15
Sorry; that diagram shows control flow within the
|
| + NewRunnableFunction(&NotifyOnUI, NotificationType::DOWNLOAD_INITIATED, |
| + render_process_host_id_, render_view_id_)); |
| if (download_handler_.get()) |
| return download_handler_->OnReadCompleted(request_id, bytes_read); |
| return true; |
| @@ -121,6 +154,10 @@ |
| int request_id, |
| const net::URLRequestStatus& status, |
| const std::string& security_info) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + NewRunnableFunction(&NotifyOnUI, NotificationType::DOWNLOAD_INITIATED, |
|
dominich
2011/02/10 20:02:17
This suffers from the same issue as above. Even th
|
| + render_process_host_id_, render_view_id_)); |
| if (download_handler_.get()) |
| return download_handler_->OnResponseCompleted(request_id, status, |
| security_info); |