1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DOWNLOAD_ALL_DOWNLOAD_ITEM_NOTIFIER_H_
6 #define CHROME_BROWSER_DOWNLOAD_ALL_DOWNLOAD_ITEM_NOTIFIER_H_
10 #include "content/public/browser/download_manager.h"
11 #include "content/public/browser/download_item.h"
13 // AllDownloadItemNotifier observes ALL the DownloadItems on a given
15 // Clients should use GetManager() instead of storing their own pointer to the
16 // manager so that they can be sensitive to managers that have gone down.
19 // class DownloadSystemConsumer : public AllDownloadItemNotifier::Observer {
21 // DownloadSystemConsumer(content::DownloadManager* original_manager,
22 // content::DownloadManager* incognito_manager)
23 // : original_notifier_(original_manager, this),
24 // incognito_notifier_(incognito_manager, this) {
27 // virtual void OnDownloadUpdated(
28 // content::DownloadManager* manager, content::DownloadItem* item) { ... }
31 // AllDownloadItemNotifier original_notifier_;
32 // AllDownloadItemNotifier incognito_notifier_;
35 class AllDownloadItemNotifier
: public content::DownloadManager::Observer
,
36 public content::DownloadItem::Observer
{
38 // All of the methods take the DownloadManager so that subclasses can observe
39 // multiple managers at once and easily distinguish which manager a given item
44 virtual ~Observer() {}
46 virtual void OnDownloadCreated(
47 content::DownloadManager
* manager
, content::DownloadItem
* item
) {}
48 virtual void OnDownloadUpdated(
49 content::DownloadManager
* manager
, content::DownloadItem
* item
) {}
50 virtual void OnDownloadOpened(
51 content::DownloadManager
* manager
, content::DownloadItem
* item
) {}
52 virtual void OnDownloadRemoved(
53 content::DownloadManager
* manager
, content::DownloadItem
* item
) {}
56 DISALLOW_COPY_AND_ASSIGN(Observer
);
59 AllDownloadItemNotifier(content::DownloadManager
* manager
,
62 ~AllDownloadItemNotifier() override
;
64 // Returns NULL if the manager has gone down.
65 content::DownloadManager
* GetManager() const { return manager_
; }
68 // content::DownloadManager::Observer
69 void ManagerGoingDown(content::DownloadManager
* manager
) override
;
70 void OnDownloadCreated(content::DownloadManager
* manager
,
71 content::DownloadItem
* item
) override
;
73 // content::DownloadItem::Observer
74 void OnDownloadUpdated(content::DownloadItem
* item
) override
;
75 void OnDownloadOpened(content::DownloadItem
* item
) override
;
76 void OnDownloadRemoved(content::DownloadItem
* item
) override
;
77 void OnDownloadDestroyed(content::DownloadItem
* item
) override
;
79 content::DownloadManager
* manager_
;
80 AllDownloadItemNotifier::Observer
* observer_
;
81 std::set
<content::DownloadItem
*> observing_
;
83 DISALLOW_COPY_AND_ASSIGN(AllDownloadItemNotifier
);
86 #endif // CHROME_BROWSER_DOWNLOAD_ALL_DOWNLOAD_ITEM_NOTIFIER_H_