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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 DownloadItemImpl* download = factory_->CreateActiveItem( | 527 DownloadItemImpl* download = factory_->CreateActiveItem( |
528 this, *info, | 528 this, *info, |
529 scoped_ptr<DownloadRequestHandleInterface>( | 529 scoped_ptr<DownloadRequestHandleInterface>( |
530 new DownloadRequestHandle(info->request_handle)).Pass(), | 530 new DownloadRequestHandle(info->request_handle)).Pass(), |
531 browser_context_->IsOffTheRecord(), bound_net_log); | 531 browser_context_->IsOffTheRecord(), bound_net_log); |
532 | 532 |
533 DCHECK(!ContainsKey(downloads_, download->GetId())); | 533 DCHECK(!ContainsKey(downloads_, download->GetId())); |
534 downloads_[download->GetId()] = download; | 534 downloads_[download->GetId()] = download; |
535 DCHECK(!ContainsKey(active_downloads_, download->GetId())); | 535 DCHECK(!ContainsKey(active_downloads_, download->GetId())); |
536 active_downloads_[download->GetId()] = download; | 536 active_downloads_[download->GetId()] = download; |
| 537 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
537 | 538 |
538 return bound_net_log; | 539 return bound_net_log; |
539 } | 540 } |
540 | 541 |
541 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem( | 542 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem( |
542 const FilePath& main_file_path, | 543 const FilePath& main_file_path, |
543 const GURL& page_url, | 544 const GURL& page_url, |
544 bool is_otr, | 545 bool is_otr, |
545 const std::string& mime_type, | 546 const std::string& mime_type, |
546 DownloadItem::Observer* observer) { | 547 DownloadItem::Observer* observer) { |
547 net::BoundNetLog bound_net_log = | 548 net::BoundNetLog bound_net_log = |
548 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 549 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
549 DownloadItemImpl* download = factory_->CreateSavePageItem( | 550 DownloadItemImpl* download = factory_->CreateSavePageItem( |
550 this, | 551 this, |
551 main_file_path, | 552 main_file_path, |
552 page_url, | 553 page_url, |
553 is_otr, | 554 is_otr, |
554 GetNextId(), | 555 GetNextId(), |
555 mime_type, | 556 mime_type, |
556 bound_net_log); | 557 bound_net_log); |
557 | 558 |
558 download->AddObserver(observer); | 559 download->AddObserver(observer); |
559 | 560 |
560 DCHECK(!ContainsKey(downloads_, download->GetId())); | 561 DCHECK(!ContainsKey(downloads_, download->GetId())); |
561 downloads_[download->GetId()] = download; | 562 downloads_[download->GetId()] = download; |
562 DCHECK(!SavePageExternalData::Get(download)); | 563 DCHECK(!SavePageExternalData::Get(download)); |
563 new SavePageExternalData(download); | 564 new SavePageExternalData(download); |
564 DCHECK(SavePageExternalData::Get(download)); | 565 DCHECK(SavePageExternalData::Get(download)); |
565 | 566 |
| 567 // TODO(benjhayden): Fire OnDownloadCreated for SavePackage downloads when |
| 568 // we're comfortable with the user interacting with them. |
| 569 // FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
| 570 |
566 // Will notify the observer in the callback. | 571 // Will notify the observer in the callback. |
567 if (delegate_) | 572 if (delegate_) |
568 delegate_->AddItemToPersistentStore(download); | 573 delegate_->AddItemToPersistentStore(download); |
569 | 574 |
570 return download; | 575 return download; |
571 } | 576 } |
572 | 577 |
573 // The target path for the download item is now valid. We proceed with the | 578 // The target path for the download item is now valid. We proceed with the |
574 // determination of an intermediate path. | 579 // determination of an intermediate path. |
575 void DownloadManagerImpl::OnTargetPathAvailable(DownloadItemImpl* download) { | 580 void DownloadManagerImpl::OnTargetPathAvailable(DownloadItemImpl* download) { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 for (size_t i = 0; i < entries->size(); ++i) { | 945 for (size_t i = 0; i < entries->size(); ++i) { |
941 int64 db_handle = entries->at(i).db_handle; | 946 int64 db_handle = entries->at(i).db_handle; |
942 base::debug::Alias(&db_handle); | 947 base::debug::Alias(&db_handle); |
943 | 948 |
944 net::BoundNetLog bound_net_log = | 949 net::BoundNetLog bound_net_log = |
945 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 950 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
946 DownloadItemImpl* download = factory_->CreatePersistedItem( | 951 DownloadItemImpl* download = factory_->CreatePersistedItem( |
947 this, GetNextId(), entries->at(i), bound_net_log); | 952 this, GetNextId(), entries->at(i), bound_net_log); |
948 DCHECK(!ContainsKey(downloads_, download->GetId())); | 953 DCHECK(!ContainsKey(downloads_, download->GetId())); |
949 downloads_[download->GetId()] = download; | 954 downloads_[download->GetId()] = download; |
| 955 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
950 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 956 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
951 << " download = " << download->DebugString(true); | 957 << " download = " << download->DebugString(true); |
952 } | 958 } |
953 NotifyModelChanged(); | 959 NotifyModelChanged(); |
954 CheckForHistoryFilesRemoval(); | 960 CheckForHistoryFilesRemoval(); |
955 } | 961 } |
956 | 962 |
957 void DownloadManagerImpl::AddDownloadItemToHistory(DownloadItemImpl* download, | 963 void DownloadManagerImpl::AddDownloadItemToHistory(DownloadItemImpl* download, |
958 int64 db_handle) { | 964 int64 db_handle) { |
959 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1175 void DownloadManagerImpl::DownloadRenamedToFinalName( |
1170 DownloadItemImpl* download) { | 1176 DownloadItemImpl* download) { |
1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1172 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1178 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
1173 // receive the DownloadRenamedToFinalName() call. | 1179 // receive the DownloadRenamedToFinalName() call. |
1174 if (delegate_) { | 1180 if (delegate_) { |
1175 delegate_->UpdatePathForItemInPersistentStore( | 1181 delegate_->UpdatePathForItemInPersistentStore( |
1176 download, download->GetFullPath()); | 1182 download, download->GetFullPath()); |
1177 } | 1183 } |
1178 } | 1184 } |
OLD | NEW |