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_BASE_FILE_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // |default_directory| and |full_path()| are empty, then a temporary file will | 49 // |default_directory| and |full_path()| are empty, then a temporary file will |
50 // be created in the default download location as determined by | 50 // be created in the default download location as determined by |
51 // ContentBrowserClient. | 51 // ContentBrowserClient. |
52 DownloadInterruptReason Initialize(const base::FilePath& default_directory); | 52 DownloadInterruptReason Initialize(const base::FilePath& default_directory); |
53 | 53 |
54 // Write a new chunk of data to the file. Returns a DownloadInterruptReason | 54 // Write a new chunk of data to the file. Returns a DownloadInterruptReason |
55 // indicating the result of the operation. | 55 // indicating the result of the operation. |
56 DownloadInterruptReason AppendDataToFile(const char* data, size_t data_len); | 56 DownloadInterruptReason AppendDataToFile(const char* data, size_t data_len); |
57 | 57 |
58 // Rename the download file. Returns a DownloadInterruptReason indicating the | 58 // Rename the download file. Returns a DownloadInterruptReason indicating the |
59 // result of the operation. A return code of NONE indicates that the rename | 59 // result of the operation. |
60 // was successful. After a failure, the full_path() and in_progress() can be | |
61 // used to determine the last known filename and whether the file is available | |
62 // for writing or retrying the rename. | |
63 virtual DownloadInterruptReason Rename(const base::FilePath& full_path); | 60 virtual DownloadInterruptReason Rename(const base::FilePath& full_path); |
64 | 61 |
65 // Detach the file so it is not deleted on destruction. | 62 // Detach the file so it is not deleted on destruction. |
66 virtual void Detach(); | 63 virtual void Detach(); |
67 | 64 |
68 // Abort the download and automatically close the file. | 65 // Abort the download and automatically close the file. |
69 void Cancel(); | 66 void Cancel(); |
70 | 67 |
71 // Indicate that the download has finished. No new data will be received. | 68 // Indicate that the download has finished. No new data will be received. |
72 void Finish(); | 69 void Finish(); |
73 | 70 |
74 // Set the client guid which will be used to identify the app to the | 71 // Set the client guid which will be used to identify the app to the |
75 // system AV scanning function. Should be called before | 72 // system AV scanning function. Should be called before |
76 // AnnotateWithSourceInformation() to take effect. | 73 // AnnotateWithSourceInformation() to take effect. |
77 void SetClientGuid(const std::string& guid); | 74 void SetClientGuid(const std::string& guid); |
78 | 75 |
79 // Informs the OS that this file came from the internet. Returns a | 76 // Informs the OS that this file came from the internet. Returns a |
80 // DownloadInterruptReason indicating the result of the operation. | 77 // DownloadInterruptReason indicating the result of the operation. |
81 // Note: SetClientGuid() should be called before this function on | 78 // Note: SetClientGuid() should be called before this function on |
82 // Windows to ensure the correct app client ID is available. | 79 // Windows to ensure the correct app client ID is available. |
83 DownloadInterruptReason AnnotateWithSourceInformation(); | 80 DownloadInterruptReason AnnotateWithSourceInformation(); |
84 | 81 |
85 // Returns the last known path to the download file. Can be empty if there's | 82 base::FilePath full_path() const { return full_path_; } |
86 // no file. | |
87 const base::FilePath& full_path() const { return full_path_; } | |
88 | |
89 // Returns true if the file is open. If true, the file can be written to or | |
90 // renamed. | |
91 bool in_progress() const { return file_.IsValid(); } | 83 bool in_progress() const { return file_.IsValid(); } |
92 | |
93 // Returns the number of bytes in the file pointed to by full_path(). | |
94 int64 bytes_so_far() const { return bytes_so_far_; } | 84 int64 bytes_so_far() const { return bytes_so_far_; } |
95 | 85 |
96 // Fills |hash| with the hash digest for the file. | 86 // Fills |hash| with the hash digest for the file. |
97 // Returns true if digest is successfully calculated. | 87 // Returns true if digest is successfully calculated. |
98 virtual bool GetHash(std::string* hash); | 88 virtual bool GetHash(std::string* hash); |
99 | 89 |
100 // Returns the current (intermediate) state of the hash as a byte string. | 90 // Returns the current (intermediate) state of the hash as a byte string. |
101 virtual std::string GetHashState(); | 91 virtual std::string GetHashState(); |
102 | 92 |
103 // Returns true if the given hash is considered empty. An empty hash is | 93 // Returns true if the given hash is considered empty. An empty hash is |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 bool detached_; | 170 bool detached_; |
181 | 171 |
182 net::BoundNetLog bound_net_log_; | 172 net::BoundNetLog bound_net_log_; |
183 | 173 |
184 DISALLOW_COPY_AND_ASSIGN(BaseFile); | 174 DISALLOW_COPY_AND_ASSIGN(BaseFile); |
185 }; | 175 }; |
186 | 176 |
187 } // namespace content | 177 } // namespace content |
188 | 178 |
189 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ | 179 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ |
OLD | NEW |