| 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_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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 typedef base::Callback<void(DownloadInterruptReason reason)> | 29 typedef base::Callback<void(DownloadInterruptReason reason)> |
| 30 InitializeCallback; | 30 InitializeCallback; |
| 31 | 31 |
| 32 // Callback used with Rename(). On a successful rename |reason| will be | 32 // Callback used with Rename(). On a successful rename |reason| will be |
| 33 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename | 33 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename |
| 34 // was done to. On a failed rename, |reason| will contain the | 34 // was done to. On a failed rename, |reason| will contain the |
| 35 // error. | 35 // error. |
| 36 typedef base::Callback<void(DownloadInterruptReason reason, | 36 typedef base::Callback<void(DownloadInterruptReason reason, |
| 37 const FilePath& path)> RenameCompletionCallback; | 37 const FilePath& path)> RenameCompletionCallback; |
| 38 | 38 |
| 39 // Callback used with Detach(). On success, |reason| will be |
| 40 // DOWNLOAD_INTERRUPT_REASON_NONE. |
| 41 typedef base::Callback<void(DownloadInterruptReason reason)> |
| 42 DetachCompletionCallback; |
| 43 |
| 39 virtual ~DownloadFile() {} | 44 virtual ~DownloadFile() {} |
| 40 | 45 |
| 41 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network | 46 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network |
| 42 // error code on failure. Upon completion, |callback| will be | 47 // error code on failure. Upon completion, |callback| will be |
| 43 // called on the UI thread as per the comment above. | 48 // called on the UI thread as per the comment above. |
| 44 virtual void Initialize(const InitializeCallback& callback) = 0; | 49 virtual void Initialize(const InitializeCallback& callback) = 0; |
| 45 | 50 |
| 46 // Rename the download file to |full_path|. If that file exists and | 51 // Rename the download file to |full_path|. If that file exists and |
| 47 // |overwrite_existing_file| is false, |full_path| will be uniquified by | 52 // |overwrite_existing_file| is false, |full_path| will be uniquified by |
| 48 // suffixing " (<number>)" to the file name before the extension. | 53 // suffixing " (<number>)" to the file name before the extension. |
| 49 // Upon completion, |callback| will be called on the UI thread | 54 // Upon completion, |callback| will be called on the UI thread |
| 50 // as per the comment above. | 55 // as per the comment above. |
| 51 virtual void Rename(const FilePath& full_path, | 56 virtual void Rename(const FilePath& full_path, |
| 52 bool overwrite_existing_file, | 57 bool overwrite_existing_file, |
| 53 const RenameCompletionCallback& callback) = 0; | 58 const RenameCompletionCallback& callback) = 0; |
| 54 | 59 |
| 55 // Detach the file so it is not deleted on destruction. | 60 // Detach the file so it is not deleted on destruction. |
| 56 // |callback| will be called on the UI thread after detach. | 61 // |callback| will be called on the UI thread after detach. |
| 57 virtual void Detach(base::Closure callback) = 0; | 62 virtual void Detach(const DetachCompletionCallback& callback) = 0; |
| 58 | 63 |
| 59 // Abort the download and automatically close the file. | 64 // Abort the download and automatically close the file. |
| 60 virtual void Cancel() = 0; | 65 virtual void Cancel() = 0; |
| 61 | 66 |
| 62 // Informs the OS that this file came from the internet. | |
| 63 virtual void AnnotateWithSourceInformation() = 0; | |
| 64 | |
| 65 virtual FilePath FullPath() const = 0; | 67 virtual FilePath FullPath() const = 0; |
| 66 virtual bool InProgress() const = 0; | 68 virtual bool InProgress() const = 0; |
| 67 virtual int64 BytesSoFar() const = 0; | 69 virtual int64 BytesSoFar() const = 0; |
| 68 virtual int64 CurrentSpeed() const = 0; | 70 virtual int64 CurrentSpeed() const = 0; |
| 69 | 71 |
| 70 // Set |hash| with sha256 digest for the file. | 72 // Set |hash| with sha256 digest for the file. |
| 71 // Returns true if digest is successfully calculated. | 73 // Returns true if digest is successfully calculated. |
| 72 virtual bool GetHash(std::string* hash) = 0; | 74 virtual bool GetHash(std::string* hash) = 0; |
| 73 | 75 |
| 74 // Returns the current (intermediate) state of the hash as a byte string. | 76 // Returns the current (intermediate) state of the hash as a byte string. |
| 75 virtual std::string GetHashState() = 0; | 77 virtual std::string GetHashState() = 0; |
| 76 | 78 |
| 77 // For testing. Must be called on FILE thread. | 79 // For testing. Must be called on FILE thread. |
| 78 // TODO(rdsmith): Replace use of EnsureNoPendingDownloads() | 80 // TODO(rdsmith): Replace use of EnsureNoPendingDownloads() |
| 79 // on the DownloadManager with a test-specific DownloadFileFactory | 81 // on the DownloadManager with a test-specific DownloadFileFactory |
| 80 // which keeps track of the number of DownloadFiles. | 82 // which keeps track of the number of DownloadFiles. |
| 81 static int GetNumberOfDownloadFiles(); | 83 static int GetNumberOfDownloadFiles(); |
| 82 | 84 |
| 83 protected: | 85 protected: |
| 84 static int number_active_objects_; | 86 static int number_active_objects_; |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 } // namespace content | 89 } // namespace content |
| 88 | 90 |
| 89 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 91 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| OLD | NEW |