OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MANAGER_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MANAGER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "chrome/common/notification_observer.h" | 13 #include "chrome/common/notification_observer.h" |
14 #include "chrome/common/notification_registrar.h" | 14 #include "chrome/common/notification_registrar.h" |
15 | 15 |
16 class DownloadRequestInfoBarDelegate; | 16 class DownloadRequestInfoBarDelegate; |
17 class MessageLoop; | |
18 class NavigationController; | 17 class NavigationController; |
19 class TabContents; | 18 class TabContents; |
20 | 19 |
21 // DownloadRequestManager is responsible for determining whether a download | 20 // DownloadRequestManager is responsible for determining whether a download |
22 // should be allowed or not. It is designed to keep pages from downloading | 21 // should be allowed or not. It is designed to keep pages from downloading |
23 // multiple files without user interaction. DownloadRequestManager is invoked | 22 // multiple files without user interaction. DownloadRequestManager is invoked |
24 // from ResourceDispatcherHost any time a download begins | 23 // from ResourceDispatcherHost any time a download begins |
25 // (CanDownloadOnIOThread). The request is processed on the UI thread, and the | 24 // (CanDownloadOnIOThread). The request is processed on the UI thread, and the |
26 // request is notified (back on the IO thread) as to whether the download should | 25 // request is notified (back on the IO thread) as to whether the download should |
27 // be allowed or denied. | 26 // be allowed or denied. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 140 |
142 // Used to remove observers installed on NavigationController. | 141 // Used to remove observers installed on NavigationController. |
143 NotificationRegistrar registrar_; | 142 NotificationRegistrar registrar_; |
144 | 143 |
145 // Handles showing the infobar to the user, may be null. | 144 // Handles showing the infobar to the user, may be null. |
146 DownloadRequestInfoBarDelegate* infobar_; | 145 DownloadRequestInfoBarDelegate* infobar_; |
147 | 146 |
148 DISALLOW_COPY_AND_ASSIGN(TabDownloadState); | 147 DISALLOW_COPY_AND_ASSIGN(TabDownloadState); |
149 }; | 148 }; |
150 | 149 |
151 DownloadRequestManager(MessageLoop* io_loop, MessageLoop* ui_loop); | 150 DownloadRequestManager(); |
152 ~DownloadRequestManager(); | 151 ~DownloadRequestManager(); |
153 | 152 |
154 // Returns the download status for a page. This does not change the state in | 153 // Returns the download status for a page. This does not change the state in |
155 // anyway. | 154 // anyway. |
156 DownloadStatus GetDownloadStatus(TabContents* tab); | 155 DownloadStatus GetDownloadStatus(TabContents* tab); |
157 | 156 |
158 // Updates the state of the page as necessary and notifies the callback. | 157 // Updates the state of the page as necessary and notifies the callback. |
159 // WARNING: both this call and the callback are invoked on the io thread. | 158 // WARNING: both this call and the callback are invoked on the io thread. |
160 // | 159 // |
161 // DownloadRequestManager does not retain/release the Callback. It is up to | 160 // DownloadRequestManager does not retain/release the Callback. It is up to |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 void ScheduleNotification(Callback* callback, bool allow); | 207 void ScheduleNotification(Callback* callback, bool allow); |
209 | 208 |
210 // Notifies the callback. This *must* be invoked on the IO thread. | 209 // Notifies the callback. This *must* be invoked on the IO thread. |
211 void NotifyCallback(Callback* callback, bool allow); | 210 void NotifyCallback(Callback* callback, bool allow); |
212 | 211 |
213 // Removes the specified TabDownloadState from the internal map and deletes | 212 // Removes the specified TabDownloadState from the internal map and deletes |
214 // it. This has the effect of resetting the status for the tab to | 213 // it. This has the effect of resetting the status for the tab to |
215 // ALLOW_ONE_DOWNLOAD. | 214 // ALLOW_ONE_DOWNLOAD. |
216 void Remove(TabDownloadState* state); | 215 void Remove(TabDownloadState* state); |
217 | 216 |
218 // Two threads we use. NULL during testing, in which case messages are | |
219 // dispatched immediately. | |
220 MessageLoop* io_loop_; | |
221 MessageLoop* ui_loop_; | |
222 | |
223 // Maps from tab to download state. The download state for a tab only exists | 217 // Maps from tab to download state. The download state for a tab only exists |
224 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state | 218 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state |
225 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD | 219 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD |
226 // the TabDownloadState is removed and deleted (by way of Remove). | 220 // the TabDownloadState is removed and deleted (by way of Remove). |
227 typedef std::map<NavigationController*, TabDownloadState*> StateMap; | 221 typedef std::map<NavigationController*, TabDownloadState*> StateMap; |
228 StateMap state_map_; | 222 StateMap state_map_; |
229 | 223 |
230 static TestingDelegate* delegate_; | 224 static TestingDelegate* delegate_; |
231 | 225 |
232 DISALLOW_COPY_AND_ASSIGN(DownloadRequestManager); | 226 DISALLOW_COPY_AND_ASSIGN(DownloadRequestManager); |
233 }; | 227 }; |
234 | 228 |
235 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MANAGER_H_ | 229 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MANAGER_H_ |
OLD | NEW |