Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 11640007: Make the UI an observer of downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Android clang build Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 void EnsureNoPendingDownloadJobsOnFile(bool* result) { 156 void EnsureNoPendingDownloadJobsOnFile(bool* result) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
158 *result = (DownloadFile::GetNumberOfDownloadFiles() == 0); 158 *result = (DownloadFile::GetNumberOfDownloadFiles() == 0);
159 BrowserThread::PostTask( 159 BrowserThread::PostTask(
160 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 160 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure());
161 } 161 }
162 162
163 class DownloadItemFactoryImpl : public DownloadItemFactory { 163 class DownloadItemFactoryImpl : public DownloadItemFactory {
164 public: 164 public:
165 DownloadItemFactoryImpl() {} 165 DownloadItemFactoryImpl() {}
166 virtual ~DownloadItemFactoryImpl() {} 166 virtual ~DownloadItemFactoryImpl() {}
167 167
168 virtual DownloadItemImpl* CreatePersistedItem( 168 virtual DownloadItemImpl* CreatePersistedItem(
169 DownloadItemImplDelegate* delegate, 169 DownloadItemImplDelegate* delegate,
170 DownloadId download_id, 170 DownloadId download_id,
171 const base::FilePath& current_path, 171 const base::FilePath& current_path,
172 const base::FilePath& target_path, 172 const base::FilePath& target_path,
173 const std::vector<GURL>& url_chain, 173 const std::vector<GURL>& url_chain,
174 const GURL& referrer_url, 174 const GURL& referrer_url,
175 const base::Time& start_time, 175 const base::Time& start_time,
176 const base::Time& end_time, 176 const base::Time& end_time,
177 int64 received_bytes, 177 int64 received_bytes,
178 int64 total_bytes, 178 int64 total_bytes,
179 DownloadItem::DownloadState state, 179 DownloadItem::DownloadState state,
180 DownloadDangerType danger_type, 180 DownloadDangerType danger_type,
181 DownloadInterruptReason interrupt_reason, 181 DownloadInterruptReason interrupt_reason,
182 bool opened, 182 bool opened,
183 const net::BoundNetLog& bound_net_log) OVERRIDE { 183 const net::BoundNetLog& bound_net_log) OVERRIDE {
184 return new DownloadItemImpl( 184 return new DownloadItemImpl(
185 delegate, 185 delegate,
186 download_id, 186 download_id,
187 current_path, 187 current_path,
188 target_path, 188 target_path,
189 url_chain, 189 url_chain,
190 referrer_url, 190 referrer_url,
191 start_time, 191 start_time,
192 end_time, 192 end_time,
193 received_bytes, 193 received_bytes,
194 total_bytes, 194 total_bytes,
195 state, 195 state,
196 danger_type, 196 danger_type,
197 interrupt_reason, 197 interrupt_reason,
198 opened, 198 opened,
199 bound_net_log); 199 bound_net_log);
200 } 200 }
201 201
202 virtual DownloadItemImpl* CreateActiveItem( 202 virtual DownloadItemImpl* CreateActiveItem(
203 DownloadItemImplDelegate* delegate, 203 DownloadItemImplDelegate* delegate,
204 const DownloadCreateInfo& info, 204 const DownloadCreateInfo& info,
205 const net::BoundNetLog& bound_net_log) OVERRIDE { 205 const net::BoundNetLog& bound_net_log) OVERRIDE {
206 return new DownloadItemImpl(delegate, info, bound_net_log); 206 return new DownloadItemImpl(delegate, info, bound_net_log);
207 } 207 }
208 208
209 virtual DownloadItemImpl* CreateSavePageItem( 209 virtual DownloadItemImpl* CreateSavePageItem(
210 DownloadItemImplDelegate* delegate, 210 DownloadItemImplDelegate* delegate,
211 const base::FilePath& path, 211 const base::FilePath& path,
212 const GURL& url, 212 const GURL& url,
213 DownloadId download_id, 213 DownloadId download_id,
214 const std::string& mime_type, 214 const std::string& mime_type,
215 const net::BoundNetLog& bound_net_log) OVERRIDE { 215 scoped_ptr<DownloadRequestHandleInterface> request_handle,
216 return new DownloadItemImpl(delegate, path, url, download_id, 216 const net::BoundNetLog& bound_net_log) OVERRIDE {
217 mime_type, bound_net_log); 217 return new DownloadItemImpl(delegate, path, url, download_id,
218 } 218 mime_type, request_handle.Pass(),
219 bound_net_log);
220 }
219 }; 221 };
220 222
221 } // namespace 223 } // namespace
222 224
223 DownloadManagerImpl::DownloadManagerImpl( 225 DownloadManagerImpl::DownloadManagerImpl(
224 net::NetLog* net_log) 226 net::NetLog* net_log)
225 : item_factory_(new DownloadItemFactoryImpl()), 227 : item_factory_(new DownloadItemFactoryImpl()),
226 file_factory_(new DownloadFileFactory()), 228 file_factory_(new DownloadFileFactory()),
227 history_size_(0), 229 history_size_(0),
228 shutdown_needed_(false), 230 shutdown_needed_(false),
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 downloads_[download->GetId()] = download; 453 downloads_[download->GetId()] = download;
452 } 454 }
453 455
454 return download; 456 return download;
455 } 457 }
456 458
457 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem( 459 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem(
458 const base::FilePath& main_file_path, 460 const base::FilePath& main_file_path,
459 const GURL& page_url, 461 const GURL& page_url,
460 const std::string& mime_type, 462 const std::string& mime_type,
463 scoped_ptr<DownloadRequestHandleInterface> request_handle,
461 DownloadItem::Observer* observer) { 464 DownloadItem::Observer* observer) {
462 net::BoundNetLog bound_net_log = 465 net::BoundNetLog bound_net_log =
463 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); 466 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD);
464 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem( 467 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem(
465 this, 468 this,
466 main_file_path, 469 main_file_path,
467 page_url, 470 page_url,
468 GetNextId(), 471 GetNextId(),
469 mime_type, 472 mime_type,
473 request_handle.Pass(),
470 bound_net_log); 474 bound_net_log);
471 475
472 download_item->AddObserver(observer); 476 download_item->AddObserver(observer);
473 DCHECK(!ContainsKey(downloads_, download_item->GetId())); 477 DCHECK(!ContainsKey(downloads_, download_item->GetId()));
474 downloads_[download_item->GetId()] = download_item; 478 downloads_[download_item->GetId()] = download_item;
475 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( 479 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(
476 this, download_item)); 480 this, download_item));
477 481
478 // TODO(asanka): Make the ui an observer.
479 ShowDownloadInBrowser(download_item);
480
481 return download_item; 482 return download_item;
482 } 483 }
483 484
484 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished( 485 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished(
485 DownloadItem* download_item) { 486 DownloadItem* download_item) {
486 FOR_EACH_OBSERVER(Observer, observers_, 487 FOR_EACH_OBSERVER(Observer, observers_,
487 OnSavePackageSuccessfullyFinished(this, download_item)); 488 OnSavePackageSuccessfullyFinished(this, download_item));
488 } 489 }
489 490
490 void DownloadManagerImpl::CancelDownload(int32 download_id) { 491 void DownloadManagerImpl::CancelDownload(int32 download_id) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 interrupt_reason, 626 interrupt_reason,
626 opened, 627 opened,
627 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); 628 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD));
628 DCHECK(!ContainsKey(downloads_, item->GetId())); 629 DCHECK(!ContainsKey(downloads_, item->GetId()));
629 downloads_[item->GetId()] = item; 630 downloads_[item->GetId()] = item;
630 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); 631 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item));
631 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); 632 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true);
632 return item; 633 return item;
633 } 634 }
634 635
635 // TODO(asanka) Move into an observer.
636 void DownloadManagerImpl::ShowDownloadInBrowser(DownloadItemImpl* download) {
637 // The 'contents' may no longer exist if the user closed the contents before
638 // we get this start completion event.
639 WebContents* content = download->GetWebContents();
640
641 // If the contents no longer exists, we ask the embedder to suggest another
642 // contents.
643 if (!content && delegate_)
644 content = delegate_->GetAlternativeWebContentsToNotifyForDownload();
645
646 if (content && content->GetDelegate())
647 content->GetDelegate()->OnStartDownload(content, download);
648 }
649
650 int DownloadManagerImpl::InProgressCount() const { 636 int DownloadManagerImpl::InProgressCount() const {
651 int count = 0; 637 int count = 0;
652 for (DownloadMap::const_iterator it = downloads_.begin(); 638 for (DownloadMap::const_iterator it = downloads_.begin();
653 it != downloads_.end(); ++it) { 639 it != downloads_.end(); ++it) {
654 if (it->second->IsInProgress()) 640 if (it->second->IsInProgress())
655 ++count; 641 ++count;
656 } 642 }
657 return count; 643 return count;
658 } 644 }
659 645
(...skipping 22 matching lines...) Expand all
682 if (delegate_) 668 if (delegate_)
683 delegate_->OpenDownload(download); 669 delegate_->OpenDownload(download);
684 } 670 }
685 671
686 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 672 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
687 if (delegate_) 673 if (delegate_)
688 delegate_->ShowDownloadInShell(download); 674 delegate_->ShowDownloadInShell(download);
689 } 675 }
690 676
691 } // namespace content 677 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl.h ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698