Chromium Code Reviews| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 DCHECK(browser_context); | 337 DCHECK(browser_context); |
| 338 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; | 338 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; |
| 339 shutdown_needed_ = true; | 339 shutdown_needed_ = true; |
| 340 | 340 |
| 341 browser_context_ = browser_context; | 341 browser_context_ = browser_context; |
| 342 | 342 |
| 343 return true; | 343 return true; |
| 344 } | 344 } |
| 345 | 345 |
| 346 // We have received a message from DownloadFileManager about a new download. | 346 // We have received a message from DownloadFileManager about a new download. |
| 347 content::DownloadId DownloadManagerImpl::StartDownload( | 347 DownloadItem* DownloadManagerImpl::StartDownload( |
| 348 scoped_ptr<DownloadCreateInfo> info, | 348 scoped_ptr<DownloadCreateInfo> info, |
| 349 scoped_ptr<content::ByteStreamReader> stream) { | 349 scoped_ptr<content::ByteStreamReader> stream) { |
| 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 351 | 351 |
| 352 // |bound_net_log| will be used for logging both the download item's and | 352 // |bound_net_log| will be used for logging both the download item's and |
| 353 // the download file's events. | 353 // the download file's events. |
| 354 net::BoundNetLog bound_net_log = CreateDownloadItem(info.get()); | 354 net::BoundNetLog bound_net_log = CreateDownloadItem(info.get()); |
| 355 | 355 |
| 356 // If info->download_id was unknown on entry to this function, it was | 356 // If info->download_id was unknown on entry to this function, it was |
| 357 // assigned in CreateDownloadItem. | 357 // assigned in CreateDownloadItem. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 369 this, download_id.local())); | 369 this, download_id.local())); |
| 370 | 370 |
| 371 BrowserThread::PostTask( | 371 BrowserThread::PostTask( |
| 372 BrowserThread::FILE, FROM_HERE, | 372 BrowserThread::FILE, FROM_HERE, |
| 373 base::Bind(&DownloadFileManager::CreateDownloadFile, | 373 base::Bind(&DownloadFileManager::CreateDownloadFile, |
| 374 file_manager_, base::Passed(info.Pass()), | 374 file_manager_, base::Passed(info.Pass()), |
| 375 base::Passed(stream.Pass()), make_scoped_refptr(this), | 375 base::Passed(stream.Pass()), make_scoped_refptr(this), |
| 376 (delegate_ && delegate_->GenerateFileHash()), bound_net_log, | 376 (delegate_ && delegate_->GenerateFileHash()), bound_net_log, |
| 377 callback)); | 377 callback)); |
| 378 | 378 |
| 379 return download_id; | 379 return GetDownload(download_id.local()); |
|
Randy Smith (Not in Mondays)
2012/10/08 19:20:52
I think that it would be a better design to refact
benjhayden
2012/10/08 19:49:45
Ya, I thought about making CreateDownloadItem retu
| |
| 380 } | 380 } |
| 381 | 381 |
| 382 void DownloadManagerImpl::OnDownloadFileCreated( | 382 void DownloadManagerImpl::OnDownloadFileCreated( |
| 383 int32 download_id, content::DownloadInterruptReason reason) { | 383 int32 download_id, content::DownloadInterruptReason reason) { |
| 384 if (reason != content::DOWNLOAD_INTERRUPT_REASON_NONE) { | 384 if (reason != content::DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 385 OnDownloadInterrupted(download_id, reason); | 385 OnDownloadInterrupted(download_id, reason); |
| 386 // TODO(rdsmith): It makes no sense to continue along the | 386 // TODO(rdsmith): It makes no sense to continue along the |
| 387 // regular download path after we've gotten an error. But it's | 387 // regular download path after we've gotten an error. But it's |
| 388 // the way the code has historically worked, and this allows us | 388 // the way the code has historically worked, and this allows us |
| 389 // to get the download persisted and observers of the download manager | 389 // to get the download persisted and observers of the download manager |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1035 void DownloadManagerImpl::DownloadRenamedToFinalName( |
| 1036 DownloadItemImpl* download) { | 1036 DownloadItemImpl* download) { |
| 1037 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1037 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1038 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1038 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1039 // receive the DownloadRenamedToFinalName() call. | 1039 // receive the DownloadRenamedToFinalName() call. |
| 1040 if (delegate_) { | 1040 if (delegate_) { |
| 1041 delegate_->UpdatePathForItemInPersistentStore( | 1041 delegate_->UpdatePathForItemInPersistentStore( |
| 1042 download, download->GetFullPath()); | 1042 download, download->GetFullPath()); |
| 1043 } | 1043 } |
| 1044 } | 1044 } |
| OLD | NEW |