Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / download / all_download_item_notifier.h
blobfa4c4be360c8d5dc0a5834979e40db0216f3c519
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_
8 #include <set>
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
14 // DownloadManager.
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.
18 // Example Usage:
19 // class DownloadSystemConsumer : public AllDownloadItemNotifier::Observer {
20 // public:
21 // DownloadSystemConsumer(content::DownloadManager* original_manager,
22 // content::DownloadManager* incognito_manager)
23 // : original_notifier_(original_manager, this),
24 // incognito_notifier_(incognito_manager, this) {
25 // }
27 // virtual void OnDownloadUpdated(
28 // content::DownloadManager* manager, content::DownloadItem* item) { ... }
30 // private:
31 // AllDownloadItemNotifier original_notifier_;
32 // AllDownloadItemNotifier incognito_notifier_;
33 // };
35 class AllDownloadItemNotifier : public content::DownloadManager::Observer,
36 public content::DownloadItem::Observer {
37 public:
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
40 // belongs to.
41 class Observer {
42 public:
43 Observer() {}
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) {}
55 private:
56 DISALLOW_COPY_AND_ASSIGN(Observer);
59 AllDownloadItemNotifier(content::DownloadManager* manager,
60 Observer* observer);
62 virtual ~AllDownloadItemNotifier();
64 // Returns NULL if the manager has gone down.
65 content::DownloadManager* GetManager() const { return manager_; }
67 private:
68 // content::DownloadManager::Observer
69 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE;
70 virtual void OnDownloadCreated(content::DownloadManager* manager,
71 content::DownloadItem* item) OVERRIDE;
73 // content::DownloadItem::Observer
74 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE;
75 virtual void OnDownloadOpened(content::DownloadItem* item) OVERRIDE;
76 virtual void OnDownloadRemoved(content::DownloadItem* item) OVERRIDE;
77 virtual 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_