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

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

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r168573 Created 8 years, 1 month 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 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, MaybeCompleteDownload, and OnDownloadCompleting 7 // interfaces Start, MaybeCompleteDownload, and OnDownloadCompleting
8 // are placed in chronological order with the other (private) routines 8 // are placed in chronological order with the other (private) routines
9 // that together define a DownloadItem's state transitions 9 // 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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 download_file->Detach(); 103 download_file->Detach();
105 } 104 }
106 105
107 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { 106 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
109 download_file->Cancel(); 108 download_file->Cancel();
110 } 109 }
111 110
112 } // namespace 111 } // namespace
113 112
114 // Our download table ID starts at 1, so we use 0 to represent a download that
115 // has started, but has not yet had its data persisted in the table. We use fake
116 // database handles in incognito mode starting at -1 and progressively getting
117 // more negative.
118 // static
119 const int DownloadItem::kUninitializedHandle = 0;
120
121 const char DownloadItem::kEmptyFileHash[] = ""; 113 const char DownloadItem::kEmptyFileHash[] = "";
122 114
123 // Our download table ID starts at 1, so we use 0 to represent a download that
124 // has started, but has not yet had its data persisted in the table. We use fake
125 // database handles in incognito mode starting at -1 and progressively getting
126 // more negative.
127
128 // Constructor for reading from the history service. 115 // Constructor for reading from the history service.
129 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, 116 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
130 DownloadId download_id, 117 DownloadId download_id,
131 const DownloadPersistentStoreInfo& info, 118 const FilePath& path,
119 const GURL& url,
120 const GURL& referrer_url,
121 const base::Time& start_time,
122 const base::Time& end_time,
123 int64 received_bytes,
124 int64 total_bytes,
125 DownloadItem::DownloadState state,
126 bool opened,
132 const net::BoundNetLog& bound_net_log) 127 const net::BoundNetLog& bound_net_log)
133 : is_save_package_download_(false), 128 : is_save_package_download_(false),
134 download_id_(download_id), 129 download_id_(download_id),
135 current_path_(info.path), 130 current_path_(path),
136 target_path_(info.path), 131 target_path_(path),
137 target_disposition_(TARGET_DISPOSITION_OVERWRITE), 132 target_disposition_(TARGET_DISPOSITION_OVERWRITE),
138 url_chain_(1, info.url), 133 url_chain_(1, url),
139 referrer_url_(info.referrer_url), 134 referrer_url_(referrer_url),
140 transition_type_(PAGE_TRANSITION_LINK), 135 transition_type_(PAGE_TRANSITION_LINK),
141 has_user_gesture_(false), 136 has_user_gesture_(false),
142 total_bytes_(info.total_bytes), 137 total_bytes_(total_bytes),
143 received_bytes_(info.received_bytes), 138 received_bytes_(received_bytes),
144 bytes_per_sec_(0), 139 bytes_per_sec_(0),
145 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 140 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
146 start_tick_(base::TimeTicks()), 141 start_tick_(base::TimeTicks()),
147 state_(ExternalToInternalState(info.state)), 142 state_(ExternalToInternalState(state)),
148 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 143 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
149 start_time_(info.start_time), 144 start_time_(start_time),
150 end_time_(info.end_time), 145 end_time_(end_time),
151 db_handle_(info.db_handle),
152 delegate_(delegate), 146 delegate_(delegate),
153 is_paused_(false), 147 is_paused_(false),
154 open_when_complete_(false), 148 open_when_complete_(false),
155 file_externally_removed_(false), 149 file_externally_removed_(false),
156 safety_state_(SAFE), 150 safety_state_(SAFE),
157 auto_opened_(false), 151 auto_opened_(false),
158 is_persisted_(true),
159 is_temporary_(false), 152 is_temporary_(false),
160 all_data_saved_(false), 153 all_data_saved_(false),
161 opened_(info.opened), 154 opened_(opened),
162 open_enabled_(true), 155 open_enabled_(true),
163 delegate_delayed_complete_(false), 156 delegate_delayed_complete_(false),
164 bound_net_log_(bound_net_log), 157 bound_net_log_(bound_net_log),
165 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 158 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
166 delegate_->Attach(); 159 delegate_->Attach();
167 if (state_ == IN_PROGRESS_INTERNAL) 160 if (state_ == IN_PROGRESS_INTERNAL)
168 state_ = CANCELLED_INTERNAL; 161 state_ = CANCELLED_INTERNAL;
169 if (state_ == COMPLETE_INTERNAL) 162 if (state_ == COMPLETE_INTERNAL)
170 all_data_saved_ = true; 163 all_data_saved_ = true;
171 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); 164 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT);
(...skipping 22 matching lines...) Expand all
194 original_mime_type_(info.original_mime_type), 187 original_mime_type_(info.original_mime_type),
195 remote_address_(info.remote_address), 188 remote_address_(info.remote_address),
196 total_bytes_(info.total_bytes), 189 total_bytes_(info.total_bytes),
197 received_bytes_(0), 190 received_bytes_(0),
198 bytes_per_sec_(0), 191 bytes_per_sec_(0),
199 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 192 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
200 start_tick_(base::TimeTicks::Now()), 193 start_tick_(base::TimeTicks::Now()),
201 state_(IN_PROGRESS_INTERNAL), 194 state_(IN_PROGRESS_INTERNAL),
202 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 195 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
203 start_time_(info.start_time), 196 start_time_(info.start_time),
204 db_handle_(DownloadItem::kUninitializedHandle),
205 delegate_(delegate), 197 delegate_(delegate),
206 is_paused_(false), 198 is_paused_(false),
207 open_when_complete_(false), 199 open_when_complete_(false),
208 file_externally_removed_(false), 200 file_externally_removed_(false),
209 safety_state_(SAFE), 201 safety_state_(SAFE),
210 auto_opened_(false), 202 auto_opened_(false),
211 is_persisted_(false),
212 is_temporary_(!info.save_info->file_path.empty()), 203 is_temporary_(!info.save_info->file_path.empty()),
213 all_data_saved_(false), 204 all_data_saved_(false),
214 opened_(false), 205 opened_(false),
215 open_enabled_(true), 206 open_enabled_(true),
216 delegate_delayed_complete_(false), 207 delegate_delayed_complete_(false),
217 bound_net_log_(bound_net_log), 208 bound_net_log_(bound_net_log),
218 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 209 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
219 delegate_->Attach(); 210 delegate_->Attach();
220 Init(true /* actively downloading */, SRC_NEW_DOWNLOAD); 211 Init(true /* actively downloading */, SRC_NEW_DOWNLOAD);
221 212
(...skipping 27 matching lines...) Expand all
249 mime_type_(mime_type), 240 mime_type_(mime_type),
250 original_mime_type_(mime_type), 241 original_mime_type_(mime_type),
251 total_bytes_(0), 242 total_bytes_(0),
252 received_bytes_(0), 243 received_bytes_(0),
253 bytes_per_sec_(0), 244 bytes_per_sec_(0),
254 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 245 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
255 start_tick_(base::TimeTicks::Now()), 246 start_tick_(base::TimeTicks::Now()),
256 state_(IN_PROGRESS_INTERNAL), 247 state_(IN_PROGRESS_INTERNAL),
257 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 248 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
258 start_time_(base::Time::Now()), 249 start_time_(base::Time::Now()),
259 db_handle_(DownloadItem::kUninitializedHandle),
260 delegate_(delegate), 250 delegate_(delegate),
261 is_paused_(false), 251 is_paused_(false),
262 open_when_complete_(false), 252 open_when_complete_(false),
263 file_externally_removed_(false), 253 file_externally_removed_(false),
264 safety_state_(SAFE), 254 safety_state_(SAFE),
265 auto_opened_(false), 255 auto_opened_(false),
266 is_persisted_(false),
267 is_temporary_(false), 256 is_temporary_(false),
268 all_data_saved_(false), 257 all_data_saved_(false),
269 opened_(false), 258 opened_(false),
270 open_enabled_(true), 259 open_enabled_(true),
271 delegate_delayed_complete_(false), 260 delegate_delayed_complete_(false),
272 bound_net_log_(bound_net_log), 261 bound_net_log_(bound_net_log),
273 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 262 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
274 delegate_->Attach(); 263 delegate_->Attach();
275 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); 264 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS);
276 } 265 }
(...skipping 26 matching lines...) Expand all
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
304 293
305 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); 294 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
306 } 295 }
307 296
308 void DownloadItemImpl::DangerousDownloadValidated() { 297 void DownloadItemImpl::DangerousDownloadValidated() {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
310 DCHECK_EQ(IN_PROGRESS, GetState()); 299 DCHECK_EQ(IN_PROGRESS, GetState());
311 DCHECK_EQ(DANGEROUS, GetSafetyState()); 300 DCHECK_EQ(DANGEROUS, GetSafetyState());
312 301
302 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
303
313 if (GetState() != IN_PROGRESS) 304 if (GetState() != IN_PROGRESS)
314 return; 305 return;
315 306
316 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated", 307 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated",
317 GetDangerType(), 308 GetDangerType(),
318 DOWNLOAD_DANGER_TYPE_MAX); 309 DOWNLOAD_DANGER_TYPE_MAX);
319 310
320 safety_state_ = DANGEROUS_BUT_VALIDATED; 311 safety_state_ = DANGEROUS_BUT_VALIDATED;
321 312
322 bound_net_log_.AddEvent( 313 bound_net_log_.AddEvent(
323 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 314 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
324 base::Bind(&ItemCheckedNetLogCallback, 315 base::Bind(&ItemCheckedNetLogCallback,
325 GetDangerType(), GetSafetyState())); 316 GetDangerType(), GetSafetyState()));
326 317
327 UpdateObservers(); 318 UpdateObservers();
328 319
329 MaybeCompleteDownload(); 320 MaybeCompleteDownload();
330 } 321 }
331 322
332 void DownloadItemImpl::TogglePause() { 323 void DownloadItemImpl::TogglePause() {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334
335 DCHECK(state_ == IN_PROGRESS_INTERNAL || state_ == COMPLETING_INTERNAL); 325 DCHECK(state_ == IN_PROGRESS_INTERNAL || state_ == COMPLETING_INTERNAL);
326 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
336 327
337 // Ignore pauses when we've passed the commit point. 328 // Ignore pauses when we've passed the commit point.
338 if (state_ == COMPLETING_INTERNAL) 329 if (state_ == COMPLETING_INTERNAL)
339 return; 330 return;
340 331
341 if (is_paused_) 332 if (is_paused_)
342 request_handle_->ResumeRequest(); 333 request_handle_->ResumeRequest();
343 else 334 else
344 request_handle_->PauseRequest(); 335 request_handle_->PauseRequest();
345 is_paused_ = !is_paused_; 336 is_paused_ = !is_paused_;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 442 }
452 443
453 int32 DownloadItemImpl::GetId() const { 444 int32 DownloadItemImpl::GetId() const {
454 return download_id_.local(); 445 return download_id_.local();
455 } 446 }
456 447
457 DownloadId DownloadItemImpl::GetGlobalId() const { 448 DownloadId DownloadItemImpl::GetGlobalId() const {
458 return download_id_; 449 return download_id_;
459 } 450 }
460 451
461 int64 DownloadItemImpl::GetDbHandle() const {
462 return db_handle_;
463 }
464
465 DownloadItem::DownloadState DownloadItemImpl::GetState() const { 452 DownloadItem::DownloadState DownloadItemImpl::GetState() const {
466 return InternalToExternalState(state_); 453 return InternalToExternalState(state_);
467 } 454 }
468 455
469 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { 456 DownloadInterruptReason DownloadItemImpl::GetLastReason() const {
470 return last_reason_; 457 return last_reason_;
471 } 458 }
472 459
473 bool DownloadItemImpl::IsPaused() const { 460 bool DownloadItemImpl::IsPaused() const {
474 return is_paused_; 461 return is_paused_;
475 } 462 }
476 463
477 bool DownloadItemImpl::IsTemporary() const { 464 bool DownloadItemImpl::IsTemporary() const {
478 return is_temporary_; 465 return is_temporary_;
479 } 466 }
480 467
481 bool DownloadItemImpl::IsPersisted() const {
482 return is_persisted_;
483 }
484
485 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to 468 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to
486 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. 469 // |IsPartialDownload()|, when resuming interrupted downloads is implemented.
487 bool DownloadItemImpl::IsPartialDownload() const { 470 bool DownloadItemImpl::IsPartialDownload() const {
488 return InternalToExternalState(state_) == IN_PROGRESS; 471 return InternalToExternalState(state_) == IN_PROGRESS;
489 } 472 }
490 473
491 bool DownloadItemImpl::IsInProgress() const { 474 bool DownloadItemImpl::IsInProgress() const {
492 return InternalToExternalState(state_) == IN_PROGRESS; 475 return InternalToExternalState(state_) == IN_PROGRESS;
493 } 476 }
494 477
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 674 }
692 675
693 bool DownloadItemImpl::GetAutoOpened() { 676 bool DownloadItemImpl::GetAutoOpened() {
694 return auto_opened_; 677 return auto_opened_;
695 } 678 }
696 679
697 bool DownloadItemImpl::GetOpened() const { 680 bool DownloadItemImpl::GetOpened() const {
698 return opened_; 681 return opened_;
699 } 682 }
700 683
701 DownloadPersistentStoreInfo DownloadItemImpl::GetPersistentStoreInfo() const {
702 // TODO(asanka): Persist GetTargetFilePath() as well.
703 return DownloadPersistentStoreInfo(GetFullPath(),
704 GetURL(),
705 GetReferrerUrl(),
706 GetStartTime(),
707 GetEndTime(),
708 GetReceivedBytes(),
709 GetTotalBytes(),
710 GetState(),
711 GetDbHandle(),
712 GetOpened());
713 }
714
715 BrowserContext* DownloadItemImpl::GetBrowserContext() const { 684 BrowserContext* DownloadItemImpl::GetBrowserContext() const {
716 return delegate_->GetBrowserContext(); 685 return delegate_->GetBrowserContext();
717 } 686 }
718 687
719 WebContents* DownloadItemImpl::GetWebContents() const { 688 WebContents* DownloadItemImpl::GetWebContents() const {
720 // TODO(rdsmith): Remove null check after removing GetWebContents() from 689 // TODO(rdsmith): Remove null check after removing GetWebContents() from
721 // paths that might be used by DownloadItems created from history import. 690 // paths that might be used by DownloadItems created from history import.
722 // Currently such items have null request_handle_s, where other items 691 // Currently such items have null request_handle_s, where other items
723 // (regular and SavePackage downloads) have actual objects off the pointer. 692 // (regular and SavePackage downloads) have actual objects off the pointer.
724 if (request_handle_.get()) 693 if (request_handle_.get())
725 return request_handle_->GetWebContents(); 694 return request_handle_->GetWebContents();
726 return NULL; 695 return NULL;
727 } 696 }
728 697
729 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { 698 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) {
730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
731 DCHECK(AllDataSaved()); 700 DCHECK(AllDataSaved());
701 VLOG(20) << __FUNCTION__ << " danger_type=" << danger_type
702 << " download=" << DebugString(true);
732 SetDangerType(danger_type); 703 SetDangerType(danger_type);
733 UpdateObservers(); 704 UpdateObservers();
734 } 705 }
735 706
736 void DownloadItemImpl::SetOpenWhenComplete(bool open) { 707 void DownloadItemImpl::SetOpenWhenComplete(bool open) {
737 open_when_complete_ = open; 708 open_when_complete_ = open;
738 } 709 }
739 710
740 void DownloadItemImpl::SetIsTemporary(bool temporary) { 711 void DownloadItemImpl::SetIsTemporary(bool temporary) {
741 is_temporary_ = temporary; 712 is_temporary_ = temporary;
(...skipping 23 matching lines...) Expand all
765 ++iter; 736 ++iter;
766 for ( ; verbose && (iter != last); ++iter) { 737 for ( ; verbose && (iter != last); ++iter) {
767 url_list += " ->\n\t"; 738 url_list += " ->\n\t";
768 const GURL& next_url = *iter; 739 const GURL& next_url = *iter;
769 url_list += next_url.spec(); 740 url_list += next_url.spec();
770 } 741 }
771 } 742 }
772 743
773 if (verbose) { 744 if (verbose) {
774 description += base::StringPrintf( 745 description += base::StringPrintf(
775 " db_handle = %" PRId64
776 " total = %" PRId64 746 " total = %" PRId64
777 " received = %" PRId64 747 " received = %" PRId64
778 " reason = %s" 748 " reason = %s"
779 " paused = %c" 749 " paused = %c"
780 " safety = %s" 750 " safety = %s"
781 " last_modified = '%s'" 751 " last_modified = '%s'"
782 " etag = '%s'" 752 " etag = '%s'"
783 " url_chain = \n\t\"%s\"\n\t" 753 " url_chain = \n\t\"%s\"\n\t"
784 " full_path = \"%" PRFilePath "\"" 754 " full_path = \"%" PRFilePath "\""
785 " target_path = \"%" PRFilePath "\"" 755 " target_path = \"%" PRFilePath "\""
786 " has download file = %s", 756 " has download file = %s",
787 GetDbHandle(),
788 GetTotalBytes(), 757 GetTotalBytes(),
789 GetReceivedBytes(), 758 GetReceivedBytes(),
790 InterruptReasonDebugString(last_reason_).c_str(), 759 InterruptReasonDebugString(last_reason_).c_str(),
791 IsPaused() ? 'T' : 'F', 760 IsPaused() ? 'T' : 'F',
792 DebugSafetyStateString(GetSafetyState()), 761 DebugSafetyStateString(GetSafetyState()),
793 GetLastModifiedTime().c_str(), 762 GetLastModifiedTime().c_str(),
794 GetETag().c_str(), 763 GetETag().c_str(),
795 url_list.c_str(), 764 url_list.c_str(),
796 GetFullPath().value().c_str(), 765 GetFullPath().value().c_str(),
797 GetTargetFilePath().value().c_str(), 766 GetTargetFilePath().value().c_str(),
(...skipping 10 matching lines...) Expand all
808 void DownloadItemImpl::MockDownloadOpenForTesting() { 777 void DownloadItemImpl::MockDownloadOpenForTesting() {
809 open_enabled_ = false; 778 open_enabled_ = false;
810 } 779 }
811 780
812 void DownloadItemImpl::NotifyRemoved() { 781 void DownloadItemImpl::NotifyRemoved() {
813 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); 782 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this));
814 } 783 }
815 784
816 void DownloadItemImpl::OnDownloadedFileRemoved() { 785 void DownloadItemImpl::OnDownloadedFileRemoved() {
817 file_externally_removed_ = true; 786 file_externally_removed_ = true;
787 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
818 UpdateObservers(); 788 UpdateObservers();
819 } 789 }
820 790
821 base::WeakPtr<DownloadDestinationObserver> 791 base::WeakPtr<DownloadDestinationObserver>
822 DownloadItemImpl::DestinationObserverAsWeakPtr() { 792 DownloadItemImpl::DestinationObserverAsWeakPtr() {
823 return weak_ptr_factory_.GetWeakPtr(); 793 return weak_ptr_factory_.GetWeakPtr();
824 } 794 }
825 795
826 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { 796 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) {
827 total_bytes_ = total_bytes; 797 total_bytes_ = total_bytes;
828 } 798 }
829 799
830 // Updates from the download thread may have been posted while this download 800 // Updates from the download thread may have been posted while this download
831 // was being cancelled in the UI thread, so we'll accept them unless we're 801 // was being cancelled in the UI thread, so we'll accept them unless we're
832 // complete. 802 // complete.
833 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, 803 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far,
834 int64 bytes_per_sec, 804 int64 bytes_per_sec,
835 const std::string& hash_state) { 805 const std::string& hash_state) {
836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
807 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far
808 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true);
837 809
838 if (state_ != IN_PROGRESS_INTERNAL) { 810 if (state_ != IN_PROGRESS_INTERNAL) {
839 // Ignore if we're no longer in-progress. This can happen if we race a 811 // Ignore if we're no longer in-progress. This can happen if we race a
840 // Cancel on the UI thread with an update on the FILE thread. 812 // Cancel on the UI thread with an update on the FILE thread.
841 // 813 //
842 // TODO(rdsmith): Arguably we should let this go through, as this means 814 // TODO(rdsmith): Arguably we should let this go through, as this means
843 // the download really did get further than we know before it was 815 // the download really did get further than we know before it was
844 // cancelled. But the gain isn't very large, and the code is more 816 // cancelled. But the gain isn't very large, and the code is more
845 // fragile if it has to support in progress updates in a non-in-progress 817 // fragile if it has to support in progress updates in a non-in-progress
846 // state. This issue should be readdressed when we revamp performance 818 // state. This issue should be readdressed when we revamp performance
(...skipping 17 matching lines...) Expand all
864 836
865 UpdateObservers(); 837 UpdateObservers();
866 } 838 }
867 839
868 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { 840 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) {
869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
870 842
871 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 843 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
872 DCHECK(!all_data_saved_); 844 DCHECK(!all_data_saved_);
873 all_data_saved_ = true; 845 all_data_saved_ = true;
846 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
874 847
875 // Store final hash and null out intermediate serialized hash state. 848 // Store final hash and null out intermediate serialized hash state.
876 hash_ = final_hash; 849 hash_ = final_hash;
877 hash_state_ = ""; 850 hash_state_ = "";
878 851
879 UpdateObservers(); 852 UpdateObservers();
880 } 853 }
881 854
882 void DownloadItemImpl::MarkAsComplete() { 855 void DownloadItemImpl::MarkAsComplete() {
883 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 856 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
884 857
885 DCHECK(all_data_saved_); 858 DCHECK(all_data_saved_);
886 end_time_ = base::Time::Now(); 859 end_time_ = base::Time::Now();
887 TransitionTo(COMPLETE_INTERNAL); 860 TransitionTo(COMPLETE_INTERNAL);
888 } 861 }
889
890 void DownloadItemImpl::SetIsPersisted() {
891 is_persisted_ = true;
892 UpdateObservers();
893 }
894
895 void DownloadItemImpl::SetDbHandle(int64 handle) {
896 db_handle_ = handle;
897
898 bound_net_log_.AddEvent(
899 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY,
900 net::NetLog::Int64Callback("db_handle", db_handle_));
901 }
902
903 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, 862 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far,
904 int64 bytes_per_sec, 863 int64 bytes_per_sec,
905 const std::string& hash_state) { 864 const std::string& hash_state) {
906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
866 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
907 867
908 if (!IsInProgress()) { 868 if (!IsInProgress()) {
909 // Ignore if we're no longer in-progress. This can happen if we race a 869 // Ignore if we're no longer in-progress. This can happen if we race a
910 // Cancel on the UI thread with an update on the FILE thread. 870 // Cancel on the UI thread with an update on the FILE thread.
911 // 871 //
912 // TODO(rdsmith): Arguably we should let this go through, as this means 872 // TODO(rdsmith): Arguably we should let this go through, as this means
913 // the download really did get further than we know before it was 873 // the download really did get further than we know before it was
914 // cancelled. But the gain isn't very large, and the code is more 874 // cancelled. But the gain isn't very large, and the code is more
915 // fragile if it has to support in progress updates in a non-in-progress 875 // fragile if it has to support in progress updates in a non-in-progress
916 // state. This issue should be readdressed when we revamp performance 876 // state. This issue should be readdressed when we revamp performance
(...skipping 13 matching lines...) Expand all
930 bound_net_log_.AddEvent( 890 bound_net_log_.AddEvent(
931 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, 891 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED,
932 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); 892 net::NetLog::Int64Callback("bytes_so_far", received_bytes_));
933 } 893 }
934 894
935 UpdateObservers(); 895 UpdateObservers();
936 } 896 }
937 897
938 void DownloadItemImpl::DestinationError(DownloadInterruptReason reason) { 898 void DownloadItemImpl::DestinationError(DownloadInterruptReason reason) {
939 // The DestinationError and Interrupt routines are being kept separate 899 // The DestinationError and Interrupt routines are being kept separate
940 // to allow for a future merging of the Cancel and Interrupt routines.. 900 // to allow for a future merging of the Cancel and Interrupt routines.
941 Interrupt(reason); 901 Interrupt(reason);
942 } 902 }
943 903
944 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { 904 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) {
905 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
945 if (!IsInProgress()) 906 if (!IsInProgress())
946 return; 907 return;
947 OnAllDataSaved(final_hash); 908 OnAllDataSaved(final_hash);
948 MaybeCompleteDownload(); 909 MaybeCompleteDownload();
949 } 910 }
950 911
951 // **** Download progression cascade 912 // **** Download progression cascade
952 913
953 void DownloadItemImpl::Init(bool active, 914 void DownloadItemImpl::Init(bool active,
954 DownloadType download_type) { 915 DownloadType download_type) {
(...skipping 12 matching lines...) Expand all
967 // See if it's set programmatically. 928 // See if it's set programmatically.
968 file_name = forced_file_path_.AsUTF8Unsafe(); 929 file_name = forced_file_path_.AsUTF8Unsafe();
969 // Possibly has a 'download' attribute for the anchor. 930 // Possibly has a 'download' attribute for the anchor.
970 if (file_name.empty()) 931 if (file_name.empty())
971 file_name = suggested_filename_; 932 file_name = suggested_filename_;
972 // From the URL file name. 933 // From the URL file name.
973 if (file_name.empty()) 934 if (file_name.empty())
974 file_name = GetURL().ExtractFileName(); 935 file_name = GetURL().ExtractFileName();
975 } 936 }
976 937
977 bound_net_log_.BeginEvent( 938 base::Callback<base::Value*(net::NetLog::LogLevel)> active_data = base::Bind(
978 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, 939 &ItemActivatedNetLogCallback, this, download_type, &file_name);
979 base::Bind(&ItemActivatedNetLogCallback, 940 if (active) {
980 this, download_type, &file_name)); 941 bound_net_log_.BeginEvent(
981 942 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data);
982 // If this is not an active download, end the ACTIVE event now. 943 } else {
983 if (!active) {
984 bound_net_log_.AddEvent( 944 bound_net_log_.AddEvent(
985 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, 945 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data);
986 net::NetLog::Int64Callback("db_handle", db_handle_));
987
988 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
989 } 946 }
990 947
991 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); 948 VLOG(20) << __FUNCTION__ << "() " << DebugString(true);
992 } 949 }
993 950
994 // We're starting the download. 951 // We're starting the download.
995 void DownloadItemImpl::Start(scoped_ptr<DownloadFile> file) { 952 void DownloadItemImpl::Start(scoped_ptr<DownloadFile> file) {
996 DCHECK(!download_file_.get()); 953 DCHECK(!download_file_.get());
997 DCHECK(file.get()); 954 DCHECK(file.get());
998 download_file_ = file.Pass(); 955 download_file_ = file.Pass();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 const FilePath& intermediate_path) { 990 const FilePath& intermediate_path) {
1034 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 991 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1035 992
1036 // If the |target_path| is empty, then we consider this download to be 993 // If the |target_path| is empty, then we consider this download to be
1037 // canceled. 994 // canceled.
1038 if (target_path.empty()) { 995 if (target_path.empty()) {
1039 Cancel(true); 996 Cancel(true);
1040 return; 997 return;
1041 } 998 }
1042 999
1000 VLOG(20) << __FUNCTION__ << " " << target_path.value() << " " << disposition
1001 << " " << danger_type << " " << DebugString(true);
1002
1043 target_path_ = target_path; 1003 target_path_ = target_path;
1044 target_disposition_ = disposition; 1004 target_disposition_ = disposition;
1045 SetDangerType(danger_type); 1005 SetDangerType(danger_type);
1046 // TODO(asanka): SetDangerType() doesn't need to send a notification here. 1006 // TODO(asanka): SetDangerType() doesn't need to send a notification here.
1047 1007
1048 // We want the intermediate and target paths to refer to the same directory so 1008 // We want the intermediate and target paths to refer to the same directory so
1049 // that they are both on the same device and subject to same 1009 // that they are both on the same device and subject to same
1050 // space/permission/availability constraints. 1010 // space/permission/availability constraints.
1051 DCHECK(intermediate_path.DirName() == target_path.DirName()); 1011 DCHECK(intermediate_path.DirName() == target_path.DirName());
1052 1012
(...skipping 22 matching lines...) Expand all
1075 base::Bind(&DownloadFile::RenameAndUniquify, 1035 base::Bind(&DownloadFile::RenameAndUniquify,
1076 // Safe because we control download file lifetime. 1036 // Safe because we control download file lifetime.
1077 base::Unretained(download_file_.get()), 1037 base::Unretained(download_file_.get()),
1078 intermediate_path, callback)); 1038 intermediate_path, callback));
1079 } 1039 }
1080 1040
1081 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( 1041 void DownloadItemImpl::OnDownloadRenamedToIntermediateName(
1082 DownloadInterruptReason reason, 1042 DownloadInterruptReason reason,
1083 const FilePath& full_path) { 1043 const FilePath& full_path) {
1084 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1044 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1045 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
1085 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { 1046 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
1086 Interrupt(reason); 1047 Interrupt(reason);
1087 } else { 1048 } else {
1088 SetFullPath(full_path); 1049 SetFullPath(full_path);
1089 UpdateObservers(); 1050 delegate_->ShowDownloadInBrowser(this);
1090 } 1051 }
1091 1052
1092 delegate_->DownloadRenamedToIntermediateName(this); 1053 MaybeCompleteDownload();
1093 } 1054 }
1094 1055
1095 // When SavePackage downloads MHTML to GData (see 1056 // When SavePackage downloads MHTML to GData (see
1096 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it 1057 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it
1097 // does for non-SavePackage downloads, but SavePackage downloads never satisfy 1058 // does for non-SavePackage downloads, but SavePackage downloads never satisfy
1098 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls 1059 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls
1099 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage 1060 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage
1100 // notices that the upload has completed and runs its normal Finish() pathway. 1061 // notices that the upload has completed and runs its normal Finish() pathway.
1101 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes 1062 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes
1102 // downloads. SavePackage always uses its own Finish() to mark downloads 1063 // downloads. SavePackage always uses its own Finish() to mark downloads
1103 // complete. 1064 // complete.
1104 void DownloadItemImpl::MaybeCompleteDownload() { 1065 void DownloadItemImpl::MaybeCompleteDownload() {
1105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1066 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1106 DCHECK(!is_save_package_download_); 1067 DCHECK(!is_save_package_download_);
1107 1068
1108 if (!IsDownloadReadyForCompletion()) 1069 if (!IsDownloadReadyForCompletion())
1109 return; 1070 return;
1110 1071
1111 // TODO(rdsmith): DCHECK that we only pass through this point 1072 // TODO(rdsmith): DCHECK that we only pass through this point
1112 // once per download. The natural way to do this is by a state 1073 // once per download. The natural way to do this is by a state
1113 // transition on the DownloadItem. 1074 // transition on the DownloadItem.
1114 1075
1115 // Confirm we're in the proper set of states to be here; 1076 // Confirm we're in the proper set of states to be here;
1116 // have all data, have a history handle, (validated or safe). 1077 // have all data, have a history handle, (validated or safe).
1117 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 1078 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
1118 DCHECK_NE(DownloadItem::DANGEROUS, GetSafetyState()); 1079 DCHECK_NE(DownloadItem::DANGEROUS, GetSafetyState());
1119 DCHECK(all_data_saved_); 1080 DCHECK(all_data_saved_);
1120 DCHECK(is_persisted_);
1121
1122 delegate_->UpdatePersistence(this);
1123 1081
1124 OnDownloadCompleting(); 1082 OnDownloadCompleting();
1125 } 1083 }
1126 1084
1127 // Called by MaybeCompleteDownload() when it has determined that the download 1085 // Called by MaybeCompleteDownload() when it has determined that the download
1128 // is ready for completion. 1086 // is ready for completion.
1129 void DownloadItemImpl::OnDownloadCompleting() { 1087 void DownloadItemImpl::OnDownloadCompleting() {
1130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1088 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1131 1089
1132 if (state_ != IN_PROGRESS_INTERNAL) 1090 if (state_ != IN_PROGRESS_INTERNAL)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 Interrupt(reason); 1149 Interrupt(reason);
1192 return; 1150 return;
1193 } 1151 }
1194 1152
1195 DCHECK(target_path_ == full_path); 1153 DCHECK(target_path_ == full_path);
1196 1154
1197 if (full_path != current_path_) { 1155 if (full_path != current_path_) {
1198 // full_path is now the current and target file path. 1156 // full_path is now the current and target file path.
1199 DCHECK(!full_path.empty()); 1157 DCHECK(!full_path.empty());
1200 SetFullPath(full_path); 1158 SetFullPath(full_path);
1201 delegate_->DownloadRenamedToFinalName(this);
1202 } 1159 }
1203 1160
1204 // Complete the download and release the DownloadFile. 1161 // Complete the download and release the DownloadFile.
1205 DCHECK(download_file_.get()); 1162 DCHECK(download_file_.get());
1206 BrowserThread::PostTask( 1163 BrowserThread::PostTask(
1207 BrowserThread::FILE, FROM_HERE, 1164 BrowserThread::FILE, FROM_HERE,
1208 base::Bind(&DownloadFileDetach, base::Passed(download_file_.Pass()))); 1165 base::Bind(&DownloadFileDetach, base::Passed(download_file_.Pass())));
1209 1166
1210 // We're not completely done with the download item yet, but at this 1167 // We're not completely done with the download item yet, but at this
1211 // point we're committed to complete the download. Cancels (or Interrupts, 1168 // point we're committed to complete the download. Cancels (or Interrupts,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 // has been released. 1247 // has been released.
1291 if (!is_save_package_download_ && download_file_.get()) { 1248 if (!is_save_package_download_ && download_file_.get()) {
1292 BrowserThread::PostTask( 1249 BrowserThread::PostTask(
1293 BrowserThread::FILE, FROM_HERE, 1250 BrowserThread::FILE, FROM_HERE,
1294 // Will be deleted at end of task execution. 1251 // Will be deleted at end of task execution.
1295 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); 1252 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass())));
1296 } 1253 }
1297 } 1254 }
1298 1255
1299 bool DownloadItemImpl::IsDownloadReadyForCompletion() { 1256 bool DownloadItemImpl::IsDownloadReadyForCompletion() {
1257 VLOG(20) << __FUNCTION__ << " " << AllDataSaved()
1258 << " " << (GetSafetyState() != DownloadItem::DANGEROUS)
1259 << " " << (state_ == IN_PROGRESS_INTERNAL)
1260 << " " << !GetTargetFilePath().empty()
1261 << " " << (target_path_.DirName() == current_path_.DirName());
1300 // If we don't have all the data, the download is not ready for 1262 // If we don't have all the data, the download is not ready for
1301 // completion. 1263 // completion.
1302 if (!AllDataSaved()) 1264 if (!AllDataSaved())
1303 return false; 1265 return false;
1304 1266
1305 // If the download is dangerous, but not yet validated, it's not ready for 1267 // If the download is dangerous, but not yet validated, it's not ready for
1306 // completion. 1268 // completion.
1307 if (GetSafetyState() == DownloadItem::DANGEROUS) 1269 if (GetSafetyState() == DownloadItem::DANGEROUS)
1308 return false; 1270 return false;
1309 1271
1310 // If the download isn't active (e.g. has been cancelled) it's not 1272 // If the download isn't active (e.g. has been cancelled) it's not
1311 // ready for completion. 1273 // ready for completion.
1312 if (state_ != IN_PROGRESS_INTERNAL) 1274 if (state_ != IN_PROGRESS_INTERNAL)
1313 return false; 1275 return false;
1314 1276
1315 // If the download hasn't been inserted into the history system 1277 // If the target filename hasn't been determined, then it's not ready for
1316 // (which occurs strictly after file name determination, intermediate 1278 // completion. This is checked in ReadyForDownloadCompletionDone().
1317 // file rename, and UI display) then it's not ready for completion. 1279 if (GetTargetFilePath().empty())
1318 if (!IsPersisted()) 1280 return false;
1281
1282 // This is checked in NeedsRename(). Without this conditional,
1283 // browser_tests:DownloadTest.DownloadMimeType fails the DCHECK.
1284 if (target_path_.DirName() != current_path_.DirName())
1319 return false; 1285 return false;
1320 1286
1321 return true; 1287 return true;
1322 } 1288 }
1323 1289
1324 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) { 1290 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) {
1325 if (state_ == new_state) 1291 if (state_ == new_state)
1326 return; 1292 return;
1327 1293
1328 DownloadInternalState old_state = state_; 1294 DownloadInternalState old_state = state_;
(...skipping 19 matching lines...) Expand all
1348 case CANCELLED_INTERNAL: 1314 case CANCELLED_INTERNAL:
1349 bound_net_log_.AddEvent( 1315 bound_net_log_.AddEvent(
1350 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, 1316 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED,
1351 base::Bind(&ItemCanceledNetLogCallback, received_bytes_, 1317 base::Bind(&ItemCanceledNetLogCallback, received_bytes_,
1352 &hash_state_)); 1318 &hash_state_));
1353 break; 1319 break;
1354 default: 1320 default:
1355 break; 1321 break;
1356 } 1322 }
1357 1323
1358 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); 1324 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true)
1325 << " " << InternalToExternalState(old_state)
1326 << " " << InternalToExternalState(state_);
1359 1327
1360 // Only update observers on user visible state changes. 1328 // Only update observers on user visible state changes.
1361 if (InternalToExternalState(old_state) != InternalToExternalState(state_)) 1329 if (InternalToExternalState(old_state) != InternalToExternalState(state_))
1362 UpdateObservers(); 1330 UpdateObservers();
1363 1331
1364 bool is_done = (state_ != IN_PROGRESS_INTERNAL && 1332 bool is_done = (state_ != IN_PROGRESS_INTERNAL &&
1365 state_ != COMPLETING_INTERNAL); 1333 state_ != COMPLETING_INTERNAL);
1366 bool was_done = (old_state != IN_PROGRESS_INTERNAL && 1334 bool was_done = (old_state != IN_PROGRESS_INTERNAL &&
1367 old_state != COMPLETING_INTERNAL); 1335 old_state != COMPLETING_INTERNAL);
1368 if (is_done && !was_done) 1336 if (is_done && !was_done)
(...skipping 15 matching lines...) Expand all
1384 } 1352 }
1385 } 1353 }
1386 1354
1387 void DownloadItemImpl::SetFullPath(const FilePath& new_path) { 1355 void DownloadItemImpl::SetFullPath(const FilePath& new_path) {
1388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1389 VLOG(20) << __FUNCTION__ << "()" 1357 VLOG(20) << __FUNCTION__ << "()"
1390 << " new_path = \"" << new_path.value() << "\"" 1358 << " new_path = \"" << new_path.value() << "\""
1391 << " " << DebugString(true); 1359 << " " << DebugString(true);
1392 DCHECK(!new_path.empty()); 1360 DCHECK(!new_path.empty());
1393 current_path_ = new_path; 1361 current_path_ = new_path;
1362 UpdateObservers();
1394 1363
1395 bound_net_log_.AddEvent( 1364 bound_net_log_.AddEvent(
1396 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, 1365 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED,
1397 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path)); 1366 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path));
1398 } 1367 }
1399 1368
1400 // static 1369 // static
1401 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( 1370 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState(
1402 DownloadInternalState internal_state) { 1371 DownloadInternalState internal_state) {
1403 switch (internal_state) { 1372 switch (internal_state) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 return "CANCELLED"; 1418 return "CANCELLED";
1450 case INTERRUPTED_INTERNAL: 1419 case INTERRUPTED_INTERNAL:
1451 return "INTERRUPTED"; 1420 return "INTERRUPTED";
1452 default: 1421 default:
1453 NOTREACHED() << "Unknown download state " << state; 1422 NOTREACHED() << "Unknown download state " << state;
1454 return "unknown"; 1423 return "unknown";
1455 }; 1424 };
1456 } 1425 }
1457 1426
1458 } // namespace content 1427 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698