| OLD | NEW |
| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 if (!download) | 299 if (!download) |
| 300 return; | 300 return; |
| 301 | 301 |
| 302 VLOG(20) << __FUNCTION__ << "()" | 302 VLOG(20) << __FUNCTION__ << "()" |
| 303 << " download = " << download->DebugString(true); | 303 << " download = " << download->DebugString(true); |
| 304 | 304 |
| 305 FilePath suggested_path = download->suggested_path(); | 305 FilePath suggested_path = download->suggested_path(); |
| 306 | 306 |
| 307 if (download->prompt_user_for_save_location()) { | 307 if (download->prompt_user_for_save_location()) { |
| 308 // We must ask the user for the place to put the download. | 308 // We must ask the user for the place to put the download. |
| 309 DownloadRequestHandle request_handle = download->request_handle(); | 309 TabContents* contents = download->GetTabContents(); |
| 310 TabContents* contents = request_handle.GetTabContents(); | |
| 311 | 310 |
| 312 // |id_ptr| will be deleted in either FileSelected() or | 311 // |id_ptr| will be deleted in either FileSelected() or |
| 313 // FileSelectionCancelled(). | 312 // FileSelectionCancelled(). |
| 314 int32* id_ptr = new int32; | 313 int32* id_ptr = new int32; |
| 315 *id_ptr = download_id; | 314 *id_ptr = download_id; |
| 316 | 315 |
| 317 delegate_->ChooseDownloadPath( | 316 delegate_->ChooseDownloadPath( |
| 318 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); | 317 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); |
| 319 | 318 |
| 320 FOR_EACH_OBSERVER(Observer, observers_, | 319 FOR_EACH_OBSERVER(Observer, observers_, |
| 321 SelectFileDialogDisplayed(download_id)); | 320 SelectFileDialogDisplayed(download_id)); |
| 322 } else { | 321 } else { |
| 323 // No prompting for download, just continue with the suggested name. | 322 // No prompting for download, just continue with the suggested name. |
| 324 ContinueDownloadWithPath(download, suggested_path); | 323 ContinueDownloadWithPath(download, suggested_path); |
| 325 } | 324 } |
| 326 } | 325 } |
| 327 | 326 |
| 328 void DownloadManager::CreateDownloadItem( | 327 void DownloadManager::CreateDownloadItem( |
| 329 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { | 328 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { |
| 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 331 | 330 |
| 332 DownloadItem* download = new DownloadItem(this, *info, | 331 DownloadItem* download = new DownloadItem( |
| 333 request_handle, | 332 this, *info, new DownloadRequestHandle(request_handle), |
| 334 browser_context_->IsOffTheRecord()); | 333 browser_context_->IsOffTheRecord()); |
| 335 int32 download_id = info->download_id; | 334 int32 download_id = info->download_id; |
| 336 DCHECK(!ContainsKey(in_progress_, download_id)); | 335 DCHECK(!ContainsKey(in_progress_, download_id)); |
| 337 | 336 |
| 338 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. | 337 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. |
| 339 CHECK(!ContainsKey(active_downloads_, download_id)); | 338 CHECK(!ContainsKey(active_downloads_, download_id)); |
| 340 downloads_.insert(download); | 339 downloads_.insert(download); |
| 341 active_downloads_[download_id] = download; | 340 active_downloads_[download_id] = download; |
| 342 } | 341 } |
| 343 | 342 |
| 344 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, | 343 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 in_progress_.erase(download_id); | 923 in_progress_.erase(download_id); |
| 925 active_downloads_.erase(download_id); | 924 active_downloads_.erase(download_id); |
| 926 delegate_->UpdateItemInPersistentStore(download); | 925 delegate_->UpdateItemInPersistentStore(download); |
| 927 download->UpdateObservers(); | 926 download->UpdateObservers(); |
| 928 } | 927 } |
| 929 } | 928 } |
| 930 | 929 |
| 931 void DownloadManager::ShowDownloadInBrowser(DownloadItem* download) { | 930 void DownloadManager::ShowDownloadInBrowser(DownloadItem* download) { |
| 932 // The 'contents' may no longer exist if the user closed the tab before we | 931 // The 'contents' may no longer exist if the user closed the tab before we |
| 933 // get this start completion event. | 932 // get this start completion event. |
| 934 DownloadRequestHandle request_handle = download->request_handle(); | 933 TabContents* content = download->GetTabContents(); |
| 935 TabContents* content = request_handle.GetTabContents(); | |
| 936 | 934 |
| 937 // If the contents no longer exists, we ask the embedder to suggest another | 935 // If the contents no longer exists, we ask the embedder to suggest another |
| 938 // tab. | 936 // tab. |
| 939 if (!content) | 937 if (!content) |
| 940 content = delegate_->GetAlternativeTabContentsToNotifyForDownload(); | 938 content = delegate_->GetAlternativeTabContentsToNotifyForDownload(); |
| 941 | 939 |
| 942 if (content) | 940 if (content) |
| 943 content->OnStartDownload(download); | 941 content->OnStartDownload(download); |
| 944 } | 942 } |
| 945 | 943 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { | 1083 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { |
| 1086 delegate_->UpdateItemInPersistentStore(download); | 1084 delegate_->UpdateItemInPersistentStore(download); |
| 1087 int num_unopened = 0; | 1085 int num_unopened = 0; |
| 1088 for (DownloadMap::iterator it = history_downloads_.begin(); | 1086 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 1089 it != history_downloads_.end(); ++it) { | 1087 it != history_downloads_.end(); ++it) { |
| 1090 if (it->second->IsComplete() && !it->second->opened()) | 1088 if (it->second->IsComplete() && !it->second->opened()) |
| 1091 ++num_unopened; | 1089 ++num_unopened; |
| 1092 } | 1090 } |
| 1093 download_stats::RecordOpensOutstanding(num_unopened); | 1091 download_stats::RecordOpensOutstanding(num_unopened); |
| 1094 } | 1092 } |
| OLD | NEW |