| Index: chrome/browser/extensions/api/downloads/downloads_api.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/api/downloads/downloads_api.cc (revision 150095)
|
| +++ chrome/browser/extensions/api/downloads/downloads_api.cc (working copy)
|
| @@ -139,6 +139,7 @@
|
| kStateInProgress,
|
| kStateComplete,
|
| kStateInterrupted,
|
| + NULL,
|
| kStateInterrupted,
|
| };
|
| COMPILE_ASSERT(arraysize(kStateStrings) == DownloadItem::MAX_DOWNLOAD_STATE,
|
| @@ -163,6 +164,7 @@
|
| DCHECK(state >= 0);
|
| DCHECK(state < static_cast<DownloadItem::DownloadState>(
|
| arraysize(kStateStrings)));
|
| + DCHECK(state != DownloadItem::REMOVING);
|
| return kStateStrings[state];
|
| }
|
|
|
| @@ -818,32 +820,25 @@
|
| UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", (fires * 100 / total));
|
| }
|
|
|
| -void ExtensionDownloadsEventRouter::OnDownloadDestroyed(DownloadItem* item) {
|
| +void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| int download_id = item->GetId();
|
| - 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_)
|
| + 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(extensions::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);
|
| return;
|
| - int download_id = item->GetId();
|
| - DispatchEvent(extensions::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));
|
| scoped_ptr<base::DictionaryValue> delta(new base::DictionaryValue());
|
| @@ -891,6 +886,10 @@
|
| item_jsons_[download_id]->Swap(new_json.get());
|
| }
|
|
|
| +void ExtensionDownloadsEventRouter::OnDownloadOpened(DownloadItem* item) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +}
|
| +
|
| void ExtensionDownloadsEventRouter::OnDownloadCreated(
|
| DownloadManager* manager, DownloadItem* download_item) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| @@ -914,7 +913,6 @@
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| manager_->RemoveObserver(this);
|
| manager_ = NULL;
|
| - profile_ = NULL;
|
| }
|
|
|
| void ExtensionDownloadsEventRouter::DispatchEvent(
|
|
|