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

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

Issue 8399001: Use a DownloadRequestHandle pointer in construction to allow mocking for tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to TOT. 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (!download) 287 if (!download)
288 return; 288 return;
289 289
290 VLOG(20) << __FUNCTION__ << "()" 290 VLOG(20) << __FUNCTION__ << "()"
291 << " download = " << download->DebugString(true); 291 << " download = " << download->DebugString(true);
292 292
293 FilePath suggested_path = download->suggested_path(); 293 FilePath suggested_path = download->suggested_path();
294 294
295 if (download->prompt_user_for_save_location()) { 295 if (download->prompt_user_for_save_location()) {
296 // We must ask the user for the place to put the download. 296 // We must ask the user for the place to put the download.
297 DownloadRequestHandle request_handle = download->request_handle(); 297 TabContents* contents = download->GetTabContents();
298 TabContents* contents = request_handle.GetTabContents();
299 298
300 // |id_ptr| will be deleted in either FileSelected() or 299 // |id_ptr| will be deleted in either FileSelected() or
301 // FileSelectionCancelled(). 300 // FileSelectionCancelled().
302 int32* id_ptr = new int32; 301 int32* id_ptr = new int32;
303 *id_ptr = download_id; 302 *id_ptr = download_id;
304 303
305 delegate_->ChooseDownloadPath( 304 delegate_->ChooseDownloadPath(
306 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); 305 contents, suggested_path, reinterpret_cast<void*>(id_ptr));
307 306
308 FOR_EACH_OBSERVER(Observer, observers_, 307 FOR_EACH_OBSERVER(Observer, observers_,
309 SelectFileDialogDisplayed(download_id)); 308 SelectFileDialogDisplayed(download_id));
310 } else { 309 } else {
311 // No prompting for download, just continue with the suggested name. 310 // No prompting for download, just continue with the suggested name.
312 ContinueDownloadWithPath(download, suggested_path); 311 ContinueDownloadWithPath(download, suggested_path);
313 } 312 }
314 } 313 }
315 314
316 void DownloadManager::CreateDownloadItem( 315 void DownloadManager::CreateDownloadItem(
317 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { 316 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
319 318
320 DownloadItem* download = new DownloadItem(this, *info, 319 DownloadItem* download = new DownloadItem(
321 request_handle, 320 this, *info, new DownloadRequestHandle(request_handle),
322 browser_context_->IsOffTheRecord()); 321 browser_context_->IsOffTheRecord());
323 int32 download_id = info->download_id.local(); 322 int32 download_id = info->download_id.local();
324 DCHECK(!ContainsKey(in_progress_, download_id)); 323 DCHECK(!ContainsKey(in_progress_, download_id));
325 324
326 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. 325 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
327 CHECK(!ContainsKey(active_downloads_, download_id)); 326 CHECK(!ContainsKey(active_downloads_, download_id));
328 downloads_.insert(download); 327 downloads_.insert(download);
329 active_downloads_[download_id] = download; 328 active_downloads_[download_id] = download;
330 } 329 }
331 330
332 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, 331 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download,
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 in_progress_.erase(download_id); 908 in_progress_.erase(download_id);
910 active_downloads_.erase(download_id); 909 active_downloads_.erase(download_id);
911 delegate_->UpdateItemInPersistentStore(download); 910 delegate_->UpdateItemInPersistentStore(download);
912 download->UpdateObservers(); 911 download->UpdateObservers();
913 } 912 }
914 } 913 }
915 914
916 void DownloadManager::ShowDownloadInBrowser(DownloadItem* download) { 915 void DownloadManager::ShowDownloadInBrowser(DownloadItem* download) {
917 // The 'contents' may no longer exist if the user closed the tab before we 916 // The 'contents' may no longer exist if the user closed the tab before we
918 // get this start completion event. 917 // get this start completion event.
919 DownloadRequestHandle request_handle = download->request_handle(); 918 TabContents* content = download->GetTabContents();
920 TabContents* content = request_handle.GetTabContents();
921 919
922 // If the contents no longer exists, we ask the embedder to suggest another 920 // If the contents no longer exists, we ask the embedder to suggest another
923 // tab. 921 // tab.
924 if (!content) 922 if (!content)
925 content = delegate_->GetAlternativeTabContentsToNotifyForDownload(); 923 content = delegate_->GetAlternativeTabContentsToNotifyForDownload();
926 924
927 if (content) 925 if (content)
928 content->OnStartDownload(download); 926 content->OnStartDownload(download);
929 } 927 }
930 928
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { 1068 void DownloadManager::MarkDownloadOpened(DownloadItem* download) {
1071 delegate_->UpdateItemInPersistentStore(download); 1069 delegate_->UpdateItemInPersistentStore(download);
1072 int num_unopened = 0; 1070 int num_unopened = 0;
1073 for (DownloadMap::iterator it = history_downloads_.begin(); 1071 for (DownloadMap::iterator it = history_downloads_.begin();
1074 it != history_downloads_.end(); ++it) { 1072 it != history_downloads_.end(); ++it) {
1075 if (it->second->IsComplete() && !it->second->opened()) 1073 if (it->second->IsComplete() && !it->second->opened())
1076 ++num_unopened; 1074 ++num_unopened;
1077 } 1075 }
1078 download_stats::RecordOpensOutstanding(num_unopened); 1076 download_stats::RecordOpensOutstanding(num_unopened);
1079 } 1077 }
OLDNEW
« no previous file with comments | « content/browser/download/download_item.cc ('k') | content/browser/download/download_request_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698