| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/download/content/download_driver_impl.h" | 5 #include "components/download/content/download_driver_impl.h" |
| 6 | 6 |
| 7 #include "components/download/internal/driver_entry.h" | 7 #include "components/download/internal/driver_entry.h" |
| 8 #include "content/public/browser/download_interrupt_reasons.h" | 8 #include "content/public/browser/download_interrupt_reasons.h" |
| 9 #include "content/public/browser/download_url_parameters.h" | 9 #include "content/public/browser/download_url_parameters.h" |
| 10 #include "content/public/browser/storage_partition.h" | 10 #include "content/public/browser/storage_partition.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 download_manager_->AddObserver(this); | 75 download_manager_->AddObserver(this); |
| 76 if (download_manager_->IsManagerInitialized()) | 76 if (download_manager_->IsManagerInitialized()) |
| 77 client_->OnDriverReady(true); | 77 client_->OnDriverReady(true); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool DownloadDriverImpl::IsReady() const { | 80 bool DownloadDriverImpl::IsReady() const { |
| 81 return client_ && download_manager_; | 81 return client_ && download_manager_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void DownloadDriverImpl::Start(const DownloadParams& params) { | 84 void DownloadDriverImpl::Start( |
| 85 const DownloadParams& params, |
| 86 const net::NetworkTrafficAnnotationTag& traffic_annotation) { |
| 85 DCHECK(!params.request_params.url.is_empty()); | 87 DCHECK(!params.request_params.url.is_empty()); |
| 86 DCHECK(!params.guid.empty()); | 88 DCHECK(!params.guid.empty()); |
| 87 if (!download_manager_) | 89 if (!download_manager_) |
| 88 return; | 90 return; |
| 89 | 91 |
| 90 content::StoragePartition* storage_partition = | 92 content::StoragePartition* storage_partition = |
| 91 content::BrowserContext::GetStoragePartitionForSite( | 93 content::BrowserContext::GetStoragePartitionForSite( |
| 92 download_manager_->GetBrowserContext(), params.request_params.url); | 94 download_manager_->GetBrowserContext(), params.request_params.url); |
| 93 DCHECK(storage_partition); | 95 DCHECK(storage_partition); |
| 94 | 96 |
| 95 std::unique_ptr<content::DownloadUrlParameters> download_url_params( | 97 std::unique_ptr<content::DownloadUrlParameters> download_url_params( |
| 96 new content::DownloadUrlParameters( | 98 new content::DownloadUrlParameters( |
| 97 params.request_params.url, | 99 params.request_params.url, |
| 98 storage_partition->GetURLRequestContext())); | 100 storage_partition->GetURLRequestContext())); |
| 99 | 101 |
| 100 // TODO(xingliu): Handle the request headers from |params|, need to tweak | 102 // TODO(xingliu): Handle the request headers from |params|, need to tweak |
| 101 // download network stack. | 103 // download network stack. |
| 102 // Make content::DownloadManager handle potential guid collision and return | 104 // Make content::DownloadManager handle potential guid collision and return |
| 103 // an error to fail the download cleanly. | 105 // an error to fail the download cleanly. |
| 104 download_url_params->set_guid(params.guid); | 106 download_url_params->set_guid(params.guid); |
| 105 download_url_params->set_transient(true); | 107 download_url_params->set_transient(true); |
| 106 download_url_params->set_method(params.request_params.method); | 108 download_url_params->set_method(params.request_params.method); |
| 107 download_url_params->set_file_path(file_dir_.AppendASCII(params.guid)); | 109 download_url_params->set_file_path(file_dir_.AppendASCII(params.guid)); |
| 108 | 110 |
| 109 download_manager_->DownloadUrl(std::move(download_url_params)); | 111 download_manager_->DownloadUrl(std::move(download_url_params), |
| 112 traffic_annotation); |
| 110 } | 113 } |
| 111 | 114 |
| 112 void DownloadDriverImpl::Cancel(const std::string& guid) { | 115 void DownloadDriverImpl::Cancel(const std::string& guid) { |
| 113 if (!download_manager_) | 116 if (!download_manager_) |
| 114 return; | 117 return; |
| 115 content::DownloadItem* item = download_manager_->GetDownloadByGuid(guid); | 118 content::DownloadItem* item = download_manager_->GetDownloadByGuid(guid); |
| 116 // Cancels the download and removes the persisted records in content layer. | 119 // Cancels the download and removes the persisted records in content layer. |
| 117 if (item) { | 120 if (item) { |
| 118 item->RemoveObserver(this); | 121 item->RemoveObserver(this); |
| 119 item->Remove(); | 122 item->Remove(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 DCHECK(download_manager_); | 182 DCHECK(download_manager_); |
| 180 client_->OnDriverReady(true); | 183 client_->OnDriverReady(true); |
| 181 } | 184 } |
| 182 | 185 |
| 183 void DownloadDriverImpl::ManagerGoingDown(content::DownloadManager* manager) { | 186 void DownloadDriverImpl::ManagerGoingDown(content::DownloadManager* manager) { |
| 184 DCHECK_EQ(download_manager_, manager); | 187 DCHECK_EQ(download_manager_, manager); |
| 185 download_manager_ = nullptr; | 188 download_manager_ = nullptr; |
| 186 } | 189 } |
| 187 | 190 |
| 188 } // namespace download | 191 } // namespace download |
| OLD | NEW |