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 16 matching lines...) Expand all Loading... |
27 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be | 27 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be |
28 // set to the reason for the failure. | 28 // set to the reason for the failure. |
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 base::FilePath& path)> |
| 38 RenameCompletionCallback; |
38 | 39 |
39 virtual ~DownloadFile() {} | 40 virtual ~DownloadFile() {} |
40 | 41 |
41 // Upon completion, |callback| will be called on the UI | 42 // Upon completion, |callback| will be called on the UI |
42 // thread as per the comment above, passing DOWNLOAD_INTERRUPT_REASON_NONE | 43 // thread as per the comment above, passing DOWNLOAD_INTERRUPT_REASON_NONE |
43 // on success, or a network download interrupt reason on failure. | 44 // on success, or a network download interrupt reason on failure. |
44 virtual void Initialize(const InitializeCallback& callback) = 0; | 45 virtual void Initialize(const InitializeCallback& callback) = 0; |
45 | 46 |
46 // Rename the download file to |full_path|. If that file exists | 47 // Rename the download file to |full_path|. If that file exists |
47 // |full_path| will be uniquified by suffixing " (<number>)" to the | 48 // |full_path| will be uniquified by suffixing " (<number>)" to the |
48 // file name before the extension. | 49 // file name before the extension. |
49 virtual void RenameAndUniquify(const FilePath& full_path, | 50 virtual void RenameAndUniquify(const base::FilePath& full_path, |
50 const RenameCompletionCallback& callback) = 0; | 51 const RenameCompletionCallback& callback) = 0; |
51 | 52 |
52 // Rename the download file to |full_path| and annotate it with | 53 // Rename the download file to |full_path| and annotate it with |
53 // "Mark of the Web" information about its source. No uniquification | 54 // "Mark of the Web" information about its source. No uniquification |
54 // will be performed. | 55 // will be performed. |
55 virtual void RenameAndAnnotate(const FilePath& full_path, | 56 virtual void RenameAndAnnotate(const base::FilePath& full_path, |
56 const RenameCompletionCallback& callback) = 0; | 57 const RenameCompletionCallback& callback) = 0; |
57 | 58 |
58 // Detach the file so it is not deleted on destruction. | 59 // Detach the file so it is not deleted on destruction. |
59 virtual void Detach() = 0; | 60 virtual void Detach() = 0; |
60 | 61 |
61 // Abort the download and automatically close the file. | 62 // Abort the download and automatically close the file. |
62 virtual void Cancel() = 0; | 63 virtual void Cancel() = 0; |
63 | 64 |
64 virtual FilePath FullPath() const = 0; | 65 virtual base::FilePath FullPath() const = 0; |
65 virtual bool InProgress() const = 0; | 66 virtual bool InProgress() const = 0; |
66 virtual int64 BytesSoFar() const = 0; | 67 virtual int64 BytesSoFar() const = 0; |
67 virtual int64 CurrentSpeed() const = 0; | 68 virtual int64 CurrentSpeed() const = 0; |
68 | 69 |
69 // Set |hash| with sha256 digest for the file. | 70 // Set |hash| with sha256 digest for the file. |
70 // Returns true if digest is successfully calculated. | 71 // Returns true if digest is successfully calculated. |
71 virtual bool GetHash(std::string* hash) = 0; | 72 virtual bool GetHash(std::string* hash) = 0; |
72 | 73 |
73 // Returns the current (intermediate) state of the hash as a byte string. | 74 // Returns the current (intermediate) state of the hash as a byte string. |
74 virtual std::string GetHashState() = 0; | 75 virtual std::string GetHashState() = 0; |
75 | 76 |
76 // For testing. Must be called on FILE thread. | 77 // For testing. Must be called on FILE thread. |
77 // TODO(rdsmith): Replace use of EnsureNoPendingDownloads() | 78 // TODO(rdsmith): Replace use of EnsureNoPendingDownloads() |
78 // on the DownloadManager with a test-specific DownloadFileFactory | 79 // on the DownloadManager with a test-specific DownloadFileFactory |
79 // which keeps track of the number of DownloadFiles. | 80 // which keeps track of the number of DownloadFiles. |
80 static int GetNumberOfDownloadFiles(); | 81 static int GetNumberOfDownloadFiles(); |
81 | 82 |
82 protected: | 83 protected: |
83 static int number_active_objects_; | 84 static int number_active_objects_; |
84 }; | 85 }; |
85 | 86 |
86 } // namespace content | 87 } // namespace content |
87 | 88 |
88 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 89 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
OLD | NEW |