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

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: Sync'd to LKGR (157436) 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[] = {
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_)
benjhayden 2012/09/19 15:44:35 s/!state_ ==/state_ !=/
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 Whooops. Done.
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) ==
benjhayden 2012/09/19 15:44:35 Could you put these up by the maps themselves?
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 I'd like to, but they need to be in the DownloadIt
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 (state_ == IN_PROGRESS_INTERNAL);
benjhayden 2012/09/19 15:44:35 Have you inspected all callers of IsPartialDownloa
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 Argggh. You triggerred my "not conceptually part
484 } 492 }
485 493
486 bool DownloadItemImpl::IsInProgress() const { 494 bool DownloadItemImpl::IsInProgress() const {
487 return (state_ == IN_PROGRESS); 495 return (state_ == IN_PROGRESS_INTERNAL || state_ == COMPLETING_INTERNAL);
488 } 496 }
489 497
490 bool DownloadItemImpl::IsCancelled() const { 498 bool DownloadItemImpl::IsCancelled() const {
491 return (state_ == CANCELLED) || 499 return (state_ == CANCELLED_INTERNAL || state_ == INTERRUPTED_INTERNAL);
492 (state_ == INTERRUPTED);
493 } 500 }
494 501
495 bool DownloadItemImpl::IsInterrupted() const { 502 bool DownloadItemImpl::IsInterrupted() const {
496 return (state_ == INTERRUPTED); 503 return (state_ == INTERRUPTED_INTERNAL);
497 } 504 }
498 505
499 bool DownloadItemImpl::IsComplete() const { 506 bool DownloadItemImpl::IsComplete() const {
500 return (state_ == COMPLETE); 507 return (state_ == COMPLETE_INTERNAL);
501 } 508 }
502 509
503 const GURL& DownloadItemImpl::GetURL() const { 510 const GURL& DownloadItemImpl::GetURL() const {
504 return url_chain_.empty() ? 511 return url_chain_.empty() ?
505 GURL::EmptyGURL() : url_chain_.back(); 512 GURL::EmptyGURL() : url_chain_.back();
506 } 513 }
507 514
508 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const { 515 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const {
509 return url_chain_; 516 return url_chain_;
510 } 517 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 670
664 base::Time DownloadItemImpl::GetStartTime() const { 671 base::Time DownloadItemImpl::GetStartTime() const {
665 return start_time_; 672 return start_time_;
666 } 673 }
667 674
668 base::Time DownloadItemImpl::GetEndTime() const { 675 base::Time DownloadItemImpl::GetEndTime() const {
669 return end_time_; 676 return end_time_;
670 } 677 }
671 678
672 bool DownloadItemImpl::CanShowInFolder() { 679 bool DownloadItemImpl::CanShowInFolder() {
673 return !IsCancelled() && !file_externally_removed_; 680 return state_ != CANCELLED_INTERNAL && !file_externally_removed_;
674 } 681 }
675 682
676 bool DownloadItemImpl::CanOpenDownload() { 683 bool DownloadItemImpl::CanOpenDownload() {
677 return !file_externally_removed_; 684 return !file_externally_removed_;
678 } 685 }
679 686
680 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() { 687 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() {
681 return delegate_->ShouldOpenFileBasedOnExtension(GetUserVerifiedFilePath()); 688 return delegate_->ShouldOpenFileBasedOnExtension(GetUserVerifiedFilePath());
682 } 689 }
683 690
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 750
744 void DownloadItemImpl::SetDisplayName(const FilePath& name) { 751 void DownloadItemImpl::SetDisplayName(const FilePath& name) {
745 display_name_ = name; 752 display_name_ = name;
746 } 753 }
747 754
748 std::string DownloadItemImpl::DebugString(bool verbose) const { 755 std::string DownloadItemImpl::DebugString(bool verbose) const {
749 std::string description = 756 std::string description =
750 base::StringPrintf("{ id = %d" 757 base::StringPrintf("{ id = %d"
751 " state = %s", 758 " state = %s",
752 download_id_.local(), 759 download_id_.local(),
753 DebugDownloadStateString(GetState())); 760 DebugDownloadStateString(state_));
754 761
755 // Construct a string of the URL chain. 762 // Construct a string of the URL chain.
756 std::string url_list("<none>"); 763 std::string url_list("<none>");
757 if (!url_chain_.empty()) { 764 if (!url_chain_.empty()) {
758 std::vector<GURL>::const_iterator iter = url_chain_.begin(); 765 std::vector<GURL>::const_iterator iter = url_chain_.begin();
759 std::vector<GURL>::const_iterator last = url_chain_.end(); 766 std::vector<GURL>::const_iterator last = url_chain_.end();
760 url_list = (*iter).spec(); 767 url_list = (*iter).spec();
761 ++iter; 768 ++iter;
762 for ( ; verbose && (iter != last); ++iter) { 769 for ( ; verbose && (iter != last); ++iter) {
763 url_list += " ->\n\t"; 770 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 834 // Somewhat counter-intuitively, it is possible for us to receive an
828 // interrupt after we've already been interrupted. The generation of 835 // interrupt after we've already been interrupted. The generation of
829 // interrupts from the file thread Renames and the generation of 836 // interrupts from the file thread Renames and the generation of
830 // interrupts from disk writes go through two different mechanisms (driven 837 // interrupts from disk writes go through two different mechanisms (driven
831 // by rename requests from UI thread and by write requests from IO thread, 838 // 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, 839 // 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 840 // this is the place where the races collide. It's also possible for
834 // interrupts to race with cancels. 841 // interrupts to race with cancels.
835 842
836 // Whatever happens, the first one to hit the UI thread wins. 843 // Whatever happens, the first one to hit the UI thread wins.
837 if (!IsInProgress()) 844 if (state_ != IN_PROGRESS_INTERNAL)
838 return; 845 return;
839 846
840 last_reason_ = reason; 847 last_reason_ = reason;
841 TransitionTo(INTERRUPTED); 848 TransitionTo(INTERRUPTED_INTERNAL);
842 download_stats::RecordDownloadInterrupted( 849 download_stats::RecordDownloadInterrupted(
843 reason, received_bytes_, total_bytes_); 850 reason, received_bytes_, total_bytes_);
844 delegate_->DownloadStopped(this); 851 delegate_->DownloadStopped(this);
845 } 852 }
846 853
847 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { 854 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) {
848 total_bytes_ = total_bytes; 855 total_bytes_ = total_bytes;
849 } 856 }
850 857
851 // Updates from the download thread may have been posted while this download 858 // 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 859 // was being cancelled in the UI thread, so we'll accept them unless we're
853 // complete. 860 // complete.
854 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, 861 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far,
855 int64 bytes_per_sec, 862 int64 bytes_per_sec,
856 const std::string& hash_state) { 863 const std::string& hash_state) {
857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
858 865
859 if (!IsInProgress()) { 866 if (state_ != IN_PROGRESS_INTERNAL) {
860 // Ignore if we're no longer in-progress. This can happen if we race a 867 // 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. 868 // Cancel on the UI thread with an update on the FILE thread.
862 // 869 //
863 // TODO(rdsmith): Arguably we should let this go through, as this means 870 // 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 871 // 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 872 // 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 873 // 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 874 // state. This issue should be readdressed when we revamp performance
868 // reporting. 875 // reporting.
869 return; 876 return;
(...skipping 24 matching lines...) Expand all
894 all_data_saved_ = true; 901 all_data_saved_ = true;
895 ProgressComplete(size, final_hash); 902 ProgressComplete(size, final_hash);
896 UpdateObservers(); 903 UpdateObservers();
897 } 904 }
898 905
899 void DownloadItemImpl::MarkAsComplete() { 906 void DownloadItemImpl::MarkAsComplete() {
900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
901 908
902 DCHECK(all_data_saved_); 909 DCHECK(all_data_saved_);
903 end_time_ = base::Time::Now(); 910 end_time_ = base::Time::Now();
904 TransitionTo(COMPLETE); 911 TransitionTo(COMPLETE_INTERNAL);
905 } 912 }
906 913
907 void DownloadItemImpl::SetIsPersisted() { 914 void DownloadItemImpl::SetIsPersisted() {
908 is_persisted_ = true; 915 is_persisted_ = true;
909 UpdateObservers(); 916 UpdateObservers();
910 } 917 }
911 918
912 void DownloadItemImpl::SetDbHandle(int64 handle) { 919 void DownloadItemImpl::SetDbHandle(int64 handle) {
913 db_handle_ = handle; 920 db_handle_ = handle;
914 921
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 target_path_ = target_path; 986 target_path_ = target_path;
980 target_disposition_ = disposition; 987 target_disposition_ = disposition;
981 SetDangerType(danger_type); 988 SetDangerType(danger_type);
982 // TODO(asanka): SetDangerType() doesn't need to send a notification here. 989 // TODO(asanka): SetDangerType() doesn't need to send a notification here.
983 990
984 // We want the intermediate and target paths to refer to the same directory so 991 // 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 992 // that they are both on the same device and subject to same
986 // space/permission/availability constraints. 993 // space/permission/availability constraints.
987 DCHECK(intermediate_path.DirName() == target_path.DirName()); 994 DCHECK(intermediate_path.DirName() == target_path.DirName());
988 995
996 if (!IsInProgress()) {
benjhayden 2012/09/19 15:44:35 Why respell some IsInProgress()/IsComplete()/etc.
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 Agreed. I had thought I had replaced them all (I
997 // If we've been cancelled or interrupted while the target was being
998 // determined, continue the cascade with a null name.
999 // The error doesn't matter as the cause of download stoppaged
benjhayden 2012/09/19 15:44:35 s/stoppaged/stoppage/
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 Done.
1000 // will already have been recorded.
benjhayden 2012/09/19 15:44:35 Could you convert "the cause of download stoppage"
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 I'm slightly confused by your question. My commen
1001 OnDownloadRenamedToIntermediateName(
1002 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, FilePath());
1003 return;
1004 }
1005
989 // Rename to intermediate name. 1006 // Rename to intermediate name.
990 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a 1007 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a
991 // spurious rename when we can just rename to the final 1008 // spurious rename when we can just rename to the final
992 // filename. Unnecessary renames may cause bugs like 1009 // filename. Unnecessary renames may cause bugs like
993 // http://crbug.com/74187. 1010 // http://crbug.com/74187.
994 DownloadFileManager::RenameCompletionCallback callback = 1011 DownloadFileManager::RenameCompletionCallback callback =
995 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, 1012 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
996 weak_ptr_factory_.GetWeakPtr()); 1013 weak_ptr_factory_.GetWeakPtr());
997 BrowserThread::PostTask( 1014 BrowserThread::PostTask(
998 BrowserThread::FILE, FROM_HERE, 1015 BrowserThread::FILE, FROM_HERE,
(...skipping 19 matching lines...) Expand all
1018 void DownloadItemImpl::MaybeCompleteDownload() { 1035 void DownloadItemImpl::MaybeCompleteDownload() {
1019 // TODO(rdsmith): Move logic for this function here. 1036 // TODO(rdsmith): Move logic for this function here.
1020 delegate_->MaybeCompleteDownload(this); 1037 delegate_->MaybeCompleteDownload(this);
1021 } 1038 }
1022 1039
1023 // Called by DownloadManagerImpl::MaybeCompleteDownload() when it has 1040 // Called by DownloadManagerImpl::MaybeCompleteDownload() when it has
1024 // determined that the download is ready for completion. 1041 // determined that the download is ready for completion.
1025 void DownloadItemImpl::OnDownloadCompleting() { 1042 void DownloadItemImpl::OnDownloadCompleting() {
1026 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1043 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1027 1044
1045 if (!IsInProgress())
1046 return;
1047
1028 VLOG(20) << __FUNCTION__ << "()" 1048 VLOG(20) << __FUNCTION__ << "()"
1029 << " needs rename = " << NeedsRename() 1049 << " needs rename = " << NeedsRename()
1030 << " " << DebugString(true); 1050 << " " << DebugString(true);
1031 DCHECK(!GetTargetFilePath().empty()); 1051 DCHECK(!GetTargetFilePath().empty());
1032 DCHECK_NE(DANGEROUS, GetSafetyState()); 1052 DCHECK_NE(DANGEROUS, GetSafetyState());
1033 1053
1034 if (NeedsRename()) { 1054 if (NeedsRename()) {
1035 DownloadFileManager::RenameCompletionCallback callback = 1055 DownloadFileManager::RenameCompletionCallback callback =
1036 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, 1056 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName,
1037 weak_ptr_factory_.GetWeakPtr()); 1057 weak_ptr_factory_.GetWeakPtr());
1038 BrowserThread::PostTask( 1058 BrowserThread::PostTask(
1039 BrowserThread::FILE, FROM_HERE, 1059 BrowserThread::FILE, FROM_HERE,
1040 base::Bind(&DownloadFileManager::RenameDownloadFile, 1060 base::Bind(&DownloadFileManager::RenameDownloadFile,
1041 delegate_->GetDownloadFileManager(), GetGlobalId(), 1061 delegate_->GetDownloadFileManager(), GetGlobalId(),
1042 GetTargetFilePath(), true, callback)); 1062 GetTargetFilePath(), true, callback));
1043 } else { 1063 } else {
1044 // Complete the download and release the DownloadFile. 1064 // Complete the download and release the DownloadFile.
1045 BrowserThread::PostTask( 1065 BrowserThread::PostTask(
1046 BrowserThread::FILE, FROM_HERE, 1066 BrowserThread::FILE, FROM_HERE,
1047 base::Bind(&DownloadFileManager::CompleteDownload, 1067 base::Bind(&DownloadFileManager::CompleteDownload,
1048 delegate_->GetDownloadFileManager(), GetGlobalId(), 1068 delegate_->GetDownloadFileManager(), GetGlobalId(),
1049 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, 1069 base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
1050 weak_ptr_factory_.GetWeakPtr()))); 1070 weak_ptr_factory_.GetWeakPtr())));
1071 TransitionTo(COMPLETING_INTERNAL);
1051 } 1072 }
1052 } 1073 }
1053 1074
1054 void DownloadItemImpl::OnDownloadRenamedToFinalName( 1075 void DownloadItemImpl::OnDownloadRenamedToFinalName(
1055 content::DownloadInterruptReason reason, 1076 content::DownloadInterruptReason reason,
1056 const FilePath& full_path) { 1077 const FilePath& full_path) {
1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1078 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1058 1079
1080 if (!IsInProgress())
benjhayden 2012/09/19 15:44:35 So, if I cancel a download *while* it's being rena
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 Huh. Good point; at a minimum we should have a co
1081 return;
1082
1059 VLOG(20) << __FUNCTION__ << "()" 1083 VLOG(20) << __FUNCTION__ << "()"
1060 << " full_path = \"" << full_path.value() << "\"" 1084 << " full_path = \"" << full_path.value() << "\""
1061 << " needed rename = " << NeedsRename() 1085 << " needed rename = " << NeedsRename()
1062 << " " << DebugString(false); 1086 << " " << DebugString(false);
1063 DCHECK(NeedsRename()); 1087 DCHECK(NeedsRename());
1064 1088
1065 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) { 1089 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
1066 Interrupt(reason); 1090 Interrupt(reason);
1067 return; 1091 return;
1068 } 1092 }
1069 1093
1070 // full_path is now the current and target file path. 1094 // full_path is now the current and target file path.
1071 DCHECK(!full_path.empty()); 1095 DCHECK(!full_path.empty());
1072 target_path_ = full_path; 1096 target_path_ = full_path;
1073 SetFullPath(full_path); 1097 SetFullPath(full_path);
1074 delegate_->DownloadRenamedToFinalName(this); 1098 delegate_->DownloadRenamedToFinalName(this);
1075 1099
1076 // Complete the download and release the DownloadFile. 1100 // Complete the download and release the DownloadFile.
1077 BrowserThread::PostTask( 1101 BrowserThread::PostTask(
1078 BrowserThread::FILE, FROM_HERE, 1102 BrowserThread::FILE, FROM_HERE,
1079 base::Bind(&DownloadFileManager::CompleteDownload, 1103 base::Bind(&DownloadFileManager::CompleteDownload,
1080 delegate_->GetDownloadFileManager(), GetGlobalId(), 1104 delegate_->GetDownloadFileManager(), GetGlobalId(),
1081 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, 1105 base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
1082 weak_ptr_factory_.GetWeakPtr()))); 1106 weak_ptr_factory_.GetWeakPtr())));
1107 TransitionTo(COMPLETING_INTERNAL);
1083 } 1108 }
1084 1109
1085 void DownloadItemImpl::OnDownloadFileReleased() { 1110 void DownloadItemImpl::OnDownloadFileReleased() {
1086 if (delegate_->ShouldOpenDownload(this)) 1111 if (delegate_->ShouldOpenDownload(this))
1087 Completed(); 1112 Completed();
1088 else 1113 else
1089 delegate_delayed_complete_ = true; 1114 delegate_delayed_complete_ = true;
1090 } 1115 }
1091 1116
1092 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { 1117 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) {
1093 auto_opened_ = auto_opened; 1118 auto_opened_ = auto_opened;
1094 Completed(); 1119 Completed();
1095 } 1120 }
1096 1121
1097 void DownloadItemImpl::Completed() { 1122 void DownloadItemImpl::Completed() {
1098 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1099 1124
1100 VLOG(20) << __FUNCTION__ << "() " << DebugString(false); 1125 VLOG(20) << __FUNCTION__ << "() " << DebugString(false);
1101 1126
1102 DCHECK(all_data_saved_); 1127 DCHECK(all_data_saved_);
1103 end_time_ = base::Time::Now(); 1128 end_time_ = base::Time::Now();
1104 TransitionTo(COMPLETE); 1129 TransitionTo(COMPLETE_INTERNAL);
1105 delegate_->DownloadCompleted(this); 1130 delegate_->DownloadCompleted(this);
1106 download_stats::RecordDownloadCompleted(start_tick_, received_bytes_); 1131 download_stats::RecordDownloadCompleted(start_tick_, received_bytes_);
1107 1132
1108 if (auto_opened_) { 1133 if (auto_opened_) {
1109 // If it was already handled by the delegate, do nothing. 1134 // If it was already handled by the delegate, do nothing.
1110 } else if (GetOpenWhenComplete() || 1135 } else if (GetOpenWhenComplete() ||
1111 ShouldOpenFileBasedOnExtension() || 1136 ShouldOpenFileBasedOnExtension() ||
1112 IsTemporary()) { 1137 IsTemporary()) {
1113 // If the download is temporary, like in drag-and-drop, do not open it but 1138 // 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 1139 // 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_ = ""; 1161 hash_state_ = "";
1137 1162
1138 received_bytes_ = bytes_so_far; 1163 received_bytes_ = bytes_so_far;
1139 1164
1140 // If we've received more data than we were expecting (bad server info?), 1165 // If we've received more data than we were expecting (bad server info?),
1141 // revert to 'unknown size mode'. 1166 // revert to 'unknown size mode'.
1142 if (received_bytes_ > total_bytes_) 1167 if (received_bytes_ > total_bytes_)
1143 total_bytes_ = 0; 1168 total_bytes_ = 0;
1144 } 1169 }
1145 1170
1146 void DownloadItemImpl::TransitionTo(DownloadState new_state) { 1171 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) {
1147 if (state_ == new_state) 1172 if (state_ == new_state)
1148 return; 1173 return;
1149 1174
1150 DownloadState old_state = state_; 1175 DownloadInternalState old_state = state_;
1151 state_ = new_state; 1176 state_ = new_state;
1152 1177
1153 switch (state_) { 1178 switch (state_) {
1154 case COMPLETE: 1179 case COMPLETING_INTERNAL:
1180 bound_net_log_.AddEvent(
1181 net::NetLog::TYPE_DOWNLOAD_ITEM_COMPLETING,
1182 base::Bind(&download_net_logs::ItemCompletingCallback,
1183 received_bytes_, &hash_));
1184 break;
1185 case COMPLETE_INTERNAL:
1155 bound_net_log_.AddEvent( 1186 bound_net_log_.AddEvent(
1156 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, 1187 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED,
1157 base::Bind(&download_net_logs::ItemFinishedCallback, 1188 base::Bind(&download_net_logs::ItemFinishedCallback,
1158 received_bytes_, &hash_)); 1189 auto_opened_));
1159 break; 1190 break;
1160 case INTERRUPTED: 1191 case INTERRUPTED_INTERNAL:
1161 bound_net_log_.AddEvent( 1192 bound_net_log_.AddEvent(
1162 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, 1193 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED,
1163 base::Bind(&download_net_logs::ItemInterruptedCallback, 1194 base::Bind(&download_net_logs::ItemInterruptedCallback,
1164 last_reason_, received_bytes_, &hash_state_)); 1195 last_reason_, received_bytes_, &hash_state_));
1165 break; 1196 break;
1166 case CANCELLED: 1197 case CANCELLED_INTERNAL:
1167 bound_net_log_.AddEvent( 1198 bound_net_log_.AddEvent(
1168 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, 1199 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED,
1169 base::Bind(&download_net_logs::ItemCanceledCallback, 1200 base::Bind(&download_net_logs::ItemCanceledCallback,
1170 received_bytes_, &hash_state_)); 1201 received_bytes_, &hash_state_));
1171 break; 1202 break;
1172 default: 1203 default:
1173 break; 1204 break;
1174 } 1205 }
1175 1206
1176 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); 1207 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true);
1177 1208
1178 UpdateObservers(); 1209 // Only update observers on user visible state changes.
1210 if (kInternalStateMap[old_state] != kInternalStateMap[state_])
benjhayden 2012/09/19 15:44:35 Should you use the state maps in IsInProgress()/Is
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 Could you put a few more words behind your argumen
1211 UpdateObservers();
1179 1212
1180 bool is_done = (state_ != IN_PROGRESS); 1213 bool is_done = (state_ != IN_PROGRESS_INTERNAL &&
1181 bool was_done = (old_state != IN_PROGRESS); 1214 state_ != COMPLETING_INTERNAL);
1215 bool was_done = (old_state != IN_PROGRESS_INTERNAL &&
1216 old_state != COMPLETING_INTERNAL);
1182 if (is_done && !was_done) 1217 if (is_done && !was_done)
1183 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); 1218 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
1184 } 1219 }
1185 1220
1186 void DownloadItemImpl::SetDangerType(content::DownloadDangerType danger_type) { 1221 void DownloadItemImpl::SetDangerType(content::DownloadDangerType danger_type) {
1187 danger_type_ = danger_type; 1222 danger_type_ = danger_type;
1188 // Notify observers if the safety state has changed as a result of the new 1223 // Notify observers if the safety state has changed as a result of the new
1189 // danger type. 1224 // danger type.
1190 SafetyState updated_value = IsDangerous() ? 1225 SafetyState updated_value = IsDangerous() ?
1191 DownloadItem::DANGEROUS : DownloadItem::SAFE; 1226 DownloadItem::DANGEROUS : DownloadItem::SAFE;
(...skipping 13 matching lines...) Expand all
1205 << " " << DebugString(true); 1240 << " " << DebugString(true);
1206 DCHECK(!new_path.empty()); 1241 DCHECK(!new_path.empty());
1207 current_path_ = new_path; 1242 current_path_ = new_path;
1208 1243
1209 bound_net_log_.AddEvent( 1244 bound_net_log_.AddEvent(
1210 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, 1245 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED,
1211 base::Bind(&download_net_logs::ItemRenamedCallback, 1246 base::Bind(&download_net_logs::ItemRenamedCallback,
1212 &current_path_, &new_path)); 1247 &current_path_, &new_path));
1213 } 1248 }
1214 1249
1250 // static
benjhayden 2012/09/19 15:44:35 What's the difference between a private static met
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 I originally followed your suggestion and took it
1251 const char* DownloadItemImpl::DebugDownloadStateString(
1252 DownloadInternalState state) {
1253 switch (state) {
1254 case IN_PROGRESS_INTERNAL:
1255 return "IN_PROGRESS";
1256 case COMPLETING_INTERNAL:
1257 return "COMPLETING";
1258 case COMPLETE_INTERNAL:
1259 return "COMPLETE";
1260 case CANCELLED_INTERNAL:
1261 return "CANCELLED";
1262 case INTERRUPTED_INTERNAL:
1263 return "INTERRUPTED";
1264 default:
1265 NOTREACHED() << "Unknown download state " << state;
1266 return "unknown";
1267 };
1268 }
1269
benjhayden 2012/09/19 15:44:35 Mind deleting all these blank lines?
Randy Smith (Not in Mondays) 2012/09/19 20:46:39 I'll have you know, I have a deep, sentimental att
1215 1270
1216 1271
1217 1272
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698