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

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

Powered by Google App Engine
This is Rietveld 408576698