| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 resource_dispatcher_host->BeginDownload( | 69 resource_dispatcher_host->BeginDownload( |
| 70 request, save_info, true, | 70 request, save_info, true, |
| 71 DownloadResourceHandler::OnStartedCallback(), | 71 DownloadResourceHandler::OnStartedCallback(), |
| 72 render_params.render_process_id_, | 72 render_params.render_process_id_, |
| 73 render_params.render_view_id_, | 73 render_params.render_view_id_, |
| 74 *context); | 74 *context); |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 namespace content { |
| 80 |
| 81 // static |
| 82 DownloadManager* DownloadManager::Create( |
| 83 content::DownloadManagerDelegate* delegate, |
| 84 DownloadIdFactory* id_factory, |
| 85 DownloadStatusUpdater* status_updater) { |
| 86 return new DownloadManagerImpl(delegate, id_factory, status_updater); |
| 87 } |
| 88 |
| 89 } // namespace content |
| 90 |
| 79 DownloadManagerImpl::DownloadManagerImpl( | 91 DownloadManagerImpl::DownloadManagerImpl( |
| 80 content::DownloadManagerDelegate* delegate, | 92 content::DownloadManagerDelegate* delegate, |
| 81 DownloadIdFactory* id_factory, | 93 DownloadIdFactory* id_factory, |
| 82 DownloadStatusUpdater* status_updater) | 94 DownloadStatusUpdater* status_updater) |
| 83 : shutdown_needed_(false), | 95 : shutdown_needed_(false), |
| 84 browser_context_(NULL), | 96 browser_context_(NULL), |
| 85 file_manager_(NULL), | 97 file_manager_(NULL), |
| 86 status_updater_((status_updater != NULL) | 98 status_updater_((status_updater != NULL) |
| 87 ? status_updater->AsWeakPtr() | 99 ? status_updater->AsWeakPtr() |
| 88 : base::WeakPtr<DownloadStatusUpdater>()), | 100 : base::WeakPtr<DownloadStatusUpdater>()), |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 239 } |
| 228 | 240 |
| 229 // Query the history service for information about all persisted downloads. | 241 // Query the history service for information about all persisted downloads. |
| 230 bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) { | 242 bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) { |
| 231 DCHECK(browser_context); | 243 DCHECK(browser_context); |
| 232 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; | 244 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; |
| 233 shutdown_needed_ = true; | 245 shutdown_needed_ = true; |
| 234 | 246 |
| 235 browser_context_ = browser_context; | 247 browser_context_ = browser_context; |
| 236 | 248 |
| 237 // In test mode, there may be no ResourceDispatcherHost. In this case it's | 249 file_manager_ = ResourceDispatcherHost::Get()->download_file_manager(); |
| 238 // safe to avoid setting |file_manager_| because we only call a small set of | 250 DCHECK(file_manager_); |
| 239 // functions, none of which need it. | |
| 240 ResourceDispatcherHost* rdh = | |
| 241 content::GetContentClient()->browser()->GetResourceDispatcherHost(); | |
| 242 if (rdh) { | |
| 243 file_manager_ = rdh->download_file_manager(); | |
| 244 DCHECK(file_manager_); | |
| 245 } | |
| 246 | 251 |
| 247 return true; | 252 return true; |
| 248 } | 253 } |
| 249 | 254 |
| 250 // We have received a message from DownloadFileManager about a new download. | 255 // We have received a message from DownloadFileManager about a new download. |
| 251 void DownloadManagerImpl::StartDownload(int32 download_id) { | 256 void DownloadManagerImpl::StartDownload(int32 download_id) { |
| 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 253 | 258 |
| 254 if (delegate_->ShouldStartDownload(download_id)) | 259 if (delegate_->ShouldStartDownload(download_id)) |
| 255 RestartDownload(download_id); | 260 RestartDownload(download_id); |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(), | 769 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(), |
| 765 web_contents); | 770 web_contents); |
| 766 } | 771 } |
| 767 | 772 |
| 768 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url, | 773 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url, |
| 769 const GURL& referrer, | 774 const GURL& referrer, |
| 770 const std::string& referrer_charset, | 775 const std::string& referrer_charset, |
| 771 const DownloadSaveInfo& save_info, | 776 const DownloadSaveInfo& save_info, |
| 772 WebContents* web_contents) { | 777 WebContents* web_contents) { |
| 773 ResourceDispatcherHost* resource_dispatcher_host = | 778 ResourceDispatcherHost* resource_dispatcher_host = |
| 774 content::GetContentClient()->browser()->GetResourceDispatcherHost(); | 779 ResourceDispatcherHost::Get(); |
| 775 | 780 |
| 776 // We send a pointer to content::ResourceContext, instead of the usual | 781 // We send a pointer to content::ResourceContext, instead of the usual |
| 777 // reference, so that a copy of the object isn't made. | 782 // reference, so that a copy of the object isn't made. |
| 778 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. | 783 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. |
| 779 BrowserThread::PostTask( | 784 BrowserThread::PostTask( |
| 780 BrowserThread::IO, FROM_HERE, | 785 BrowserThread::IO, FROM_HERE, |
| 781 base::Bind(&BeginDownload, | 786 base::Bind(&BeginDownload, |
| 782 URLParams(url, referrer), save_info, resource_dispatcher_host, | 787 URLParams(url, referrer), save_info, resource_dispatcher_host, |
| 783 RenderParams(web_contents->GetRenderProcessHost()->GetID(), | 788 RenderParams(web_contents->GetRenderProcessHost()->GetID(), |
| 784 web_contents->GetRenderViewHost()->routing_id()), | 789 web_contents->GetRenderViewHost()->routing_id()), |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 it != history_downloads_.end(); ++it) { | 1142 it != history_downloads_.end(); ++it) { |
| 1138 if (it->second->IsComplete() && !it->second->GetOpened()) | 1143 if (it->second->IsComplete() && !it->second->GetOpened()) |
| 1139 ++num_unopened; | 1144 ++num_unopened; |
| 1140 } | 1145 } |
| 1141 download_stats::RecordOpensOutstanding(num_unopened); | 1146 download_stats::RecordOpensOutstanding(num_unopened); |
| 1142 } | 1147 } |
| 1143 | 1148 |
| 1144 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { | 1149 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { |
| 1145 file_manager_ = file_manager; | 1150 file_manager_ = file_manager; |
| 1146 } | 1151 } |
| OLD | NEW |