Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: content/public/browser/download_manager.h

Issue 10232010: DownloadUrlParameters (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/test/mock_download_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/browser/download_manager.h
diff --git a/content/public/browser/download_manager.h b/content/public/browser/download_manager.h
index d67a385a4141f8f2e691a78154debff61ae81479..37a94d6e7537052848cddb03b4659d4fb1116e77 100644
--- a/content/public/browser/download_manager.h
+++ b/content/public/browser/download_manager.h
@@ -35,17 +35,20 @@
#include "base/callback.h"
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop_helpers.h"
#include "base/time.h"
+#include "base/values.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_id.h"
#include "content/public/browser/download_interrupt_reasons.h"
#include "content/public/browser/download_item.h"
-#include "content/public/browser/browser_thread.h"
-#include "net/base/net_log.h"
+#include "content/public/browser/download_save_info.h"
+#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
+#include "net/base/net_log.h"
class DownloadRequestHandle;
-class GURL;
struct DownloadCreateInfo;
struct DownloadRetrieveInfo;
@@ -53,16 +56,111 @@ namespace content {
class BrowserContext;
class DownloadManagerDelegate;
class DownloadQuery;
-class WebContents;
-struct DownloadSaveInfo;
+class ResourceContext;
+class ResourceDispatcherHostImpl;
+
+// Pass an instance of DownloadUrlParameters to DownloadManager::DownloadUrl in
+// order to download the content at |url|. |referrer| and |referrer_encoding|
+// are the referrer for the download, and may be empty. If |prefer_cache| is
+// true, then if the response to |url| is in the HTTP cache it will be used
+// without revalidation. If |post_id| is non-negative, then it identifies the
+// post transaction used to originally retrieve the |url| resource - it also
+// requires |prefer_cache| to be |true| since re-post'ing is not done.
+// |save_info| specifies where the downloaded file should be saved, and whether
+// the user should be prompted about the download. |web_contents| is the web
+// page that the download is done in context of, and must be non-NULL.
+// |callback| will be called when the download starts, or if an error occurs
+// that prevents a download item from being created. We send a pointer to
+// content::ResourceContext instead of the usual reference so that a copy of
+// the object isn't made.
+class CONTENT_EXPORT DownloadUrlParameters {
jam 2012/04/26 20:55:16 please put this in a separate file. in general for
benjhayden 2012/04/27 14:17:08 Some of the members are non-POD, and one (extra_he
+ public:
+ // NOTE: If there is an error, the DownloadId will be invalid.
+ typedef base::Callback<void(DownloadId, net::Error)> OnStartedCallback;
+
+ static DownloadUrlParameters* FromWebContents(
+ content::WebContents* web_contents,
+ const GURL& url,
+ const content::DownloadSaveInfo& save_info);
+
+ DownloadUrlParameters(
+ const GURL& url,
+ int render_process_host_id,
+ int render_view_host_routing_id,
+ content::ResourceContext* resource_context,
+ const content::DownloadSaveInfo& save_info);
+
+ ~DownloadUrlParameters();
+
+ void set_extra_headers(scoped_ptr<base::ListValue> extra_headers) {
+ extra_headers_ = extra_headers.Pass();
+ }
+ void set_referrer(const GURL& referrer) { referrer_ = referrer; }
+ void set_referrer_encoding(const std::string& referrer_encoding) {
+ referrer_encoding_ = referrer_encoding;
+ }
+ void set_load_flags(int load_flags) { load_flags_ |= load_flags; }
+ void set_method(const std::string& method) { method_ = method; }
+ void set_post_body(const std::string& post_body) {
+ post_body_ = post_body;
+ }
+ void set_prefer_cache(bool prefer_cache) { prefer_cache_ = prefer_cache; }
+ void set_post_id(int64 post_id) {
+ post_id_ = post_id;
+ set_method("POST");
+ set_prefer_cache(true);
+ }
+ void set_callback(const OnStartedCallback& callback) {
+ callback_ = callback;
+ }
+
+ const OnStartedCallback& callback() const { return callback_; }
+ base::ListValue* extra_headers() const { return extra_headers_.get(); }
+ int load_flags() const { return load_flags_; }
+ const std::string& method() const { return method_; }
+ const std::string& post_body() const { return post_body_; }
+ int64 post_id() const { return post_id_; }
+ bool prefer_cache() const { return prefer_cache_; }
+ const GURL& referrer() const { return referrer_; }
+ const std::string& referrer_encoding() const { return referrer_encoding_; }
+ int render_process_host_id() const { return render_process_host_id_; }
+ int render_view_host_routing_id() const {
+ return render_view_host_routing_id_;
+ }
+ content::ResourceContext* resource_context() const {
+ return resource_context_;
+ }
+ ResourceDispatcherHostImpl* resource_dispatcher_host() const {
+ return resource_dispatcher_host_;
+ }
+ const content::DownloadSaveInfo& save_info() const { return save_info_; }
+ const GURL& url() const { return url_; }
+
+ private:
+ OnStartedCallback callback_;
+ scoped_ptr<base::ListValue> extra_headers_;
+ int load_flags_;
+ std::string method_;
+ std::string post_body_;
+ int64 post_id_;
+ bool prefer_cache_;
+ GURL referrer_;
+ std::string referrer_encoding_;
+ int render_process_host_id_;
+ int render_view_host_routing_id_;
+ ResourceContext* resource_context_;
+ ResourceDispatcherHostImpl* resource_dispatcher_host_;
+ DownloadSaveInfo save_info_;
+ GURL url_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters);
+};
+
// Browser's download manager: manages all downloads and destination view.
class CONTENT_EXPORT DownloadManager
: public base::RefCountedThreadSafe<DownloadManager> {
public:
- // NOTE: If there is an error, the DownloadId will be invalid.
- typedef base::Callback<void(DownloadId, net::Error)> OnStartedCallback;
-
virtual ~DownloadManager() {}
static DownloadManager* Create(
@@ -172,26 +270,8 @@ class CONTENT_EXPORT DownloadManager
// deleted is returned back to the caller.
virtual int RemoveAllDownloads() = 0;
- // Downloads the content at |url|. |referrer| and |referrer_encoding| are the
- // referrer for the download, and may be empty. If |prefer_cache| is true,
- // then if the response to |url| is in the HTTP cache it will be used without
- // revalidation. If |post_id| is non-negative, then it identifies the post
- // transaction used to originally retrieve the |url| resource - it also
- // requires |prefer_cache| to be |true| since re-post'ing is not done.
- // |save_info| specifies where the downloaded file should be
- // saved, and whether the user should be prompted about the download.
- // |web_contents| is the web page that the download is done in context of,
- // and must be non-NULL.
- // |callback| will be called when the download starts, or if an error
- // occurs that prevents a download item from being created.
- virtual void DownloadUrl(const GURL& url,
- const GURL& referrer,
- const std::string& referrer_encoding,
- bool prefer_cache,
- int64 post_id,
- const DownloadSaveInfo& save_info,
- WebContents* web_contents,
- const OnStartedCallback& callback) = 0;
+ // Takes ownership of |parameters|.
+ virtual void DownloadUrl(DownloadUrlParameters* parameters) = 0;
// Allow objects to observe the download creation process.
virtual void AddObserver(Observer* observer) = 0;
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/test/mock_download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698