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

Side by Side Diff: content/public/browser/download_url_parameters.h

Issue 10232010: DownloadUrlParameters (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_
6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h"
15 #include "content/public/browser/download_save_info.h"
16 #include "googleurl/src/gurl.h"
17 #include "net/base/net_errors.h"
18
19 namespace content {
20
21 class ResourceContext;
22 class ResourceDispatcherHostImpl;
23
24 // Pass an instance of DownloadUrlParameters to DownloadManager::DownloadUrl in
25 // order to download the content at |url|. |referrer| and |referrer_encoding|
26 // are the referrer for the download, and may be empty. If |prefer_cache| is
27 // true, then if the response to |url| is in the HTTP cache it will be used
28 // without revalidation. If |post_id| is non-negative, then it identifies the
29 // post transaction used to originally retrieve the |url| resource - it also
30 // requires |prefer_cache| to be |true| since re-post'ing is not done.
31 // |save_info| specifies where the downloaded file should be saved, and whether
32 // the user should be prompted about the download. |web_contents| is the web
33 // page that the download is done in context of, and must be non-NULL.
34 // |callback| will be called when the download starts, or if an error occurs
Randy Smith (Not in Mondays) 2012/04/30 19:44:48 nit: "If not null".
benjhayden 2012/05/02 15:11:54 Done.
35 // that prevents a download item from being created. We send a pointer to
36 // content::ResourceContext instead of the usual reference so that a copy of
37 // the object isn't made.
Randy Smith (Not in Mondays) 2012/04/30 19:44:48 Could you specify the format of the extra headers?
benjhayden 2012/05/02 15:11:54 PTAL
Randy Smith (Not in Mondays) 2012/05/02 18:36:22 Looks good.
38 class CONTENT_EXPORT DownloadUrlParameters {
39 public:
40 // NOTE: If there is an error, the DownloadId will be invalid.
41 typedef base::Callback<void(DownloadId, net::Error)> OnStartedCallback;
42
43 static DownloadUrlParameters* FromWebContents(
44 content::WebContents* web_contents,
45 const GURL& url,
46 const content::DownloadSaveInfo& save_info);
47
48 DownloadUrlParameters(
49 const GURL& url,
50 int render_process_host_id,
51 int render_view_host_routing_id,
52 content::ResourceContext* resource_context,
53 const content::DownloadSaveInfo& save_info);
54
55 ~DownloadUrlParameters();
56
57 void set_extra_headers(scoped_ptr<base::ListValue> extra_headers) {
58 extra_headers_ = extra_headers.Pass();
59 }
60 void set_referrer(const GURL& referrer) { referrer_ = referrer; }
61 void set_referrer_encoding(const std::string& referrer_encoding) {
62 referrer_encoding_ = referrer_encoding;
63 }
64 void set_load_flags(int load_flags) { load_flags_ |= load_flags; }
65 void set_method(const std::string& method) { method_ = method; }
66 void set_post_body(const std::string& post_body) {
67 post_body_ = post_body;
68 }
69 void set_prefer_cache(bool prefer_cache) { prefer_cache_ = prefer_cache; }
70 void set_post_id(int64 post_id) {
71 post_id_ = post_id;
72 if (post_id_ >= 0) {
73 set_method("POST");
74 set_prefer_cache(true);
75 } else {
76 set_method("GET");
77 set_prefer_cache(false);
Randy Smith (Not in Mondays) 2012/04/30 19:44:48 I'm a bit concerned about this violating principle
benjhayden 2012/05/02 15:11:54 You're right, this behavior was surprising, and it
78 }
79 }
80 void set_callback(const OnStartedCallback& callback) {
81 callback_ = callback;
82 }
83
84 const OnStartedCallback& callback() const { return callback_; }
85 base::ListValue* extra_headers() const { return extra_headers_.get(); }
86 int load_flags() const { return load_flags_; }
87 const std::string& method() const { return method_; }
88 const std::string& post_body() const { return post_body_; }
89 int64 post_id() const { return post_id_; }
90 bool prefer_cache() const { return prefer_cache_; }
91 const GURL& referrer() const { return referrer_; }
92 const std::string& referrer_encoding() const { return referrer_encoding_; }
93 int render_process_host_id() const { return render_process_host_id_; }
94 int render_view_host_routing_id() const {
95 return render_view_host_routing_id_;
96 }
97 content::ResourceContext* resource_context() const {
98 return resource_context_;
99 }
100 ResourceDispatcherHostImpl* resource_dispatcher_host() const {
101 return resource_dispatcher_host_;
102 }
103 const content::DownloadSaveInfo& save_info() const { return save_info_; }
104 const GURL& url() const { return url_; }
105
106 private:
107 OnStartedCallback callback_;
108 scoped_ptr<base::ListValue> extra_headers_;
109 int load_flags_;
110 std::string method_;
111 std::string post_body_;
112 int64 post_id_;
113 bool prefer_cache_;
114 GURL referrer_;
115 std::string referrer_encoding_;
116 int render_process_host_id_;
117 int render_view_host_routing_id_;
118 ResourceContext* resource_context_;
119 ResourceDispatcherHostImpl* resource_dispatcher_host_;
120 DownloadSaveInfo save_info_;
Randy Smith (Not in Mondays) 2012/04/30 19:44:48 Given the creation of DownloadUrlParameters, I'd l
benjhayden 2012/05/02 15:11:54 Agreed, that's definitely worth trying, but not fo
Randy Smith (Not in Mondays) 2012/05/02 18:36:22 Awesome; it's yours.
121 GURL url_;
122
123 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters);
124 };
125
126 } // namespace content
127
128 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698