Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: chrome/browser/download/download_item.h

Issue 3127008: Preliminary work on resuming downloads whose connections have expired.
Patch Set: Waiting to send download automation error message until after other downloads are canceled. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Each download is represented by a DownloadItem, and all DownloadItems 5 // Each download is represented by a DownloadItem, and all DownloadItems
6 // are owned by the DownloadManager which maintains a global list of all 6 // are owned by the DownloadManager which maintains a global list of all
7 // downloads. DownloadItems are created when a user initiates a download, 7 // downloads. DownloadItems are created when a user initiates a download,
8 // and exist for the duration of the browser life time. 8 // and exist for the duration of the browser life time.
9 // 9 //
10 // Download observers: 10 // Download observers:
(...skipping 21 matching lines...) Expand all
32 32
33 // One DownloadItem per download. This is the model class that stores all the 33 // One DownloadItem per download. This is the model class that stores all the
34 // state for a download. Multiple views, such as a tab's download shelf and the 34 // state for a download. Multiple views, such as a tab's download shelf and the
35 // Destination tab's download view, may refer to a given DownloadItem. 35 // Destination tab's download view, may refer to a given DownloadItem.
36 class DownloadItem { 36 class DownloadItem {
37 public: 37 public:
38 enum DownloadState { 38 enum DownloadState {
39 IN_PROGRESS, 39 IN_PROGRESS,
40 COMPLETE, 40 COMPLETE,
41 CANCELLED, 41 CANCELLED,
42 REMOVING 42 REMOVING,
43 INTERRUPTED
43 }; 44 };
44 45
45 enum SafetyState { 46 enum SafetyState {
46 SAFE = 0, 47 SAFE = 0,
47 DANGEROUS, 48 DANGEROUS,
48 DANGEROUS_BUT_VALIDATED // Dangerous but the user confirmed the download. 49 DANGEROUS_BUT_VALIDATED // Dangerous but the user confirmed the download.
49 }; 50 };
50 51
51 // Interface that observers of a particular download must implement in order 52 // Interface that observers of a particular download must implement in order
52 // to receive updates to the download's status. 53 // to receive updates to the download's status.
53 class Observer { 54 class Observer {
54 public: 55 public:
55 virtual void OnDownloadUpdated(DownloadItem* download) = 0; 56 virtual void OnDownloadUpdated(DownloadItem* download) = 0;
56 57
57 // Called when a downloaded file has been completed. 58 // Called when a downloaded file has been completed.
58 virtual void OnDownloadFileCompleted(DownloadItem* download) = 0; 59 virtual void OnDownloadFileCompleted(DownloadItem* download) = 0;
59 60
60 // Called when a downloaded file has been opened. 61 // Called when a downloaded file has been opened.
61 virtual void OnDownloadOpened(DownloadItem* download) = 0; 62 virtual void OnDownloadOpened(DownloadItem* download) = 0;
62 63
64 // Called when a downloaded file has been interrupted (had an error).
65 virtual void OnDownloadInterrupted(DownloadItem* download) = 0;
66
63 protected: 67 protected:
64 virtual ~Observer() {} 68 virtual ~Observer() {}
65 }; 69 };
66 70
67 // Constructing from persistent store: 71 // Constructing from persistent store:
68 DownloadItem(DownloadManager* download_manager, 72 DownloadItem(DownloadManager* download_manager,
69 const DownloadCreateInfo& info); 73 const DownloadCreateInfo& info);
70 74
71 // Constructing for a regular download: 75 // Constructing for a regular download:
72 DownloadItem(DownloadManager* download_manager, 76 DownloadItem(DownloadManager* download_manager,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // when resuming a download (assuming the server supports byte ranges). 129 // when resuming a download (assuming the server supports byte ranges).
126 void Cancel(bool update_history); 130 void Cancel(bool update_history);
127 131
128 // Called when all data has been saved. 132 // Called when all data has been saved.
129 void OnAllDataSaved(int64 size); 133 void OnAllDataSaved(int64 size);
130 134
131 // Called when the entire download operation (including renaming etc) 135 // Called when the entire download operation (including renaming etc)
132 // is finished. 136 // is finished.
133 void Finished(); 137 void Finished();
134 138
139 // Download operation had an error.
140 // |size| is the amount of data received so far, and |os_error| is the error
141 // code that the operation received.
142 void Interrupted(int64 size, int os_error);
143
144 // User has resumed a download after an interruption.
145 // |new_request_id| is the new request ID associated with the download.
146 void Resumed(int new_request_id);
147
135 // The user wants to remove the download from the views and history. If 148 // The user wants to remove the download from the views and history. If
136 // |delete_file| is true, the file is deleted on the disk. 149 // |delete_file| is true, the file is deleted on the disk.
137 void Remove(bool delete_file); 150 void Remove(bool delete_file);
138 151
139 // Simple calculation of the amount of time remaining to completion. Fills 152 // Simple calculation of the amount of time remaining to completion. Fills
140 // |*remaining| with the amount of time remaining if successful. Fails and 153 // |*remaining| with the amount of time remaining if successful. Fails and
141 // returns false if we do not have the number of bytes or the speed so can 154 // returns false if we do not have the number of bytes or the speed so can
142 // not estimate. 155 // not estimate.
143 bool TimeRemaining(base::TimeDelta* remaining) const; 156 bool TimeRemaining(base::TimeDelta* remaining) const;
144 157
(...skipping 10 matching lines...) Expand all
155 168
156 // Allow the user to temporarily pause a download or resume a paused download. 169 // Allow the user to temporarily pause a download or resume a paused download.
157 void TogglePause(); 170 void TogglePause();
158 171
159 // Called when the name of the download is finalized. 172 // Called when the name of the download is finalized.
160 void OnNameFinalized(); 173 void OnNameFinalized();
161 174
162 // Returns true if this item matches |query|. |query| must be lower-cased. 175 // Returns true if this item matches |query|. |query| must be lower-cased.
163 bool MatchesQuery(const string16& query) const; 176 bool MatchesQuery(const string16& query) const;
164 177
178 bool IsPartialDownload() const;
179 bool IsInterruptedDownload() const;
180
165 // Accessors 181 // Accessors
166 DownloadState state() const { return state_; } 182 DownloadState state() const { return state_; }
167 FilePath full_path() const { return full_path_; } 183 FilePath full_path() const { return full_path_; }
168 void set_path_uniquifier(int uniquifier) { path_uniquifier_ = uniquifier; } 184 void set_path_uniquifier(int uniquifier) { path_uniquifier_ = uniquifier; }
169 GURL url() const { return url_; } 185 GURL url() const { return url_; }
170 GURL referrer_url() const { return referrer_url_; } 186 GURL referrer_url() const { return referrer_url_; }
171 std::string mime_type() const { return mime_type_; } 187 std::string mime_type() const { return mime_type_; }
172 std::string original_mime_type() const { return original_mime_type_; } 188 std::string original_mime_type() const { return original_mime_type_; }
173 int64 total_bytes() const { return total_bytes_; } 189 int64 total_bytes() const { return total_bytes_; }
174 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } 190 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; }
175 int64 received_bytes() const { return received_bytes_; } 191 int64 received_bytes() const { return received_bytes_; }
192 int last_os_error() const { return last_os_error_; }
176 int32 id() const { return id_; } 193 int32 id() const { return id_; }
177 base::Time start_time() const { return start_time_; } 194 base::Time start_time() const { return start_time_; }
178 void set_db_handle(int64 handle) { db_handle_ = handle; } 195 void set_db_handle(int64 handle) { db_handle_ = handle; }
179 int64 db_handle() const { return db_handle_; } 196 int64 db_handle() const { return db_handle_; }
180 bool is_paused() const { return is_paused_; } 197 bool is_paused() const { return is_paused_; }
181 bool open_when_complete() const { return open_when_complete_; } 198 bool open_when_complete() const { return open_when_complete_; }
182 void set_open_when_complete(bool open) { open_when_complete_ = open; } 199 void set_open_when_complete(bool open) { open_when_complete_ = open; }
183 int render_process_id() const { return render_process_id_; } 200 int render_process_id() const { return render_process_id_; }
184 int request_id() const { return request_id_; } 201 int request_id() const { return request_id_; }
185 SafetyState safety_state() const { return safety_state_; } 202 SafetyState safety_state() const { return safety_state_; }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // The value of the content type header received when downloading 257 // The value of the content type header received when downloading
241 // this item. |mime_type_| may be different because of type sniffing. 258 // this item. |mime_type_| may be different because of type sniffing.
242 std::string original_mime_type_; 259 std::string original_mime_type_;
243 260
244 // Total bytes expected 261 // Total bytes expected
245 int64 total_bytes_; 262 int64 total_bytes_;
246 263
247 // Current received bytes 264 // Current received bytes
248 int64 received_bytes_; 265 int64 received_bytes_;
249 266
267 // Last error.
268 int last_os_error_;
269
250 // Start time for calculating remaining time 270 // Start time for calculating remaining time
251 base::TimeTicks start_tick_; 271 base::TimeTicks start_tick_;
252 272
253 // The current state of this download 273 // The current state of this download
254 DownloadState state_; 274 DownloadState state_;
255 275
256 // The views of this item in the download shelf and download tab 276 // The views of this item in the download shelf and download tab
257 ObserverList<Observer> observers_; 277 ObserverList<Observer> observers_;
258 278
259 // Time the download was started 279 // Time the download was started
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // Did the user open the item either directly or indirectly (such as by 332 // Did the user open the item either directly or indirectly (such as by
313 // setting always open files of this type)? The shelf also sets this field 333 // setting always open files of this type)? The shelf also sets this field
314 // when the user closes the shelf before the item has been opened but should 334 // when the user closes the shelf before the item has been opened but should
315 // be treated as though the user opened it. 335 // be treated as though the user opened it.
316 bool opened_; 336 bool opened_;
317 337
318 DISALLOW_COPY_AND_ASSIGN(DownloadItem); 338 DISALLOW_COPY_AND_ASSIGN(DownloadItem);
319 }; 339 };
320 340
321 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 341 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698