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..7f1bd202d0fed7106bebabe4ac73f2c7d3513fbd 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,6 +256,8 @@ class DownloadsDragFunction : public AsyncDownloadsFunction { |
DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction); |
}; |
+// Observes a single DownloadManager and dispatches onCreated and onErased |
+// events. |
class ExtensionDownloadsEventRouter : public DownloadManager::Observer { |
public: |
explicit ExtensionDownloadsEventRouter(Profile* profile); |
@@ -264,13 +267,35 @@ class ExtensionDownloadsEventRouter : public DownloadManager::Observer { |
virtual void ManagerGoingDown() OVERRIDE; |
private: |
- void DispatchEvent(const char* event_name, base::Value* json_arg); |
+ // Observes a single DownloadItem and dispatches onChanged events. |
Randy Smith (Not in Mondays)
2011/10/12 18:46:30
Might want a comment here as to why it's not a mix
benjhayden
2011/10/13 16:30:29
Done.
|
+ class ItemObserver : public DownloadItem::Observer { |
+ public: |
+ typedef base::Callback<void(base::Value*)> EventDispatcher; |
+ ItemObserver(const EventDispatcher& dispatcher, DownloadItem* item); |
+ virtual ~ItemObserver(); |
+ |
+ virtual void OnDownloadUpdated(DownloadItem* download); |
+ virtual void OnDownloadOpened(DownloadItem* download); |
+ |
+ private: |
+ EventDispatcher dispatcher_; |
+ DownloadItem* item_; |
+ scoped_ptr<base::DictionaryValue> json_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ItemObserver); |
+ }; |
+ |
typedef base::hash_map<int, DownloadItem*> ItemMap; |
typedef std::set<int> DownloadIdSet; |
+ typedef base::hash_map<int, ItemObserver*> ItemObserverMap; |
+ |
+ void DispatchEvent(const char* event_name, base::Value* json_arg); |
Profile* profile_; |
DownloadManager* manager_; |
DownloadIdSet downloads_; |
+ ItemObserverMap item_observers_; |
+ STLValueDeleter<ItemObserverMap> delete_item_observers_; |
DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
}; |