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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ResourceDispatcherHost::Get()->BeginDownload( | 127 ResourceDispatcherHost::Get()->BeginDownload( |
128 request.Pass(), params->referrer(), params->content_initiated(), | 128 request.Pass(), params->referrer(), params->content_initiated(), |
129 params->resource_context(), params->render_process_host_id(), | 129 params->resource_context(), params->render_process_host_id(), |
130 params->render_view_host_routing_id(), | 130 params->render_view_host_routing_id(), |
131 params->render_frame_host_routing_id(), params->prefer_cache(), | 131 params->render_frame_host_routing_id(), params->prefer_cache(), |
132 params->do_not_prompt_for_login(), save_info.Pass(), download_id, | 132 params->do_not_prompt_for_login(), save_info.Pass(), download_id, |
133 params->callback()); | 133 params->callback()); |
134 return nullptr; | 134 return nullptr; |
135 } | 135 } |
136 return scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>( | 136 return scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>( |
137 UrlDownloader::BeginDownload( | 137 UrlDownloader::BeginDownload(download_manager, request.Pass(), |
138 download_manager, request.Pass(), params->referrer(), false, | 138 params->referrer(), params->prefer_cache(), |
139 params->prefer_cache(), true, save_info.Pass(), download_id, | 139 save_info.Pass(), download_id, |
140 params->callback()) | 140 params->callback()) |
141 .release()); | 141 .release()); |
142 } | 142 } |
143 | 143 |
144 class DownloadItemFactoryImpl : public DownloadItemFactory { | 144 class DownloadItemFactoryImpl : public DownloadItemFactory { |
145 public: | 145 public: |
146 DownloadItemFactoryImpl() {} | 146 DownloadItemFactoryImpl() {} |
147 ~DownloadItemFactoryImpl() override {} | 147 ~DownloadItemFactoryImpl() override {} |
148 | 148 |
149 DownloadItemImpl* CreatePersistedItem( | 149 DownloadItemImpl* CreatePersistedItem( |
150 DownloadItemImplDelegate* delegate, | 150 DownloadItemImplDelegate* delegate, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (new_download) { | 371 if (new_download) { |
372 download = CreateActiveItem(id, *info); | 372 download = CreateActiveItem(id, *info); |
373 } else { | 373 } else { |
374 DownloadMap::iterator item_iterator = downloads_.find(id); | 374 DownloadMap::iterator item_iterator = downloads_.find(id); |
375 // Trying to resume an interrupted download. | 375 // Trying to resume an interrupted download. |
376 if (item_iterator == downloads_.end() || | 376 if (item_iterator == downloads_.end() || |
377 (item_iterator->second->GetState() == DownloadItem::CANCELLED)) { | 377 (item_iterator->second->GetState() == DownloadItem::CANCELLED)) { |
378 // If the download is no longer known to the DownloadManager, then it was | 378 // If the download is no longer known to the DownloadManager, then it was |
379 // removed after it was resumed. Ignore. If the download is cancelled | 379 // removed after it was resumed. Ignore. If the download is cancelled |
380 // while resuming, then also ignore the request. | 380 // while resuming, then also ignore the request. |
381 info->request_handle.CancelRequest(); | 381 info->request_handle->CancelRequest(); |
382 if (!on_started.is_null()) | 382 if (!on_started.is_null()) |
383 on_started.Run(NULL, DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); | 383 on_started.Run(NULL, DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); |
384 return; | 384 return; |
385 } | 385 } |
386 download = item_iterator->second; | 386 download = item_iterator->second; |
387 DCHECK_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 387 DCHECK_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
388 download->MergeOriginInfoOnResume(*info); | 388 download->MergeOriginInfoOnResume(*info); |
389 } | 389 } |
390 | 390 |
391 base::FilePath default_download_directory; | 391 base::FilePath default_download_directory; |
(...skipping 12 matching lines...) Expand all Loading... |
404 delegate_ && delegate_->GenerateFileHash(), | 404 delegate_ && delegate_->GenerateFileHash(), |
405 stream.Pass(), download->GetBoundNetLog(), | 405 stream.Pass(), download->GetBoundNetLog(), |
406 download->DestinationObserverAsWeakPtr())); | 406 download->DestinationObserverAsWeakPtr())); |
407 | 407 |
408 // Attach the client ID identifying the app to the AV system. | 408 // Attach the client ID identifying the app to the AV system. |
409 if (download_file.get() && delegate_) { | 409 if (download_file.get() && delegate_) { |
410 download_file->SetClientGuid( | 410 download_file->SetClientGuid( |
411 delegate_->ApplicationClientIdForFileScanning()); | 411 delegate_->ApplicationClientIdForFileScanning()); |
412 } | 412 } |
413 | 413 |
414 scoped_ptr<DownloadRequestHandleInterface> req_handle( | 414 download->Start(download_file.Pass(), info->request_handle.Pass()); |
415 new DownloadRequestHandle(info->request_handle)); | |
416 download->Start(download_file.Pass(), req_handle.Pass()); | |
417 | 415 |
418 // For interrupted downloads, Start() will transition the state to | 416 // For interrupted downloads, Start() will transition the state to |
419 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated(). | 417 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated(). |
420 // For new downloads, we notify here, rather than earlier, so that | 418 // For new downloads, we notify here, rather than earlier, so that |
421 // the download_file is bound to download and all the usual | 419 // the download_file is bound to download and all the usual |
422 // setters (e.g. Cancel) work. | 420 // setters (e.g. Cancel) work. |
423 if (new_download) | 421 if (new_download) |
424 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); | 422 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
425 | 423 |
426 if (!on_started.is_null()) | 424 if (!on_started.is_null()) |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 if (delegate_) | 749 if (delegate_) |
752 delegate_->OpenDownload(download); | 750 delegate_->OpenDownload(download); |
753 } | 751 } |
754 | 752 |
755 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 753 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
756 if (delegate_) | 754 if (delegate_) |
757 delegate_->ShowDownloadInShell(download); | 755 delegate_->ShowDownloadInShell(download); |
758 } | 756 } |
759 | 757 |
760 } // namespace content | 758 } // namespace content |
OLD | NEW |