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 // File method ordering: Methods in this file are in the same order as | 5 // File method ordering: Methods in this file are in the same order as |
6 // in download_item_impl.h, with the following exception: The public | 6 // in download_item_impl.h, with the following exception: The public |
7 // interfaces Start, DelayedDownloadOpened, MaybeCompleteDownload, and | 7 // interfaces Start, DelayedDownloadOpened, MaybeCompleteDownload, and |
8 // OnDownloadCompleting are placed in chronological order with the other | 8 // OnDownloadCompleting are placed in chronological order with the other |
9 // (private) routines that together define a DownloadItem's state transitions | 9 // (private) routines that together define a DownloadItem's state transitions |
10 // as the download progresses. See "Download progression cascade" later in | 10 // as the download progresses. See "Download progression cascade" later in |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "base/utf_string_conversions.h" | 37 #include "base/utf_string_conversions.h" |
38 #include "content/browser/download/download_create_info.h" | 38 #include "content/browser/download/download_create_info.h" |
39 #include "content/browser/download/download_file.h" | 39 #include "content/browser/download/download_file.h" |
40 #include "content/browser/download/download_interrupt_reasons_impl.h" | 40 #include "content/browser/download/download_interrupt_reasons_impl.h" |
41 #include "content/browser/download/download_item_impl_delegate.h" | 41 #include "content/browser/download/download_item_impl_delegate.h" |
42 #include "content/browser/download/download_request_handle.h" | 42 #include "content/browser/download/download_request_handle.h" |
43 #include "content/browser/download/download_stats.h" | 43 #include "content/browser/download/download_stats.h" |
44 #include "content/browser/web_contents/web_contents_impl.h" | 44 #include "content/browser/web_contents/web_contents_impl.h" |
45 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
46 #include "content/public/browser/content_browser_client.h" | 46 #include "content/public/browser/content_browser_client.h" |
47 #include "content/public/browser/download_persistent_store_info.h" | |
48 #include "net/base/net_util.h" | 47 #include "net/base/net_util.h" |
49 | 48 |
50 namespace content { | 49 namespace content { |
51 namespace { | 50 namespace { |
52 | 51 |
53 static void DeleteDownloadedFile(const FilePath& path) { | 52 static void DeleteDownloadedFile(const FilePath& path) { |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
55 | 54 |
56 // Make sure we only delete files. | 55 // Make sure we only delete files. |
57 if (!file_util::DirectoryExists(path)) | 56 if (!file_util::DirectoryExists(path)) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 download_file->Detach(callback); | 105 download_file->Detach(callback); |
107 } | 106 } |
108 | 107 |
109 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { | 108 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
111 download_file->Cancel(); | 110 download_file->Cancel(); |
112 } | 111 } |
113 | 112 |
114 } // namespace | 113 } // namespace |
115 | 114 |
116 // Our download table ID starts at 1, so we use 0 to represent a download that | |
117 // has started, but has not yet had its data persisted in the table. We use fake | |
118 // database handles in incognito mode starting at -1 and progressively getting | |
119 // more negative. | |
120 // static | |
121 const int DownloadItem::kUninitializedHandle = 0; | |
122 | |
123 const char DownloadItem::kEmptyFileHash[] = ""; | 115 const char DownloadItem::kEmptyFileHash[] = ""; |
124 | 116 |
125 // Our download table ID starts at 1, so we use 0 to represent a download that | |
126 // has started, but has not yet had its data persisted in the table. We use fake | |
127 // database handles in incognito mode starting at -1 and progressively getting | |
128 // more negative. | |
129 | |
130 // Constructor for reading from the history service. | 117 // Constructor for reading from the history service. |
131 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, | 118 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, |
132 DownloadId download_id, | 119 DownloadId download_id, |
133 const DownloadPersistentStoreInfo& info, | 120 const FilePath& path, |
| 121 const GURL& url, |
| 122 const GURL& referrer_url, |
| 123 const base::Time& start_time, |
| 124 const base::Time& end_time, |
| 125 int64 received_bytes, |
| 126 int64 total_bytes, |
| 127 DownloadItem::DownloadState state, |
| 128 bool opened, |
134 const net::BoundNetLog& bound_net_log) | 129 const net::BoundNetLog& bound_net_log) |
135 : is_save_package_download_(false), | 130 : is_save_package_download_(false), |
136 download_id_(download_id), | 131 download_id_(download_id), |
137 current_path_(info.path), | 132 current_path_(path), |
138 target_path_(info.path), | 133 target_path_(path), |
139 target_disposition_(TARGET_DISPOSITION_OVERWRITE), | 134 target_disposition_(TARGET_DISPOSITION_OVERWRITE), |
140 url_chain_(1, info.url), | 135 url_chain_(1, url), |
141 referrer_url_(info.referrer_url), | 136 referrer_url_(referrer_url), |
142 transition_type_(PAGE_TRANSITION_LINK), | 137 transition_type_(PAGE_TRANSITION_LINK), |
143 has_user_gesture_(false), | 138 has_user_gesture_(false), |
144 total_bytes_(info.total_bytes), | 139 total_bytes_(total_bytes), |
145 received_bytes_(info.received_bytes), | 140 received_bytes_(received_bytes), |
146 bytes_per_sec_(0), | 141 bytes_per_sec_(0), |
147 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 142 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
148 start_tick_(base::TimeTicks()), | 143 start_tick_(base::TimeTicks()), |
149 state_(ExternalToInternalState(info.state)), | 144 state_(ExternalToInternalState(state)), |
150 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), | 145 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), |
151 start_time_(info.start_time), | 146 start_time_(start_time), |
152 end_time_(info.end_time), | 147 end_time_(end_time), |
153 db_handle_(info.db_handle), | |
154 delegate_(delegate), | 148 delegate_(delegate), |
155 is_paused_(false), | 149 is_paused_(false), |
156 open_when_complete_(false), | 150 open_when_complete_(false), |
157 file_externally_removed_(false), | 151 file_externally_removed_(false), |
158 safety_state_(SAFE), | 152 safety_state_(SAFE), |
159 auto_opened_(false), | 153 auto_opened_(false), |
160 is_persisted_(true), | |
161 is_temporary_(false), | 154 is_temporary_(false), |
162 all_data_saved_(false), | 155 all_data_saved_(false), |
163 opened_(info.opened), | 156 opened_(opened), |
164 open_enabled_(true), | 157 open_enabled_(true), |
165 delegate_delayed_complete_(false), | 158 delegate_delayed_complete_(false), |
166 bound_net_log_(bound_net_log), | 159 bound_net_log_(bound_net_log), |
167 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 160 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
168 delegate_->Attach(); | 161 delegate_->Attach(); |
169 if (state_ == IN_PROGRESS_INTERNAL) | 162 if (state_ == IN_PROGRESS_INTERNAL) |
170 state_ = CANCELLED_INTERNAL; | 163 state_ = CANCELLED_INTERNAL; |
171 if (state_ == COMPLETE_INTERNAL) | 164 if (state_ == COMPLETE_INTERNAL) |
172 all_data_saved_ = true; | 165 all_data_saved_ = true; |
173 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); | 166 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); |
(...skipping 22 matching lines...) Expand all Loading... |
196 original_mime_type_(info.original_mime_type), | 189 original_mime_type_(info.original_mime_type), |
197 remote_address_(info.remote_address), | 190 remote_address_(info.remote_address), |
198 total_bytes_(info.total_bytes), | 191 total_bytes_(info.total_bytes), |
199 received_bytes_(0), | 192 received_bytes_(0), |
200 bytes_per_sec_(0), | 193 bytes_per_sec_(0), |
201 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 194 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
202 start_tick_(base::TimeTicks::Now()), | 195 start_tick_(base::TimeTicks::Now()), |
203 state_(IN_PROGRESS_INTERNAL), | 196 state_(IN_PROGRESS_INTERNAL), |
204 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), | 197 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), |
205 start_time_(info.start_time), | 198 start_time_(info.start_time), |
206 db_handle_(DownloadItem::kUninitializedHandle), | |
207 delegate_(delegate), | 199 delegate_(delegate), |
208 is_paused_(false), | 200 is_paused_(false), |
209 open_when_complete_(false), | 201 open_when_complete_(false), |
210 file_externally_removed_(false), | 202 file_externally_removed_(false), |
211 safety_state_(SAFE), | 203 safety_state_(SAFE), |
212 auto_opened_(false), | 204 auto_opened_(false), |
213 is_persisted_(false), | |
214 is_temporary_(!info.save_info->file_path.empty()), | 205 is_temporary_(!info.save_info->file_path.empty()), |
215 all_data_saved_(false), | 206 all_data_saved_(false), |
216 opened_(false), | 207 opened_(false), |
217 open_enabled_(true), | 208 open_enabled_(true), |
218 delegate_delayed_complete_(false), | 209 delegate_delayed_complete_(false), |
219 bound_net_log_(bound_net_log), | 210 bound_net_log_(bound_net_log), |
220 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 211 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
221 delegate_->Attach(); | 212 delegate_->Attach(); |
222 Init(true /* actively downloading */, SRC_NEW_DOWNLOAD); | 213 Init(true /* actively downloading */, SRC_NEW_DOWNLOAD); |
223 | 214 |
(...skipping 27 matching lines...) Expand all Loading... |
251 mime_type_(mime_type), | 242 mime_type_(mime_type), |
252 original_mime_type_(mime_type), | 243 original_mime_type_(mime_type), |
253 total_bytes_(0), | 244 total_bytes_(0), |
254 received_bytes_(0), | 245 received_bytes_(0), |
255 bytes_per_sec_(0), | 246 bytes_per_sec_(0), |
256 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 247 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
257 start_tick_(base::TimeTicks::Now()), | 248 start_tick_(base::TimeTicks::Now()), |
258 state_(IN_PROGRESS_INTERNAL), | 249 state_(IN_PROGRESS_INTERNAL), |
259 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), | 250 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), |
260 start_time_(base::Time::Now()), | 251 start_time_(base::Time::Now()), |
261 db_handle_(DownloadItem::kUninitializedHandle), | |
262 delegate_(delegate), | 252 delegate_(delegate), |
263 is_paused_(false), | 253 is_paused_(false), |
264 open_when_complete_(false), | 254 open_when_complete_(false), |
265 file_externally_removed_(false), | 255 file_externally_removed_(false), |
266 safety_state_(SAFE), | 256 safety_state_(SAFE), |
267 auto_opened_(false), | 257 auto_opened_(false), |
268 is_persisted_(false), | |
269 is_temporary_(false), | 258 is_temporary_(false), |
270 all_data_saved_(false), | 259 all_data_saved_(false), |
271 opened_(false), | 260 opened_(false), |
272 open_enabled_(true), | 261 open_enabled_(true), |
273 delegate_delayed_complete_(false), | 262 delegate_delayed_complete_(false), |
274 bound_net_log_(bound_net_log), | 263 bound_net_log_(bound_net_log), |
275 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 264 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
276 delegate_->Attach(); | 265 delegate_->Attach(); |
277 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); | 266 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); |
278 } | 267 } |
(...skipping 26 matching lines...) Expand all Loading... |
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
306 | 295 |
307 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); | 296 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); |
308 } | 297 } |
309 | 298 |
310 void DownloadItemImpl::DangerousDownloadValidated() { | 299 void DownloadItemImpl::DangerousDownloadValidated() { |
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
312 DCHECK_EQ(IN_PROGRESS, GetState()); | 301 DCHECK_EQ(IN_PROGRESS, GetState()); |
313 DCHECK_EQ(DANGEROUS, GetSafetyState()); | 302 DCHECK_EQ(DANGEROUS, GetSafetyState()); |
314 | 303 |
| 304 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
| 305 |
315 if (GetState() != IN_PROGRESS) | 306 if (GetState() != IN_PROGRESS) |
316 return; | 307 return; |
317 | 308 |
318 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated", | 309 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated", |
319 GetDangerType(), | 310 GetDangerType(), |
320 DOWNLOAD_DANGER_TYPE_MAX); | 311 DOWNLOAD_DANGER_TYPE_MAX); |
321 | 312 |
322 safety_state_ = DANGEROUS_BUT_VALIDATED; | 313 safety_state_ = DANGEROUS_BUT_VALIDATED; |
323 | 314 |
324 bound_net_log_.AddEvent( | 315 bound_net_log_.AddEvent( |
325 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, | 316 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
326 base::Bind(&ItemCheckedNetLogCallback, | 317 base::Bind(&ItemCheckedNetLogCallback, |
327 GetDangerType(), GetSafetyState())); | 318 GetDangerType(), GetSafetyState())); |
328 | 319 |
329 UpdateObservers(); | 320 UpdateObservers(); |
330 | 321 |
331 MaybeCompleteDownload(); | 322 MaybeCompleteDownload(); |
332 } | 323 } |
333 | 324 |
334 void DownloadItemImpl::TogglePause() { | 325 void DownloadItemImpl::TogglePause() { |
335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
336 | |
337 DCHECK(state_ == IN_PROGRESS_INTERNAL || state_ == COMPLETING_INTERNAL); | 327 DCHECK(state_ == IN_PROGRESS_INTERNAL || state_ == COMPLETING_INTERNAL); |
| 328 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
338 | 329 |
339 // Ignore pauses when we've passed the commit point. | 330 // Ignore pauses when we've passed the commit point. |
340 if (state_ == COMPLETING_INTERNAL) | 331 if (state_ == COMPLETING_INTERNAL) |
341 return; | 332 return; |
342 | 333 |
343 if (is_paused_) | 334 if (is_paused_) |
344 request_handle_->ResumeRequest(); | 335 request_handle_->ResumeRequest(); |
345 else | 336 else |
346 request_handle_->PauseRequest(); | 337 request_handle_->PauseRequest(); |
347 is_paused_ = !is_paused_; | 338 is_paused_ = !is_paused_; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 444 } |
454 | 445 |
455 int32 DownloadItemImpl::GetId() const { | 446 int32 DownloadItemImpl::GetId() const { |
456 return download_id_.local(); | 447 return download_id_.local(); |
457 } | 448 } |
458 | 449 |
459 DownloadId DownloadItemImpl::GetGlobalId() const { | 450 DownloadId DownloadItemImpl::GetGlobalId() const { |
460 return download_id_; | 451 return download_id_; |
461 } | 452 } |
462 | 453 |
463 int64 DownloadItemImpl::GetDbHandle() const { | |
464 return db_handle_; | |
465 } | |
466 | |
467 DownloadItem::DownloadState DownloadItemImpl::GetState() const { | 454 DownloadItem::DownloadState DownloadItemImpl::GetState() const { |
468 return InternalToExternalState(state_); | 455 return InternalToExternalState(state_); |
469 } | 456 } |
470 | 457 |
471 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { | 458 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { |
472 return last_reason_; | 459 return last_reason_; |
473 } | 460 } |
474 | 461 |
475 bool DownloadItemImpl::IsPaused() const { | 462 bool DownloadItemImpl::IsPaused() const { |
476 return is_paused_; | 463 return is_paused_; |
477 } | 464 } |
478 | 465 |
479 bool DownloadItemImpl::IsTemporary() const { | 466 bool DownloadItemImpl::IsTemporary() const { |
480 return is_temporary_; | 467 return is_temporary_; |
481 } | 468 } |
482 | 469 |
483 bool DownloadItemImpl::IsPersisted() const { | |
484 return is_persisted_; | |
485 } | |
486 | |
487 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to | 470 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to |
488 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. | 471 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. |
489 bool DownloadItemImpl::IsPartialDownload() const { | 472 bool DownloadItemImpl::IsPartialDownload() const { |
490 return InternalToExternalState(state_) == IN_PROGRESS; | 473 return InternalToExternalState(state_) == IN_PROGRESS; |
491 } | 474 } |
492 | 475 |
493 bool DownloadItemImpl::IsInProgress() const { | 476 bool DownloadItemImpl::IsInProgress() const { |
494 return InternalToExternalState(state_) == IN_PROGRESS; | 477 return InternalToExternalState(state_) == IN_PROGRESS; |
495 } | 478 } |
496 | 479 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 676 } |
694 | 677 |
695 bool DownloadItemImpl::GetAutoOpened() { | 678 bool DownloadItemImpl::GetAutoOpened() { |
696 return auto_opened_; | 679 return auto_opened_; |
697 } | 680 } |
698 | 681 |
699 bool DownloadItemImpl::GetOpened() const { | 682 bool DownloadItemImpl::GetOpened() const { |
700 return opened_; | 683 return opened_; |
701 } | 684 } |
702 | 685 |
703 DownloadPersistentStoreInfo DownloadItemImpl::GetPersistentStoreInfo() const { | |
704 // TODO(asanka): Persist GetTargetFilePath() as well. | |
705 return DownloadPersistentStoreInfo(GetFullPath(), | |
706 GetURL(), | |
707 GetReferrerUrl(), | |
708 GetStartTime(), | |
709 GetEndTime(), | |
710 GetReceivedBytes(), | |
711 GetTotalBytes(), | |
712 GetState(), | |
713 GetDbHandle(), | |
714 GetOpened()); | |
715 } | |
716 | |
717 BrowserContext* DownloadItemImpl::GetBrowserContext() const { | 686 BrowserContext* DownloadItemImpl::GetBrowserContext() const { |
718 return delegate_->GetBrowserContext(); | 687 return delegate_->GetBrowserContext(); |
719 } | 688 } |
720 | 689 |
721 WebContents* DownloadItemImpl::GetWebContents() const { | 690 WebContents* DownloadItemImpl::GetWebContents() const { |
722 // TODO(rdsmith): Remove null check after removing GetWebContents() from | 691 // TODO(rdsmith): Remove null check after removing GetWebContents() from |
723 // paths that might be used by DownloadItems created from history import. | 692 // paths that might be used by DownloadItems created from history import. |
724 // Currently such items have null request_handle_s, where other items | 693 // Currently such items have null request_handle_s, where other items |
725 // (regular and SavePackage downloads) have actual objects off the pointer. | 694 // (regular and SavePackage downloads) have actual objects off the pointer. |
726 if (request_handle_.get()) | 695 if (request_handle_.get()) |
727 return request_handle_->GetWebContents(); | 696 return request_handle_->GetWebContents(); |
728 return NULL; | 697 return NULL; |
729 } | 698 } |
730 | 699 |
731 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { | 700 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { |
732 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
733 DCHECK(AllDataSaved()); | 702 DCHECK(AllDataSaved()); |
| 703 VLOG(20) << __FUNCTION__ << " danger_type=" << danger_type |
| 704 << " download=" << DebugString(true); |
734 SetDangerType(danger_type); | 705 SetDangerType(danger_type); |
735 UpdateObservers(); | 706 UpdateObservers(); |
736 } | 707 } |
737 | 708 |
738 void DownloadItemImpl::SetOpenWhenComplete(bool open) { | 709 void DownloadItemImpl::SetOpenWhenComplete(bool open) { |
739 open_when_complete_ = open; | 710 open_when_complete_ = open; |
740 } | 711 } |
741 | 712 |
742 void DownloadItemImpl::SetIsTemporary(bool temporary) { | 713 void DownloadItemImpl::SetIsTemporary(bool temporary) { |
743 is_temporary_ = temporary; | 714 is_temporary_ = temporary; |
(...skipping 23 matching lines...) Expand all Loading... |
767 ++iter; | 738 ++iter; |
768 for ( ; verbose && (iter != last); ++iter) { | 739 for ( ; verbose && (iter != last); ++iter) { |
769 url_list += " ->\n\t"; | 740 url_list += " ->\n\t"; |
770 const GURL& next_url = *iter; | 741 const GURL& next_url = *iter; |
771 url_list += next_url.spec(); | 742 url_list += next_url.spec(); |
772 } | 743 } |
773 } | 744 } |
774 | 745 |
775 if (verbose) { | 746 if (verbose) { |
776 description += base::StringPrintf( | 747 description += base::StringPrintf( |
777 " db_handle = %" PRId64 | |
778 " total = %" PRId64 | 748 " total = %" PRId64 |
779 " received = %" PRId64 | 749 " received = %" PRId64 |
780 " reason = %s" | 750 " reason = %s" |
781 " paused = %c" | 751 " paused = %c" |
782 " safety = %s" | 752 " safety = %s" |
783 " last_modified = '%s'" | 753 " last_modified = '%s'" |
784 " etag = '%s'" | 754 " etag = '%s'" |
785 " url_chain = \n\t\"%s\"\n\t" | 755 " url_chain = \n\t\"%s\"\n\t" |
786 " full_path = \"%" PRFilePath "\"" | 756 " full_path = \"%" PRFilePath "\"" |
787 " target_path = \"%" PRFilePath "\"" | 757 " target_path = \"%" PRFilePath "\"" |
788 " has download file = %s", | 758 " has download file = %s", |
789 GetDbHandle(), | |
790 GetTotalBytes(), | 759 GetTotalBytes(), |
791 GetReceivedBytes(), | 760 GetReceivedBytes(), |
792 InterruptReasonDebugString(last_reason_).c_str(), | 761 InterruptReasonDebugString(last_reason_).c_str(), |
793 IsPaused() ? 'T' : 'F', | 762 IsPaused() ? 'T' : 'F', |
794 DebugSafetyStateString(GetSafetyState()), | 763 DebugSafetyStateString(GetSafetyState()), |
795 GetLastModifiedTime().c_str(), | 764 GetLastModifiedTime().c_str(), |
796 GetETag().c_str(), | 765 GetETag().c_str(), |
797 url_list.c_str(), | 766 url_list.c_str(), |
798 GetFullPath().value().c_str(), | 767 GetFullPath().value().c_str(), |
799 GetTargetFilePath().value().c_str(), | 768 GetTargetFilePath().value().c_str(), |
(...skipping 10 matching lines...) Expand all Loading... |
810 void DownloadItemImpl::MockDownloadOpenForTesting() { | 779 void DownloadItemImpl::MockDownloadOpenForTesting() { |
811 open_enabled_ = false; | 780 open_enabled_ = false; |
812 } | 781 } |
813 | 782 |
814 void DownloadItemImpl::NotifyRemoved() { | 783 void DownloadItemImpl::NotifyRemoved() { |
815 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); | 784 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); |
816 } | 785 } |
817 | 786 |
818 void DownloadItemImpl::OnDownloadedFileRemoved() { | 787 void DownloadItemImpl::OnDownloadedFileRemoved() { |
819 file_externally_removed_ = true; | 788 file_externally_removed_ = true; |
| 789 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
820 UpdateObservers(); | 790 UpdateObservers(); |
821 } | 791 } |
822 | 792 |
823 // An error occurred somewhere. | 793 // An error occurred somewhere. |
824 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { | 794 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { |
825 // Somewhat counter-intuitively, it is possible for us to receive an | 795 // Somewhat counter-intuitively, it is possible for us to receive an |
826 // interrupt after we've already been interrupted. The generation of | 796 // interrupt after we've already been interrupted. The generation of |
827 // interrupts from the file thread Renames and the generation of | 797 // interrupts from the file thread Renames and the generation of |
828 // interrupts from disk writes go through two different mechanisms (driven | 798 // interrupts from disk writes go through two different mechanisms (driven |
829 // by rename requests from UI thread and by write requests from IO thread, | 799 // by rename requests from UI thread and by write requests from IO thread, |
(...skipping 26 matching lines...) Expand all Loading... |
856 total_bytes_ = total_bytes; | 826 total_bytes_ = total_bytes; |
857 } | 827 } |
858 | 828 |
859 // Updates from the download thread may have been posted while this download | 829 // Updates from the download thread may have been posted while this download |
860 // was being cancelled in the UI thread, so we'll accept them unless we're | 830 // was being cancelled in the UI thread, so we'll accept them unless we're |
861 // complete. | 831 // complete. |
862 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, | 832 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, |
863 int64 bytes_per_sec, | 833 int64 bytes_per_sec, |
864 const std::string& hash_state) { | 834 const std::string& hash_state) { |
865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 836 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far |
| 837 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); |
866 | 838 |
867 if (state_ != IN_PROGRESS_INTERNAL) { | 839 if (state_ != IN_PROGRESS_INTERNAL) { |
868 // Ignore if we're no longer in-progress. This can happen if we race a | 840 // Ignore if we're no longer in-progress. This can happen if we race a |
869 // Cancel on the UI thread with an update on the FILE thread. | 841 // Cancel on the UI thread with an update on the FILE thread. |
870 // | 842 // |
871 // TODO(rdsmith): Arguably we should let this go through, as this means | 843 // TODO(rdsmith): Arguably we should let this go through, as this means |
872 // the download really did get further than we know before it was | 844 // the download really did get further than we know before it was |
873 // cancelled. But the gain isn't very large, and the code is more | 845 // cancelled. But the gain isn't very large, and the code is more |
874 // fragile if it has to support in progress updates in a non-in-progress | 846 // fragile if it has to support in progress updates in a non-in-progress |
875 // state. This issue should be readdressed when we revamp performance | 847 // state. This issue should be readdressed when we revamp performance |
(...skipping 17 matching lines...) Expand all Loading... |
893 | 865 |
894 UpdateObservers(); | 866 UpdateObservers(); |
895 } | 867 } |
896 | 868 |
897 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { | 869 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { |
898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 870 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
899 | 871 |
900 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); | 872 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); |
901 DCHECK(!all_data_saved_); | 873 DCHECK(!all_data_saved_); |
902 all_data_saved_ = true; | 874 all_data_saved_ = true; |
| 875 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
903 | 876 |
904 // Store final hash and null out intermediate serialized hash state. | 877 // Store final hash and null out intermediate serialized hash state. |
905 hash_ = final_hash; | 878 hash_ = final_hash; |
906 hash_state_ = ""; | 879 hash_state_ = ""; |
907 | 880 |
908 UpdateObservers(); | 881 UpdateObservers(); |
909 } | 882 } |
910 | 883 |
911 void DownloadItemImpl::MarkAsComplete() { | 884 void DownloadItemImpl::MarkAsComplete() { |
912 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 885 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
913 | 886 |
914 DCHECK(all_data_saved_); | 887 DCHECK(all_data_saved_); |
915 end_time_ = base::Time::Now(); | 888 end_time_ = base::Time::Now(); |
916 TransitionTo(COMPLETE_INTERNAL); | 889 TransitionTo(COMPLETE_INTERNAL); |
917 } | 890 } |
918 | |
919 void DownloadItemImpl::SetIsPersisted() { | |
920 is_persisted_ = true; | |
921 UpdateObservers(); | |
922 } | |
923 | |
924 void DownloadItemImpl::SetDbHandle(int64 handle) { | |
925 db_handle_ = handle; | |
926 | |
927 bound_net_log_.AddEvent( | |
928 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, | |
929 net::NetLog::Int64Callback("db_handle", db_handle_)); | |
930 } | |
931 | |
932 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, | 891 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, |
933 int64 bytes_per_sec, | 892 int64 bytes_per_sec, |
934 const std::string& hash_state) { | 893 const std::string& hash_state) { |
935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 895 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
936 | 896 |
937 if (!IsInProgress()) { | 897 if (!IsInProgress()) { |
938 // Ignore if we're no longer in-progress. This can happen if we race a | 898 // Ignore if we're no longer in-progress. This can happen if we race a |
939 // Cancel on the UI thread with an update on the FILE thread. | 899 // Cancel on the UI thread with an update on the FILE thread. |
940 // | 900 // |
941 // TODO(rdsmith): Arguably we should let this go through, as this means | 901 // TODO(rdsmith): Arguably we should let this go through, as this means |
942 // the download really did get further than we know before it was | 902 // the download really did get further than we know before it was |
943 // cancelled. But the gain isn't very large, and the code is more | 903 // cancelled. But the gain isn't very large, and the code is more |
944 // fragile if it has to support in progress updates in a non-in-progress | 904 // fragile if it has to support in progress updates in a non-in-progress |
945 // state. This issue should be readdressed when we revamp performance | 905 // state. This issue should be readdressed when we revamp performance |
(...skipping 13 matching lines...) Expand all Loading... |
959 bound_net_log_.AddEvent( | 919 bound_net_log_.AddEvent( |
960 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, | 920 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, |
961 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); | 921 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); |
962 } | 922 } |
963 | 923 |
964 UpdateObservers(); | 924 UpdateObservers(); |
965 } | 925 } |
966 | 926 |
967 void DownloadItemImpl::DestinationError(DownloadInterruptReason reason) { | 927 void DownloadItemImpl::DestinationError(DownloadInterruptReason reason) { |
968 // The DestinationError and Interrupt routines are being kept separate | 928 // The DestinationError and Interrupt routines are being kept separate |
969 // to allow for a future merging of the Cancel and Interrupt routines.. | 929 // to allow for a future merging of the Cancel and Interrupt routines. |
970 Interrupt(reason); | 930 Interrupt(reason); |
971 } | 931 } |
972 | 932 |
973 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { | 933 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { |
| 934 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
974 if (!IsInProgress()) | 935 if (!IsInProgress()) |
975 return; | 936 return; |
976 OnAllDataSaved(final_hash); | 937 OnAllDataSaved(final_hash); |
977 MaybeCompleteDownload(); | 938 MaybeCompleteDownload(); |
978 } | 939 } |
979 | 940 |
980 // **** Download progression cascade | 941 // **** Download progression cascade |
981 | 942 |
982 void DownloadItemImpl::Init(bool active, | 943 void DownloadItemImpl::Init(bool active, |
983 DownloadType download_type) { | 944 DownloadType download_type) { |
(...skipping 12 matching lines...) Expand all Loading... |
996 // See if it's set programmatically. | 957 // See if it's set programmatically. |
997 file_name = forced_file_path_.AsUTF8Unsafe(); | 958 file_name = forced_file_path_.AsUTF8Unsafe(); |
998 // Possibly has a 'download' attribute for the anchor. | 959 // Possibly has a 'download' attribute for the anchor. |
999 if (file_name.empty()) | 960 if (file_name.empty()) |
1000 file_name = suggested_filename_; | 961 file_name = suggested_filename_; |
1001 // From the URL file name. | 962 // From the URL file name. |
1002 if (file_name.empty()) | 963 if (file_name.empty()) |
1003 file_name = GetURL().ExtractFileName(); | 964 file_name = GetURL().ExtractFileName(); |
1004 } | 965 } |
1005 | 966 |
1006 bound_net_log_.BeginEvent( | 967 base::Callback<base::Value*(net::NetLog::LogLevel)> active_data = base::Bind( |
1007 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, | 968 &ItemActivatedNetLogCallback, this, download_type, &file_name); |
1008 base::Bind(&ItemActivatedNetLogCallback, | 969 if (active) { |
1009 this, download_type, &file_name)); | 970 bound_net_log_.BeginEvent( |
1010 | 971 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); |
1011 // If this is not an active download, end the ACTIVE event now. | 972 } else { |
1012 if (!active) { | |
1013 bound_net_log_.AddEvent( | 973 bound_net_log_.AddEvent( |
1014 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, | 974 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); |
1015 net::NetLog::Int64Callback("db_handle", db_handle_)); | |
1016 | |
1017 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); | |
1018 } | 975 } |
1019 | 976 |
1020 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); | 977 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
1021 } | 978 } |
1022 | 979 |
1023 // We're starting the download. | 980 // We're starting the download. |
1024 void DownloadItemImpl::Start(scoped_ptr<DownloadFile> file) { | 981 void DownloadItemImpl::Start(scoped_ptr<DownloadFile> file) { |
1025 DCHECK(!download_file_.get()); | 982 DCHECK(!download_file_.get()); |
1026 DCHECK(file.get()); | 983 DCHECK(file.get()); |
1027 download_file_ = file.Pass(); | 984 download_file_ = file.Pass(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 const FilePath& intermediate_path) { | 1019 const FilePath& intermediate_path) { |
1063 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1020 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1064 | 1021 |
1065 // If the |target_path| is empty, then we consider this download to be | 1022 // If the |target_path| is empty, then we consider this download to be |
1066 // canceled. | 1023 // canceled. |
1067 if (target_path.empty()) { | 1024 if (target_path.empty()) { |
1068 Cancel(true); | 1025 Cancel(true); |
1069 return; | 1026 return; |
1070 } | 1027 } |
1071 | 1028 |
| 1029 VLOG(20) << __FUNCTION__ << " " << target_path.value() << " " << disposition |
| 1030 << " " << danger_type << " " << DebugString(true); |
| 1031 |
1072 target_path_ = target_path; | 1032 target_path_ = target_path; |
1073 target_disposition_ = disposition; | 1033 target_disposition_ = disposition; |
1074 SetDangerType(danger_type); | 1034 SetDangerType(danger_type); |
1075 // TODO(asanka): SetDangerType() doesn't need to send a notification here. | 1035 // TODO(asanka): SetDangerType() doesn't need to send a notification here. |
1076 | 1036 |
1077 // We want the intermediate and target paths to refer to the same directory so | 1037 // We want the intermediate and target paths to refer to the same directory so |
1078 // that they are both on the same device and subject to same | 1038 // that they are both on the same device and subject to same |
1079 // space/permission/availability constraints. | 1039 // space/permission/availability constraints. |
1080 DCHECK(intermediate_path.DirName() == target_path.DirName()); | 1040 DCHECK(intermediate_path.DirName() == target_path.DirName()); |
1081 | 1041 |
(...skipping 22 matching lines...) Expand all Loading... |
1104 base::Bind(&DownloadFile::Rename, | 1064 base::Bind(&DownloadFile::Rename, |
1105 // Safe because we control download file lifetime. | 1065 // Safe because we control download file lifetime. |
1106 base::Unretained(download_file_.get()), | 1066 base::Unretained(download_file_.get()), |
1107 intermediate_path, false, callback)); | 1067 intermediate_path, false, callback)); |
1108 } | 1068 } |
1109 | 1069 |
1110 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( | 1070 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( |
1111 DownloadInterruptReason reason, | 1071 DownloadInterruptReason reason, |
1112 const FilePath& full_path) { | 1072 const FilePath& full_path) { |
1113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1073 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1074 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
1114 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { | 1075 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
1115 Interrupt(reason); | 1076 Interrupt(reason); |
1116 } else { | 1077 } else { |
1117 SetFullPath(full_path); | 1078 SetFullPath(full_path); |
1118 UpdateObservers(); | 1079 delegate_->ShowDownloadInBrowser(this); |
1119 } | 1080 } |
1120 | 1081 |
1121 delegate_->DownloadRenamedToIntermediateName(this); | 1082 MaybeCompleteDownload(); |
1122 } | 1083 } |
1123 | 1084 |
1124 // When SavePackage downloads MHTML to GData (see | 1085 // When SavePackage downloads MHTML to GData (see |
1125 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it | 1086 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it |
1126 // does for non-SavePackage downloads, but SavePackage downloads never satisfy | 1087 // does for non-SavePackage downloads, but SavePackage downloads never satisfy |
1127 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls | 1088 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls |
1128 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage | 1089 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage |
1129 // notices that the upload has completed and runs its normal Finish() pathway. | 1090 // notices that the upload has completed and runs its normal Finish() pathway. |
1130 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes | 1091 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes |
1131 // downloads. SavePackage always uses its own Finish() to mark downloads | 1092 // downloads. SavePackage always uses its own Finish() to mark downloads |
1132 // complete. | 1093 // complete. |
1133 void DownloadItemImpl::MaybeCompleteDownload() { | 1094 void DownloadItemImpl::MaybeCompleteDownload() { |
1134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1135 | 1096 |
1136 if (!IsDownloadReadyForCompletion()) | 1097 if (!IsDownloadReadyForCompletion()) |
1137 return; | 1098 return; |
1138 | 1099 |
1139 // TODO(rdsmith): DCHECK that we only pass through this point | 1100 // TODO(rdsmith): DCHECK that we only pass through this point |
1140 // once per download. The natural way to do this is by a state | 1101 // once per download. The natural way to do this is by a state |
1141 // transition on the DownloadItem. | 1102 // transition on the DownloadItem. |
1142 | 1103 |
1143 // Confirm we're in the proper set of states to be here; | 1104 // Confirm we're in the proper set of states to be here; |
1144 // have all data, have a history handle, (validated or safe). | 1105 // have all data, have a history handle, (validated or safe). |
1145 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); | 1106 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); |
1146 DCHECK_NE(DownloadItem::DANGEROUS, GetSafetyState()); | 1107 DCHECK_NE(DownloadItem::DANGEROUS, GetSafetyState()); |
1147 DCHECK(all_data_saved_); | 1108 DCHECK(all_data_saved_); |
1148 DCHECK(is_persisted_); | |
1149 | |
1150 delegate_->UpdatePersistence(this); | |
1151 | 1109 |
1152 OnDownloadCompleting(); | 1110 OnDownloadCompleting(); |
1153 } | 1111 } |
1154 | 1112 |
1155 // Called by MaybeCompleteDownload() when it has determined that the download | 1113 // Called by MaybeCompleteDownload() when it has determined that the download |
1156 // is ready for completion. | 1114 // is ready for completion. |
1157 void DownloadItemImpl::OnDownloadCompleting() { | 1115 void DownloadItemImpl::OnDownloadCompleting() { |
1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1159 | 1117 |
1160 if (state_ != IN_PROGRESS_INTERNAL) | 1118 if (state_ != IN_PROGRESS_INTERNAL) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 | 1176 |
1219 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { | 1177 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
1220 Interrupt(reason); | 1178 Interrupt(reason); |
1221 return; | 1179 return; |
1222 } | 1180 } |
1223 | 1181 |
1224 // full_path is now the current and target file path. | 1182 // full_path is now the current and target file path. |
1225 DCHECK(!full_path.empty()); | 1183 DCHECK(!full_path.empty()); |
1226 target_path_ = full_path; | 1184 target_path_ = full_path; |
1227 SetFullPath(full_path); | 1185 SetFullPath(full_path); |
1228 delegate_->DownloadRenamedToFinalName(this); | |
1229 | 1186 |
1230 ReleaseDownloadFile(); | 1187 ReleaseDownloadFile(); |
1231 } | 1188 } |
1232 | 1189 |
1233 void DownloadItemImpl::ReleaseDownloadFile() { | 1190 void DownloadItemImpl::ReleaseDownloadFile() { |
1234 // Complete the download and release the DownloadFile. | 1191 // Complete the download and release the DownloadFile. |
1235 DCHECK(!is_save_package_download_); | 1192 DCHECK(!is_save_package_download_); |
1236 DCHECK(download_file_.get()); | 1193 DCHECK(download_file_.get()); |
1237 BrowserThread::PostTask( | 1194 BrowserThread::PostTask( |
1238 BrowserThread::FILE, FROM_HERE, | 1195 BrowserThread::FILE, FROM_HERE, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 // has been released. | 1256 // has been released. |
1300 if (!is_save_package_download_ && download_file_.get()) { | 1257 if (!is_save_package_download_ && download_file_.get()) { |
1301 BrowserThread::PostTask( | 1258 BrowserThread::PostTask( |
1302 BrowserThread::FILE, FROM_HERE, | 1259 BrowserThread::FILE, FROM_HERE, |
1303 // Will be deleted at end of task execution. | 1260 // Will be deleted at end of task execution. |
1304 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); | 1261 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); |
1305 } | 1262 } |
1306 } | 1263 } |
1307 | 1264 |
1308 bool DownloadItemImpl::IsDownloadReadyForCompletion() { | 1265 bool DownloadItemImpl::IsDownloadReadyForCompletion() { |
| 1266 VLOG(20) << __FUNCTION__ << " " << AllDataSaved() |
| 1267 << " " << (GetSafetyState() != DownloadItem::DANGEROUS) |
| 1268 << " " << (state_ == IN_PROGRESS_INTERNAL) |
| 1269 << " " << !GetTargetFilePath().empty() |
| 1270 << " " << (target_path_.DirName() == current_path_.DirName()); |
1309 // If we don't have all the data, the download is not ready for | 1271 // If we don't have all the data, the download is not ready for |
1310 // completion. | 1272 // completion. |
1311 if (!AllDataSaved()) | 1273 if (!AllDataSaved()) |
1312 return false; | 1274 return false; |
1313 | 1275 |
1314 // If the download is dangerous, but not yet validated, it's not ready for | 1276 // If the download is dangerous, but not yet validated, it's not ready for |
1315 // completion. | 1277 // completion. |
1316 if (GetSafetyState() == DownloadItem::DANGEROUS) | 1278 if (GetSafetyState() == DownloadItem::DANGEROUS) |
1317 return false; | 1279 return false; |
1318 | 1280 |
1319 // If the download isn't active (e.g. has been cancelled) it's not | 1281 // If the download isn't active (e.g. has been cancelled) it's not |
1320 // ready for completion. | 1282 // ready for completion. |
1321 if (state_ != IN_PROGRESS_INTERNAL) | 1283 if (state_ != IN_PROGRESS_INTERNAL) |
1322 return false; | 1284 return false; |
1323 | 1285 |
1324 // If the download hasn't been inserted into the history system | 1286 // If the target filename hasn't been determined, then it's not ready for |
1325 // (which occurs strictly after file name determination, intermediate | 1287 // completion. This is checked in ReadyForDownloadCompletionDone(). |
1326 // file rename, and UI display) then it's not ready for completion. | 1288 if (GetTargetFilePath().empty()) |
1327 if (!IsPersisted()) | 1289 return false; |
| 1290 |
| 1291 // This is checked in NeedsRename(). Without this conditional, |
| 1292 // browser_tests:DownloadTest.DownloadMimeType fails the DCHECK. |
| 1293 if (target_path_.DirName() != current_path_.DirName()) |
1328 return false; | 1294 return false; |
1329 | 1295 |
1330 return true; | 1296 return true; |
1331 } | 1297 } |
1332 | 1298 |
1333 bool DownloadItemImpl::NeedsRename() const { | 1299 bool DownloadItemImpl::NeedsRename() const { |
1334 DCHECK(target_path_.DirName() == current_path_.DirName()); | 1300 DCHECK(target_path_.DirName() == current_path_.DirName()); |
1335 return target_path_ != current_path_; | 1301 return target_path_ != current_path_; |
1336 } | 1302 } |
1337 | 1303 |
(...skipping 24 matching lines...) Expand all Loading... |
1362 case CANCELLED_INTERNAL: | 1328 case CANCELLED_INTERNAL: |
1363 bound_net_log_.AddEvent( | 1329 bound_net_log_.AddEvent( |
1364 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, | 1330 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, |
1365 base::Bind(&ItemCanceledNetLogCallback, received_bytes_, | 1331 base::Bind(&ItemCanceledNetLogCallback, received_bytes_, |
1366 &hash_state_)); | 1332 &hash_state_)); |
1367 break; | 1333 break; |
1368 default: | 1334 default: |
1369 break; | 1335 break; |
1370 } | 1336 } |
1371 | 1337 |
1372 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); | 1338 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) |
| 1339 << " " << InternalToExternalState(old_state) |
| 1340 << " " << InternalToExternalState(state_); |
1373 | 1341 |
1374 // Only update observers on user visible state changes. | 1342 // Only update observers on user visible state changes. |
1375 if (InternalToExternalState(old_state) != InternalToExternalState(state_)) | 1343 if (InternalToExternalState(old_state) != InternalToExternalState(state_)) |
1376 UpdateObservers(); | 1344 UpdateObservers(); |
1377 | 1345 |
1378 bool is_done = (state_ != IN_PROGRESS_INTERNAL && | 1346 bool is_done = (state_ != IN_PROGRESS_INTERNAL && |
1379 state_ != COMPLETING_INTERNAL); | 1347 state_ != COMPLETING_INTERNAL); |
1380 bool was_done = (old_state != IN_PROGRESS_INTERNAL && | 1348 bool was_done = (old_state != IN_PROGRESS_INTERNAL && |
1381 old_state != COMPLETING_INTERNAL); | 1349 old_state != COMPLETING_INTERNAL); |
1382 if (is_done && !was_done) | 1350 if (is_done && !was_done) |
(...skipping 15 matching lines...) Expand all Loading... |
1398 } | 1366 } |
1399 } | 1367 } |
1400 | 1368 |
1401 void DownloadItemImpl::SetFullPath(const FilePath& new_path) { | 1369 void DownloadItemImpl::SetFullPath(const FilePath& new_path) { |
1402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1403 VLOG(20) << __FUNCTION__ << "()" | 1371 VLOG(20) << __FUNCTION__ << "()" |
1404 << " new_path = \"" << new_path.value() << "\"" | 1372 << " new_path = \"" << new_path.value() << "\"" |
1405 << " " << DebugString(true); | 1373 << " " << DebugString(true); |
1406 DCHECK(!new_path.empty()); | 1374 DCHECK(!new_path.empty()); |
1407 current_path_ = new_path; | 1375 current_path_ = new_path; |
| 1376 UpdateObservers(); |
1408 | 1377 |
1409 bound_net_log_.AddEvent( | 1378 bound_net_log_.AddEvent( |
1410 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, | 1379 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, |
1411 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); | 1380 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); |
1412 } | 1381 } |
1413 | 1382 |
1414 // static | 1383 // static |
1415 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( | 1384 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( |
1416 DownloadInternalState internal_state) { | 1385 DownloadInternalState internal_state) { |
1417 switch (internal_state) { | 1386 switch (internal_state) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 return "CANCELLED"; | 1432 return "CANCELLED"; |
1464 case INTERRUPTED_INTERNAL: | 1433 case INTERRUPTED_INTERNAL: |
1465 return "INTERRUPTED"; | 1434 return "INTERRUPTED"; |
1466 default: | 1435 default: |
1467 NOTREACHED() << "Unknown download state " << state; | 1436 NOTREACHED() << "Unknown download state " << state; |
1468 return "unknown"; | 1437 return "unknown"; |
1469 }; | 1438 }; |
1470 } | 1439 } |
1471 | 1440 |
1472 } // namespace content | 1441 } // namespace content |
OLD | NEW |