Index: chrome/browser/automation/automation_provider_observers.cc |
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc |
index f927c503353c993982c44ae074d76ef734bb290b..4ba2584539c1178594ca177189823eda0733dabb 100644 |
--- a/chrome/browser/automation/automation_provider_observers.cc |
+++ b/chrome/browser/automation/automation_provider_observers.cc |
@@ -1134,11 +1134,45 @@ void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { |
delete this; |
} |
+void AutomationProviderDownloadItemObserver::OnDownloadUpdated( |
+ DownloadItem* download) { |
+ // If any download was interrupted, on the next update each outstanding |
+ // download is cancelled. |
+ if (interrupted_) { |
+ download->Cancel(false); |
+ RemoveAndCleanupOnLastEntry(download); |
+ } |
+} |
+ |
void AutomationProviderDownloadItemObserver::OnDownloadFileCompleted( |
DownloadItem* download) { |
+ RemoveAndCleanupOnLastEntry(download); |
+} |
+ |
+void AutomationProviderDownloadItemObserver::OnDownloadInterrupted( |
Paweł Hajdan Jr.
2010/10/01 09:03:55
This is broken, as said in http://codereview.chrom
|
+ DownloadItem* download) { |
+ // Mark as interrupted. |
+ interrupted_ = true; |
+ // Cancel, so we don't pop up a dialog on exit. |
+ download->Cancel(false); |
+ RemoveAndCleanupOnLastEntry(download); |
+} |
+ |
+// We don't want to send multiple messages, as the behavior is undefined. |
+// Set |interrupted_| on error, and on the last download completed/ |
+// interrupted, send either an error or a success message. |
+void AutomationProviderDownloadItemObserver::RemoveAndCleanupOnLastEntry( |
+ DownloadItem* download) { |
+ // Forget about the download. |
download->RemoveObserver(this); |
+ // If we are observing no more downloads, clean up. |
if (--downloads_ == 0) { |
- AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); |
+ if (interrupted_) { |
+ AutomationJSONReply(provider_, reply_message_).SendError( |
+ "Download Interrupted"); |
+ } else { |
+ AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); |
+ } |
delete this; |
} |
} |