Chromium Code Reviews| Index: chrome/browser/extensions/api/downloads/downloads_api.cc |
| diff --git a/chrome/browser/extensions/api/downloads/downloads_api.cc b/chrome/browser/extensions/api/downloads/downloads_api.cc |
| index 49e8f77f553440ca3f2a4d7be78c38cf922222d9..5bdc67bdf7ba67238c192a4565c71ced9687e275 100644 |
| --- a/chrome/browser/extensions/api/downloads/downloads_api.cc |
| +++ b/chrome/browser/extensions/api/downloads/downloads_api.cc |
| @@ -137,7 +137,6 @@ const char* kStateStrings[] = { |
| kStateInProgress, |
| kStateComplete, |
| kStateInterrupted, |
| - NULL, |
| kStateInterrupted, |
| }; |
| COMPILE_ASSERT(arraysize(kStateStrings) == DownloadItem::MAX_DOWNLOAD_STATE, |
| @@ -162,7 +161,6 @@ const char* StateString(DownloadItem::DownloadState state) { |
| DCHECK(state >= 0); |
| DCHECK(state < static_cast<DownloadItem::DownloadState>( |
| arraysize(kStateStrings))); |
| - DCHECK(state != DownloadItem::REMOVING); |
| return kStateStrings[state]; |
| } |
| @@ -949,24 +947,33 @@ ExtensionDownloadsEventRouter::OnChangedStat::~OnChangedStat() { |
| UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", (fires * 100 / total)); |
| } |
| -void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) { |
| +void ExtensionDownloadsEventRouter::OnDownloadDestroyed(DownloadItem* item) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (!profile_) |
| + return; |
|
Randy Smith (Not in Mondays)
2012/07/11 17:55:37
If we're getting notification and the download is
benjhayden
2012/07/13 20:03:17
Done.
|
| int download_id = item->GetId(); |
| - if (item->GetState() == DownloadItem::REMOVING) { |
| - // The REMOVING state indicates that this item is being erased. |
| - // Let's unregister as an observer so that we don't see any more updates |
| - // from it, dispatch the onErased event, and remove its json and is |
| - // OnChangedStat from our maps. |
| - downloads_.erase(download_id); |
| - item->RemoveObserver(this); |
| - DispatchEvent(extension_event_names::kOnDownloadErased, |
| - base::Value::CreateIntegerValue(download_id)); |
| - delete item_jsons_[download_id]; |
| - item_jsons_.erase(download_id); |
| - delete on_changed_stats_[download_id]; |
| - on_changed_stats_.erase(download_id); |
| + downloads_.erase(download_id); |
| + item->RemoveObserver(this); |
| + delete item_jsons_[download_id]; |
| + item_jsons_.erase(download_id); |
| + delete on_changed_stats_[download_id]; |
| + on_changed_stats_.erase(download_id); |
| +} |
| + |
| +void ExtensionDownloadsEventRouter::OnDownloadRemoved(DownloadItem* item) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (!profile_) |
| return; |
| - } |
| + int download_id = item->GetId(); |
| + DispatchEvent(extension_event_names::kOnDownloadErased, |
| + base::Value::CreateIntegerValue(download_id)); |
| +} |
| + |
| +void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (!profile_) |
| + return; |
| + int download_id = item->GetId(); |
| base::DictionaryValue* old_json = item_jsons_[download_id]; |
| scoped_ptr<base::DictionaryValue> new_json(DownloadItemToJSON(item)); |
| @@ -1015,10 +1022,6 @@ void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) { |
| item_jsons_[download_id]->Swap(new_json.get()); |
| } |
| -void ExtensionDownloadsEventRouter::OnDownloadOpened(DownloadItem* item) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| -} |
| - |
| void ExtensionDownloadsEventRouter::ModelChanged(DownloadManager* manager) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(manager_ == manager); |
| @@ -1067,9 +1070,6 @@ void ExtensionDownloadsEventRouter::ModelChanged(DownloadManager* manager) { |
| item_jsons_[*iter] = item.release(); |
| } |
| downloads_.swap(current_map); |
| - |
| - // Dispatching onErased is handled in OnDownloadUpdated when an item |
| - // transitions to the REMOVING state. |
| } |
| void ExtensionDownloadsEventRouter::ManagerGoingDown( |