OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_DOWNLOAD_HYPERBOLIC_DOWNLOAD_ITEM_NOTIFIER_H_ | |
6 #define CHROME_BROWSER_DOWNLOAD_HYPERBOLIC_DOWNLOAD_ITEM_NOTIFIER_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "content/public/browser/download_manager.h" | |
11 #include "content/public/browser/download_item.h" | |
12 | |
13 // HyperbolicDownloadItemNotifier 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. | |
17 | |
18 // Example Usage: | |
19 // class AndAHalf : public HyperbolicDownloadItemNotifier::Observer { | |
20 // public: | |
21 // AndAHalf(content::DownloadManager* original_manager, | |
22 // content::DownloadManager* incognito_manager) | |
23 // : ALLOW_THIS_IN_INITIALIZATION_LIST(original_hyperbole_( | |
24 // original_manager, this)), | |
25 // ALLOW_THIS_IN_INITIALIZATION_LIST(incognito_hyperbole_( | |
26 // incognito_manager, this)) { | |
27 // } | |
28 // | |
29 // virtual void OnDownloadUpdated( | |
30 // content::DownloadManager* manager, content::DownloadItem* item) { ... } | |
31 // | |
32 // private: | |
33 // HyperbolicDownloadItemNotifier original_hyperbole_; | |
34 // HyperbolicDownloadItemNotifier incognito_hyperbole_; | |
35 // }; | |
36 | |
37 class HyperbolicDownloadItemNotifier | |
38 : public content::DownloadManager::Observer, | |
39 public content::DownloadItem::Observer { | |
40 public: | |
41 // All of the methods take the DownloadManager so that subclasses can observe | |
42 // multiple managers at once and easily distinguish which manager a given item | |
43 // belongs to. | |
44 class Observer { | |
45 public: | |
46 Observer() {} | |
47 virtual ~Observer() {} | |
48 | |
49 virtual void OnDownloadCreated( | |
50 content::DownloadManager* manager, content::DownloadItem* item) {} | |
51 virtual void OnDownloadUpdated( | |
52 content::DownloadManager* manager, content::DownloadItem* item) {} | |
53 virtual void OnDownloadOpened( | |
54 content::DownloadManager* manager, content::DownloadItem* item) {} | |
55 virtual void OnDownloadRemoved( | |
56 content::DownloadManager* manager, content::DownloadItem* item) {} | |
57 | |
58 private: | |
59 DISALLOW_COPY_AND_ASSIGN(Observer); | |
60 }; | |
61 | |
62 HyperbolicDownloadItemNotifier(content::DownloadManager* manager, | |
63 Observer* observer); | |
64 | |
65 virtual ~HyperbolicDownloadItemNotifier(); | |
66 | |
67 // Returns NULL if the manager has gone down. | |
68 content::DownloadManager* GetManager() const { return manager_; } | |
69 | |
70 private: | |
71 // content::DownloadManager::Observer | |
72 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; | |
73 virtual void OnDownloadCreated(content::DownloadManager* manager, | |
74 content::DownloadItem* item) OVERRIDE; | |
75 | |
76 // content::DownloadItem::Observer | |
77 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE; | |
78 virtual void OnDownloadOpened(content::DownloadItem* item) OVERRIDE; | |
79 virtual void OnDownloadRemoved(content::DownloadItem* item) OVERRIDE; | |
80 virtual void OnDownloadDestroyed(content::DownloadItem* item) OVERRIDE; | |
81 | |
82 content::DownloadManager* manager_; | |
83 HyperbolicDownloadItemNotifier::Observer* observer_; | |
84 std::set<content::DownloadItem*> observing_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(HyperbolicDownloadItemNotifier); | |
87 }; | |
88 | |
89 #endif // CHROME_BROWSER_DOWNLOAD_HYPERBOLIC_DOWNLOAD_ITEM_NOTIFIER_H_ | |
OLD | NEW |