| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/url_downloader.h" | 5 #include "content/browser/download/url_downloader.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/threading/sequenced_task_runner_handle.h" | 10 #include "base/threading/sequenced_task_runner_handle.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 DISALLOW_COPY_AND_ASSIGN(RequestHandle); | 70 DISALLOW_COPY_AND_ASSIGN(RequestHandle); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // static | 73 // static |
| 74 scoped_ptr<UrlDownloader> UrlDownloader::BeginDownload( | 74 scoped_ptr<UrlDownloader> UrlDownloader::BeginDownload( |
| 75 base::WeakPtr<DownloadManagerImpl> download_manager, | 75 base::WeakPtr<DownloadManagerImpl> download_manager, |
| 76 scoped_ptr<net::URLRequest> request, | 76 scoped_ptr<net::URLRequest> request, |
| 77 const Referrer& referrer, | 77 const Referrer& referrer, |
| 78 bool prefer_cache, | 78 bool prefer_cache, |
| 79 scoped_ptr<DownloadSaveInfo> save_info, | 79 scoped_ptr<DownloadSaveInfo> save_info, |
| 80 uint32 download_id, | 80 uint32_t download_id, |
| 81 const DownloadUrlParameters::OnStartedCallback& started_callback) { | 81 const DownloadUrlParameters::OnStartedCallback& started_callback) { |
| 82 if (!referrer.url.is_valid()) | 82 if (!referrer.url.is_valid()) |
| 83 request->SetReferrer(std::string()); | 83 request->SetReferrer(std::string()); |
| 84 else | 84 else |
| 85 request->SetReferrer(referrer.url.spec()); | 85 request->SetReferrer(referrer.url.spec()); |
| 86 | 86 |
| 87 int extra_load_flags = net::LOAD_NORMAL; | 87 int extra_load_flags = net::LOAD_NORMAL; |
| 88 if (prefer_cache) { | 88 if (prefer_cache) { |
| 89 // If there is upload data attached, only retrieve from cache because there | 89 // If there is upload data attached, only retrieve from cache because there |
| 90 // is no current mechanism to prompt the user for their consent for a | 90 // is no current mechanism to prompt the user for their consent for a |
| (...skipping 18 matching lines...) Expand all Loading... |
| 109 std::move(save_info), download_id, started_callback)); | 109 std::move(save_info), download_id, started_callback)); |
| 110 downloader->Start(); | 110 downloader->Start(); |
| 111 | 111 |
| 112 return downloader; | 112 return downloader; |
| 113 } | 113 } |
| 114 | 114 |
| 115 UrlDownloader::UrlDownloader( | 115 UrlDownloader::UrlDownloader( |
| 116 scoped_ptr<net::URLRequest> request, | 116 scoped_ptr<net::URLRequest> request, |
| 117 base::WeakPtr<DownloadManagerImpl> manager, | 117 base::WeakPtr<DownloadManagerImpl> manager, |
| 118 scoped_ptr<DownloadSaveInfo> save_info, | 118 scoped_ptr<DownloadSaveInfo> save_info, |
| 119 uint32 download_id, | 119 uint32_t download_id, |
| 120 const DownloadUrlParameters::OnStartedCallback& on_started_callback) | 120 const DownloadUrlParameters::OnStartedCallback& on_started_callback) |
| 121 : request_(std::move(request)), | 121 : request_(std::move(request)), |
| 122 manager_(manager), | 122 manager_(manager), |
| 123 download_id_(download_id), | 123 download_id_(download_id), |
| 124 on_started_callback_(on_started_callback), | 124 on_started_callback_(on_started_callback), |
| 125 handler_( | 125 handler_( |
| 126 request_.get(), | 126 request_.get(), |
| 127 std::move(save_info), | 127 std::move(save_info), |
| 128 base::Bind(&UrlDownloader::ResumeReading, base::Unretained(this))), | 128 base::Bind(&UrlDownloader::ResumeReading, base::Unretained(this))), |
| 129 weak_ptr_factory_(this) {} | 129 weak_ptr_factory_(this) {} |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 handler_.ResumeRequest(); | 282 handler_.ResumeRequest(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void UrlDownloader::CancelRequest() { | 285 void UrlDownloader::CancelRequest() { |
| 286 BrowserThread::PostTask( | 286 BrowserThread::PostTask( |
| 287 BrowserThread::UI, FROM_HERE, | 287 BrowserThread::UI, FROM_HERE, |
| 288 base::Bind(&DownloadManagerImpl::RemoveUrlDownloader, manager_, this)); | 288 base::Bind(&DownloadManagerImpl::RemoveUrlDownloader, manager_, this)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 } // namespace content | 291 } // namespace content |
| OLD | NEW |