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

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: fixes 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 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "content/public/browser/download_id.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 ResourceDispatcherHost;
23 class WebContents;
24
25 // Pass an instance of DownloadUrlParameters to DownloadManager::DownloadUrl()
26 // to download the content at |url|. All parameters with setters are optional.
27 // |referrer| and |referrer_encoding| are the referrer for the download. If
28 // |prefer_cache| is true, then if the response to |url| is in the HTTP cache it
29 // will be used without revalidation. If |post_id| is non-negative, then it
30 // identifies the post transaction used to originally retrieve the |url|
31 // resource - it also requires |prefer_cache| to be |true| since re-post'ing is
32 // not done. |save_info| specifies where the downloaded file should be saved,
33 // and whether the user should be prompted about the download. If not null,
34 // |callback| will be called when the download starts, or if an error occurs
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 the
37 // object isn't made.
38
39 class CONTENT_EXPORT DownloadUrlParameters {
40 public:
41 // If there is an error, the DownloadId will be invalid.
42 typedef base::Callback<void(DownloadId, net::Error)> OnStartedCallback;
43
44 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair;
45 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType;
46
47 static DownloadUrlParameters* FromWebContents(
48 WebContents* web_contents,
49 const GURL& url,
50 const DownloadSaveInfo& save_info);
51
52 DownloadUrlParameters(
53 const GURL& url,
54 int render_process_host_id,
55 int render_view_host_routing_id,
56 content::ResourceContext* resource_context,
57 const DownloadSaveInfo& save_info);
58
59 ~DownloadUrlParameters();
60
61 void add_request_header(const std::string& name, const std::string& value) {
62 request_headers_.push_back(make_pair(name, value));
63 }
64 void set_referrer(const GURL& referrer) { referrer_ = referrer; }
65 void set_referrer_encoding(const std::string& referrer_encoding) {
66 referrer_encoding_ = referrer_encoding;
67 }
68 void set_load_flags(int load_flags) { load_flags_ |= load_flags; }
69 void set_method(const std::string& method) {
70 method_ = method;
71 }
72 void set_post_body(const std::string& post_body) {
73 post_body_ = post_body;
74 }
75 void set_prefer_cache(bool prefer_cache) {
76 prefer_cache_ = prefer_cache;
77 }
78 void set_post_id(int64 post_id) { post_id_ = post_id; }
79 void set_callback(const OnStartedCallback& callback) {
80 callback_ = callback;
81 }
82
83 const OnStartedCallback& callback() const { return callback_; }
84 int load_flags() const { return load_flags_; }
85 const std::string& method() const { return method_; }
86 const std::string& post_body() const { return post_body_; }
87 int64 post_id() const { return post_id_; }
88 bool prefer_cache() const { return prefer_cache_; }
89 const GURL& referrer() const { return referrer_; }
90 const std::string& referrer_encoding() const { return referrer_encoding_; }
91 int render_process_host_id() const { return render_process_host_id_; }
92 int render_view_host_routing_id() const {
93 return render_view_host_routing_id_;
94 }
95 RequestHeadersType::const_iterator request_headers_begin() const {
96 return request_headers_.begin();
97 }
98 RequestHeadersType::const_iterator request_headers_end() const {
99 return request_headers_.end();
100 }
101 content::ResourceContext* resource_context() const {
102 return resource_context_;
103 }
104 ResourceDispatcherHost* resource_dispatcher_host() const {
105 return resource_dispatcher_host_;
106 }
107 const DownloadSaveInfo& save_info() const { return save_info_; }
108 const GURL& url() const { return url_; }
109
110 private:
111 OnStartedCallback callback_;
112 RequestHeadersType request_headers_;
113 int load_flags_;
114 std::string method_;
115 std::string post_body_;
116 int64 post_id_;
117 bool prefer_cache_;
118 GURL referrer_;
119 std::string referrer_encoding_;
120 int render_process_host_id_;
121 int render_view_host_routing_id_;
122 ResourceContext* resource_context_;
123 ResourceDispatcherHost* resource_dispatcher_host_;
124 DownloadSaveInfo save_info_;
125 GURL url_;
126
127 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters);
128 };
129
130 } // namespace content
131
132 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_
OLDNEW
« no previous file with comments | « content/public/browser/download_manager.h ('k') | content/public/browser/download_url_parameters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698