Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" | 5 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/renderer_host/download_resource_handler.h" | 8 #include "chrome/browser/renderer_host/download_resource_handler.h" |
| 9 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 9 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 11 #include "chrome/common/notification_service.h" | |
| 10 #include "chrome/common/resource_response.h" | 12 #include "chrome/common/resource_response.h" |
| 11 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 12 #include "net/base/mime_sniffer.h" | 14 #include "net/base/mime_sniffer.h" |
| 13 | 15 |
| 16 namespace { | |
| 17 void NotifyOnUI(NotificationType::Type notification_type, | |
| 18 int process_id, int view_id) { | |
| 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 20 RenderViewHost* rvh = RenderViewHost::FromID(process_id, view_id); | |
| 21 if (!rvh) | |
| 22 return; | |
| 23 | |
| 24 NotificationService::current()->Notify(notification_type, | |
| 25 Source<RenderViewHost>(rvh), | |
| 26 NotificationService::NoDetails()); | |
| 27 } | |
| 28 } // namespace | |
|
Randy Smith (Not in Mondays)
2011/02/13 03:08:36
Is dislike duplicating this code; is there anywher
dominich
2011/02/14 16:07:12
I do want to keep it generic as I can see this bei
| |
| 29 | |
| 14 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( | 30 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( |
| 15 ResourceDispatcherHost* host, | 31 ResourceDispatcherHost* host, |
| 16 net::URLRequest* request, | 32 net::URLRequest* request, |
| 17 const GURL& url, | 33 const GURL& url, |
| 18 int render_process_host_id, | 34 int render_process_host_id, |
| 19 int render_view_id, | 35 int render_view_id, |
| 20 int request_id, | 36 int request_id, |
| 21 bool in_complete) | 37 bool in_complete) |
| 22 : host_(host), | 38 : host_(host), |
| 23 request_(request), | 39 request_(request), |
| 24 url_(url), | 40 url_(url), |
| 25 render_process_host_id_(render_process_host_id), | 41 render_process_host_id_(render_process_host_id), |
| 26 render_view_id_(render_view_id), | 42 render_view_id_(render_view_id), |
| 27 request_id_(request_id), | 43 request_id_(request_id), |
| 28 tmp_buffer_length_(0), | 44 tmp_buffer_length_(0), |
| 29 ignore_on_read_complete_(in_complete) { | 45 ignore_on_read_complete_(in_complete) { |
| 30 // Pause the request. | 46 // Pause the request. |
| 31 host_->PauseRequest(render_process_host_id_, request_id_, true); | 47 host_->PauseRequest(render_process_host_id_, request_id_, true); |
| 32 host_->download_request_limiter()->CanDownloadOnIOThread( | 48 host_->download_request_limiter()->CanDownloadOnIOThread( |
| 33 render_process_host_id_, render_view_id, this); | 49 render_process_host_id_, render_view_id, this); |
| 34 } | 50 BrowserThread::PostTask( |
| 51 BrowserThread::UI, FROM_HERE, | |
| 52 NewRunnableFunction(&NotifyOnUI, NotificationType::DOWNLOAD_INITIATED, | |
| 53 render_process_host_id_, render_view_id_)); | |
| 54 } | |
| 35 | 55 |
| 36 DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() { | 56 DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() { |
| 37 } | 57 } |
| 38 | 58 |
| 39 bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id, | 59 bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id, |
| 40 uint64 position, | 60 uint64 position, |
| 41 uint64 size) { | 61 uint64 size) { |
| 42 if (download_handler_.get()) | 62 if (download_handler_.get()) |
| 43 return download_handler_->OnUploadProgress(request_id, position, size); | 63 return download_handler_->OnUploadProgress(request_id, position, size); |
| 44 return true; | 64 return true; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 int buf_size; | 196 int buf_size; |
| 177 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, | 197 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, |
| 178 tmp_buffer_length_)) { | 198 tmp_buffer_length_)) { |
| 179 CHECK(buf_size >= tmp_buffer_length_); | 199 CHECK(buf_size >= tmp_buffer_length_); |
| 180 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); | 200 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); |
| 181 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); | 201 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); |
| 182 } | 202 } |
| 183 tmp_buffer_length_ = 0; | 203 tmp_buffer_length_ = 0; |
| 184 tmp_buffer_ = NULL; | 204 tmp_buffer_ = NULL; |
| 185 } | 205 } |
| OLD | NEW |