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" | |
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: |
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 | |
27 // Callback used with Rename(). On a successful rename |reason| will be | 32 // Callback used with Rename(). On a successful rename |reason| will be |
28 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename | 33 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename |
29 // was done to. On a failed rename, |reason| will contain the | 34 // was done to. On a failed rename, |reason| will contain the |
30 // error. | 35 // error. |
31 typedef base::Callback<void(DownloadInterruptReason reason, | 36 typedef base::Callback<void(DownloadInterruptReason reason, |
32 const FilePath& path)> RenameCompletionCallback; | 37 const FilePath& path)> RenameCompletionCallback; |
33 | 38 |
34 virtual ~DownloadFile() {} | 39 virtual ~DownloadFile() {} |
35 | 40 |
36 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network | 41 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network |
37 // error code on failure. Upon completion, |callback| will be | 42 // error code on failure. Upon completion, |callback| will be |
38 // called on the UI thread as per the comment above. | 43 // called on the UI thread as per the comment above. |
39 virtual content::DownloadInterruptReason Initialize() = 0; | 44 virtual void Initialize(const InitializeCallback& callback) = 0; |
40 | 45 |
41 // Rename the download file to |full_path|. If that file exists and | 46 // Rename the download file to |full_path|. If that file exists and |
42 // |overwrite_existing_file| is false, |full_path| will be uniquified by | 47 // |overwrite_existing_file| is false, |full_path| will be uniquified by |
43 // suffixing " (<number>)" to the file name before the extension. | 48 // suffixing " (<number>)" to the file name before the extension. |
44 // Upon completion, |callback| will be called on the UI thread | 49 // Upon completion, |callback| will be called on the UI thread |
45 // as per the comment above. | 50 // as per the comment above. |
46 virtual void Rename(const FilePath& full_path, | 51 virtual void Rename(const FilePath& full_path, |
47 bool overwrite_existing_file, | 52 bool overwrite_existing_file, |
48 const RenameCompletionCallback& callback) = 0; | 53 const RenameCompletionCallback& callback) = 0; |
49 | 54 |
(...skipping 12 matching lines...) Expand all Loading... | |
62 virtual int64 BytesSoFar() const = 0; | 67 virtual int64 BytesSoFar() const = 0; |
63 virtual int64 CurrentSpeed() const = 0; | 68 virtual int64 CurrentSpeed() const = 0; |
64 | 69 |
65 // Set |hash| with sha256 digest for the file. | 70 // Set |hash| with sha256 digest for the file. |
66 // Returns true if digest is successfully calculated. | 71 // Returns true if digest is successfully calculated. |
67 virtual bool GetHash(std::string* hash) = 0; | 72 virtual bool GetHash(std::string* hash) = 0; |
68 | 73 |
69 // 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. |
70 virtual std::string GetHashState() = 0; | 75 virtual std::string GetHashState() = 0; |
71 | 76 |
72 // Cancels the download request associated with this file. | 77 // For testing. Must be called on FILE thread. |
73 virtual void CancelDownloadRequest() = 0; | 78 // TODO(rdsmith): Remove use of EnsureNoPendingDownloads() |
79 // on the DownloadManager is replaced by a test-specific DownloadFileFactory | |
benjhayden
2012/09/24 17:43:27
Grammar check
Randy Smith (Not in Mondays)
2012/09/26 21:01:05
Done.
| |
80 // which keeps track of the number of DownloadFiles. | |
81 static int GetNumberOfDownloadFiles(); | |
74 | 82 |
75 virtual int Id() const = 0; | 83 protected: |
76 virtual DownloadManager* GetDownloadManager() = 0; | 84 static int number_active_objects_; |
77 virtual const DownloadId& GlobalId() const = 0; | |
78 | |
79 virtual std::string DebugString() const = 0; | |
80 }; | 85 }; |
81 | 86 |
82 } // namespace content | 87 } // namespace content |
83 | 88 |
84 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 89 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
OLD | NEW |