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

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

Issue 10689093: Move Rename functionality from DownloadFileManager to DownloadFileImple. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to TOT to avoid showing already committed changes in Rietveld. Created 8 years, 5 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 #include "content/browser/download/download_item_impl.h" 5 #include "content/browser/download/download_item_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 482
483 download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT); 483 download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT);
484 484
485 TransitionTo(CANCELLED); 485 TransitionTo(CANCELLED);
486 if (user_cancel) 486 if (user_cancel)
487 delegate_->DownloadStopped(this); 487 delegate_->DownloadStopped(this);
488 } 488 }
489 489
490 // An error occurred somewhere. 490 // An error occurred somewhere.
491 void DownloadItemImpl::Interrupt(content::DownloadInterruptReason reason) { 491 void DownloadItemImpl::Interrupt(content::DownloadInterruptReason reason) {
492 // It should not be possible both to have an error and complete. 492 // Somewhat counter-intuitively, it is possible for us to receive an
493 DCHECK(IsInProgress()); 493 // interrupt after we've already been interrupted. The generation of
494 // interrupts from the file thread Renames and the generation of
495 // interrupts from disk writes go through two different mechanisms (driven
496 // by rename requests from UI thread and by write requests from IO thread,
497 // respectively), and since we choose not to keep state on the File thread,
498 // this is the place where the races collide. It's also possible for
499 // interrupts to race with cancels.
500
501 // Whatever happens, the first one to hit the UI thread wins.
502 if (!IsInProgress())
503 return;
504
494 last_reason_ = reason; 505 last_reason_ = reason;
495 TransitionTo(INTERRUPTED); 506 TransitionTo(INTERRUPTED);
496 download_stats::RecordDownloadInterrupted( 507 download_stats::RecordDownloadInterrupted(
497 reason, received_bytes_, total_bytes_); 508 reason, received_bytes_, total_bytes_);
498 delegate_->DownloadStopped(this); 509 delegate_->DownloadStopped(this);
499 } 510 }
500 511
501 void DownloadItemImpl::MarkAsComplete() { 512 void DownloadItemImpl::MarkAsComplete() {
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
503 514
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 BrowserThread::FILE, FROM_HERE, 743 BrowserThread::FILE, FROM_HERE,
733 base::Bind(&DownloadFileManager::CompleteDownload, 744 base::Bind(&DownloadFileManager::CompleteDownload,
734 file_manager, GetGlobalId(), 745 file_manager, GetGlobalId(),
735 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, 746 base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
736 weak_ptr_factory_.GetWeakPtr()))); 747 weak_ptr_factory_.GetWeakPtr())));
737 } 748 }
738 } 749 }
739 750
740 void DownloadItemImpl::OnDownloadRenamedToFinalName( 751 void DownloadItemImpl::OnDownloadRenamedToFinalName(
741 DownloadFileManager* file_manager, 752 DownloadFileManager* file_manager,
753 content::DownloadInterruptReason reason,
742 const FilePath& full_path) { 754 const FilePath& full_path) {
743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 755 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
744 756
745 VLOG(20) << __FUNCTION__ << "()" 757 VLOG(20) << __FUNCTION__ << "()"
746 << " full_path = \"" << full_path.value() << "\"" 758 << " full_path = \"" << full_path.value() << "\""
747 << " needed rename = " << NeedsRename() 759 << " needed rename = " << NeedsRename()
748 << " " << DebugString(false); 760 << " " << DebugString(false);
749 DCHECK(NeedsRename()); 761 DCHECK(NeedsRename());
750 762
751 if (full_path.empty()) 763 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
752 // Indicates error; also reported 764 Interrupt(reason);
753 // by DownloadManagerImpl::OnDownloadInterrupted.
754 return; 765 return;
766 }
755 767
756 // full_path is now the current and target file path. 768 // full_path is now the current and target file path.
asanka 2012/07/05 18:47:21 Nit: DCHECK(!full_path.empty())
Randy Smith (Not in Mondays) 2012/07/09 20:35:51 Done.
757 target_path_ = full_path; 769 target_path_ = full_path;
758 SetFullPath(full_path); 770 SetFullPath(full_path);
759 delegate_->DownloadRenamedToFinalName(this); 771 delegate_->DownloadRenamedToFinalName(this);
760 772
761 // Complete the download and release the DownloadFile. 773 // Complete the download and release the DownloadFile.
762 BrowserThread::PostTask( 774 BrowserThread::PostTask(
763 BrowserThread::FILE, FROM_HERE, 775 BrowserThread::FILE, FROM_HERE,
764 base::Bind(&DownloadFileManager::CompleteDownload, 776 base::Bind(&DownloadFileManager::CompleteDownload,
765 file_manager, GetGlobalId(), 777 file_manager, GetGlobalId(),
766 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, 778 base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
767 weak_ptr_factory_.GetWeakPtr()))); 779 weak_ptr_factory_.GetWeakPtr())));
768 } 780 }
769 781
770 void DownloadItemImpl::OnDownloadFileReleased() { 782 void DownloadItemImpl::OnDownloadFileReleased() {
771 if (delegate_->ShouldOpenDownload(this)) 783 if (delegate_->ShouldOpenDownload(this))
772 Completed(); 784 Completed();
773 else 785 else
774 delegate_delayed_complete_ = true; 786 delegate_delayed_complete_ = true;
775 } 787 }
776 788
777 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( 789 void DownloadItemImpl::OnDownloadRenamedToIntermediateName(
790 content::DownloadInterruptReason reason,
778 const FilePath& full_path) { 791 const FilePath& full_path) {
779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 792 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
780 if (!full_path.empty()) { 793 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
794 Interrupt(reason);
795 } else {
781 SetFullPath(full_path); 796 SetFullPath(full_path);
782 UpdateObservers(); 797 UpdateObservers();
783 } 798 }
799
784 delegate_->DownloadRenamedToIntermediateName(this); 800 delegate_->DownloadRenamedToIntermediateName(this);
785 } 801 }
786 802
787 bool DownloadItemImpl::MatchesQuery(const string16& query) const { 803 bool DownloadItemImpl::MatchesQuery(const string16& query) const {
788 if (query.empty()) 804 if (query.empty())
789 return true; 805 return true;
790 806
791 DCHECK_EQ(query, base::i18n::ToLower(query)); 807 DCHECK_EQ(query, base::i18n::ToLower(query));
792 808
793 string16 url_raw(UTF8ToUTF16(GetURL().spec())); 809 string16 url_raw(UTF8ToUTF16(GetURL().spec()));
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 std::map<const void*, ExternalData*>::iterator it = 1202 std::map<const void*, ExternalData*>::iterator it =
1187 external_data_map_.find(key); 1203 external_data_map_.find(key);
1188 1204
1189 if (it == external_data_map_.end()) { 1205 if (it == external_data_map_.end()) {
1190 external_data_map_[key] = data; 1206 external_data_map_[key] = data;
1191 } else if (it->second != data) { 1207 } else if (it->second != data) {
1192 delete it->second; 1208 delete it->second;
1193 it->second = data; 1209 it->second = data;
1194 } 1210 }
1195 } 1211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698