summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_request_manager.h
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-24 18:33:49 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-24 18:33:49 +0000
commitb0f16b6c2d73f55512dade4545d448daa9bb57c0 (patch)
tree57dec9ab1d0a4026b60612383fadb28eb46aabf5 /chrome/browser/download/download_request_manager.h
parent143cb01067b26440ad710a9db8b24982f0196c47 (diff)
downloadchromium_src-b0f16b6c2d73f55512dade4545d448daa9bb57c0.zip
chromium_src-b0f16b6c2d73f55512dade4545d448daa9bb57c0.tar.gz
chromium_src-b0f16b6c2d73f55512dade4545d448daa9bb57c0.tar.bz2
Download request manager refactoring.
Pull out the dialog delegate to a separate file so we can swap it out with other implementations on other platforms. Also, build download_request_manager.cc on POSIX. Review URL: http://codereview.chromium.org/27062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10270 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/download_request_manager.h')
-rw-r--r--chrome/browser/download/download_request_manager.h93
1 files changed, 88 insertions, 5 deletions
diff --git a/chrome/browser/download/download_request_manager.h b/chrome/browser/download/download_request_manager.h
index 90180f8..f9351c8 100644
--- a/chrome/browser/download/download_request_manager.h
+++ b/chrome/browser/download/download_request_manager.h
@@ -6,10 +6,14 @@
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MANAGER_H_
#include <map>
+#include <string>
#include <vector>
#include "base/ref_counted.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+class DownloadRequestDialogDelegate;
class MessageLoop;
class NavigationController;
class TabContents;
@@ -40,8 +44,6 @@ class TabContents;
class DownloadRequestManager :
public base::RefCountedThreadSafe<DownloadRequestManager> {
public:
- class TabDownloadState;
-
// Download status for a particular page. See class description for details.
enum DownloadStatus {
ALLOW_ONE_DOWNLOAD,
@@ -50,9 +52,6 @@ class DownloadRequestManager :
DOWNLOADS_NOT_ALLOWED
};
- DownloadRequestManager(MessageLoop* io_loop, MessageLoop* ui_loop);
- ~DownloadRequestManager();
-
// The callback from CanDownloadOnIOThread. This is invoked on the io thread.
class Callback {
public:
@@ -60,6 +59,90 @@ class DownloadRequestManager :
virtual void CancelDownload() = 0;
};
+ // TabDownloadState maintains the download state for a particular tab.
+ // TabDownloadState installs observers to update the download status
+ // appropriately. Additionally TabDownloadState prompts the user as necessary.
+ // TabDownloadState deletes itself (by invoking
+ // DownloadRequestManager::Remove) as necessary.
+ class TabDownloadState : public NotificationObserver {
+ public:
+ // Creates a new TabDownloadState. |controller| is the controller the
+ // TabDownloadState tracks the state of and is the host for any dialogs that
+ // are displayed. |originating_controller| is used to determine the host of
+ // the initial download. If |originating_controller| is null, |controller|
+ // is used. |originating_controller| is typically null, but differs from
+ // |controller| in the case of a constrained popup requesting the download.
+ TabDownloadState(DownloadRequestManager* host,
+ NavigationController* controller,
+ NavigationController* originating_controller);
+ ~TabDownloadState();
+
+ // Status of the download.
+ void set_download_status(DownloadRequestManager::DownloadStatus status) {
+ status_ = status;
+ }
+ DownloadRequestManager::DownloadStatus download_status() const {
+ return status_;
+ }
+
+ // Invoked when a user gesture occurs (mouse click, enter or space). This
+ // may result in invoking Remove on DownloadRequestManager.
+ void OnUserGesture();
+
+ // Asks the user if they really want to allow the download.
+ // See description above CanDownloadOnIOThread for details on lifetime of
+ // callback.
+ void PromptUserForDownload(TabContents* tab,
+ DownloadRequestManager::Callback* callback);
+
+ // Are we showing a prompt to the user?
+ bool is_showing_prompt() const { return (dialog_delegate_ != NULL); }
+
+ // NavigationController we're tracking.
+ NavigationController* controller() const { return controller_; }
+
+ // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and
+ // changes the status appropriately.
+ void Cancel();
+ void Accept();
+
+ private:
+ // NotificationObserver method.
+ void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // Notifies the callbacks as to whether the download is allowed or not.
+ // Updates status_ appropriately.
+ void NotifyCallbacks(bool allow);
+
+ DownloadRequestManager* host_;
+
+ NavigationController* controller_;
+
+ // Host of the first page the download started on. This may be empty.
+ std::string initial_page_host_;
+
+ DownloadRequestManager::DownloadStatus status_;
+
+ // Callbacks we need to notify. This is only non-empty if we're showing a
+ // dialog.
+ // See description above CanDownloadOnIOThread for details on lifetime of
+ // callbacks.
+ std::vector<DownloadRequestManager::Callback*> callbacks_;
+
+ // Used to remove observers installed on NavigationController.
+ NotificationRegistrar registrar_;
+
+ // Handles showing the dialog to the user, may be null.
+ DownloadRequestDialogDelegate* dialog_delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabDownloadState);
+ };
+
+ DownloadRequestManager(MessageLoop* io_loop, MessageLoop* ui_loop);
+ ~DownloadRequestManager();
+
// Returns the download status for a page. This does not change the state in
// anyway.
DownloadStatus GetDownloadStatus(TabContents* tab);