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

Unified Diff: chrome/browser/automation/automation_provider_observers.cc

Issue 3127008: Preliminary work on resuming downloads whose connections have expired.
Patch Set: Waiting to send download automation error message until after other downloads are canceled. Created 10 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 side-by-side diff with in-line comments
Download patch
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;
}
}

Powered by Google App Engine
This is Rietveld 408576698