Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 10950015: Shift "commit point" for when a download will no longer accept cancels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 5 // File method ordering: Methods in this file are in the same order
6 // as in download_item_impl.h, with the following exception: The public 6 // as in download_item_impl.h, with the following exception: The public
7 // interfaces DelayedDownloadOpened, OnDownloadTargetDetermined, and 7 // interfaces DelayedDownloadOpened, OnDownloadTargetDetermined, 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 case DownloadItem::DANGEROUS: 73 case DownloadItem::DANGEROUS:
74 return "DANGEROUS"; 74 return "DANGEROUS";
75 case DownloadItem::DANGEROUS_BUT_VALIDATED: 75 case DownloadItem::DANGEROUS_BUT_VALIDATED:
76 return "DANGEROUS_BUT_VALIDATED"; 76 return "DANGEROUS_BUT_VALIDATED";
77 default: 77 default:
78 NOTREACHED() << "Unknown safety state " << state; 78 NOTREACHED() << "Unknown safety state " << state;
79 return "unknown"; 79 return "unknown";
80 }; 80 };
81 } 81 }
82 82
83 const char* DebugDownloadStateString(DownloadItem::DownloadState state) {
84 switch (state) {
85 case DownloadItem::IN_PROGRESS:
86 return "IN_PROGRESS";
87 case DownloadItem::COMPLETE:
88 return "COMPLETE";
89 case DownloadItem::CANCELLED:
90 return "CANCELLED";
91 case DownloadItem::INTERRUPTED:
92 return "INTERRUPTED";
93 default:
94 NOTREACHED() << "Unknown download state " << state;
95 return "unknown";
96 };
97 }
98
99 // Classes to null out request handle calls (for SavePage DownloadItems, which 83 // Classes to null out request handle calls (for SavePage DownloadItems, which
100 // may have, e.g., Cancel() called on them without it doing anything) 84 // may have, e.g., Cancel() called on them without it doing anything)
101 // and to DCHECK on them (for history DownloadItems, which should never have 85 // and to DCHECK on them (for history DownloadItems, which should never have
102 // any operation that implies an off-thread component, since they don't 86 // any operation that implies an off-thread component, since they don't
103 // have any). 87 // have any).
104 class NullDownloadRequestHandle : public DownloadRequestHandleInterface { 88 class NullDownloadRequestHandle : public DownloadRequestHandleInterface {
105 public: 89 public:
106 NullDownloadRequestHandle() {} 90 NullDownloadRequestHandle() {}
107 91
108 // DownloadRequestHandleInterface calls 92 // DownloadRequestHandleInterface calls
(...skipping 19 matching lines...) Expand all
128 // has started, but has not yet had its data persisted in the table. We use fake 112 // has started, but has not yet had its data persisted in the table. We use fake
129 // database handles in incognito mode starting at -1 and progressively getting 113 // database handles in incognito mode starting at -1 and progressively getting
130 // more negative. 114 // more negative.
131 // static 115 // static
132 const int DownloadItem::kUninitializedHandle = 0; 116 const int DownloadItem::kUninitializedHandle = 0;
133 117
134 const char DownloadItem::kEmptyFileHash[] = ""; 118 const char DownloadItem::kEmptyFileHash[] = "";
135 119
136 } 120 }
137 121
122 const content::DownloadItem::DownloadState
123 DownloadItemImpl::kInternalStateMap[] = {
asanka 2012/09/20 18:42:15 A minor suggestion: Perhaps a switch based mapping
Randy Smith (Not in Mondays) 2012/09/21 21:58:01 Good idea. I think it removes the pain around the
124 content::DownloadItem::IN_PROGRESS,
125 content::DownloadItem::IN_PROGRESS,
126 content::DownloadItem::COMPLETE,
127 content::DownloadItem::CANCELLED,
128 content::DownloadItem::INTERRUPTED,
129 };
130
131 const DownloadItemImpl::DownloadInternalState
132 DownloadItemImpl::kExternalStateMap[] = {
133 DownloadItemImpl::IN_PROGRESS_INTERNAL,
134 DownloadItemImpl::COMPLETE_INTERNAL,
135 DownloadItemImpl::CANCELLED_INTERNAL,
136 DownloadItemImpl::INTERRUPTED_INTERNAL,
137 };
138
138 // Our download table ID starts at 1, so we use 0 to represent a download that 139 // Our download table ID starts at 1, so we use 0 to represent a download that
139 // has started, but has not yet had its data persisted in the table. We use fake 140 // has started, but has not yet had its data persisted in the table. We use fake
140 // database handles in incognito mode starting at -1 and progressively getting 141 // database handles in incognito mode starting at -1 and progressively getting
141 // more negative. 142 // more negative.
142 143
143 // Constructor for reading from the history service. 144 // Constructor for reading from the history service.
144 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, 145 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
145 DownloadId download_id, 146 DownloadId download_id,
146 const DownloadPersistentStoreInfo& info, 147 const DownloadPersistentStoreInfo& info,
147 const net::BoundNetLog& bound_net_log) 148 const net::BoundNetLog& bound_net_log)
148 : download_id_(download_id), 149 : download_id_(download_id),
149 current_path_(info.path), 150 current_path_(info.path),
150 target_path_(info.path), 151 target_path_(info.path),
151 target_disposition_(TARGET_DISPOSITION_OVERWRITE), 152 target_disposition_(TARGET_DISPOSITION_OVERWRITE),
152 url_chain_(1, info.url), 153 url_chain_(1, info.url),
153 referrer_url_(info.referrer_url), 154 referrer_url_(info.referrer_url),
154 transition_type_(content::PAGE_TRANSITION_LINK), 155 transition_type_(content::PAGE_TRANSITION_LINK),
155 has_user_gesture_(false), 156 has_user_gesture_(false),
156 total_bytes_(info.total_bytes), 157 total_bytes_(info.total_bytes),
157 received_bytes_(info.received_bytes), 158 received_bytes_(info.received_bytes),
158 bytes_per_sec_(0), 159 bytes_per_sec_(0),
159 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 160 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE),
160 start_tick_(base::TimeTicks()), 161 start_tick_(base::TimeTicks()),
161 state_(info.state), 162 state_(kExternalStateMap[info.state]),
162 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 163 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
163 start_time_(info.start_time), 164 start_time_(info.start_time),
164 end_time_(info.end_time), 165 end_time_(info.end_time),
165 db_handle_(info.db_handle), 166 db_handle_(info.db_handle),
166 delegate_(delegate), 167 delegate_(delegate),
167 is_paused_(false), 168 is_paused_(false),
168 open_when_complete_(false), 169 open_when_complete_(false),
169 file_externally_removed_(false), 170 file_externally_removed_(false),
170 safety_state_(SAFE), 171 safety_state_(SAFE),
171 auto_opened_(false), 172 auto_opened_(false),
172 is_persisted_(true), 173 is_persisted_(true),
173 is_temporary_(false), 174 is_temporary_(false),
174 all_data_saved_(false), 175 all_data_saved_(false),
175 opened_(info.opened), 176 opened_(info.opened),
176 open_enabled_(true), 177 open_enabled_(true),
177 delegate_delayed_complete_(false), 178 delegate_delayed_complete_(false),
178 bound_net_log_(bound_net_log), 179 bound_net_log_(bound_net_log),
179 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 180 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
180 delegate_->Attach(); 181 delegate_->Attach();
181 if (IsInProgress()) 182 if (state_ == IN_PROGRESS_INTERNAL)
182 state_ = CANCELLED; 183 state_ = CANCELLED_INTERNAL;
183 if (IsComplete()) 184 if (state_ == COMPLETE_INTERNAL)
184 all_data_saved_ = true; 185 all_data_saved_ = true;
185 Init(false /* not actively downloading */, 186 Init(false /* not actively downloading */,
186 download_net_logs::SRC_HISTORY_IMPORT); 187 download_net_logs::SRC_HISTORY_IMPORT);
187 } 188 }
188 189
189 // Constructing for a regular download: 190 // Constructing for a regular download:
190 DownloadItemImpl::DownloadItemImpl( 191 DownloadItemImpl::DownloadItemImpl(
191 DownloadItemImplDelegate* delegate, 192 DownloadItemImplDelegate* delegate,
192 const DownloadCreateInfo& info, 193 const DownloadCreateInfo& info,
193 scoped_ptr<DownloadRequestHandleInterface> request_handle, 194 scoped_ptr<DownloadRequestHandleInterface> request_handle,
(...skipping 12 matching lines...) Expand all
206 content_disposition_(info.content_disposition), 207 content_disposition_(info.content_disposition),
207 mime_type_(info.mime_type), 208 mime_type_(info.mime_type),
208 original_mime_type_(info.original_mime_type), 209 original_mime_type_(info.original_mime_type),
209 referrer_charset_(info.referrer_charset), 210 referrer_charset_(info.referrer_charset),
210 remote_address_(info.remote_address), 211 remote_address_(info.remote_address),
211 total_bytes_(info.total_bytes), 212 total_bytes_(info.total_bytes),
212 received_bytes_(0), 213 received_bytes_(0),
213 bytes_per_sec_(0), 214 bytes_per_sec_(0),
214 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 215 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE),
215 start_tick_(base::TimeTicks::Now()), 216 start_tick_(base::TimeTicks::Now()),
216 state_(IN_PROGRESS), 217 state_(kExternalStateMap[IN_PROGRESS]),
217 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 218 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
218 start_time_(info.start_time), 219 start_time_(info.start_time),
219 db_handle_(DownloadItem::kUninitializedHandle), 220 db_handle_(DownloadItem::kUninitializedHandle),
220 delegate_(delegate), 221 delegate_(delegate),
221 is_paused_(false), 222 is_paused_(false),
222 open_when_complete_(false), 223 open_when_complete_(false),
223 file_externally_removed_(false), 224 file_externally_removed_(false),
224 safety_state_(SAFE), 225 safety_state_(SAFE),
225 auto_opened_(false), 226 auto_opened_(false),
226 is_persisted_(false), 227 is_persisted_(false),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 referrer_url_(GURL()), 262 referrer_url_(GURL()),
262 transition_type_(content::PAGE_TRANSITION_LINK), 263 transition_type_(content::PAGE_TRANSITION_LINK),
263 has_user_gesture_(false), 264 has_user_gesture_(false),
264 mime_type_(mime_type), 265 mime_type_(mime_type),
265 original_mime_type_(mime_type), 266 original_mime_type_(mime_type),
266 total_bytes_(0), 267 total_bytes_(0),
267 received_bytes_(0), 268 received_bytes_(0),
268 bytes_per_sec_(0), 269 bytes_per_sec_(0),
269 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 270 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE),
270 start_tick_(base::TimeTicks::Now()), 271 start_tick_(base::TimeTicks::Now()),
271 state_(IN_PROGRESS), 272 state_(kExternalStateMap[IN_PROGRESS]),
272 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 273 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
273 start_time_(base::Time::Now()), 274 start_time_(base::Time::Now()),
274 db_handle_(DownloadItem::kUninitializedHandle), 275 db_handle_(DownloadItem::kUninitializedHandle),
275 delegate_(delegate), 276 delegate_(delegate),
276 is_paused_(false), 277 is_paused_(false),
277 open_when_complete_(false), 278 open_when_complete_(false),
278 file_externally_removed_(false), 279 file_externally_removed_(false),
279 safety_state_(SAFE), 280 safety_state_(SAFE),
280 auto_opened_(false), 281 auto_opened_(false),
281 is_persisted_(false), 282 is_persisted_(false),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 GetDangerType(), GetSafetyState())); 333 GetDangerType(), GetSafetyState()));
333 334
334 UpdateObservers(); 335 UpdateObservers();
335 336
336 delegate_->MaybeCompleteDownload(this); 337 delegate_->MaybeCompleteDownload(this);
337 } 338 }
338 339
339 void DownloadItemImpl::TogglePause() { 340 void DownloadItemImpl::TogglePause() {
340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
341 342
342 DCHECK(IsInProgress()); 343 DCHECK(state_ == IN_PROGRESS_INTERNAL || state_ == COMPLETING_INTERNAL);
343 if (is_paused_) 344 if (is_paused_)
344 request_handle_->ResumeRequest(); 345 request_handle_->ResumeRequest();
345 else 346 else
346 request_handle_->PauseRequest(); 347 request_handle_->PauseRequest();
347 is_paused_ = !is_paused_; 348 is_paused_ = !is_paused_;
348 UpdateObservers(); 349 UpdateObservers();
349 } 350 }
350 351
351 void DownloadItemImpl::Cancel(bool user_cancel) { 352 void DownloadItemImpl::Cancel(bool user_cancel) {
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
353 354
354 last_reason_ = user_cancel ? 355 last_reason_ = user_cancel ?
355 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED : 356 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED :
356 content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN; 357 content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN;
357 358
358 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 359 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
359 if (!IsPartialDownload()) { 360 if (state_ != IN_PROGRESS_INTERNAL) {
360 // Small downloads might be complete before this method has 361 // Small downloads might be complete before this method has
361 // a chance to run. 362 // a chance to run.
362 return; 363 return;
363 } 364 }
364 365
365 download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT); 366 download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT);
366 367
367 TransitionTo(CANCELLED); 368 TransitionTo(CANCELLED_INTERNAL);
368 if (user_cancel) 369 if (user_cancel)
369 delegate_->DownloadStopped(this); 370 delegate_->DownloadStopped(this);
370 } 371 }
371 372
372 void DownloadItemImpl::Delete(DeleteReason reason) { 373 void DownloadItemImpl::Delete(DeleteReason reason) {
373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
374 375
375 switch (reason) { 376 switch (reason) {
376 case DELETE_DUE_TO_USER_DISCARD: 377 case DELETE_DUE_TO_USER_DISCARD:
377 UMA_HISTOGRAM_ENUMERATION( 378 UMA_HISTOGRAM_ENUMERATION(
(...skipping 25 matching lines...) Expand all
403 delegate_->AssertStateConsistent(this); 404 delegate_->AssertStateConsistent(this);
404 405
405 NotifyRemoved(); 406 NotifyRemoved();
406 delegate_->DownloadRemoved(this); 407 delegate_->DownloadRemoved(this);
407 // We have now been deleted. 408 // We have now been deleted.
408 } 409 }
409 410
410 void DownloadItemImpl::OpenDownload() { 411 void DownloadItemImpl::OpenDownload() {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
412 413
413 if (IsPartialDownload()) { 414 if (state_ == IN_PROGRESS_INTERNAL) {
414 // We don't honor the open_when_complete_ flag for temporary 415 // We don't honor the open_when_complete_ flag for temporary
415 // downloads. Don't set it because it shows up in the UI. 416 // downloads. Don't set it because it shows up in the UI.
416 if (!IsTemporary()) 417 if (!IsTemporary())
417 open_when_complete_ = !open_when_complete_; 418 open_when_complete_ = !open_when_complete_;
418 return; 419 return;
419 } 420 }
420 421
421 if (!IsComplete() || file_externally_removed_) 422 if (state_ != COMPLETE_INTERNAL || file_externally_removed_)
422 return; 423 return;
423 424
424 // Ideally, we want to detect errors in opening and report them, but we 425 // Ideally, we want to detect errors in opening and report them, but we
425 // don't generally have the proper interface for that to the external 426 // don't generally have the proper interface for that to the external
426 // program that opens the file. So instead we spawn a check to update 427 // program that opens the file. So instead we spawn a check to update
427 // the UI if the file has been deleted in parallel with the open. 428 // the UI if the file has been deleted in parallel with the open.
428 delegate_->CheckForFileRemoval(this); 429 delegate_->CheckForFileRemoval(this);
429 download_stats::RecordOpen(GetEndTime(), !GetOpened()); 430 download_stats::RecordOpen(GetEndTime(), !GetOpened());
430 opened_ = true; 431 opened_ = true;
431 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this)); 432 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
(...skipping 19 matching lines...) Expand all
451 452
452 DownloadId DownloadItemImpl::GetGlobalId() const { 453 DownloadId DownloadItemImpl::GetGlobalId() const {
453 return download_id_; 454 return download_id_;
454 } 455 }
455 456
456 int64 DownloadItemImpl::GetDbHandle() const { 457 int64 DownloadItemImpl::GetDbHandle() const {
457 return db_handle_; 458 return db_handle_;
458 } 459 }
459 460
460 DownloadItem::DownloadState DownloadItemImpl::GetState() const { 461 DownloadItem::DownloadState DownloadItemImpl::GetState() const {
461 return state_; 462 // Make sure the mapping arrays satisfy constraints.
463 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(kInternalStateMap) ==
asanka 2012/09/20 18:42:15 Nit: Perhaps keep the COMPILE_ASSERTs next to the
Randy Smith (Not in Mondays) 2012/09/21 21:58:01 See above; now moot.
464 MAX_DOWNLOAD_INTERNAL_STATE,
465 internal_state_map_conflicts_with_states);
466 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(kExternalStateMap) == MAX_DOWNLOAD_STATE,
467 external_state_map_conflicts_with_states);
468
469 return kInternalStateMap[state_];
462 } 470 }
463 471
464 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const { 472 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const {
465 return last_reason_; 473 return last_reason_;
466 } 474 }
467 475
468 bool DownloadItemImpl::IsPaused() const { 476 bool DownloadItemImpl::IsPaused() const {
469 return is_paused_; 477 return is_paused_;
470 } 478 }
471 479
472 bool DownloadItemImpl::IsTemporary() const { 480 bool DownloadItemImpl::IsTemporary() const {
473 return is_temporary_; 481 return is_temporary_;
474 } 482 }
475 483
476 bool DownloadItemImpl::IsPersisted() const { 484 bool DownloadItemImpl::IsPersisted() const {
477 return is_persisted_; 485 return is_persisted_;
478 } 486 }
479 487
480 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to 488 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to
481 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. 489 // |IsPartialDownload()|, when resuming interrupted downloads is implemented.
482 bool DownloadItemImpl::IsPartialDownload() const { 490 bool DownloadItemImpl::IsPartialDownload() const {
483 return (state_ == IN_PROGRESS); 491 return kInternalStateMap[state_] == IN_PROGRESS;
484 } 492 }
485 493
486 bool DownloadItemImpl::IsInProgress() const { 494 bool DownloadItemImpl::IsInProgress() const {
487 return (state_ == IN_PROGRESS); 495 return kInternalStateMap[state_] == IN_PROGRESS;
488 } 496 }
489 497
490 bool DownloadItemImpl::IsCancelled() const { 498 bool DownloadItemImpl::IsCancelled() const {
491 return (state_ == CANCELLED) || 499 DownloadState external_state = kInternalStateMap[state_];
492 (state_ == INTERRUPTED); 500 return external_state == CANCELLED || external_state == INTERRUPTED;
493 } 501 }
494 502
495 bool DownloadItemImpl::IsInterrupted() const { 503 bool DownloadItemImpl::IsInterrupted() const {
496 return (state_ == INTERRUPTED); 504 return kInternalStateMap[state_] == INTERRUPTED;
497 } 505 }
498 506
499 bool DownloadItemImpl::IsComplete() const { 507 bool DownloadItemImpl::IsComplete() const {
500 return (state_ == COMPLETE); 508 return kInternalStateMap[state_] == COMPLETE;
501 } 509 }
502 510
503 const GURL& DownloadItemImpl::GetURL() const { 511 const GURL& DownloadItemImpl::GetURL() const {
504 return url_chain_.empty() ? 512 return url_chain_.empty() ?
505 GURL::EmptyGURL() : url_chain_.back(); 513 GURL::EmptyGURL() : url_chain_.back();
506 } 514 }
507 515
508 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const { 516 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const {
509 return url_chain_; 517 return url_chain_;
510 } 518 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 671
664 base::Time DownloadItemImpl::GetStartTime() const { 672 base::Time DownloadItemImpl::GetStartTime() const {
665 return start_time_; 673 return start_time_;
666 } 674 }
667 675
668 base::Time DownloadItemImpl::GetEndTime() const { 676 base::Time DownloadItemImpl::GetEndTime() const {
669 return end_time_; 677 return end_time_;
670 } 678 }
671 679
672 bool DownloadItemImpl::CanShowInFolder() { 680 bool DownloadItemImpl::CanShowInFolder() {
673 return !IsCancelled() && !file_externally_removed_; 681 return state_ != CANCELLED_INTERNAL && !file_externally_removed_;
674 } 682 }
675 683
676 bool DownloadItemImpl::CanOpenDownload() { 684 bool DownloadItemImpl::CanOpenDownload() {
677 return !file_externally_removed_; 685 return !file_externally_removed_;
678 } 686 }
679 687
680 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() { 688 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() {
681 return delegate_->ShouldOpenFileBasedOnExtension(GetUserVerifiedFilePath()); 689 return delegate_->ShouldOpenFileBasedOnExtension(GetUserVerifiedFilePath());
682 } 690 }
683 691
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 751
744 void DownloadItemImpl::SetDisplayName(const FilePath& name) { 752 void DownloadItemImpl::SetDisplayName(const FilePath& name) {
745 display_name_ = name; 753 display_name_ = name;
746 } 754 }
747 755
748 std::string DownloadItemImpl::DebugString(bool verbose) const { 756 std::string DownloadItemImpl::DebugString(bool verbose) const {
749 std::string description = 757 std::string description =
750 base::StringPrintf("{ id = %d" 758 base::StringPrintf("{ id = %d"
751 " state = %s", 759 " state = %s",
752 download_id_.local(), 760 download_id_.local(),
753 DebugDownloadStateString(GetState())); 761 DebugDownloadStateString(state_));
754 762
755 // Construct a string of the URL chain. 763 // Construct a string of the URL chain.
756 std::string url_list("<none>"); 764 std::string url_list("<none>");
757 if (!url_chain_.empty()) { 765 if (!url_chain_.empty()) {
758 std::vector<GURL>::const_iterator iter = url_chain_.begin(); 766 std::vector<GURL>::const_iterator iter = url_chain_.begin();
759 std::vector<GURL>::const_iterator last = url_chain_.end(); 767 std::vector<GURL>::const_iterator last = url_chain_.end();
760 url_list = (*iter).spec(); 768 url_list = (*iter).spec();
761 ++iter; 769 ++iter;
762 for ( ; verbose && (iter != last); ++iter) { 770 for ( ; verbose && (iter != last); ++iter) {
763 url_list += " ->\n\t"; 771 url_list += " ->\n\t";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 // Somewhat counter-intuitively, it is possible for us to receive an 835 // Somewhat counter-intuitively, it is possible for us to receive an
828 // interrupt after we've already been interrupted. The generation of 836 // interrupt after we've already been interrupted. The generation of
829 // interrupts from the file thread Renames and the generation of 837 // interrupts from the file thread Renames and the generation of
830 // interrupts from disk writes go through two different mechanisms (driven 838 // interrupts from disk writes go through two different mechanisms (driven
831 // by rename requests from UI thread and by write requests from IO thread, 839 // by rename requests from UI thread and by write requests from IO thread,
832 // respectively), and since we choose not to keep state on the File thread, 840 // respectively), and since we choose not to keep state on the File thread,
833 // this is the place where the races collide. It's also possible for 841 // this is the place where the races collide. It's also possible for
834 // interrupts to race with cancels. 842 // interrupts to race with cancels.
835 843
836 // Whatever happens, the first one to hit the UI thread wins. 844 // Whatever happens, the first one to hit the UI thread wins.
837 if (!IsInProgress()) 845 if (state_ != IN_PROGRESS_INTERNAL)
838 return; 846 return;
839 847
840 last_reason_ = reason; 848 last_reason_ = reason;
841 TransitionTo(INTERRUPTED); 849 TransitionTo(INTERRUPTED_INTERNAL);
842 download_stats::RecordDownloadInterrupted( 850 download_stats::RecordDownloadInterrupted(
843 reason, received_bytes_, total_bytes_); 851 reason, received_bytes_, total_bytes_);
844 delegate_->DownloadStopped(this); 852 delegate_->DownloadStopped(this);
845 } 853 }
846 854
847 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { 855 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) {
848 total_bytes_ = total_bytes; 856 total_bytes_ = total_bytes;
849 } 857 }
850 858
851 // Updates from the download thread may have been posted while this download 859 // Updates from the download thread may have been posted while this download
852 // was being cancelled in the UI thread, so we'll accept them unless we're 860 // was being cancelled in the UI thread, so we'll accept them unless we're
853 // complete. 861 // complete.
854 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, 862 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far,
855 int64 bytes_per_sec, 863 int64 bytes_per_sec,
856 const std::string& hash_state) { 864 const std::string& hash_state) {
857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
858 866
859 if (!IsInProgress()) { 867 if (state_ != IN_PROGRESS_INTERNAL) {
860 // Ignore if we're no longer in-progress. This can happen if we race a 868 // Ignore if we're no longer in-progress. This can happen if we race a
861 // Cancel on the UI thread with an update on the FILE thread. 869 // Cancel on the UI thread with an update on the FILE thread.
862 // 870 //
863 // TODO(rdsmith): Arguably we should let this go through, as this means 871 // TODO(rdsmith): Arguably we should let this go through, as this means
864 // the download really did get further than we know before it was 872 // the download really did get further than we know before it was
865 // cancelled. But the gain isn't very large, and the code is more 873 // cancelled. But the gain isn't very large, and the code is more
866 // fragile if it has to support in progress updates in a non-in-progress 874 // fragile if it has to support in progress updates in a non-in-progress
867 // state. This issue should be readdressed when we revamp performance 875 // state. This issue should be readdressed when we revamp performance
868 // reporting. 876 // reporting.
869 return; 877 return;
(...skipping 24 matching lines...) Expand all
894 all_data_saved_ = true; 902 all_data_saved_ = true;
895 ProgressComplete(size, final_hash); 903 ProgressComplete(size, final_hash);
896 UpdateObservers(); 904 UpdateObservers();
897 } 905 }
898 906
899 void DownloadItemImpl::MarkAsComplete() { 907 void DownloadItemImpl::MarkAsComplete() {
900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
901 909
902 DCHECK(all_data_saved_); 910 DCHECK(all_data_saved_);
903 end_time_ = base::Time::Now(); 911 end_time_ = base::Time::Now();
904 TransitionTo(COMPLETE); 912 TransitionTo(COMPLETE_INTERNAL);
905 } 913 }
906 914
907 void DownloadItemImpl::SetIsPersisted() { 915 void DownloadItemImpl::SetIsPersisted() {
908 is_persisted_ = true; 916 is_persisted_ = true;
909 UpdateObservers(); 917 UpdateObservers();
910 } 918 }
911 919
912 void DownloadItemImpl::SetDbHandle(int64 handle) { 920 void DownloadItemImpl::SetDbHandle(int64 handle) {
913 db_handle_ = handle; 921 db_handle_ = handle;
914 922
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 target_path_ = target_path; 987 target_path_ = target_path;
980 target_disposition_ = disposition; 988 target_disposition_ = disposition;
981 SetDangerType(danger_type); 989 SetDangerType(danger_type);
982 // TODO(asanka): SetDangerType() doesn't need to send a notification here. 990 // TODO(asanka): SetDangerType() doesn't need to send a notification here.
983 991
984 // We want the intermediate and target paths to refer to the same directory so 992 // We want the intermediate and target paths to refer to the same directory so
985 // that they are both on the same device and subject to same 993 // that they are both on the same device and subject to same
986 // space/permission/availability constraints. 994 // space/permission/availability constraints.
987 DCHECK(intermediate_path.DirName() == target_path.DirName()); 995 DCHECK(intermediate_path.DirName() == target_path.DirName());
988 996
997 if (state_ != IN_PROGRESS_INTERNAL) {
998 // If we've been cancelled or interrupted while the target was being
999 // determined, continue the cascade with a null name.
1000 // The error doesn't matter as the cause of download stoppage
1001 // will already have been recorded and will be retained, but we use
1002 // whatever was recorded for consistency.
1003 OnDownloadRenamedToIntermediateName(last_reason_, FilePath());
1004 return;
1005 }
1006
989 // Rename to intermediate name. 1007 // Rename to intermediate name.
990 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a 1008 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a
991 // spurious rename when we can just rename to the final 1009 // spurious rename when we can just rename to the final
992 // filename. Unnecessary renames may cause bugs like 1010 // filename. Unnecessary renames may cause bugs like
993 // http://crbug.com/74187. 1011 // http://crbug.com/74187.
994 DownloadFileManager::RenameCompletionCallback callback = 1012 DownloadFileManager::RenameCompletionCallback callback =
995 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, 1013 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
996 weak_ptr_factory_.GetWeakPtr()); 1014 weak_ptr_factory_.GetWeakPtr());
997 BrowserThread::PostTask( 1015 BrowserThread::PostTask(
998 BrowserThread::FILE, FROM_HERE, 1016 BrowserThread::FILE, FROM_HERE,
(...skipping 19 matching lines...) Expand all
1018 void DownloadItemImpl::MaybeCompleteDownload() { 1036 void DownloadItemImpl::MaybeCompleteDownload() {
1019 // TODO(rdsmith): Move logic for this function here. 1037 // TODO(rdsmith): Move logic for this function here.
1020 delegate_->MaybeCompleteDownload(this); 1038 delegate_->MaybeCompleteDownload(this);
1021 } 1039 }
1022 1040
1023 // Called by DownloadManagerImpl::MaybeCompleteDownload() when it has 1041 // Called by DownloadManagerImpl::MaybeCompleteDownload() when it has
1024 // determined that the download is ready for completion. 1042 // determined that the download is ready for completion.
1025 void DownloadItemImpl::OnDownloadCompleting() { 1043 void DownloadItemImpl::OnDownloadCompleting() {
1026 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1044 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1027 1045
1046 if (state_ != IN_PROGRESS_INTERNAL)
1047 return;
1048
1028 VLOG(20) << __FUNCTION__ << "()" 1049 VLOG(20) << __FUNCTION__ << "()"
1029 << " needs rename = " << NeedsRename() 1050 << " needs rename = " << NeedsRename()
1030 << " " << DebugString(true); 1051 << " " << DebugString(true);
1031 DCHECK(!GetTargetFilePath().empty()); 1052 DCHECK(!GetTargetFilePath().empty());
1032 DCHECK_NE(DANGEROUS, GetSafetyState()); 1053 DCHECK_NE(DANGEROUS, GetSafetyState());
1033 1054
1034 if (NeedsRename()) { 1055 if (NeedsRename()) {
1035 DownloadFileManager::RenameCompletionCallback callback = 1056 DownloadFileManager::RenameCompletionCallback callback =
1036 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, 1057 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName,
1037 weak_ptr_factory_.GetWeakPtr()); 1058 weak_ptr_factory_.GetWeakPtr());
1038 BrowserThread::PostTask( 1059 BrowserThread::PostTask(
1039 BrowserThread::FILE, FROM_HERE, 1060 BrowserThread::FILE, FROM_HERE,
1040 base::Bind(&DownloadFileManager::RenameDownloadFile, 1061 base::Bind(&DownloadFileManager::RenameDownloadFile,
1041 delegate_->GetDownloadFileManager(), GetGlobalId(), 1062 delegate_->GetDownloadFileManager(), GetGlobalId(),
1042 GetTargetFilePath(), true, callback)); 1063 GetTargetFilePath(), true, callback));
1043 } else { 1064 } else {
1044 // Complete the download and release the DownloadFile. 1065 // Complete the download and release the DownloadFile.
1045 BrowserThread::PostTask( 1066 BrowserThread::PostTask(
1046 BrowserThread::FILE, FROM_HERE, 1067 BrowserThread::FILE, FROM_HERE,
1047 base::Bind(&DownloadFileManager::CompleteDownload, 1068 base::Bind(&DownloadFileManager::CompleteDownload,
1048 delegate_->GetDownloadFileManager(), GetGlobalId(), 1069 delegate_->GetDownloadFileManager(), GetGlobalId(),
1049 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, 1070 base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
1050 weak_ptr_factory_.GetWeakPtr()))); 1071 weak_ptr_factory_.GetWeakPtr())));
1072 TransitionTo(COMPLETING_INTERNAL);
1051 } 1073 }
1052 } 1074 }
1053 1075
1054 void DownloadItemImpl::OnDownloadRenamedToFinalName( 1076 void DownloadItemImpl::OnDownloadRenamedToFinalName(
1055 content::DownloadInterruptReason reason, 1077 content::DownloadInterruptReason reason,
1056 const FilePath& full_path) { 1078 const FilePath& full_path) {
1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1079 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1058 1080
1081 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which
1082 // will result in deleting the file on the file thread. So we don't
1083 // care about the name having been changed.
1084 if (state_ != IN_PROGRESS_INTERNAL)
1085 return;
1086
1059 VLOG(20) << __FUNCTION__ << "()" 1087 VLOG(20) << __FUNCTION__ << "()"
1060 << " full_path = \"" << full_path.value() << "\"" 1088 << " full_path = \"" << full_path.value() << "\""
1061 << " needed rename = " << NeedsRename() 1089 << " needed rename = " << NeedsRename()
1062 << " " << DebugString(false); 1090 << " " << DebugString(false);
1063 DCHECK(NeedsRename()); 1091 DCHECK(NeedsRename());
1064 1092
1065 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) { 1093 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
1066 Interrupt(reason); 1094 Interrupt(reason);
1067 return; 1095 return;
1068 } 1096 }
1069 1097
1070 // full_path is now the current and target file path. 1098 // full_path is now the current and target file path.
1071 DCHECK(!full_path.empty()); 1099 DCHECK(!full_path.empty());
1072 target_path_ = full_path; 1100 target_path_ = full_path;
1073 SetFullPath(full_path); 1101 SetFullPath(full_path);
1074 delegate_->DownloadRenamedToFinalName(this); 1102 delegate_->DownloadRenamedToFinalName(this);
1075 1103
1076 // Complete the download and release the DownloadFile. 1104 // Complete the download and release the DownloadFile.
1077 BrowserThread::PostTask( 1105 BrowserThread::PostTask(
1078 BrowserThread::FILE, FROM_HERE, 1106 BrowserThread::FILE, FROM_HERE,
1079 base::Bind(&DownloadFileManager::CompleteDownload, 1107 base::Bind(&DownloadFileManager::CompleteDownload,
1080 delegate_->GetDownloadFileManager(), GetGlobalId(), 1108 delegate_->GetDownloadFileManager(), GetGlobalId(),
1081 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, 1109 base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
1082 weak_ptr_factory_.GetWeakPtr()))); 1110 weak_ptr_factory_.GetWeakPtr())));
1111 TransitionTo(COMPLETING_INTERNAL);
1083 } 1112 }
1084 1113
1085 void DownloadItemImpl::OnDownloadFileReleased() { 1114 void DownloadItemImpl::OnDownloadFileReleased() {
1086 if (delegate_->ShouldOpenDownload(this)) 1115 if (delegate_->ShouldOpenDownload(this))
1087 Completed(); 1116 Completed();
1088 else 1117 else
1089 delegate_delayed_complete_ = true; 1118 delegate_delayed_complete_ = true;
1090 } 1119 }
1091 1120
1092 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { 1121 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) {
1093 auto_opened_ = auto_opened; 1122 auto_opened_ = auto_opened;
1094 Completed(); 1123 Completed();
1095 } 1124 }
1096 1125
1097 void DownloadItemImpl::Completed() { 1126 void DownloadItemImpl::Completed() {
1098 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1099 1128
1100 VLOG(20) << __FUNCTION__ << "() " << DebugString(false); 1129 VLOG(20) << __FUNCTION__ << "() " << DebugString(false);
1101 1130
1102 DCHECK(all_data_saved_); 1131 DCHECK(all_data_saved_);
1103 end_time_ = base::Time::Now(); 1132 end_time_ = base::Time::Now();
1104 TransitionTo(COMPLETE); 1133 TransitionTo(COMPLETE_INTERNAL);
1105 delegate_->DownloadCompleted(this); 1134 delegate_->DownloadCompleted(this);
1106 download_stats::RecordDownloadCompleted(start_tick_, received_bytes_); 1135 download_stats::RecordDownloadCompleted(start_tick_, received_bytes_);
1107 1136
1108 if (auto_opened_) { 1137 if (auto_opened_) {
1109 // If it was already handled by the delegate, do nothing. 1138 // If it was already handled by the delegate, do nothing.
1110 } else if (GetOpenWhenComplete() || 1139 } else if (GetOpenWhenComplete() ||
1111 ShouldOpenFileBasedOnExtension() || 1140 ShouldOpenFileBasedOnExtension() ||
1112 IsTemporary()) { 1141 IsTemporary()) {
1113 // If the download is temporary, like in drag-and-drop, do not open it but 1142 // If the download is temporary, like in drag-and-drop, do not open it but
1114 // we still need to set it auto-opened so that it can be removed from the 1143 // we still need to set it auto-opened so that it can be removed from the
(...skipping 21 matching lines...) Expand all
1136 hash_state_ = ""; 1165 hash_state_ = "";
1137 1166
1138 received_bytes_ = bytes_so_far; 1167 received_bytes_ = bytes_so_far;
1139 1168
1140 // If we've received more data than we were expecting (bad server info?), 1169 // If we've received more data than we were expecting (bad server info?),
1141 // revert to 'unknown size mode'. 1170 // revert to 'unknown size mode'.
1142 if (received_bytes_ > total_bytes_) 1171 if (received_bytes_ > total_bytes_)
1143 total_bytes_ = 0; 1172 total_bytes_ = 0;
1144 } 1173 }
1145 1174
1146 void DownloadItemImpl::TransitionTo(DownloadState new_state) { 1175 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) {
1147 if (state_ == new_state) 1176 if (state_ == new_state)
1148 return; 1177 return;
1149 1178
1150 DownloadState old_state = state_; 1179 DownloadInternalState old_state = state_;
1151 state_ = new_state; 1180 state_ = new_state;
1152 1181
1153 switch (state_) { 1182 switch (state_) {
1154 case COMPLETE: 1183 case COMPLETING_INTERNAL:
1184 bound_net_log_.AddEvent(
1185 net::NetLog::TYPE_DOWNLOAD_ITEM_COMPLETING,
1186 base::Bind(&download_net_logs::ItemCompletingCallback,
1187 received_bytes_, &hash_));
1188 break;
1189 case COMPLETE_INTERNAL:
1155 bound_net_log_.AddEvent( 1190 bound_net_log_.AddEvent(
1156 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, 1191 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED,
1157 base::Bind(&download_net_logs::ItemFinishedCallback, 1192 base::Bind(&download_net_logs::ItemFinishedCallback,
1158 received_bytes_, &hash_)); 1193 auto_opened_));
1159 break; 1194 break;
1160 case INTERRUPTED: 1195 case INTERRUPTED_INTERNAL:
1161 bound_net_log_.AddEvent( 1196 bound_net_log_.AddEvent(
1162 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, 1197 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED,
1163 base::Bind(&download_net_logs::ItemInterruptedCallback, 1198 base::Bind(&download_net_logs::ItemInterruptedCallback,
1164 last_reason_, received_bytes_, &hash_state_)); 1199 last_reason_, received_bytes_, &hash_state_));
1165 break; 1200 break;
1166 case CANCELLED: 1201 case CANCELLED_INTERNAL:
1167 bound_net_log_.AddEvent( 1202 bound_net_log_.AddEvent(
1168 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, 1203 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED,
1169 base::Bind(&download_net_logs::ItemCanceledCallback, 1204 base::Bind(&download_net_logs::ItemCanceledCallback,
1170 received_bytes_, &hash_state_)); 1205 received_bytes_, &hash_state_));
1171 break; 1206 break;
1172 default: 1207 default:
1173 break; 1208 break;
1174 } 1209 }
1175 1210
1176 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); 1211 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true);
1177 1212
1178 UpdateObservers(); 1213 // Only update observers on user visible state changes.
1214 if (kInternalStateMap[old_state] != kInternalStateMap[state_])
1215 UpdateObservers();
1179 1216
1180 bool is_done = (state_ != IN_PROGRESS); 1217 bool is_done = (state_ != IN_PROGRESS_INTERNAL &&
1181 bool was_done = (old_state != IN_PROGRESS); 1218 state_ != COMPLETING_INTERNAL);
1219 bool was_done = (old_state != IN_PROGRESS_INTERNAL &&
1220 old_state != COMPLETING_INTERNAL);
1182 if (is_done && !was_done) 1221 if (is_done && !was_done)
1183 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); 1222 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
1184 } 1223 }
1185 1224
1186 void DownloadItemImpl::SetDangerType(content::DownloadDangerType danger_type) { 1225 void DownloadItemImpl::SetDangerType(content::DownloadDangerType danger_type) {
1187 danger_type_ = danger_type; 1226 danger_type_ = danger_type;
1188 // Notify observers if the safety state has changed as a result of the new 1227 // Notify observers if the safety state has changed as a result of the new
1189 // danger type. 1228 // danger type.
1190 SafetyState updated_value = IsDangerous() ? 1229 SafetyState updated_value = IsDangerous() ?
1191 DownloadItem::DANGEROUS : DownloadItem::SAFE; 1230 DownloadItem::DANGEROUS : DownloadItem::SAFE;
(...skipping 13 matching lines...) Expand all
1205 << " " << DebugString(true); 1244 << " " << DebugString(true);
1206 DCHECK(!new_path.empty()); 1245 DCHECK(!new_path.empty());
1207 current_path_ = new_path; 1246 current_path_ = new_path;
1208 1247
1209 bound_net_log_.AddEvent( 1248 bound_net_log_.AddEvent(
1210 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, 1249 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED,
1211 base::Bind(&download_net_logs::ItemRenamedCallback, 1250 base::Bind(&download_net_logs::ItemRenamedCallback,
1212 &current_path_, &new_path)); 1251 &current_path_, &new_path));
1213 } 1252 }
1214 1253
1215 1254 const char* DownloadItemImpl::DebugDownloadStateString(
1216 1255 DownloadInternalState state) {
1217 1256 switch (state) {
1257 case IN_PROGRESS_INTERNAL:
1258 return "IN_PROGRESS";
1259 case COMPLETING_INTERNAL:
1260 return "COMPLETING";
1261 case COMPLETE_INTERNAL:
1262 return "COMPLETE";
1263 case CANCELLED_INTERNAL:
1264 return "CANCELLED";
1265 case INTERRUPTED_INTERNAL:
1266 return "INTERRUPTED";
1267 default:
1268 NOTREACHED() << "Unknown download state " << state;
1269 return "unknown";
1270 };
1271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698