Commit d8472d93 authored by rdsmith@chromium.org's avatar rdsmith@chromium.org

Made the cancel from CancelDownloadOnRename go through the full cancel path,

and added a few more checks for 85408.

BUG=85408


Review URL: http://codereview.chromium.org/7749013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98474 0039d316-1c4b-4281-b951-d872f2087c98
parent 4723a449
...@@ -583,7 +583,7 @@ class DownloadTest : public InProcessBrowserTest { ...@@ -583,7 +583,7 @@ class DownloadTest : public InProcessBrowserTest {
return new DownloadsObserver( return new DownloadsObserver(
download_manager, num_downloads, download_manager, num_downloads,
DownloadItem::COMPLETE, // Really done DownloadItem::COMPLETE, // Really done
false, // Bail on select file true, // Bail on select file
ON_DANGEROUS_DOWNLOAD_FAIL); ON_DANGEROUS_DOWNLOAD_FAIL);
} }
......
...@@ -364,7 +364,7 @@ void DownloadFileManager::CancelDownloadOnRename(int id) { ...@@ -364,7 +364,7 @@ void DownloadFileManager::CancelDownloadOnRename(int id) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
NewRunnableMethod(download_manager, NewRunnableMethod(download_manager,
&DownloadManager::DownloadCancelled, id)); &DownloadManager::CancelDownload, id));
} }
void DownloadFileManager::EraseDownload(int id) { void DownloadFileManager::EraseDownload(int id) {
......
...@@ -367,7 +367,7 @@ void DownloadItem::Cancel(bool update_history) { ...@@ -367,7 +367,7 @@ void DownloadItem::Cancel(bool update_history) {
TransitionTo(CANCELLED); TransitionTo(CANCELLED);
StopProgressTimer(); StopProgressTimer();
if (update_history) if (update_history)
download_manager_->DownloadCancelled(download_id_); download_manager_->DownloadCancelledInternal(this);
} }
void DownloadItem::MarkAsComplete() { void DownloadItem::MarkAsComplete() {
...@@ -703,6 +703,16 @@ FilePath DownloadItem::GetUserVerifiedFilePath() const { ...@@ -703,6 +703,16 @@ FilePath DownloadItem::GetUserVerifiedFilePath() const {
GetTargetFilePath() : full_path_; GetTargetFilePath() : full_path_;
} }
void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
request_handle_.CancelRequest();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
file_manager, &DownloadFileManager::CancelDownload, download_id_));
}
void DownloadItem::Init(bool active) { void DownloadItem::Init(bool active) {
// TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
...@@ -170,7 +170,7 @@ class DownloadItem { ...@@ -170,7 +170,7 @@ class DownloadItem {
// to display progress when the DownloadItem should be considered complete. // to display progress when the DownloadItem should be considered complete.
void MarkAsComplete(); void MarkAsComplete();
// Called by the delegate after it delayed completing the download in // Called by the delegate after it delayed completing the download in
// DownloadManagerDelegate::ShouldCompleteDownload. // DownloadManagerDelegate::ShouldCompleteDownload.
void CompleteDelayedDownload(); void CompleteDelayedDownload();
...@@ -322,6 +322,14 @@ class DownloadItem { ...@@ -322,6 +322,14 @@ class DownloadItem {
return state_info_.target_name != full_path_.BaseName(); return state_info_.target_name != full_path_.BaseName();
} }
// Cancels the off-thread aspects of the download.
// TODO(rdsmith): This should be private and only called from
// DownloadItem::Cancel/Interrupt; it isn't now because we can't
// call those functions from
// DownloadManager::FileSelectionCancelled() without doing some
// rewrites of the DownloadManager queues.
void OffThreadCancel(DownloadFileManager* file_manager);
std::string DebugString(bool verbose) const; std::string DebugString(bool verbose) const;
#ifdef UNIT_TEST #ifdef UNIT_TEST
......
...@@ -52,7 +52,8 @@ DownloadManager::DownloadManager(DownloadManagerDelegate* delegate, ...@@ -52,7 +52,8 @@ DownloadManager::DownloadManager(DownloadManagerDelegate* delegate,
browser_context_(NULL), browser_context_(NULL),
file_manager_(NULL), file_manager_(NULL),
status_updater_(status_updater->AsWeakPtr()), status_updater_(status_updater->AsWeakPtr()),
delegate_(delegate) { delegate_(delegate),
largest_db_handle_in_history_(DownloadItem::kUninitializedHandle) {
if (status_updater_) if (status_updater_)
status_updater_->AddDelegate(this); status_updater_->AddDelegate(this);
} }
...@@ -288,6 +289,8 @@ void DownloadManager::CreateDownloadItem(DownloadCreateInfo* info) { ...@@ -288,6 +289,8 @@ void DownloadManager::CreateDownloadItem(DownloadCreateInfo* info) {
browser_context_->IsOffTheRecord()); browser_context_->IsOffTheRecord());
int32 download_id = info->download_id; int32 download_id = info->download_id;
DCHECK(!ContainsKey(in_progress_, download_id)); DCHECK(!ContainsKey(in_progress_, download_id));
// TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
CHECK(!ContainsKey(active_downloads_, download_id)); CHECK(!ContainsKey(active_downloads_, download_id));
downloads_.insert(download); downloads_.insert(download);
active_downloads_[download_id] = download; active_downloads_[download_id] = download;
...@@ -506,38 +509,36 @@ void DownloadManager::OnDownloadRenamedToFinalName(int download_id, ...@@ -506,38 +509,36 @@ void DownloadManager::OnDownloadRenamedToFinalName(int download_id,
delegate_->UpdatePathForItemInPersistentStore(item, full_path); delegate_->UpdatePathForItemInPersistentStore(item, full_path);
} }
void DownloadManager::DownloadCancelled(int32 download_id) { void DownloadManager::CancelDownload(int32 download_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DownloadMap::iterator it = in_progress_.find(download_id); DownloadItem* download = GetDownloadItem(download_id);
if (it == in_progress_.end()) if (!download)
return; return;
DownloadItem* download = it->second;
VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id download->Cancel(true);
}
void DownloadManager::DownloadCancelledInternal(DownloadItem* download) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
int download_id = download->id();
VLOG(20) << __FUNCTION__ << "()"
<< " download = " << download->DebugString(true); << " download = " << download->DebugString(true);
// Clean up will happen when the history system create callback runs if we // Clean up will happen when the history system create callback runs if we
// don't have a valid db_handle yet. // don't have a valid db_handle yet.
if (download->db_handle() != DownloadItem::kUninitializedHandle) { if (download->db_handle() != DownloadItem::kUninitializedHandle) {
in_progress_.erase(it); in_progress_.erase(download_id);
active_downloads_.erase(download_id); active_downloads_.erase(download_id);
UpdateDownloadProgress(); // Reflect removal from in_progress_. UpdateDownloadProgress(); // Reflect removal from in_progress_.
delegate_->UpdateItemInPersistentStore(download); delegate_->UpdateItemInPersistentStore(download);
// This function is called from the DownloadItem, so DI state
// should already have been updated.
AssertQueueStateConsistent(download); AssertQueueStateConsistent(download);
} }
DownloadCancelledInternal(download_id, download->request_handle()); download->OffThreadCancel(file_manager_);
}
void DownloadManager::DownloadCancelledInternal(
int download_id, const DownloadRequestHandle& request_handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
request_handle.CancelRequest();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
file_manager_, &DownloadFileManager::CancelDownload, download_id));
} }
void DownloadManager::OnDownloadError(int32 download_id, void DownloadManager::OnDownloadError(int32 download_id,
...@@ -762,7 +763,7 @@ void DownloadManager::FileSelectionCanceled(void* params) { ...@@ -762,7 +763,7 @@ void DownloadManager::FileSelectionCanceled(void* params) {
VLOG(20) << __FUNCTION__ << "()" VLOG(20) << __FUNCTION__ << "()"
<< " download = " << download->DebugString(true); << " download = " << download->DebugString(true);
DownloadCancelledInternal(download_id, download->request_handle()); download->OffThreadCancel(file_manager_);
} }
// Operations posted to us from the history service ---------------------------- // Operations posted to us from the history service ----------------------------
...@@ -771,13 +772,21 @@ void DownloadManager::FileSelectionCanceled(void* params) { ...@@ -771,13 +772,21 @@ void DownloadManager::FileSelectionCanceled(void* params) {
// 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time).
void DownloadManager::OnPersistentStoreQueryComplete( void DownloadManager::OnPersistentStoreQueryComplete(
std::vector<DownloadPersistentStoreInfo>* entries) { std::vector<DownloadPersistentStoreInfo>* entries) {
// TODO(rdsmith): Remove this and related logic when
// http://crbug.com/84508 is fixed.
largest_db_handle_in_history_ = 0;
for (size_t i = 0; i < entries->size(); ++i) { for (size_t i = 0; i < entries->size(); ++i) {
DownloadItem* download = new DownloadItem(this, entries->at(i)); DownloadItem* download = new DownloadItem(this, entries->at(i));
// TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
CHECK(!ContainsKey(history_downloads_, download->db_handle())); CHECK(!ContainsKey(history_downloads_, download->db_handle()));
downloads_.insert(download); downloads_.insert(download);
history_downloads_[download->db_handle()] = download; history_downloads_[download->db_handle()] = download;
VLOG(20) << __FUNCTION__ << "()" << i << ">" VLOG(20) << __FUNCTION__ << "()" << i << ">"
<< " download = " << download->DebugString(true); << " download = " << download->DebugString(true);
if (download->db_handle() > largest_db_handle_in_history_)
largest_db_handle_in_history_ = download->db_handle();
} }
NotifyModelChanged(); NotifyModelChanged();
CheckForHistoryFilesRemoval(); CheckForHistoryFilesRemoval();
...@@ -794,6 +803,8 @@ void DownloadManager::AddDownloadItemToHistory(DownloadItem* download, ...@@ -794,6 +803,8 @@ void DownloadManager::AddDownloadItemToHistory(DownloadItem* download,
DCHECK(download->db_handle() == DownloadItem::kUninitializedHandle); DCHECK(download->db_handle() == DownloadItem::kUninitializedHandle);
download->set_db_handle(db_handle); download->set_db_handle(db_handle);
// TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508
// is fixed.
CHECK(!ContainsKey(history_downloads_, download->db_handle())); CHECK(!ContainsKey(history_downloads_, download->db_handle()));
history_downloads_[download->db_handle()] = download; history_downloads_[download->db_handle()] = download;
...@@ -830,6 +841,11 @@ void DownloadManager::OnDownloadItemAddedToPersistentStore(int32 download_id, ...@@ -830,6 +841,11 @@ void DownloadManager::OnDownloadItemAddedToPersistentStore(int32 download_id,
<< " download_id = " << download_id << " download_id = " << download_id
<< " download = " << download->DebugString(true); << " download = " << download->DebugString(true);
// TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
CHECK(!ContainsKey(history_downloads_, download->db_handle()));
int64 largest_handle = largest_db_handle_in_history_;
base::debug::Alias(&largest_handle);
AddDownloadItemToHistory(download, db_handle); AddDownloadItemToHistory(download, db_handle);
// If the download is still in progress, try to complete it. // If the download is still in progress, try to complete it.
...@@ -842,6 +858,8 @@ void DownloadManager::OnDownloadItemAddedToPersistentStore(int32 download_id, ...@@ -842,6 +858,8 @@ void DownloadManager::OnDownloadItemAddedToPersistentStore(int32 download_id,
if (download->IsInProgress()) { if (download->IsInProgress()) {
MaybeCompleteDownload(download); MaybeCompleteDownload(download);
} else { } else {
// TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508
// is fixed.
CHECK(download->IsCancelled()) CHECK(download->IsCancelled())
<< " download = " << download->DebugString(true); << " download = " << download->DebugString(true);
in_progress_.erase(download_id); in_progress_.erase(download_id);
...@@ -979,6 +997,11 @@ void DownloadManager::OnSavePageItemAddedToPersistentStore(int32 download_id, ...@@ -979,6 +997,11 @@ void DownloadManager::OnSavePageItemAddedToPersistentStore(int32 download_id,
return; return;
} }
// TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
CHECK(!ContainsKey(history_downloads_, download->db_handle()));
int64 largest_handle = largest_db_handle_in_history_;
base::debug::Alias(&largest_handle);
AddDownloadItemToHistory(download, db_handle); AddDownloadItemToHistory(download, db_handle);
// Finalize this download if it finished before the history callback. // Finalize this download if it finished before the history callback.
......
...@@ -117,8 +117,15 @@ class DownloadManager ...@@ -117,8 +117,15 @@ class DownloadManager
void OnResponseCompleted(int32 download_id, int64 size, int os_error, void OnResponseCompleted(int32 download_id, int64 size, int os_error,
const std::string& hash); const std::string& hash);
// Offthread target for cancelling a particular download. Will be a no-op
// if the download has already been cancelled.
void CancelDownload(int32 download_id);
// Called from DownloadItem to handle the DownloadManager portion of a
// Cancel; should not be called from other locations.
void DownloadCancelledInternal(DownloadItem* download);
// Called from a view when a user clicks a UI button or link. // Called from a view when a user clicks a UI button or link.
void DownloadCancelled(int32 download_id);
void RemoveDownload(int64 download_handle); void RemoveDownload(int64 download_handle);
// Determine if the download is ready for completion, i.e. has had // Determine if the download is ready for completion, i.e. has had
...@@ -278,10 +285,6 @@ class DownloadManager ...@@ -278,10 +285,6 @@ class DownloadManager
void ContinueDownloadWithPath(DownloadItem* download, void ContinueDownloadWithPath(DownloadItem* download,
const FilePath& chosen_file); const FilePath& chosen_file);
// Download cancel helper function.
void DownloadCancelledInternal(int download_id,
const DownloadRequestHandle& request_handle);
// All data has been downloaded. // All data has been downloaded.
// |hash| is sha256 hash for the downloaded file. It is empty when the hash // |hash| is sha256 hash for the downloaded file. It is empty when the hash
// is not available. // is not available.
...@@ -378,6 +381,10 @@ class DownloadManager ...@@ -378,6 +381,10 @@ class DownloadManager
// Allows an embedder to control behavior. Guaranteed to outlive this object. // Allows an embedder to control behavior. Guaranteed to outlive this object.
DownloadManagerDelegate* delegate_; DownloadManagerDelegate* delegate_;
// TODO(rdsmith): Remove when http://crbug.com/84508 is fixed.
// For debugging only.
int64 largest_db_handle_in_history_;
DISALLOW_COPY_AND_ASSIGN(DownloadManager); DISALLOW_COPY_AND_ASSIGN(DownloadManager);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment