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_resource_handler.h" | 5 #include "chrome/browser/renderer_host/download_resource_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 14 #include "chrome/browser/download/download_item.h" | 14 #include "chrome/browser/download/download_item.h" |
| 15 #include "chrome/browser/download/download_file_manager.h" | 15 #include "chrome/browser/download/download_file_manager.h" |
| 16 #include "chrome/browser/history/download_create_info.h" | 16 #include "chrome/browser/history/download_create_info.h" |
| 17 #include "chrome/browser/renderer_host/global_request_id.h" | 17 #include "chrome/browser/renderer_host/global_request_id.h" |
| 18 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 19 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 19 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" | 20 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 21 #include "chrome/common/notification_service.h" | |
| 20 #include "chrome/common/resource_response.h" | 22 #include "chrome/common/resource_response.h" |
| 21 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| 22 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
| 23 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 24 | 26 |
| 27 namespace { | |
| 28 void NotifyOnUI(NotificationType::Type notification_type, | |
| 29 int process_id, int view_id) { | |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 31 RenderViewHost* rvh = RenderViewHost::FromID(process_id, view_id); | |
| 32 if (!rvh) | |
| 33 return; | |
| 34 | |
| 35 NotificationService::current()->Notify(notification_type, | |
| 36 Source<RenderViewHost>(rvh), | |
| 37 NotificationService::NoDetails()); | |
| 38 } | |
| 39 } // namespace | |
| 40 | |
| 25 DownloadResourceHandler::DownloadResourceHandler( | 41 DownloadResourceHandler::DownloadResourceHandler( |
| 26 ResourceDispatcherHost* rdh, | 42 ResourceDispatcherHost* rdh, |
| 27 int render_process_host_id, | 43 int render_process_host_id, |
| 28 int render_view_id, | 44 int render_view_id, |
| 29 int request_id, | 45 int request_id, |
| 30 const GURL& url, | 46 const GURL& url, |
| 31 DownloadFileManager* download_file_manager, | 47 DownloadFileManager* download_file_manager, |
| 32 net::URLRequest* request, | 48 net::URLRequest* request, |
| 33 bool save_as, | 49 bool save_as, |
| 34 const DownloadSaveInfo& save_info) | 50 const DownloadSaveInfo& save_info) |
| 35 : download_id_(-1), | 51 : download_id_(-1), |
| 36 global_id_(render_process_host_id, request_id), | 52 global_id_(render_process_host_id, request_id), |
| 37 render_view_id_(render_view_id), | 53 render_view_id_(render_view_id), |
| 38 url_(url), | 54 url_(url), |
| 39 original_url_(url), | 55 original_url_(url), |
| 40 content_length_(0), | 56 content_length_(0), |
| 41 download_file_manager_(download_file_manager), | 57 download_file_manager_(download_file_manager), |
| 42 request_(request), | 58 request_(request), |
| 43 save_as_(save_as), | 59 save_as_(save_as), |
| 44 save_info_(save_info), | 60 save_info_(save_info), |
| 45 buffer_(new DownloadBuffer), | 61 buffer_(new DownloadBuffer), |
| 46 rdh_(rdh), | 62 rdh_(rdh), |
| 47 is_paused_(false), | 63 is_paused_(false), |
| 48 url_check_pending_(false) { | 64 url_check_pending_(false) { |
| 65 BrowserThread::PostTask( | |
| 66 BrowserThread::UI, FROM_HERE, | |
| 67 NewRunnableFunction(&NotifyOnUI, NotificationType::DOWNLOAD_INITIATED, | |
| 68 render_process_host_id, render_view_id_)); | |
|
Randy Smith (Not in Mondays)
2011/02/13 03:08:36
I'd rather not notify from the DownloadResourceHan
dominich
2011/02/14 16:07:12
I was considering download_util::DownloadUrl as an
Randy Smith (Not in Mondays)
2011/02/14 19:20:51
Neither one's particularly future-proof, I'm afrai
| |
| 49 } | 69 } |
| 50 | 70 |
| 51 bool DownloadResourceHandler::OnUploadProgress(int request_id, | 71 bool DownloadResourceHandler::OnUploadProgress(int request_id, |
| 52 uint64 position, | 72 uint64 position, |
| 53 uint64 size) { | 73 uint64 size) { |
| 54 return true; | 74 return true; |
| 55 } | 75 } |
| 56 | 76 |
| 57 // Not needed, as this event handler ought to be the final resource. | 77 // Not needed, as this event handler ought to be the final resource. |
| 58 bool DownloadResourceHandler::OnRequestRedirected(int request_id, | 78 bool DownloadResourceHandler::OnRequestRedirected(int request_id, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 render_view_id_, | 329 render_view_id_, |
| 310 save_info_.file_path.value().c_str()); | 330 save_info_.file_path.value().c_str()); |
| 311 } | 331 } |
| 312 | 332 |
| 313 void DownloadResourceHandler::UpdateDownloadUrlCheckStats( | 333 void DownloadResourceHandler::UpdateDownloadUrlCheckStats( |
| 314 SBStatsType stat_type) { | 334 SBStatsType stat_type) { |
| 315 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadUrlChecks", | 335 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadUrlChecks", |
| 316 stat_type, | 336 stat_type, |
| 317 DOWNLOAD_URL_CHECKS_MAX); | 337 DOWNLOAD_URL_CHECKS_MAX); |
| 318 } | 338 } |
| OLD | NEW |