[email protected] | 6c69796d | 2010-07-16 21:41:16 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | e93d2823 | 2009-01-30 05:59:59 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
6 | #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | f5c016b | 2009-06-16 17:12:31 | [diff] [blame] | 8 | #include <map> |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 9 | #include <string> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include <vector> |
11 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | f5c016b | 2009-06-16 17:12:31 | [diff] [blame] | 13 | #include "base/file_path.h" |
[email protected] | 2314403 | 2008-09-08 20:51:30 | [diff] [blame] | 14 | #include "base/hash_tables.h" |
[email protected] | 8af9d03 | 2010-02-10 00:00:32 | [diff] [blame] | 15 | #include "base/linked_ptr.h" |
[email protected] | 6c69796d | 2010-07-16 21:41:16 | [diff] [blame^] | 16 | #include "chrome/browser/download/download_types.h" |
[email protected] | 36e93a77 | 2009-10-23 04:18:05 | [diff] [blame] | 17 | #include "chrome/browser/power_save_blocker.h" |
[email protected] | f5c016b | 2009-06-16 17:12:31 | [diff] [blame] | 18 | #include "googleurl/src/gurl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | f5c016b | 2009-06-16 17:12:31 | [diff] [blame] | 20 | struct DownloadCreateInfo; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | |
22 | // These objects live exclusively on the download thread and handle the writing | ||||
23 | // operations for one download. These objects live only for the duration that | ||||
24 | // the download is 'in progress': once the download has been completed or | ||||
25 | // cancelled, the DownloadFile is destroyed. | ||||
26 | class DownloadFile { | ||||
27 | public: | ||||
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 28 | explicit DownloadFile(const DownloadCreateInfo* info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 29 | ~DownloadFile(); |
30 | |||||
31 | bool Initialize(); | ||||
32 | |||||
33 | // Write a new chunk of data to the file. Returns true on success. | ||||
34 | bool AppendDataToFile(const char* data, int data_len); | ||||
35 | |||||
36 | // Abort the download and automatically close the file. | ||||
37 | void Cancel(); | ||||
38 | |||||
39 | // Rename the download file. Returns 'true' if the rename was successful. | ||||
[email protected] | 7ae7c2cb | 2009-01-06 23:31:41 | [diff] [blame] | 40 | bool Rename(const FilePath& full_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | |
[email protected] | df72c09 | 2009-09-10 19:56:17 | [diff] [blame] | 42 | // Informs the OS that this file came from the internet. |
43 | void AnnotateWithSourceInformation(); | ||||
44 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 45 | // Accessors. |
46 | int64 bytes_so_far() const { return bytes_so_far_; } | ||||
47 | int id() const { return id_; } | ||||
[email protected] | 7ae7c2cb | 2009-01-06 23:31:41 | [diff] [blame] | 48 | FilePath full_path() const { return full_path_; } |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 49 | int child_id() const { return child_id_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | int render_view_id() const { return render_view_id_; } |
51 | int request_id() const { return request_id_; } | ||||
52 | bool path_renamed() const { return path_renamed_; } | ||||
[email protected] | 8af9d03 | 2010-02-10 00:00:32 | [diff] [blame] | 53 | bool in_progress() const { return file_stream_ != NULL; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | void set_in_progress(bool in_progress) { in_progress_ = in_progress; } |
55 | |||||
56 | private: | ||||
[email protected] | 8af9d03 | 2010-02-10 00:00:32 | [diff] [blame] | 57 | // Open or Close the OS file stream. The stream is opened in the constructor |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | // based on creation information passed to it, and automatically closed in |
59 | // the destructor. | ||||
60 | void Close(); | ||||
[email protected] | 8af9d03 | 2010-02-10 00:00:32 | [diff] [blame] | 61 | bool Open(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 62 | |
[email protected] | 8af9d03 | 2010-02-10 00:00:32 | [diff] [blame] | 63 | // OS file stream for writing |
64 | linked_ptr<net::FileStream> file_stream_; | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | |
[email protected] | 8ef0637 | 2009-04-27 21:11:34 | [diff] [blame] | 66 | // Source URL for the file being downloaded. |
67 | GURL source_url_; | ||||
68 | |||||
69 | // The URL where the download was initiated. | ||||
70 | GURL referrer_url_; | ||||
71 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 72 | // The unique identifier for this download, assigned at creation by |
73 | // the DownloadFileManager for its internal record keeping. | ||||
74 | int id_; | ||||
75 | |||||
76 | // IDs for looking up the tab we are associated with. | ||||
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 77 | int child_id_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | int render_view_id_; |
79 | |||||
80 | // Handle for informing the ResourceDispatcherHost of a UI based cancel. | ||||
81 | int request_id_; | ||||
82 | |||||
83 | // Amount of data received up to this point. We may not know in advance how | ||||
84 | // much data to expect since some servers don't provide that information. | ||||
85 | int64 bytes_so_far_; | ||||
86 | |||||
87 | // Full path to the downloaded file. | ||||
[email protected] | 7ae7c2cb | 2009-01-06 23:31:41 | [diff] [blame] | 88 | FilePath full_path_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 89 | |
90 | // Whether the download is still using its initial temporary path. | ||||
91 | bool path_renamed_; | ||||
92 | |||||
93 | // Whether the download is still receiving data. | ||||
94 | bool in_progress_; | ||||
95 | |||||
[email protected] | 36e93a77 | 2009-10-23 04:18:05 | [diff] [blame] | 96 | // RAII handle to keep the system from sleeping while we're downloading. |
97 | PowerSaveBlocker dont_sleep_; | ||||
98 | |||||
[email protected] | 8af9d03 | 2010-02-10 00:00:32 | [diff] [blame] | 99 | // The provider used to save the download data. |
100 | DownloadSaveInfo save_info_; | ||||
101 | |||||
[email protected] | e93d2823 | 2009-01-30 05:59:59 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(DownloadFile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 103 | }; |
104 | |||||
[email protected] | e93d2823 | 2009-01-30 05:59:59 | [diff] [blame] | 105 | #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |