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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
41 #include "content/public/browser/notification_types.h" | 41 #include "content/public/browser/notification_types.h" |
42 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
43 #include "content/public/browser/resource_context.h" | 43 #include "content/public/browser/resource_context.h" |
44 #include "content/public/browser/web_contents_delegate.h" | 44 #include "content/public/browser/web_contents_delegate.h" |
45 #include "content/public/common/referrer.h" | 45 #include "content/public/common/referrer.h" |
46 #include "net/base/elements_upload_data_stream.h" | 46 #include "net/base/elements_upload_data_stream.h" |
47 #include "net/base/load_flags.h" | 47 #include "net/base/load_flags.h" |
48 #include "net/base/request_priority.h" | 48 #include "net/base/request_priority.h" |
49 #include "net/base/upload_bytes_element_reader.h" | 49 #include "net/base/upload_bytes_element_reader.h" |
| 50 #include "net/log/net_log_source_type.h" |
50 #include "net/url_request/url_request_context.h" | 51 #include "net/url_request/url_request_context.h" |
51 #include "storage/browser/blob/blob_url_request_job_factory.h" | 52 #include "storage/browser/blob/blob_url_request_job_factory.h" |
52 #include "url/origin.h" | 53 #include "url/origin.h" |
53 | 54 |
54 namespace content { | 55 namespace content { |
55 namespace { | 56 namespace { |
56 | 57 |
57 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload( | 58 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload( |
58 std::unique_ptr<DownloadUrlParameters> params, | 59 std::unique_ptr<DownloadUrlParameters> params, |
59 content::ResourceContext* resource_context, | 60 content::ResourceContext* resource_context, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 DownloadManagerImpl::~DownloadManagerImpl() { | 186 DownloadManagerImpl::~DownloadManagerImpl() { |
186 DCHECK(!shutdown_needed_); | 187 DCHECK(!shutdown_needed_); |
187 } | 188 } |
188 | 189 |
189 DownloadItemImpl* DownloadManagerImpl::CreateActiveItem( | 190 DownloadItemImpl* DownloadManagerImpl::CreateActiveItem( |
190 uint32_t id, | 191 uint32_t id, |
191 const DownloadCreateInfo& info) { | 192 const DownloadCreateInfo& info) { |
192 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
193 DCHECK(!base::ContainsKey(downloads_, id)); | 194 DCHECK(!base::ContainsKey(downloads_, id)); |
194 net::BoundNetLog bound_net_log = | 195 net::BoundNetLog bound_net_log = |
195 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 196 net::BoundNetLog::Make(net_log_, net::NetLogSourceType::DOWNLOAD); |
196 DownloadItemImpl* download = | 197 DownloadItemImpl* download = |
197 item_factory_->CreateActiveItem(this, id, info, bound_net_log); | 198 item_factory_->CreateActiveItem(this, id, info, bound_net_log); |
198 downloads_[id] = download; | 199 downloads_[id] = download; |
199 downloads_by_guid_[download->GetGuid()] = download; | 200 downloads_by_guid_[download->GetGuid()] = download; |
200 return download; | 201 return download; |
201 } | 202 } |
202 | 203 |
203 void DownloadManagerImpl::GetNextId(const DownloadIdCallback& callback) { | 204 void DownloadManagerImpl::GetNextId(const DownloadIdCallback& callback) { |
204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 205 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
205 if (delegate_) { | 206 if (delegate_) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 const base::FilePath& main_file_path, | 438 const base::FilePath& main_file_path, |
438 const GURL& page_url, | 439 const GURL& page_url, |
439 const std::string& mime_type, | 440 const std::string& mime_type, |
440 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 441 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
441 const DownloadItemImplCreated& item_created, | 442 const DownloadItemImplCreated& item_created, |
442 uint32_t id) { | 443 uint32_t id) { |
443 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 444 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
444 DCHECK_NE(content::DownloadItem::kInvalidId, id); | 445 DCHECK_NE(content::DownloadItem::kInvalidId, id); |
445 DCHECK(!base::ContainsKey(downloads_, id)); | 446 DCHECK(!base::ContainsKey(downloads_, id)); |
446 net::BoundNetLog bound_net_log = | 447 net::BoundNetLog bound_net_log = |
447 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 448 net::BoundNetLog::Make(net_log_, net::NetLogSourceType::DOWNLOAD); |
448 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem( | 449 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem( |
449 this, id, main_file_path, page_url, mime_type, std::move(request_handle), | 450 this, id, main_file_path, page_url, mime_type, std::move(request_handle), |
450 bound_net_log); | 451 bound_net_log); |
451 downloads_[download_item->GetId()] = download_item; | 452 downloads_[download_item->GetId()] = download_item; |
452 DCHECK(!base::ContainsKey(downloads_by_guid_, download_item->GetGuid())); | 453 DCHECK(!base::ContainsKey(downloads_by_guid_, download_item->GetGuid())); |
453 downloads_by_guid_[download_item->GetGuid()] = download_item; | 454 downloads_by_guid_[download_item->GetGuid()] = download_item; |
454 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( | 455 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( |
455 this, download_item)); | 456 this, download_item)); |
456 if (!item_created.is_null()) | 457 if (!item_created.is_null()) |
457 item_created.Run(download_item); | 458 item_created.Run(download_item); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 if (base::ContainsKey(downloads_, id)) { | 687 if (base::ContainsKey(downloads_, id)) { |
687 NOTREACHED(); | 688 NOTREACHED(); |
688 return NULL; | 689 return NULL; |
689 } | 690 } |
690 DCHECK(!base::ContainsKey(downloads_by_guid_, guid)); | 691 DCHECK(!base::ContainsKey(downloads_by_guid_, guid)); |
691 DownloadItemImpl* item = item_factory_->CreatePersistedItem( | 692 DownloadItemImpl* item = item_factory_->CreatePersistedItem( |
692 this, guid, id, current_path, target_path, url_chain, referrer_url, | 693 this, guid, id, current_path, target_path, url_chain, referrer_url, |
693 site_url, tab_url, tab_refererr_url, mime_type, original_mime_type, | 694 site_url, tab_url, tab_refererr_url, mime_type, original_mime_type, |
694 start_time, end_time, etag, last_modified, received_bytes, total_bytes, | 695 start_time, end_time, etag, last_modified, received_bytes, total_bytes, |
695 hash, state, danger_type, interrupt_reason, opened, | 696 hash, state, danger_type, interrupt_reason, opened, |
696 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); | 697 net::BoundNetLog::Make(net_log_, net::NetLogSourceType::DOWNLOAD)); |
697 downloads_[id] = item; | 698 downloads_[id] = item; |
698 downloads_by_guid_[guid] = item; | 699 downloads_by_guid_[guid] = item; |
699 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); | 700 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); |
700 DVLOG(20) << __func__ << "() download = " << item->DebugString(true); | 701 DVLOG(20) << __func__ << "() download = " << item->DebugString(true); |
701 return item; | 702 return item; |
702 } | 703 } |
703 | 704 |
704 int DownloadManagerImpl::InProgressCount() const { | 705 int DownloadManagerImpl::InProgressCount() const { |
705 int count = 0; | 706 int count = 0; |
706 for (const auto& it : downloads_) { | 707 for (const auto& it : downloads_) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 if (delegate_) | 756 if (delegate_) |
756 delegate_->OpenDownload(download); | 757 delegate_->OpenDownload(download); |
757 } | 758 } |
758 | 759 |
759 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 760 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
760 if (delegate_) | 761 if (delegate_) |
761 delegate_->ShowDownloadInShell(download); | 762 delegate_->ShowDownloadInShell(download); |
762 } | 763 } |
763 | 764 |
764 } // namespace content | 765 } // namespace content |
OLD | NEW |