| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/download_interrupt_reasons.h" | 16 #include "content/public/browser/download_interrupt_reasons.h" |
| 16 | 17 |
| 17 class GURL; | 18 class GURL; |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 22 class ByteStreamReader; |
| 23 |
| 21 // These objects live exclusively on the file thread and handle the writing | 24 // These objects live exclusively on the file thread and handle the writing |
| 22 // operations for one download. These objects live only for the duration that | 25 // operations for one download. These objects live only for the duration that |
| 23 // the download is 'in progress': once the download has been completed or | 26 // the download is 'in progress': once the download has been completed or |
| 24 // cancelled, the DownloadFile is destroyed. | 27 // cancelled, the DownloadFile is destroyed. |
| 25 class CONTENT_EXPORT DownloadFile { | 28 class CONTENT_EXPORT DownloadFile { |
| 26 public: | 29 public: |
| 27 // Callback used with Initialize. On a successful initialize, |reason| will | 30 // Callback used with Initialize. On a successful initialize, |reason| will |
| 28 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be | 31 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be |
| 29 // set to the reason for the failure. | 32 // set to the reason for the failure. |
| 30 typedef base::Callback<void(DownloadInterruptReason reason)> | 33 typedef base::Callback<void(DownloadInterruptReason reason)> |
| 31 InitializeCallback; | 34 InitializeCallback; |
| 32 | 35 |
| 33 // Callback used with Rename*(). On a successful rename |reason| will be | 36 // Callback used with Rename*(). On a successful rename |reason| will be |
| 34 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename | 37 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename |
| 35 // was done to. On a failed rename, |reason| will contain the | 38 // was done to. On a failed rename, |reason| will contain the |
| 36 // error. | 39 // error. |
| 37 typedef base::Callback<void(DownloadInterruptReason reason, | 40 typedef base::Callback<void(DownloadInterruptReason reason, |
| 38 const base::FilePath& path)> | 41 const base::FilePath& path)> |
| 39 RenameCompletionCallback; | 42 RenameCompletionCallback; |
| 40 | 43 |
| 41 virtual ~DownloadFile() {} | 44 virtual ~DownloadFile() {} |
| 42 | 45 |
| 43 // Upon completion, |callback| will be called on the UI | 46 // Upon completion, |callback| will be called on the UI |
| 44 // thread as per the comment above, passing DOWNLOAD_INTERRUPT_REASON_NONE | 47 // thread as per the comment above, passing DOWNLOAD_INTERRUPT_REASON_NONE |
| 45 // on success, or a network download interrupt reason on failure. | 48 // on success, or a network download interrupt reason on failure. |
| 46 virtual void Initialize(const InitializeCallback& callback) = 0; | 49 virtual void Initialize(const InitializeCallback& callback) = 0; |
| 47 | 50 |
| 51 // Add a byte stream reader to write into a slice of the file, used for |
| 52 // parallel download. Called on the file thread. |
| 53 virtual void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, |
| 54 int64_t offset) = 0; |
| 55 |
| 48 // Rename the download file to |full_path|. If that file exists | 56 // Rename the download file to |full_path|. If that file exists |
| 49 // |full_path| will be uniquified by suffixing " (<number>)" to the | 57 // |full_path| will be uniquified by suffixing " (<number>)" to the |
| 50 // file name before the extension. | 58 // file name before the extension. |
| 51 virtual void RenameAndUniquify(const base::FilePath& full_path, | 59 virtual void RenameAndUniquify(const base::FilePath& full_path, |
| 52 const RenameCompletionCallback& callback) = 0; | 60 const RenameCompletionCallback& callback) = 0; |
| 53 | 61 |
| 54 // Rename the download file to |full_path| and annotate it with | 62 // Rename the download file to |full_path| and annotate it with |
| 55 // "Mark of the Web" information about its source. No uniquification | 63 // "Mark of the Web" information about its source. No uniquification |
| 56 // will be performed. | 64 // will be performed. |
| 57 virtual void RenameAndAnnotate(const base::FilePath& full_path, | 65 virtual void RenameAndAnnotate(const base::FilePath& full_path, |
| 58 const std::string& client_guid, | 66 const std::string& client_guid, |
| 59 const GURL& source_url, | 67 const GURL& source_url, |
| 60 const GURL& referrer_url, | 68 const GURL& referrer_url, |
| 61 const RenameCompletionCallback& callback) = 0; | 69 const RenameCompletionCallback& callback) = 0; |
| 62 | 70 |
| 63 // Detach the file so it is not deleted on destruction. | 71 // Detach the file so it is not deleted on destruction. |
| 64 virtual void Detach() = 0; | 72 virtual void Detach() = 0; |
| 65 | 73 |
| 66 // Abort the download and automatically close the file. | 74 // Abort the download and automatically close the file. |
| 67 virtual void Cancel() = 0; | 75 virtual void Cancel() = 0; |
| 68 | 76 |
| 69 virtual const base::FilePath& FullPath() const = 0; | 77 virtual const base::FilePath& FullPath() const = 0; |
| 70 virtual bool InProgress() const = 0; | 78 virtual bool InProgress() const = 0; |
| 71 }; | 79 }; |
| 72 | 80 |
| 73 } // namespace content | 81 } // namespace content |
| 74 | 82 |
| 75 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 83 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| OLD | NEW |