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" |
| 11 #include "base/callback_forward.h" |
11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
13 #include "content/public/browser/download_id.h" | 14 #include "content/public/browser/download_id.h" |
14 #include "content/public/browser/download_interrupt_reasons.h" | 15 #include "content/public/browser/download_interrupt_reasons.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 class DownloadManager; | 19 class DownloadManager; |
19 | 20 |
20 // These objects live exclusively on the file thread and handle the writing | 21 // These objects live exclusively on the file thread and handle the writing |
21 // operations for one download. These objects live only for the duration that | 22 // operations for one download. These objects live only for the duration that |
22 // the download is 'in progress': once the download has been completed or | 23 // the download is 'in progress': once the download has been completed or |
23 // cancelled, the DownloadFile is destroyed. | 24 // cancelled, the DownloadFile is destroyed. |
24 class CONTENT_EXPORT DownloadFile { | 25 class CONTENT_EXPORT DownloadFile { |
25 public: | 26 public: |
| 27 // Callback used with Rename(). On a successful rename |reason| will be |
| 28 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename |
| 29 // was done to. On a failed rename, |reason| will contain the |
| 30 // error. |
| 31 typedef base::Callback<void(content::DownloadInterruptReason reason, |
| 32 const FilePath& path)> RenameCompletionCallback; |
| 33 |
26 virtual ~DownloadFile() {} | 34 virtual ~DownloadFile() {} |
27 | 35 |
28 // If calculate_hash is true, sha256 hash will be calculated. | 36 // If calculate_hash is true, sha256 hash will be calculated. |
29 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network | 37 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network |
30 // error code on failure. | 38 // error code on failure. |
31 virtual DownloadInterruptReason Initialize() = 0; | 39 virtual DownloadInterruptReason Initialize() = 0; |
32 | 40 |
33 // Rename the download file. | 41 // Rename the download file to |full_path|. If that file exists and |
34 // Returns net::OK on success, or a network error code on failure. | 42 // |overwrite_existing_file| is false, |full_path| will be uniquified by |
35 virtual DownloadInterruptReason Rename(const FilePath& full_path) = 0; | 43 // suffixing " (<number>)" to the file name before the extension. |
| 44 // Upon completion, |callback| will be called on the UI thread |
| 45 // as per the comment above. |
| 46 virtual void Rename(const FilePath& full_path, |
| 47 bool overwrite_existing_file, |
| 48 const RenameCompletionCallback& callback) = 0; |
36 | 49 |
37 // Detach the file so it is not deleted on destruction. | 50 // Detach the file so it is not deleted on destruction. |
38 virtual void Detach() = 0; | 51 virtual void Detach() = 0; |
39 | 52 |
40 // Abort the download and automatically close the file. | 53 // Abort the download and automatically close the file. |
41 virtual void Cancel() = 0; | 54 virtual void Cancel() = 0; |
42 | 55 |
43 // Informs the OS that this file came from the internet. | 56 // Informs the OS that this file came from the internet. |
44 virtual void AnnotateWithSourceInformation() = 0; | 57 virtual void AnnotateWithSourceInformation() = 0; |
45 | 58 |
(...skipping 15 matching lines...) Expand all Loading... |
61 virtual int Id() const = 0; | 74 virtual int Id() const = 0; |
62 virtual DownloadManager* GetDownloadManager() = 0; | 75 virtual DownloadManager* GetDownloadManager() = 0; |
63 virtual const DownloadId& GlobalId() const = 0; | 76 virtual const DownloadId& GlobalId() const = 0; |
64 | 77 |
65 virtual std::string DebugString() const = 0; | 78 virtual std::string DebugString() const = 0; |
66 }; | 79 }; |
67 | 80 |
68 } // namespace content | 81 } // namespace content |
69 | 82 |
70 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 83 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
OLD | NEW |