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

Unified Diff: chrome/browser/extensions/extension_downloads_api.h

Issue 8203005: Implement chrome.experimental.downloads.onChanged (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: on_changed_stats_,OnChangedStat Created 9 years, 2 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/extension_downloads_api.h
diff --git a/chrome/browser/extensions/extension_downloads_api.h b/chrome/browser/extensions/extension_downloads_api.h
index b0cf0e90cc3db310d6ae215aa9250fcfbb2156c4..466b31e06bedb767cea0ab4e96994d04527a8d59 100644
--- a/chrome/browser/extensions/extension_downloads_api.h
+++ b/chrome/browser/extensions/extension_downloads_api.h
@@ -12,6 +12,7 @@
#include "base/file_path.h"
#include "base/memory/singleton.h"
+#include "base/stl_util.h"
#include "base/string16.h"
#include "chrome/browser/extensions/extension_function.h"
#include "content/browser/download/download_item.h"
@@ -255,22 +256,40 @@ class DownloadsDragFunction : public AsyncDownloadsFunction {
DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction);
};
-class ExtensionDownloadsEventRouter : public DownloadManager::Observer {
+// Observes a single DownloadManager and many DownloadItems and dispatches
+// onCreated and onErased events.
+class ExtensionDownloadsEventRouter : public DownloadManager::Observer,
+ public DownloadItem::Observer {
public:
explicit ExtensionDownloadsEventRouter(Profile* profile);
virtual ~ExtensionDownloadsEventRouter();
virtual void ModelChanged() OVERRIDE;
virtual void ManagerGoingDown() OVERRIDE;
+ virtual void OnDownloadUpdated(DownloadItem* download) OVERRIDE;
+ virtual void OnDownloadOpened(DownloadItem* download) OVERRIDE;
private:
+ struct OnChangedStat {
+ OnChangedStat();
+ ~OnChangedStat();
+ int fires;
+ int total;
+ };
+
+ typedef std::map<int, DownloadItem*> ItemMap;
+ typedef std::map<int, base::DictionaryValue*> ItemJsonMap;
+ typedef std::map<int, OnChangedStat*> OnChangedStatMap;
+
void DispatchEvent(const char* event_name, base::Value* json_arg);
- typedef base::hash_map<int, DownloadItem*> ItemMap;
- typedef std::set<int> DownloadIdSet;
Profile* profile_;
DownloadManager* manager_;
- DownloadIdSet downloads_;
+ ItemMap downloads_;
+ ItemJsonMap item_jsons_;
+ STLValueDeleter<ItemJsonMap> delete_item_jsons_;
+ OnChangedStatMap on_changed_stats_;
+ STLValueDeleter<OnChangedStatMap> delete_on_changed_stats_;
DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
};

Powered by Google App Engine
This is Rietveld 408576698