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_request_core.h" | 5 #include "content/browser/download/download_request_core.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 static void Attach(net::URLRequest* request, | 55 static void Attach(net::URLRequest* request, |
56 DownloadUrlParameters* download_parameters, | 56 DownloadUrlParameters* download_parameters, |
57 uint32_t download_id); | 57 uint32_t download_id); |
58 static DownloadRequestData* Get(net::URLRequest* request); | 58 static DownloadRequestData* Get(net::URLRequest* request); |
59 static void Detach(net::URLRequest* request); | 59 static void Detach(net::URLRequest* request); |
60 | 60 |
61 std::unique_ptr<DownloadSaveInfo> TakeSaveInfo() { | 61 std::unique_ptr<DownloadSaveInfo> TakeSaveInfo() { |
62 return std::move(save_info_); | 62 return std::move(save_info_); |
63 } | 63 } |
64 uint32_t download_id() const { return download_id_; } | 64 uint32_t download_id() const { return download_id_; } |
| 65 bool is_transient() const { return transient_; } |
65 const DownloadUrlParameters::OnStartedCallback& callback() const { | 66 const DownloadUrlParameters::OnStartedCallback& callback() const { |
66 return on_started_callback_; | 67 return on_started_callback_; |
67 } | 68 } |
68 | 69 |
69 private: | 70 private: |
70 static const int kKey; | 71 static const int kKey; |
71 | 72 |
72 std::unique_ptr<DownloadSaveInfo> save_info_; | 73 std::unique_ptr<DownloadSaveInfo> save_info_; |
73 uint32_t download_id_ = DownloadItem::kInvalidId; | 74 uint32_t download_id_ = DownloadItem::kInvalidId; |
| 75 bool transient_ = false; |
74 DownloadUrlParameters::OnStartedCallback on_started_callback_; | 76 DownloadUrlParameters::OnStartedCallback on_started_callback_; |
75 }; | 77 }; |
76 | 78 |
77 // static | 79 // static |
78 const int DownloadRequestData::kKey = 0; | 80 const int DownloadRequestData::kKey = 0; |
79 | 81 |
80 // static | 82 // static |
81 void DownloadRequestData::Attach(net::URLRequest* request, | 83 void DownloadRequestData::Attach(net::URLRequest* request, |
82 DownloadUrlParameters* parameters, | 84 DownloadUrlParameters* parameters, |
83 uint32_t download_id) { | 85 uint32_t download_id) { |
84 DownloadRequestData* request_data = new DownloadRequestData; | 86 DownloadRequestData* request_data = new DownloadRequestData; |
85 request_data->save_info_.reset( | 87 request_data->save_info_.reset( |
86 new DownloadSaveInfo(parameters->GetSaveInfo())); | 88 new DownloadSaveInfo(parameters->GetSaveInfo())); |
87 request_data->download_id_ = download_id; | 89 request_data->download_id_ = download_id; |
| 90 request_data->transient_ = parameters->is_transient(); |
88 request_data->on_started_callback_ = parameters->callback(); | 91 request_data->on_started_callback_ = parameters->callback(); |
89 request->SetUserData(&kKey, request_data); | 92 request->SetUserData(&kKey, request_data); |
90 } | 93 } |
91 | 94 |
92 // static | 95 // static |
93 DownloadRequestData* DownloadRequestData::Get(net::URLRequest* request) { | 96 DownloadRequestData* DownloadRequestData::Get(net::URLRequest* request) { |
94 return static_cast<DownloadRequestData*>(request->GetUserData(&kKey)); | 97 return static_cast<DownloadRequestData*>(request->GetUserData(&kKey)); |
95 } | 98 } |
96 | 99 |
97 // static | 100 // static |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 RecordDownloadCount(UNTHROTTLED_COUNT); | 195 RecordDownloadCount(UNTHROTTLED_COUNT); |
193 power_save_blocker_.reset(new device::PowerSaveBlocker( | 196 power_save_blocker_.reset(new device::PowerSaveBlocker( |
194 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 197 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
195 device::PowerSaveBlocker::kReasonOther, "Download in progress", | 198 device::PowerSaveBlocker::kReasonOther, "Download in progress", |
196 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 199 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
197 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 200 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
198 DownloadRequestData* request_data = DownloadRequestData::Get(request_); | 201 DownloadRequestData* request_data = DownloadRequestData::Get(request_); |
199 if (request_data) { | 202 if (request_data) { |
200 save_info_ = request_data->TakeSaveInfo(); | 203 save_info_ = request_data->TakeSaveInfo(); |
201 download_id_ = request_data->download_id(); | 204 download_id_ = request_data->download_id(); |
| 205 transient_ = request_data->is_transient(); |
202 on_started_callback_ = request_data->callback(); | 206 on_started_callback_ = request_data->callback(); |
203 DownloadRequestData::Detach(request_); | 207 DownloadRequestData::Detach(request_); |
204 is_partial_request_ = save_info_->offset > 0; | 208 is_partial_request_ = save_info_->offset > 0; |
205 } else { | 209 } else { |
206 save_info_.reset(new DownloadSaveInfo); | 210 save_info_.reset(new DownloadSaveInfo); |
207 } | 211 } |
208 } | 212 } |
209 | 213 |
210 DownloadRequestCore::~DownloadRequestCore() { | 214 DownloadRequestCore::~DownloadRequestCore() { |
211 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
212 // Remove output stream callback if a stream exists. | 216 // Remove output stream callback if a stream exists. |
213 if (stream_writer_) | 217 if (stream_writer_) |
214 stream_writer_->RegisterCallback(base::Closure()); | 218 stream_writer_->RegisterCallback(base::Closure()); |
215 } | 219 } |
216 | 220 |
217 std::unique_ptr<DownloadCreateInfo> | 221 std::unique_ptr<DownloadCreateInfo> |
218 DownloadRequestCore::CreateDownloadCreateInfo(DownloadInterruptReason result) { | 222 DownloadRequestCore::CreateDownloadCreateInfo(DownloadInterruptReason result) { |
219 DCHECK(!started_); | 223 DCHECK(!started_); |
220 started_ = true; | 224 started_ = true; |
221 std::unique_ptr<DownloadCreateInfo> create_info(new DownloadCreateInfo( | 225 std::unique_ptr<DownloadCreateInfo> create_info(new DownloadCreateInfo( |
222 base::Time::Now(), request()->net_log(), std::move(save_info_))); | 226 base::Time::Now(), request()->net_log(), std::move(save_info_))); |
223 | 227 |
224 if (result == DOWNLOAD_INTERRUPT_REASON_NONE) | 228 if (result == DOWNLOAD_INTERRUPT_REASON_NONE) |
225 create_info->remote_address = request()->GetSocketAddress().host(); | 229 create_info->remote_address = request()->GetSocketAddress().host(); |
226 create_info->connection_info = request()->response_info().connection_info; | 230 create_info->connection_info = request()->response_info().connection_info; |
227 create_info->url_chain = request()->url_chain(); | 231 create_info->url_chain = request()->url_chain(); |
228 create_info->referrer_url = GURL(request()->referrer()); | 232 create_info->referrer_url = GURL(request()->referrer()); |
229 create_info->result = result; | 233 create_info->result = result; |
230 create_info->download_id = download_id_; | 234 create_info->download_id = download_id_; |
| 235 create_info->transient = transient_; |
231 create_info->offset = create_info->save_info->offset; | 236 create_info->offset = create_info->save_info->offset; |
232 create_info->length = create_info->save_info->length; | 237 create_info->length = create_info->save_info->length; |
233 return create_info; | 238 return create_info; |
234 } | 239 } |
235 | 240 |
236 bool DownloadRequestCore::OnResponseStarted( | 241 bool DownloadRequestCore::OnResponseStarted( |
237 const std::string& override_mime_type) { | 242 const std::string& override_mime_type) { |
238 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 243 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
239 DVLOG(20) << __func__ << "() " << DebugString(); | 244 DVLOG(20) << __func__ << "() " << DebugString(); |
240 download_start_time_ = base::TimeTicks::Now(); | 245 download_start_time_ = base::TimeTicks::Now(); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 // old servers that didn't implement "If-Match" and must be ignored when | 675 // old servers that didn't implement "If-Match" and must be ignored when |
671 // "If-Match" presents. | 676 // "If-Match" presents. |
672 if (has_last_modified) { | 677 if (has_last_modified) { |
673 request->SetExtraRequestHeaderByName( | 678 request->SetExtraRequestHeaderByName( |
674 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(), | 679 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(), |
675 true); | 680 true); |
676 } | 681 } |
677 } | 682 } |
678 | 683 |
679 } // namespace content | 684 } // namespace content |
OLD | NEW |