OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/automation/automation_provider_observers.h" | 5 #include "chrome/browser/automation/automation_provider_observers.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1127 model_->RemoveObserver(this); | 1127 model_->RemoveObserver(this); |
1128 } | 1128 } |
1129 | 1129 |
1130 void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { | 1130 void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { |
1131 AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( | 1131 AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( |
1132 reply_message_, success); | 1132 reply_message_, success); |
1133 automation_provider_->Send(reply_message_); | 1133 automation_provider_->Send(reply_message_); |
1134 delete this; | 1134 delete this; |
1135 } | 1135 } |
1136 | 1136 |
1137 void AutomationProviderDownloadItemObserver::OnDownloadUpdated( | |
1138 DownloadItem* download) { | |
1139 // If any download was interrupted, on the next update each outstanding | |
1140 // download is cancelled. | |
1141 if (interrupted_) { | |
1142 download->Cancel(false); | |
1143 RemoveAndCleanupOnLastEntry(download); | |
1144 } | |
1145 } | |
1146 | |
1137 void AutomationProviderDownloadItemObserver::OnDownloadFileCompleted( | 1147 void AutomationProviderDownloadItemObserver::OnDownloadFileCompleted( |
1138 DownloadItem* download) { | 1148 DownloadItem* download) { |
1149 RemoveAndCleanupOnLastEntry(download); | |
1150 } | |
1151 | |
1152 void AutomationProviderDownloadItemObserver::OnDownloadInterrupted( | |
Paweł Hajdan Jr.
2010/10/01 09:03:55
This is broken, as said in http://codereview.chrom
| |
1153 DownloadItem* download) { | |
1154 // Mark as interrupted. | |
1155 interrupted_ = true; | |
1156 // Cancel, so we don't pop up a dialog on exit. | |
1157 download->Cancel(false); | |
1158 RemoveAndCleanupOnLastEntry(download); | |
1159 } | |
1160 | |
1161 // We don't want to send multiple messages, as the behavior is undefined. | |
1162 // Set |interrupted_| on error, and on the last download completed/ | |
1163 // interrupted, send either an error or a success message. | |
1164 void AutomationProviderDownloadItemObserver::RemoveAndCleanupOnLastEntry( | |
1165 DownloadItem* download) { | |
1166 // Forget about the download. | |
1139 download->RemoveObserver(this); | 1167 download->RemoveObserver(this); |
1168 // If we are observing no more downloads, clean up. | |
1140 if (--downloads_ == 0) { | 1169 if (--downloads_ == 0) { |
1141 AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); | 1170 if (interrupted_) { |
1171 AutomationJSONReply(provider_, reply_message_).SendError( | |
1172 "Download Interrupted"); | |
1173 } else { | |
1174 AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); | |
1175 } | |
1142 delete this; | 1176 delete this; |
1143 } | 1177 } |
1144 } | 1178 } |
1145 | 1179 |
1146 void AutomationProviderDownloadUpdatedObserver::OnDownloadUpdated( | 1180 void AutomationProviderDownloadUpdatedObserver::OnDownloadUpdated( |
1147 DownloadItem* download) { | 1181 DownloadItem* download) { |
1148 // If this observer is watching for open, only send the reply if the download | 1182 // If this observer is watching for open, only send the reply if the download |
1149 // has been auto-opened. | 1183 // has been auto-opened. |
1150 if (wait_for_open_ && !download->auto_opened()) | 1184 if (wait_for_open_ && !download->auto_opened()) |
1151 return; | 1185 return; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1302 const NotificationSource& source, | 1336 const NotificationSource& source, |
1303 const NotificationDetails& details) { | 1337 const NotificationDetails& details) { |
1304 if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { | 1338 if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { |
1305 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); | 1339 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); |
1306 delete this; | 1340 delete this; |
1307 } else { | 1341 } else { |
1308 NOTREACHED(); | 1342 NOTREACHED(); |
1309 } | 1343 } |
1310 } | 1344 } |
1311 | 1345 |
OLD | NEW |