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

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

Issue 8351052: Created a DownloadManager interface, for use in unit tests.. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Mac & Clang issues. Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "content/browser/download/download_manager.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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); 306 contents, suggested_path, reinterpret_cast<void*>(id_ptr));
307 307
308 FOR_EACH_OBSERVER(Observer, observers_, 308 FOR_EACH_OBSERVER(Observer, observers_,
309 SelectFileDialogDisplayed(download_id)); 309 SelectFileDialogDisplayed(download_id));
310 } else { 310 } else {
311 // No prompting for download, just continue with the suggested name. 311 // No prompting for download, just continue with the suggested name.
312 ContinueDownloadWithPath(download, suggested_path); 312 ContinueDownloadWithPath(download, suggested_path);
313 } 313 }
314 } 314 }
315 315
316 content::BrowserContext* DownloadManager::BrowserContext() {
317 return browser_context_;
318 }
319
320 FilePath DownloadManager::LastDownloadPath() {
321 return last_download_path_;
322 }
323
316 void DownloadManager::CreateDownloadItem( 324 void DownloadManager::CreateDownloadItem(
317 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { 325 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
319 327
320 DownloadItem* download = new DownloadItem(this, *info, 328 DownloadItem* download = new DownloadItem(this, *info,
321 request_handle, 329 request_handle,
322 browser_context_->IsOffTheRecord()); 330 browser_context_->IsOffTheRecord());
323 int32 download_id = info->download_id.local(); 331 int32 download_id = info->download_id.local();
324 DCHECK(!ContainsKey(in_progress_, download_id)); 332 DCHECK(!ContainsKey(in_progress_, download_id));
325 333
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 // Clean up will happen when the history system create callback runs if we 606 // Clean up will happen when the history system create callback runs if we
599 // don't have a valid db_handle yet. 607 // don't have a valid db_handle yet.
600 if (download->db_handle() != DownloadItem::kUninitializedHandle) { 608 if (download->db_handle() != DownloadItem::kUninitializedHandle) {
601 in_progress_.erase(download->id()); 609 in_progress_.erase(download->id());
602 active_downloads_.erase(download->id()); 610 active_downloads_.erase(download->id());
603 UpdateDownloadProgress(); // Reflect removal from in_progress_. 611 UpdateDownloadProgress(); // Reflect removal from in_progress_.
604 delegate_->UpdateItemInPersistentStore(download); 612 delegate_->UpdateItemInPersistentStore(download);
605 } 613 }
606 } 614 }
607 615
616 content::DownloadManagerDelegate* DownloadManager::delegate() const {
617 return delegate_;
618 }
619
608 void DownloadManager::SetDownloadManagerDelegate( 620 void DownloadManager::SetDownloadManagerDelegate(
609 content::DownloadManagerDelegate* delegate) { 621 content::DownloadManagerDelegate* delegate) {
610 delegate_ = delegate; 622 delegate_ = delegate;
611 } 623 }
612 624
613 void DownloadManager::UpdateDownloadProgress() { 625 void DownloadManager::UpdateDownloadProgress() {
614 delegate_->DownloadProgressUpdated(); 626 delegate_->DownloadProgressUpdated();
615 } 627 }
616 628
617 int DownloadManager::RemoveDownloadItems( 629 int DownloadManager::RemoveDownloadItems(
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 933
922 // If the contents no longer exists, we ask the embedder to suggest another 934 // If the contents no longer exists, we ask the embedder to suggest another
923 // tab. 935 // tab.
924 if (!content) 936 if (!content)
925 content = delegate_->GetAlternativeTabContentsToNotifyForDownload(); 937 content = delegate_->GetAlternativeTabContentsToNotifyForDownload();
926 938
927 if (content) 939 if (content)
928 content->OnStartDownload(download); 940 content->OnStartDownload(download);
929 } 941 }
930 942
943 int DownloadManager::InProgressCount() const {
944 return static_cast<int>(in_progress_.size());
945 }
946
931 // Clears the last download path, used to initialize "save as" dialogs. 947 // Clears the last download path, used to initialize "save as" dialogs.
932 void DownloadManager::ClearLastDownloadPath() { 948 void DownloadManager::ClearLastDownloadPath() {
933 last_download_path_ = FilePath(); 949 last_download_path_ = FilePath();
934 } 950 }
935 951
936 void DownloadManager::NotifyModelChanged() { 952 void DownloadManager::NotifyModelChanged() {
937 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); 953 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged());
938 } 954 }
939 955
940 DownloadItem* DownloadManager::GetDownloadItem(int download_id) { 956 DownloadItem* DownloadManager::GetDownloadItem(int download_id) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { 1086 void DownloadManager::MarkDownloadOpened(DownloadItem* download) {
1071 delegate_->UpdateItemInPersistentStore(download); 1087 delegate_->UpdateItemInPersistentStore(download);
1072 int num_unopened = 0; 1088 int num_unopened = 0;
1073 for (DownloadMap::iterator it = history_downloads_.begin(); 1089 for (DownloadMap::iterator it = history_downloads_.begin();
1074 it != history_downloads_.end(); ++it) { 1090 it != history_downloads_.end(); ++it) {
1075 if (it->second->IsComplete() && !it->second->opened()) 1091 if (it->second->IsComplete() && !it->second->opened())
1076 ++num_unopened; 1092 ++num_unopened;
1077 } 1093 }
1078 download_stats::RecordOpensOutstanding(num_unopened); 1094 download_stats::RecordOpensOutstanding(num_unopened);
1079 } 1095 }
1096
1097 void DownloadManager::SetFileManager(DownloadFileManager* file_manager) {
1098 file_manager_ = file_manager;
1099 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698