| 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_SAVE_INFO_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_SAVE_INFO_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_SAVE_INFO_H_ | 6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_SAVE_INFO_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "crypto/secure_hash.h" | 16 #include "crypto/secure_hash.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 // Holds the information about how to save a download file. | 20 // Holds the information about how to save a download file. |
| 21 // In the case of download continuation, |file_path| is set to the current file | 21 // In the case of download continuation, |file_path| is set to the current file |
| 22 // name, |offset| is set to the point where we left off, and |hash_state| will | 22 // name, |offset| is set to the point where we left off, and |hash_state| will |
| 23 // hold the state of the hash algorithm where we left off. | 23 // hold the state of the hash algorithm where we left off. |
| 24 struct CONTENT_EXPORT DownloadSaveInfo { | 24 struct CONTENT_EXPORT DownloadSaveInfo { |
| 25 // The default value for |length|. Used when request the rest of the file |
| 26 // starts from |offset|. |
| 27 static const int64_t kLengthFullContent; |
| 28 |
| 25 DownloadSaveInfo(); | 29 DownloadSaveInfo(); |
| 26 ~DownloadSaveInfo(); | 30 ~DownloadSaveInfo(); |
| 27 DownloadSaveInfo(DownloadSaveInfo&& that); | 31 DownloadSaveInfo(DownloadSaveInfo&& that); |
| 28 | 32 |
| 29 // If non-empty, contains the full target path of the download that has been | 33 // If non-empty, contains the full target path of the download that has been |
| 30 // determined prior to download initiation. This is considered to be a trusted | 34 // determined prior to download initiation. This is considered to be a trusted |
| 31 // path. | 35 // path. |
| 32 base::FilePath file_path; | 36 base::FilePath file_path; |
| 33 | 37 |
| 34 // If non-empty, contains an untrusted filename suggestion. This can't contain | 38 // If non-empty, contains an untrusted filename suggestion. This can't contain |
| 35 // a path (only a filename), and is only effective if |file_path| is empty. | 39 // a path (only a filename), and is only effective if |file_path| is empty. |
| 36 base::string16 suggested_name; | 40 base::string16 suggested_name; |
| 37 | 41 |
| 38 // If valid, contains the source data stream for the file contents. | 42 // If valid, contains the source data stream for the file contents. |
| 39 base::File file; | 43 base::File file; |
| 40 | 44 |
| 41 // The file offset at which to start the download. May be 0. | 45 // The file offset at which to start the download. May be 0. |
| 42 int64_t offset; | 46 int64_t offset; |
| 43 | 47 |
| 48 // The number of the bytes to download from |offset|. Set to |
| 49 // |kLengthFullContent| by default. |
| 50 // Ask to retrieve segment of the download file when length is greater than 0. |
| 51 // Request the rest of the file starting from |offset|, when length is |
| 52 // |kLengthFullContent|. |
| 53 int64_t length; |
| 54 |
| 44 // The state of the hash. If specified, this hash state must indicate the | 55 // The state of the hash. If specified, this hash state must indicate the |
| 45 // state of the partial file for the first |offset| bytes. | 56 // state of the partial file for the first |offset| bytes. |
| 46 std::unique_ptr<crypto::SecureHash> hash_state; | 57 std::unique_ptr<crypto::SecureHash> hash_state; |
| 47 | 58 |
| 48 // SHA-256 hash of the first |offset| bytes of the file. Only used if |offset| | 59 // SHA-256 hash of the first |offset| bytes of the file. Only used if |offset| |
| 49 // is non-zero and either |file_path| or |file| specifies the file which | 60 // is non-zero and either |file_path| or |file| specifies the file which |
| 50 // contains the |offset| number of bytes. Can be empty, in which case no | 61 // contains the |offset| number of bytes. Can be empty, in which case no |
| 51 // verification is done on the existing file. | 62 // verification is done on the existing file. |
| 52 std::string hash_of_partial_file; | 63 std::string hash_of_partial_file; |
| 53 | 64 |
| 54 // If |prompt_for_save_location| is true, and |file_path| is empty, then | 65 // If |prompt_for_save_location| is true, and |file_path| is empty, then |
| 55 // the user will be prompted for a location to save the download. Otherwise, | 66 // the user will be prompted for a location to save the download. Otherwise, |
| 56 // the location will be determined automatically using |file_path| as a | 67 // the location will be determined automatically using |file_path| as a |
| 57 // basis if |file_path| is not empty. | 68 // basis if |file_path| is not empty. |
| 58 // |prompt_for_save_location| defaults to false. | 69 // |prompt_for_save_location| defaults to false. |
| 59 bool prompt_for_save_location; | 70 bool prompt_for_save_location; |
| 60 | 71 |
| 61 private: | 72 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(DownloadSaveInfo); | 73 DISALLOW_COPY_AND_ASSIGN(DownloadSaveInfo); |
| 63 }; | 74 }; |
| 64 | 75 |
| 65 } // namespace content | 76 } // namespace content |
| 66 | 77 |
| 67 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_SAVE_INFO_H_ | 78 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_SAVE_INFO_H_ |
| OLD | NEW |