| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "content/browser/download/base_file.h" | 12 #include "content/browser/download/base_file.h" |
| 13 #include "content/browser/download/download_id.h" | 13 #include "content/browser/download/download_id.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 | 16 |
| 17 class DownloadManager; | 17 class DownloadManager; |
| 18 | 18 |
| 19 // These objects live exclusively on the file thread and handle the writing | 19 // These objects live exclusively on the file thread and handle the writing |
| 20 // operations for one download. These objects live only for the duration that | 20 // operations for one download. These objects live only for the duration that |
| 21 // the download is 'in progress': once the download has been completed or | 21 // the download is 'in progress': once the download has been completed or |
| 22 // cancelled, the DownloadFile is destroyed. | 22 // cancelled, the DownloadFile is destroyed. |
| 23 class CONTENT_EXPORT DownloadFile { | 23 class CONTENT_EXPORT DownloadFile { |
| 24 public: | 24 public: |
| 25 virtual ~DownloadFile() {} | 25 virtual ~DownloadFile() {} |
| 26 | 26 |
| 27 // If calculate_hash is true, sha256 hash will be calculated. | 27 // If calculate_hash is true, sha256 hash will be calculated. |
| 28 // Returns net::OK on success, or a network error code on failure. | 28 // Returns net::OK on success, or a network error code on failure. |
| 29 virtual net::Error Initialize(bool calculate_hash) = 0; | 29 virtual net::Error Initialize() = 0; |
| 30 | 30 |
| 31 // Write a new chunk of data to the file. | 31 // Write a new chunk of data to the file. |
| 32 // Returns net::OK on success (all bytes written to the file), | 32 // Returns net::OK on success (all bytes written to the file), |
| 33 // or a network error code on failure. | 33 // or a network error code on failure. |
| 34 virtual net::Error AppendDataToFile(const char* data, size_t data_len) = 0; | 34 virtual net::Error AppendDataToFile(const char* data, size_t data_len) = 0; |
| 35 | 35 |
| 36 // Rename the download file. | 36 // Rename the download file. |
| 37 // Returns net::OK on success, or a network error code on failure. | 37 // Returns net::OK on success, or a network error code on failure. |
| 38 virtual net::Error Rename(const FilePath& full_path) = 0; | 38 virtual net::Error Rename(const FilePath& full_path) = 0; |
| 39 | 39 |
| 40 // Detach the file so it is not deleted on destruction. | 40 // Detach the file so it is not deleted on destruction. |
| 41 virtual void Detach() = 0; | 41 virtual void Detach() = 0; |
| 42 | 42 |
| 43 // Abort the download and automatically close the file. | 43 // Abort the download and automatically close the file. |
| 44 virtual void Cancel() = 0; | 44 virtual void Cancel() = 0; |
| 45 | 45 |
| 46 // Indicate that the download has finished. No new data will be received. | 46 // Indicate that the download has finished. No new data will be received. |
| 47 virtual void Finish() = 0; | 47 virtual void Finish() = 0; |
| 48 | 48 |
| 49 // Informs the OS that this file came from the internet. | 49 // Informs the OS that this file came from the internet. |
| 50 virtual void AnnotateWithSourceInformation() = 0; | 50 virtual void AnnotateWithSourceInformation() = 0; |
| 51 | 51 |
| 52 virtual FilePath FullPath() const = 0; | 52 virtual FilePath FullPath() const = 0; |
| 53 virtual bool InProgress() const = 0; | 53 virtual bool InProgress() const = 0; |
| 54 virtual int64 BytesSoFar() const = 0; | 54 virtual int64 BytesSoFar() const = 0; |
| 55 virtual int64 CurrentSpeed() const = 0; | 55 virtual int64 CurrentSpeed() const = 0; |
| 56 | 56 |
| 57 // Set |hash| with sha256 digest for the file. | 57 // Set |hash| with sha256 digest for the file. |
| 58 // Returns true if digest is successfully calculated. | 58 // Returns true if digest is successfully calculated. |
| 59 virtual bool GetSha256Hash(std::string* hash) = 0; | 59 virtual bool GetHash(std::string* hash) = 0; |
| 60 |
| 61 // Returns the current (intermediate) state of the hash as a byte string. |
| 62 virtual std::string GetHashState() = 0; |
| 60 | 63 |
| 61 // Cancels the download request associated with this file. | 64 // Cancels the download request associated with this file. |
| 62 virtual void CancelDownloadRequest() = 0; | 65 virtual void CancelDownloadRequest() = 0; |
| 63 | 66 |
| 64 virtual int Id() const = 0; | 67 virtual int Id() const = 0; |
| 65 virtual DownloadManager* GetDownloadManager() = 0; | 68 virtual DownloadManager* GetDownloadManager() = 0; |
| 66 virtual const DownloadId& GlobalId() const = 0; | 69 virtual const DownloadId& GlobalId() const = 0; |
| 67 | 70 |
| 68 virtual std::string DebugString() const = 0; | 71 virtual std::string DebugString() const = 0; |
| 69 | 72 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 // Same as GetUniquePathNumber, except that it also checks the existence | 86 // Same as GetUniquePathNumber, except that it also checks the existence |
| 84 // of it with the given suffix. | 87 // of it with the given suffix. |
| 85 // If |path| does not exist, 0 is returned. If it fails to find such | 88 // If |path| does not exist, 0 is returned. If it fails to find such |
| 86 // a number, -1 is returned. | 89 // a number, -1 is returned. |
| 87 static int GetUniquePathNumberWithSuffix( | 90 static int GetUniquePathNumberWithSuffix( |
| 88 const FilePath& path, | 91 const FilePath& path, |
| 89 const FilePath::StringType& suffix); | 92 const FilePath::StringType& suffix); |
| 90 }; | 93 }; |
| 91 | 94 |
| 92 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 95 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| OLD | NEW |