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