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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 GetNextId(), | 445 GetNextId(), |
446 mime_type, | 446 mime_type, |
447 bound_net_log); | 447 bound_net_log); |
448 | 448 |
449 download_item->AddObserver(observer); | 449 download_item->AddObserver(observer); |
450 DCHECK(!ContainsKey(downloads_, download_item->GetId())); | 450 DCHECK(!ContainsKey(downloads_, download_item->GetId())); |
451 downloads_[download_item->GetId()] = download_item; | 451 downloads_[download_item->GetId()] = download_item; |
452 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( | 452 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( |
453 this, download_item)); | 453 this, download_item)); |
454 | 454 |
455 // TODO(asanka): Make the ui an observer. | |
456 ShowDownloadInBrowser(download_item); | |
457 | |
458 return download_item; | 455 return download_item; |
459 } | 456 } |
460 | 457 |
461 void DownloadManagerImpl::CancelDownload(int32 download_id) { | 458 void DownloadManagerImpl::CancelDownload(int32 download_id) { |
462 DownloadItem* download = GetDownload(download_id); | 459 DownloadItem* download = GetDownload(download_id); |
463 if (!download || !download->IsInProgress()) | 460 if (!download || !download->IsInProgress()) |
464 return; | 461 return; |
465 download->Cancel(true); | 462 download->Cancel(true); |
466 } | 463 } |
467 | 464 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 state, | 575 state, |
579 opened, | 576 opened, |
580 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); | 577 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); |
581 DCHECK(!ContainsKey(downloads_, item->GetId())); | 578 DCHECK(!ContainsKey(downloads_, item->GetId())); |
582 downloads_[item->GetId()] = item; | 579 downloads_[item->GetId()] = item; |
583 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); | 580 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); |
584 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); | 581 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); |
585 return item; | 582 return item; |
586 } | 583 } |
587 | 584 |
588 // TODO(asanka) Move into an observer. | |
589 void DownloadManagerImpl::ShowDownloadInBrowser(DownloadItemImpl* download) { | |
590 // The 'contents' may no longer exist if the user closed the contents before | |
591 // we get this start completion event. | |
592 WebContents* content = download->GetWebContents(); | |
593 | |
594 // If the contents no longer exists, we ask the embedder to suggest another | |
595 // contents. | |
596 if (!content && delegate_) | |
597 content = delegate_->GetAlternativeWebContentsToNotifyForDownload(); | |
598 | |
599 if (content && content->GetDelegate()) | |
600 content->GetDelegate()->OnStartDownload(content, download); | |
601 } | |
602 | |
603 int DownloadManagerImpl::InProgressCount() const { | 585 int DownloadManagerImpl::InProgressCount() const { |
604 int count = 0; | 586 int count = 0; |
605 for (DownloadMap::const_iterator it = downloads_.begin(); | 587 for (DownloadMap::const_iterator it = downloads_.begin(); |
606 it != downloads_.end(); ++it) { | 588 it != downloads_.end(); ++it) { |
607 if (it->second->IsInProgress()) | 589 if (it->second->IsInProgress()) |
608 ++count; | 590 ++count; |
609 } | 591 } |
610 return count; | 592 return count; |
611 } | 593 } |
612 | 594 |
(...skipping 14 matching lines...) Expand all Loading... |
627 it != downloads_.end(); ++it) { | 609 it != downloads_.end(); ++it) { |
628 DownloadItemImpl* item = it->second; | 610 DownloadItemImpl* item = it->second; |
629 if (item->IsComplete() && | 611 if (item->IsComplete() && |
630 !item->GetOpened()) | 612 !item->GetOpened()) |
631 ++num_unopened; | 613 ++num_unopened; |
632 } | 614 } |
633 RecordOpensOutstanding(num_unopened); | 615 RecordOpensOutstanding(num_unopened); |
634 } | 616 } |
635 | 617 |
636 } // namespace content | 618 } // namespace content |
OLD | NEW |