OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ | 6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
9 #include <string> | 11 #include <string> |
10 #include <utility> | 12 #include <utility> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/callback.h" | 15 #include "base/callback.h" |
14 #include "base/macros.h" | 16 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "content/public/browser/download_interrupt_reasons.h" | 17 #include "content/public/browser/download_interrupt_reasons.h" |
17 #include "content/public/browser/download_save_info.h" | 18 #include "content/public/browser/download_save_info.h" |
18 #include "content/public/common/referrer.h" | 19 #include "content/public/common/referrer.h" |
19 #include "storage/browser/blob/blob_data_handle.h" | 20 #include "storage/browser/blob/blob_data_handle.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 | 24 |
24 class DownloadItem; | 25 class DownloadItem; |
25 class ResourceContext; | 26 class ResourceContext; |
(...skipping 27 matching lines...) Expand all Loading... |
53 // download request. I.e. the download triggered a warning of some sort and | 54 // download request. I.e. the download triggered a warning of some sort and |
54 // the user chose to not to proceed with the download as a result. | 55 // the user chose to not to proceed with the download as a result. |
55 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)> | 56 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)> |
56 OnStartedCallback; | 57 OnStartedCallback; |
57 | 58 |
58 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair; | 59 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair; |
59 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType; | 60 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType; |
60 | 61 |
61 // Construct DownloadUrlParameters for downloading the resource at |url| and | 62 // Construct DownloadUrlParameters for downloading the resource at |url| and |
62 // associating the download with |web_contents|. | 63 // associating the download with |web_contents|. |
63 static scoped_ptr<DownloadUrlParameters> FromWebContents( | 64 static std::unique_ptr<DownloadUrlParameters> FromWebContents( |
64 WebContents* web_contents, | 65 WebContents* web_contents, |
65 const GURL& url); | 66 const GURL& url); |
66 | 67 |
67 // Construct DownloadUrlParameters for downloading the resource at |url| and | 68 // Construct DownloadUrlParameters for downloading the resource at |url| and |
68 // associating the download with the WebContents identified by | 69 // associating the download with the WebContents identified by |
69 // |render_process_host_id| and |render_view_host_routing_id|. | 70 // |render_process_host_id| and |render_view_host_routing_id|. |
70 // | 71 // |
71 // If the download is not associated with a WebContents, then set the IDs to | 72 // If the download is not associated with a WebContents, then set the IDs to |
72 // -1. | 73 // -1. |
73 // NOTE: This is not safe and should only be done in a limited set of cases | 74 // NOTE: This is not safe and should only be done in a limited set of cases |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // meaningful if a partial file exists and is identified by either the | 163 // meaningful if a partial file exists and is identified by either the |
163 // |file_path()| or |file()|. | 164 // |file_path()| or |file()|. |
164 void set_hash_of_partial_file(const std::string& hash_of_partial_file) { | 165 void set_hash_of_partial_file(const std::string& hash_of_partial_file) { |
165 save_info_.hash_of_partial_file = hash_of_partial_file; | 166 save_info_.hash_of_partial_file = hash_of_partial_file; |
166 } | 167 } |
167 | 168 |
168 // If |offset| is non-zero, then |hash_state| indicates the SHA-256 hash state | 169 // If |offset| is non-zero, then |hash_state| indicates the SHA-256 hash state |
169 // of the first |offset| bytes of the target file. In this case, the prefix | 170 // of the first |offset| bytes of the target file. In this case, the prefix |
170 // hash will be ignored since the |hash_state| is assumed to be correct if | 171 // hash will be ignored since the |hash_state| is assumed to be correct if |
171 // provided. | 172 // provided. |
172 void set_hash_state(scoped_ptr<crypto::SecureHash> hash_state) { | 173 void set_hash_state(std::unique_ptr<crypto::SecureHash> hash_state) { |
173 save_info_.hash_state = std::move(hash_state); | 174 save_info_.hash_state = std::move(hash_state); |
174 } | 175 } |
175 | 176 |
176 // If |prompt| is true, then the user will be prompted for a filename. Ignored | 177 // If |prompt| is true, then the user will be prompted for a filename. Ignored |
177 // if |file_path| is non-empty. | 178 // if |file_path| is non-empty. |
178 void set_prompt(bool prompt) { save_info_.prompt_for_save_location = prompt; } | 179 void set_prompt(bool prompt) { save_info_.prompt_for_save_location = prompt; } |
179 void set_file(base::File file) { save_info_.file = std::move(file); } | 180 void set_file(base::File file) { save_info_.file = std::move(file); } |
180 void set_do_not_prompt_for_login(bool do_not_prompt) { | 181 void set_do_not_prompt_for_login(bool do_not_prompt) { |
181 do_not_prompt_for_login_ = do_not_prompt; | 182 do_not_prompt_for_login_ = do_not_prompt; |
182 } | 183 } |
183 | 184 |
184 // For downloads of blob URLs, the caller can store a BlobDataHandle in the | 185 // For downloads of blob URLs, the caller can store a BlobDataHandle in the |
185 // DownloadUrlParameters object so that the blob will remain valid until | 186 // DownloadUrlParameters object so that the blob will remain valid until |
186 // the download starts. The BlobDataHandle will be attached to the associated | 187 // the download starts. The BlobDataHandle will be attached to the associated |
187 // URLRequest. | 188 // URLRequest. |
188 // | 189 // |
189 // This is optional. If left unspecified, and the blob URL cannot be mapped to | 190 // This is optional. If left unspecified, and the blob URL cannot be mapped to |
190 // a blob by the time the download request starts, then the download will | 191 // a blob by the time the download request starts, then the download will |
191 // fail. | 192 // fail. |
192 void set_blob_data_handle( | 193 void set_blob_data_handle( |
193 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 194 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { |
194 blob_data_handle_ = std::move(blob_data_handle); | 195 blob_data_handle_ = std::move(blob_data_handle); |
195 } | 196 } |
196 | 197 |
197 const OnStartedCallback& callback() const { return callback_; } | 198 const OnStartedCallback& callback() const { return callback_; } |
198 bool content_initiated() const { return content_initiated_; } | 199 bool content_initiated() const { return content_initiated_; } |
199 const std::string& last_modified() const { return last_modified_; } | 200 const std::string& last_modified() const { return last_modified_; } |
200 const std::string& etag() const { return etag_; } | 201 const std::string& etag() const { return etag_; } |
201 const std::string& method() const { return method_; } | 202 const std::string& method() const { return method_; } |
202 const std::string& post_body() const { return post_body_; } | 203 const std::string& post_body() const { return post_body_; } |
203 int64_t post_id() const { return post_id_; } | 204 int64_t post_id() const { return post_id_; } |
(...skipping 15 matching lines...) Expand all Loading... |
219 } | 220 } |
220 int64_t offset() const { return save_info_.offset; } | 221 int64_t offset() const { return save_info_.offset; } |
221 const std::string& hash_of_partial_file() const { | 222 const std::string& hash_of_partial_file() const { |
222 return save_info_.hash_of_partial_file; | 223 return save_info_.hash_of_partial_file; |
223 } | 224 } |
224 bool prompt() const { return save_info_.prompt_for_save_location; } | 225 bool prompt() const { return save_info_.prompt_for_save_location; } |
225 const GURL& url() const { return url_; } | 226 const GURL& url() const { return url_; } |
226 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; } | 227 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; } |
227 | 228 |
228 // STATE_CHANGING: Return the BlobDataHandle. | 229 // STATE_CHANGING: Return the BlobDataHandle. |
229 scoped_ptr<storage::BlobDataHandle> GetBlobDataHandle() { | 230 std::unique_ptr<storage::BlobDataHandle> GetBlobDataHandle() { |
230 return std::move(blob_data_handle_); | 231 return std::move(blob_data_handle_); |
231 } | 232 } |
232 | 233 |
233 // STATE CHANGING: All save_info_ sub-objects will be in an indeterminate | 234 // STATE CHANGING: All save_info_ sub-objects will be in an indeterminate |
234 // state following this call. | 235 // state following this call. |
235 DownloadSaveInfo GetSaveInfo() { return std::move(save_info_); } | 236 DownloadSaveInfo GetSaveInfo() { return std::move(save_info_); } |
236 | 237 |
237 private: | 238 private: |
238 OnStartedCallback callback_; | 239 OnStartedCallback callback_; |
239 bool content_initiated_; | 240 bool content_initiated_; |
240 RequestHeadersType request_headers_; | 241 RequestHeadersType request_headers_; |
241 std::string last_modified_; | 242 std::string last_modified_; |
242 std::string etag_; | 243 std::string etag_; |
243 std::string method_; | 244 std::string method_; |
244 std::string post_body_; | 245 std::string post_body_; |
245 int64_t post_id_; | 246 int64_t post_id_; |
246 bool prefer_cache_; | 247 bool prefer_cache_; |
247 Referrer referrer_; | 248 Referrer referrer_; |
248 std::string referrer_encoding_; | 249 std::string referrer_encoding_; |
249 int render_process_host_id_; | 250 int render_process_host_id_; |
250 int render_view_host_routing_id_; | 251 int render_view_host_routing_id_; |
251 int render_frame_host_routing_id_; | 252 int render_frame_host_routing_id_; |
252 ResourceContext* resource_context_; | 253 ResourceContext* resource_context_; |
253 DownloadSaveInfo save_info_; | 254 DownloadSaveInfo save_info_; |
254 GURL url_; | 255 GURL url_; |
255 bool do_not_prompt_for_login_; | 256 bool do_not_prompt_for_login_; |
256 scoped_ptr<storage::BlobDataHandle> blob_data_handle_; | 257 std::unique_ptr<storage::BlobDataHandle> blob_data_handle_; |
257 | 258 |
258 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); | 259 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); |
259 }; | 260 }; |
260 | 261 |
261 } // namespace content | 262 } // namespace content |
262 | 263 |
263 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ | 264 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
OLD | NEW |