OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | |
13 #include "content/browser/download/base_file.h" | 12 #include "content/browser/download/base_file.h" |
14 #include "content/browser/download/download_id.h" | 13 #include "content/browser/download/download_id.h" |
15 #include "content/browser/download/download_request_handle.h" | |
16 #include "content/browser/download/download_types.h" | |
17 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "net/base/net_errors.h" | |
18 | 16 |
19 struct DownloadCreateInfo; | |
20 class DownloadManager; | 17 class DownloadManager; |
21 class ResourceDispatcherHost; | |
22 | 18 |
23 // These objects live exclusively on the download thread and handle the writing | 19 class CONTENT_EXPORT DownloadFile { |
24 // operations for one download. These objects live only for the duration that | |
25 // the download is 'in progress': once the download has been completed or | |
26 // cancelled, the DownloadFile is destroyed. | |
27 class CONTENT_EXPORT DownloadFile : public BaseFile { | |
28 public: | 20 public: |
29 // Takes ownership of the object pointed to by |request_handle|. | 21 virtual ~DownloadFile() {} |
30 DownloadFile(const DownloadCreateInfo* info, | 22 |
31 DownloadRequestHandleInterface* request_handle, | 23 // If calculate_hash is true, sha256 hash will be calculated. |
32 DownloadManager* download_manager); | 24 // Returns net::OK on success, or a network error code on failure. |
33 virtual ~DownloadFile(); | 25 virtual net::Error Initialize(bool calculate_hash) = 0; |
26 | |
27 // Write a new chunk of data to the file. | |
28 // Returns net::OK on success (all bytes written to the file), | |
29 // or a network error code on failure. | |
30 virtual net::Error AppendDataToFile(const char* data, size_t data_len) = 0; | |
31 | |
32 // Rename the download file. | |
33 // Returns net::OK on success, or a network error code on failure. | |
34 virtual net::Error Rename(const FilePath& full_path) = 0; | |
35 | |
36 // Detach the file so it is not deleted on destruction. | |
37 virtual void Detach() = 0; | |
38 | |
39 // Abort the download and automatically close the file. | |
40 virtual void Cancel() = 0; | |
41 | |
42 // Indicate that the download has finished. No new data will be received. | |
43 virtual void Finish() = 0; | |
44 | |
45 // Informs the OS that this file came from the internet. | |
46 virtual void AnnotateWithSourceInformation() = 0; | |
47 | |
48 virtual FilePath FullPath() const = 0; | |
49 virtual bool InProgress() const = 0; | |
50 virtual int64 BytesSoFar() const = 0; | |
51 | |
52 // Set |hash| with sha256 digest for the file. | |
53 // Returns true if digest is successfully calculated. | |
54 virtual bool GetSha256Hash(std::string* hash) = 0; | |
34 | 55 |
35 // Cancels the download request associated with this file. | 56 // Cancels the download request associated with this file. |
36 void CancelDownloadRequest(); | 57 virtual void CancelDownloadRequest() = 0; |
37 | 58 |
38 int id() const { return id_.local(); } | 59 virtual int Id() const = 0; |
39 DownloadManager* GetDownloadManager(); | 60 virtual DownloadManager* GetDownloadManager() = 0; |
40 const DownloadId& global_id() const { return id_; } | 61 virtual const DownloadId& GlobalId() const = 0; |
41 | 62 |
42 virtual std::string DebugString() const; | 63 virtual std::string DebugString() const = 0; |
43 | 64 |
44 // Appends the passed the number between parenthesis the path before the | 65 // Appends the passed-in |number| between parenthesis to the |path| before |
45 // extension. | 66 // the file extension. |
46 static void AppendNumberToPath(FilePath* path, int number); | 67 static void AppendNumberToPath(FilePath* path, int number); |
47 | 68 |
48 // Attempts to find a number that can be appended to that path to make it | 69 // Appends the passed-in |suffix| to the |path|. |
Randy Smith (Not in Mondays)
2011/11/10 21:58:43
Why the ordering change? (I don't care, I'm just
ahendrickson
2011/11/13 00:50:21
I just wanted the similar functions grouped togeth
| |
70 static FilePath AppendSuffixToPath(const FilePath& path, | |
71 const FilePath::StringType& suffix); | |
72 | |
73 // Attempts to find a number that can be appended to the |path| to make it | |
49 // unique. If |path| does not exist, 0 is returned. If it fails to find such | 74 // unique. If |path| does not exist, 0 is returned. If it fails to find such |
50 // a number, -1 is returned. | 75 // a number, -1 is returned. |
51 static int GetUniquePathNumber(const FilePath& path); | 76 static int GetUniquePathNumber(const FilePath& path); |
52 | 77 |
53 static FilePath AppendSuffixToPath(const FilePath& path, | |
54 const FilePath::StringType& suffix); | |
55 | |
56 // Same as GetUniquePathNumber, except that it also checks the existence | 78 // Same as GetUniquePathNumber, except that it also checks the existence |
57 // of it with the given suffix. | 79 // of it with the given suffix. |
58 // If |path| does not exist, 0 is returned. If it fails to find such | 80 // If |path| does not exist, 0 is returned. If it fails to find such |
59 // a number, -1 is returned. | 81 // a number, -1 is returned. |
60 static int GetUniquePathNumberWithSuffix( | 82 static int GetUniquePathNumberWithSuffix( |
61 const FilePath& path, | 83 const FilePath& path, |
62 const FilePath::StringType& suffix); | 84 const FilePath::StringType& suffix); |
63 | |
64 private: | |
65 // The unique identifier for this download, assigned at creation by | |
66 // the DownloadFileManager for its internal record keeping. | |
67 DownloadId id_; | |
68 | |
69 // The handle to the request information. Used for operations outside the | |
70 // download system, specifically canceling a download. | |
71 scoped_ptr<DownloadRequestHandleInterface> request_handle_; | |
72 | |
73 // DownloadManager this download belongs to. | |
74 scoped_refptr<DownloadManager> download_manager_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(DownloadFile); | |
77 }; | 85 }; |
78 | 86 |
79 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 87 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
OLD | NEW |