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/callback_forward.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.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: |
26 // Callback used with Initialize. On a successful initialize, |reason| will | |
27 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be | |
28 // set to the reason for the failure. | |
29 typedef base::Callback<void(content::DownloadInterruptReason reason)> | |
30 InitializeCallback; | |
31 | |
32 // Callback used with Rename(). On a successful rename |reason| will be | 27 // Callback used with Rename(). On a successful rename |reason| will be |
33 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename | 28 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename |
34 // was done to. On a failed rename, |reason| will contain the | 29 // was done to. On a failed rename, |reason| will contain the |
35 // error. | 30 // error. |
36 typedef base::Callback<void(content::DownloadInterruptReason reason, | 31 typedef base::Callback<void(content::DownloadInterruptReason reason, |
37 const FilePath& path)> RenameCompletionCallback; | 32 const FilePath& path)> RenameCompletionCallback; |
38 | 33 |
39 virtual ~DownloadFile() {} | 34 virtual ~DownloadFile() {} |
40 | 35 |
| 36 // If calculate_hash is true, sha256 hash will be calculated. |
41 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network | 37 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network |
42 // error code on failure. Upon completion, |callback| will be | 38 // error code on failure. |
43 // called on the UI thread as per the comment above. | 39 virtual DownloadInterruptReason Initialize() = 0; |
44 virtual void Initialize(const InitializeCallback& callback) = 0; | |
45 | 40 |
46 // Rename the download file to |full_path|. If that file exists and | 41 // Rename the download file to |full_path|. If that file exists and |
47 // |overwrite_existing_file| is false, |full_path| will be uniquified by | 42 // |overwrite_existing_file| is false, |full_path| will be uniquified by |
48 // suffixing " (<number>)" to the file name before the extension. | 43 // suffixing " (<number>)" to the file name before the extension. |
49 // Upon completion, |callback| will be called on the UI thread | 44 // Upon completion, |callback| will be called on the UI thread |
50 // as per the comment above. | 45 // as per the comment above. |
51 virtual void Rename(const FilePath& full_path, | 46 virtual void Rename(const FilePath& full_path, |
52 bool overwrite_existing_file, | 47 bool overwrite_existing_file, |
53 const RenameCompletionCallback& callback) = 0; | 48 const RenameCompletionCallback& callback) = 0; |
54 | 49 |
(...skipping 11 matching lines...) Expand all Loading... |
66 virtual int64 BytesSoFar() const = 0; | 61 virtual int64 BytesSoFar() const = 0; |
67 virtual int64 CurrentSpeed() const = 0; | 62 virtual int64 CurrentSpeed() const = 0; |
68 | 63 |
69 // Set |hash| with sha256 digest for the file. | 64 // Set |hash| with sha256 digest for the file. |
70 // Returns true if digest is successfully calculated. | 65 // Returns true if digest is successfully calculated. |
71 virtual bool GetHash(std::string* hash) = 0; | 66 virtual bool GetHash(std::string* hash) = 0; |
72 | 67 |
73 // Returns the current (intermediate) state of the hash as a byte string. | 68 // Returns the current (intermediate) state of the hash as a byte string. |
74 virtual std::string GetHashState() = 0; | 69 virtual std::string GetHashState() = 0; |
75 | 70 |
76 // For testing. Must be called on FILE thread. | 71 // Cancels the download request associated with this file. |
77 static int GetNumberOfDownloadFiles(); | 72 virtual void CancelDownloadRequest() = 0; |
78 | 73 |
79 protected: | 74 virtual int Id() const = 0; |
80 static int number_active_objects_; | 75 virtual DownloadManager* GetDownloadManager() = 0; |
| 76 virtual const DownloadId& GlobalId() const = 0; |
| 77 |
| 78 virtual std::string DebugString() const = 0; |
81 }; | 79 }; |
82 | 80 |
83 } // namespace content | 81 } // namespace content |
84 | 82 |
85 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 83 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
OLD | NEW |