OLD | NEW |
1 // Copyright (c) 2011 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_item_impl.h" | 5 #include "content/browser/download/download_item_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 // Our download table ID starts at 1, so we use 0 to represent a download that | 155 // Our download table ID starts at 1, so we use 0 to represent a download that |
156 // has started, but has not yet had its data persisted in the table. We use fake | 156 // has started, but has not yet had its data persisted in the table. We use fake |
157 // database handles in incognito mode starting at -1 and progressively getting | 157 // database handles in incognito mode starting at -1 and progressively getting |
158 // more negative. | 158 // more negative. |
159 | 159 |
160 // Constructor for reading from the history service. | 160 // Constructor for reading from the history service. |
161 DownloadItemImpl::DownloadItemImpl(Delegate* delegate, | 161 DownloadItemImpl::DownloadItemImpl(Delegate* delegate, |
162 DownloadId download_id, | 162 DownloadId download_id, |
163 const DownloadPersistentStoreInfo& info) | 163 const DownloadPersistentStoreInfo& info, |
| 164 const net::BoundNetLog& bound_net_log) |
164 : download_id_(download_id), | 165 : download_id_(download_id), |
165 full_path_(info.path), | 166 full_path_(info.path), |
166 url_chain_(1, info.url), | 167 url_chain_(1, info.url), |
167 referrer_url_(info.referrer_url), | 168 referrer_url_(info.referrer_url), |
168 total_bytes_(info.total_bytes), | 169 total_bytes_(info.total_bytes), |
169 received_bytes_(info.received_bytes), | 170 received_bytes_(info.received_bytes), |
170 bytes_per_sec_(0), | 171 bytes_per_sec_(0), |
171 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 172 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
172 start_tick_(base::TimeTicks()), | 173 start_tick_(base::TimeTicks()), |
173 state_(static_cast<DownloadState>(info.state)), | 174 state_(static_cast<DownloadState>(info.state)), |
174 start_time_(info.start_time), | 175 start_time_(info.start_time), |
175 end_time_(info.end_time), | 176 end_time_(info.end_time), |
176 db_handle_(info.db_handle), | 177 db_handle_(info.db_handle), |
177 delegate_(delegate), | 178 delegate_(delegate), |
178 is_paused_(false), | 179 is_paused_(false), |
179 open_when_complete_(false), | 180 open_when_complete_(false), |
180 file_externally_removed_(false), | 181 file_externally_removed_(false), |
181 safety_state_(SAFE), | 182 safety_state_(SAFE), |
182 auto_opened_(false), | 183 auto_opened_(false), |
183 is_otr_(false), | 184 is_otr_(false), |
184 is_temporary_(false), | 185 is_temporary_(false), |
185 all_data_saved_(false), | 186 all_data_saved_(false), |
186 opened_(info.opened), | 187 opened_(info.opened), |
187 open_enabled_(true), | 188 open_enabled_(true), |
188 delegate_delayed_complete_(false) { | 189 delegate_delayed_complete_(false), |
| 190 bound_net_log_(bound_net_log) { |
189 delegate_->Attach(); | 191 delegate_->Attach(); |
190 if (IsInProgress()) | 192 if (IsInProgress()) |
191 state_ = CANCELLED; | 193 state_ = CANCELLED; |
192 if (IsComplete()) | 194 if (IsComplete()) |
193 all_data_saved_ = true; | 195 all_data_saved_ = true; |
194 Init(false /* not actively downloading */); | 196 Init(false /* not actively downloading */, |
| 197 download_net_logs::SRC_HISTORY_IMPORT); |
195 } | 198 } |
196 | 199 |
197 // Constructing for a regular download: | 200 // Constructing for a regular download: |
198 DownloadItemImpl::DownloadItemImpl( | 201 DownloadItemImpl::DownloadItemImpl( |
199 Delegate* delegate, | 202 Delegate* delegate, |
200 const DownloadCreateInfo& info, | 203 const DownloadCreateInfo& info, |
201 DownloadRequestHandleInterface* request_handle, | 204 DownloadRequestHandleInterface* request_handle, |
202 bool is_otr) | 205 bool is_otr, |
| 206 const net::BoundNetLog& bound_net_log) |
203 : state_info_(info.original_name, info.save_info.file_path, | 207 : state_info_(info.original_name, info.save_info.file_path, |
204 info.has_user_gesture, info.transition_type, | 208 info.has_user_gesture, info.transition_type, |
205 info.prompt_user_for_save_location), | 209 info.prompt_user_for_save_location), |
206 request_handle_(request_handle), | 210 request_handle_(request_handle), |
207 download_id_(info.download_id), | 211 download_id_(info.download_id), |
208 full_path_(info.path), | 212 full_path_(info.path), |
209 url_chain_(info.url_chain), | 213 url_chain_(info.url_chain), |
210 referrer_url_(info.referrer_url), | 214 referrer_url_(info.referrer_url), |
211 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), | 215 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), |
212 content_disposition_(info.content_disposition), | 216 content_disposition_(info.content_disposition), |
(...skipping 13 matching lines...) Expand all Loading... |
226 is_paused_(false), | 230 is_paused_(false), |
227 open_when_complete_(false), | 231 open_when_complete_(false), |
228 file_externally_removed_(false), | 232 file_externally_removed_(false), |
229 safety_state_(SAFE), | 233 safety_state_(SAFE), |
230 auto_opened_(false), | 234 auto_opened_(false), |
231 is_otr_(is_otr), | 235 is_otr_(is_otr), |
232 is_temporary_(!info.save_info.file_path.empty()), | 236 is_temporary_(!info.save_info.file_path.empty()), |
233 all_data_saved_(false), | 237 all_data_saved_(false), |
234 opened_(false), | 238 opened_(false), |
235 open_enabled_(true), | 239 open_enabled_(true), |
236 delegate_delayed_complete_(false) { | 240 delegate_delayed_complete_(false), |
| 241 bound_net_log_(bound_net_log) { |
237 delegate_->Attach(); | 242 delegate_->Attach(); |
238 Init(true /* actively downloading */); | 243 Init(true /* actively downloading */, |
| 244 download_net_logs::SRC_NEW_DOWNLOAD); |
239 } | 245 } |
240 | 246 |
241 // Constructing for the "Save Page As..." feature: | 247 // Constructing for the "Save Page As..." feature: |
242 DownloadItemImpl::DownloadItemImpl(Delegate* delegate, | 248 DownloadItemImpl::DownloadItemImpl(Delegate* delegate, |
243 const FilePath& path, | 249 const FilePath& path, |
244 const GURL& url, | 250 const GURL& url, |
245 bool is_otr, | 251 bool is_otr, |
246 DownloadId download_id) | 252 DownloadId download_id, |
| 253 const net::BoundNetLog& bound_net_log) |
247 : request_handle_(new NullDownloadRequestHandle()), | 254 : request_handle_(new NullDownloadRequestHandle()), |
248 download_id_(download_id), | 255 download_id_(download_id), |
249 full_path_(path), | 256 full_path_(path), |
250 url_chain_(1, url), | 257 url_chain_(1, url), |
251 referrer_url_(GURL()), | 258 referrer_url_(GURL()), |
252 total_bytes_(0), | 259 total_bytes_(0), |
253 received_bytes_(0), | 260 received_bytes_(0), |
254 bytes_per_sec_(0), | 261 bytes_per_sec_(0), |
255 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 262 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
256 start_tick_(base::TimeTicks::Now()), | 263 start_tick_(base::TimeTicks::Now()), |
257 state_(IN_PROGRESS), | 264 state_(IN_PROGRESS), |
258 start_time_(base::Time::Now()), | 265 start_time_(base::Time::Now()), |
259 db_handle_(DownloadItem::kUninitializedHandle), | 266 db_handle_(DownloadItem::kUninitializedHandle), |
260 delegate_(delegate), | 267 delegate_(delegate), |
261 is_paused_(false), | 268 is_paused_(false), |
262 open_when_complete_(false), | 269 open_when_complete_(false), |
263 file_externally_removed_(false), | 270 file_externally_removed_(false), |
264 safety_state_(SAFE), | 271 safety_state_(SAFE), |
265 auto_opened_(false), | 272 auto_opened_(false), |
266 is_otr_(is_otr), | 273 is_otr_(is_otr), |
267 is_temporary_(false), | 274 is_temporary_(false), |
268 all_data_saved_(false), | 275 all_data_saved_(false), |
269 opened_(false), | 276 opened_(false), |
270 open_enabled_(true), | 277 open_enabled_(true), |
271 delegate_delayed_complete_(false) { | 278 delegate_delayed_complete_(false), |
| 279 bound_net_log_(bound_net_log) { |
272 delegate_->Attach(); | 280 delegate_->Attach(); |
273 Init(true /* actively downloading */); | 281 Init(true /* actively downloading */, |
| 282 download_net_logs::SRC_SAVE_PAGE_AS); |
274 } | 283 } |
275 | 284 |
276 DownloadItemImpl::~DownloadItemImpl() { | 285 DownloadItemImpl::~DownloadItemImpl() { |
277 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 286 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
278 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 287 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
279 | 288 |
280 TransitionTo(REMOVING); | 289 TransitionTo(REMOVING); |
281 STLDeleteContainerPairSecondPointers( | 290 STLDeleteContainerPairSecondPointers( |
282 external_data_map_.begin(), external_data_map_.end()); | 291 external_data_map_.begin(), external_data_map_.end()); |
283 delegate_->AssertStateConsistent(this); | 292 delegate_->AssertStateConsistent(this); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 365 |
357 void DownloadItemImpl::DangerousDownloadValidated() { | 366 void DownloadItemImpl::DangerousDownloadValidated() { |
358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
359 DCHECK_EQ(DANGEROUS, GetSafetyState()); | 368 DCHECK_EQ(DANGEROUS, GetSafetyState()); |
360 | 369 |
361 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated", | 370 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated", |
362 GetDangerType(), | 371 GetDangerType(), |
363 content::DOWNLOAD_DANGER_TYPE_MAX); | 372 content::DOWNLOAD_DANGER_TYPE_MAX); |
364 | 373 |
365 safety_state_ = DANGEROUS_BUT_VALIDATED; | 374 safety_state_ = DANGEROUS_BUT_VALIDATED; |
| 375 |
| 376 bound_net_log_.AddEvent( |
| 377 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
| 378 make_scoped_refptr(new download_net_logs::ItemCheckedParameters( |
| 379 GetDangerType(), GetSafetyState()))); |
| 380 |
366 UpdateObservers(); | 381 UpdateObservers(); |
367 | 382 |
368 delegate_->MaybeCompleteDownload(this); | 383 delegate_->MaybeCompleteDownload(this); |
369 } | 384 } |
370 | 385 |
371 void DownloadItemImpl::ProgressComplete(int64 bytes_so_far, | 386 void DownloadItemImpl::ProgressComplete(int64 bytes_so_far, |
372 const std::string& final_hash) { | 387 const std::string& final_hash) { |
373 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 388 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
374 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 389 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
375 | 390 |
(...skipping 11 matching lines...) Expand all Loading... |
387 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, | 402 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, |
388 const std::string& hash_state) { | 403 const std::string& hash_state) { |
389 hash_state_ = hash_state; | 404 hash_state_ = hash_state; |
390 | 405 |
391 received_bytes_ = bytes_so_far; | 406 received_bytes_ = bytes_so_far; |
392 | 407 |
393 // If we've received more data than we were expecting (bad server info?), | 408 // If we've received more data than we were expecting (bad server info?), |
394 // revert to 'unknown size mode'. | 409 // revert to 'unknown size mode'. |
395 if (received_bytes_ > total_bytes_) | 410 if (received_bytes_ > total_bytes_) |
396 total_bytes_ = 0; | 411 total_bytes_ = 0; |
| 412 |
| 413 if (bound_net_log_.IsLoggingAllEvents()) { |
| 414 bound_net_log_.AddEvent( |
| 415 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, |
| 416 make_scoped_refptr( |
| 417 new download_net_logs::ItemUpdatedParameters(received_bytes_))); |
| 418 } |
397 } | 419 } |
398 | 420 |
399 // Updates from the download thread may have been posted while this download | 421 // Updates from the download thread may have been posted while this download |
400 // was being cancelled in the UI thread, so we'll accept them unless we're | 422 // was being cancelled in the UI thread, so we'll accept them unless we're |
401 // complete. | 423 // complete. |
402 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, | 424 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, |
403 int64 bytes_per_sec, | 425 int64 bytes_per_sec, |
404 const std::string& hash_state) { | 426 const std::string& hash_state) { |
405 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 427 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
406 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 428 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 518 |
497 auto_opened_ = true; | 519 auto_opened_ = true; |
498 UpdateObservers(); | 520 UpdateObservers(); |
499 } | 521 } |
500 } | 522 } |
501 | 523 |
502 void DownloadItemImpl::TransitionTo(DownloadState new_state) { | 524 void DownloadItemImpl::TransitionTo(DownloadState new_state) { |
503 if (state_ == new_state) | 525 if (state_ == new_state) |
504 return; | 526 return; |
505 | 527 |
| 528 DownloadState old_state = state_; |
506 state_ = new_state; | 529 state_ = new_state; |
| 530 |
| 531 switch (state_) { |
| 532 case COMPLETE: |
| 533 bound_net_log_.AddEvent( |
| 534 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, |
| 535 make_scoped_refptr( |
| 536 new download_net_logs::ItemFinishedParameters(received_bytes_, |
| 537 hash_))); |
| 538 break; |
| 539 case INTERRUPTED: |
| 540 bound_net_log_.AddEvent( |
| 541 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, |
| 542 make_scoped_refptr( |
| 543 new download_net_logs::ItemInterruptedParameters(last_reason_, |
| 544 received_bytes_, |
| 545 hash_state_))); |
| 546 break; |
| 547 case CANCELLED: |
| 548 bound_net_log_.AddEvent( |
| 549 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, |
| 550 make_scoped_refptr( |
| 551 new download_net_logs::ItemCanceledParameters(received_bytes_, |
| 552 hash_state_))); |
| 553 break; |
| 554 default: |
| 555 break; |
| 556 } |
| 557 |
507 UpdateObservers(); | 558 UpdateObservers(); |
| 559 |
| 560 bool is_done = (state_ != IN_PROGRESS); |
| 561 bool was_done = (old_state != IN_PROGRESS); |
| 562 if (is_done && !was_done) |
| 563 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, NULL); |
508 } | 564 } |
509 | 565 |
510 void DownloadItemImpl::UpdateSafetyState() { | 566 void DownloadItemImpl::UpdateSafetyState() { |
511 SafetyState updated_value = state_info_.IsDangerous() ? | 567 SafetyState updated_value = state_info_.IsDangerous() ? |
512 DownloadItem::DANGEROUS : DownloadItem::SAFE; | 568 DownloadItem::DANGEROUS : DownloadItem::SAFE; |
513 if (updated_value != safety_state_) { | 569 if (updated_value != safety_state_) { |
514 safety_state_ = updated_value; | 570 safety_state_ = updated_value; |
| 571 |
| 572 bound_net_log_.AddEvent( |
| 573 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
| 574 make_scoped_refptr(new download_net_logs::ItemCheckedParameters( |
| 575 GetDangerType(), GetSafetyState()))); |
| 576 |
515 UpdateObservers(); | 577 UpdateObservers(); |
516 } | 578 } |
517 } | 579 } |
518 | 580 |
519 void DownloadItemImpl::UpdateTarget() { | 581 void DownloadItemImpl::UpdateTarget() { |
520 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 582 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
521 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 583 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
522 | 584 |
523 if (state_info_.target_name.value().empty()) | 585 if (state_info_.target_name.value().empty()) |
524 state_info_.target_name = full_path_.BaseName(); | 586 state_info_.target_name = full_path_.BaseName(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 } | 679 } |
618 | 680 |
619 void DownloadItemImpl::Rename(const FilePath& full_path) { | 681 void DownloadItemImpl::Rename(const FilePath& full_path) { |
620 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 682 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
621 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 683 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
622 | 684 |
623 VLOG(20) << __FUNCTION__ << "()" | 685 VLOG(20) << __FUNCTION__ << "()" |
624 << " full_path = \"" << full_path.value() << "\"" | 686 << " full_path = \"" << full_path.value() << "\"" |
625 << " " << DebugString(true); | 687 << " " << DebugString(true); |
626 DCHECK(!full_path.empty()); | 688 DCHECK(!full_path.empty()); |
| 689 |
| 690 bound_net_log_.AddEvent( |
| 691 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, |
| 692 make_scoped_refptr( |
| 693 new download_net_logs::ItemRenamedParameters( |
| 694 full_path_.AsUTF8Unsafe(), full_path.AsUTF8Unsafe()))); |
| 695 |
627 full_path_ = full_path; | 696 full_path_ = full_path; |
628 } | 697 } |
629 | 698 |
630 void DownloadItemImpl::TogglePause() { | 699 void DownloadItemImpl::TogglePause() { |
631 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 700 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
632 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 701 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
633 | 702 |
634 DCHECK(IsInProgress()); | 703 DCHECK(IsInProgress()); |
635 if (is_paused_) | 704 if (is_paused_) |
636 request_handle_->ResumeRequest(); | 705 request_handle_->ResumeRequest(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 void DownloadItemImpl::OffThreadCancel(DownloadFileManager* file_manager) { | 873 void DownloadItemImpl::OffThreadCancel(DownloadFileManager* file_manager) { |
805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 874 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
806 request_handle_->CancelRequest(); | 875 request_handle_->CancelRequest(); |
807 | 876 |
808 BrowserThread::PostTask( | 877 BrowserThread::PostTask( |
809 BrowserThread::FILE, FROM_HERE, | 878 BrowserThread::FILE, FROM_HERE, |
810 base::Bind(&DownloadFileManager::CancelDownload, | 879 base::Bind(&DownloadFileManager::CancelDownload, |
811 file_manager, download_id_)); | 880 file_manager, download_id_)); |
812 } | 881 } |
813 | 882 |
814 void DownloadItemImpl::Init(bool active) { | 883 void DownloadItemImpl::Init(bool active, |
| 884 download_net_logs::DownloadType download_type) { |
815 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 885 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
816 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 886 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
817 | 887 |
818 UpdateTarget(); | 888 UpdateTarget(); |
819 if (active) | 889 if (active) |
820 download_stats::RecordDownloadCount(download_stats::START_COUNT); | 890 download_stats::RecordDownloadCount(download_stats::START_COUNT); |
| 891 |
| 892 std::string file_name; |
| 893 if (download_type == download_net_logs::SRC_HISTORY_IMPORT) { |
| 894 // full_path_ works for History and Save As versions. |
| 895 file_name = full_path_.AsUTF8Unsafe(); |
| 896 } else { |
| 897 // See if it's set programmatically. |
| 898 file_name = state_info_.force_file_name.AsUTF8Unsafe(); |
| 899 // Possibly has a 'download' attribute for the anchor. |
| 900 if (file_name.empty()) |
| 901 file_name = suggested_filename_; |
| 902 // From the URL file name. |
| 903 if (file_name.empty()) |
| 904 file_name = GetURL().ExtractFileName(); |
| 905 } |
| 906 |
| 907 bound_net_log_.BeginEvent( |
| 908 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, |
| 909 make_scoped_refptr(new download_net_logs::ItemActivatedParameters( |
| 910 download_type, |
| 911 download_id_.local(), |
| 912 GetOriginalUrl().spec(), |
| 913 GetURL().spec(), |
| 914 file_name, |
| 915 GetDangerType(), |
| 916 GetSafetyState(), |
| 917 received_bytes_))); |
| 918 |
| 919 // If this is not an active download, end the ACTIVE event now. |
| 920 if (!active) { |
| 921 bound_net_log_.AddEvent( |
| 922 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, |
| 923 make_scoped_refptr( |
| 924 new download_net_logs::ItemInHistoryParameters(db_handle_))); |
| 925 |
| 926 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, NULL); |
| 927 } |
| 928 |
821 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); | 929 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
822 } | 930 } |
823 | 931 |
824 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to | 932 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to |
825 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. | 933 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. |
826 bool DownloadItemImpl::IsPartialDownload() const { | 934 bool DownloadItemImpl::IsPartialDownload() const { |
827 return (state_ == IN_PROGRESS); | 935 return (state_ == IN_PROGRESS); |
828 } | 936 } |
829 | 937 |
830 bool DownloadItemImpl::IsInProgress() const { | 938 bool DownloadItemImpl::IsInProgress() const { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 } | 1048 } |
941 const std::string& DownloadItemImpl::GetHash() const { return hash_; } | 1049 const std::string& DownloadItemImpl::GetHash() const { return hash_; } |
942 int64 DownloadItemImpl::GetReceivedBytes() const { return received_bytes_; } | 1050 int64 DownloadItemImpl::GetReceivedBytes() const { return received_bytes_; } |
943 const std::string& DownloadItemImpl::GetHashState() const { | 1051 const std::string& DownloadItemImpl::GetHashState() const { |
944 return hash_state_; | 1052 return hash_state_; |
945 } | 1053 } |
946 int32 DownloadItemImpl::GetId() const { return download_id_.local(); } | 1054 int32 DownloadItemImpl::GetId() const { return download_id_.local(); } |
947 DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; } | 1055 DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; } |
948 base::Time DownloadItemImpl::GetStartTime() const { return start_time_; } | 1056 base::Time DownloadItemImpl::GetStartTime() const { return start_time_; } |
949 base::Time DownloadItemImpl::GetEndTime() const { return end_time_; } | 1057 base::Time DownloadItemImpl::GetEndTime() const { return end_time_; } |
950 void DownloadItemImpl::SetDbHandle(int64 handle) { db_handle_ = handle; } | 1058 |
| 1059 void DownloadItemImpl::SetDbHandle(int64 handle) { |
| 1060 db_handle_ = handle; |
| 1061 |
| 1062 bound_net_log_.AddEvent( |
| 1063 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, |
| 1064 make_scoped_refptr( |
| 1065 new download_net_logs::ItemInHistoryParameters(db_handle_))); |
| 1066 } |
| 1067 |
951 int64 DownloadItemImpl::GetDbHandle() const { return db_handle_; } | 1068 int64 DownloadItemImpl::GetDbHandle() const { return db_handle_; } |
952 bool DownloadItemImpl::IsPaused() const { return is_paused_; } | 1069 bool DownloadItemImpl::IsPaused() const { return is_paused_; } |
953 bool DownloadItemImpl::GetOpenWhenComplete() const { | 1070 bool DownloadItemImpl::GetOpenWhenComplete() const { |
954 return open_when_complete_; | 1071 return open_when_complete_; |
955 } | 1072 } |
956 void DownloadItemImpl::SetOpenWhenComplete(bool open) { | 1073 void DownloadItemImpl::SetOpenWhenComplete(bool open) { |
957 open_when_complete_ = open; | 1074 open_when_complete_ = open; |
958 } | 1075 } |
959 bool DownloadItemImpl::GetFileExternallyRemoved() const { | 1076 bool DownloadItemImpl::GetFileExternallyRemoved() const { |
960 return file_externally_removed_; | 1077 return file_externally_removed_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 std::map<const void*, ExternalData*>::iterator it = | 1118 std::map<const void*, ExternalData*>::iterator it = |
1002 external_data_map_.find(key); | 1119 external_data_map_.find(key); |
1003 | 1120 |
1004 if (it == external_data_map_.end()) { | 1121 if (it == external_data_map_.end()) { |
1005 external_data_map_[key] = data; | 1122 external_data_map_[key] = data; |
1006 } else if (it->second != data) { | 1123 } else if (it->second != data) { |
1007 delete it->second; | 1124 delete it->second; |
1008 it->second = data; | 1125 it->second = data; |
1009 } | 1126 } |
1010 } | 1127 } |
OLD | NEW |