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

Unified Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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/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 bbfe75d755619ac13d455bc1404cd22c1b9eb7fd..9ccd22cde98b6cccbad901e281444b21c442c27a 100644
--- a/chrome/browser/extensions/api/downloads/downloads_api.cc
+++ b/chrome/browser/extensions/api/downloads/downloads_api.cc
@@ -139,7 +139,6 @@ const char* kStateStrings[] = {
kStateInProgress,
kStateComplete,
kStateInterrupted,
- NULL,
kStateInterrupted,
};
COMPILE_ASSERT(arraysize(kStateStrings) == DownloadItem::MAX_DOWNLOAD_STATE,
@@ -164,7 +163,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];
}
@@ -820,24 +818,31 @@ 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));
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(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);
+ 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(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));
@@ -886,10 +891,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::OnDownloadCreated(
DownloadManager* manager, DownloadItem* download_item) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -913,6 +914,7 @@ void ExtensionDownloadsEventRouter::ManagerGoingDown(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
manager_->RemoveObserver(this);
manager_ = NULL;
+ profile_ = NULL;
}
void ExtensionDownloadsEventRouter::DispatchEvent(

Powered by Google App Engine
This is Rietveld 408576698