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