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

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

Issue 7294013: Modified cancel and interrupt processing to avoid race with history. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged to TOT. Again :-}. Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_history.cc ('k') | chrome/browser/download/download_item.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 // Show the download via the OS shell. 157 // Show the download via the OS shell.
158 void ShowDownloadInShell(); 158 void ShowDownloadInShell();
159 159
160 // Called when the user has validated the download of a dangerous file. 160 // Called when the user has validated the download of a dangerous file.
161 void DangerousDownloadValidated(); 161 void DangerousDownloadValidated();
162 162
163 // Received a new chunk of data 163 // Received a new chunk of data
164 void Update(int64 bytes_so_far); 164 void Update(int64 bytes_so_far);
165 165
166 // Cancel the download operation. We need to distinguish between cancels at 166 // Cancel the download operation. This may be called at any time; if
167 // exit (DownloadManager destructor) from user interface initiated cancels 167 // it is called before all download attributes have been finalized and
168 // because at exit, the history system may not exist, and any updates to it 168 // the download entered into the history, it will remove the download from
169 // require AddRef'ing the DownloadManager in the destructor which results in 169 // the system.
170 // a DCHECK failure. Set 'update_history' to false when canceling from at 170 void Cancel();
171 // exit to prevent this crash. This may result in a difference between the
172 // downloaded file's size on disk, and what the history system's last record
173 // of it is. At worst, we'll end up re-downloading a small portion of the file
174 // when resuming a download (assuming the server supports byte ranges).
175 void Cancel(bool update_history);
176 171
177 // Called by external code (SavePackage) using the DownloadItem interface 172 // Called by external code (SavePackage) using the DownloadItem interface
178 // to display progress when the DownloadItem should be considered complete. 173 // to display progress when the DownloadItem should be considered complete.
179 void MarkAsComplete(); 174 void MarkAsComplete();
180 175
181 // Called when all data has been saved. Only has display effects. 176 // Called when all data has been saved. Only has display effects.
182 void OnAllDataSaved(int64 size); 177 void OnAllDataSaved(int64 size);
183 178
184 // Called when the downloaded file is removed. 179 // Called when the downloaded file is removed.
185 void OnDownloadedFileRemoved(); 180 void OnDownloadedFileRemoved();
186 181
187 // Download operation had an error. 182 // Download operation had an error; call to interrupt the processing.
183 // Note that if the download attributes haven't yet been finalized and
184 // the download entered into the history (which implies that it hasn't
185 // yet been made visible in the UI), this call will remove the
186 // download from the system.
188 // |size| is the amount of data received so far, and |os_error| is the error 187 // |size| is the amount of data received so far, and |os_error| is the error
189 // code that the operation received. 188 // code that the operation received.
190 void Interrupted(int64 size, int os_error); 189 void Interrupt(int64 size, int os_error);
191 190
192 // Deletes the file from disk and removes the download from the views and 191 // Deletes the file from disk and removes the download from the views and
193 // history. |user| should be true if this is the result of the user clicking 192 // history. |user| should be true if this is the result of the user clicking
194 // the discard button, and false if it is being deleted for other reasons like 193 // the discard button, and false if it is being deleted for other reasons like
195 // browser shutdown. 194 // browser shutdown.
196 void Delete(DeleteReason reason); 195 void Delete(DeleteReason reason);
197 196
198 // Removes the download from the views and history. 197 // Removes the download from the views and history.
199 void Remove(); 198 void Remove();
200 199
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 #endif 345 #endif
347 346
348 private: 347 private:
349 // Construction common to all constructors. |active| should be true for new 348 // Construction common to all constructors. |active| should be true for new
350 // downloads and false for downloads from the history. 349 // downloads and false for downloads from the history.
351 void Init(bool active); 350 void Init(bool active);
352 351
353 // Internal helper for maintaining consistent received and total sizes. 352 // Internal helper for maintaining consistent received and total sizes.
354 void UpdateSize(int64 size); 353 void UpdateSize(int64 size);
355 354
355 // Internal function to do the main work of cancelling or
356 // interrupting a download.
357 void StopInternal(DownloadState target_state);
358
356 // Called when the entire download operation (including renaming etc) 359 // Called when the entire download operation (including renaming etc)
357 // is completed. 360 // is completed.
358 void Completed(); 361 void Completed();
359 362
360 // Start/stop sending periodic updates to our observers 363 // Start/stop sending periodic updates to our observers
361 void StartProgressTimer(); 364 void StartProgressTimer();
362 void StopProgressTimer(); 365 void StopProgressTimer();
363 366
364 // Call to install this item as a CRX. Should only be called on 367 // Call to install this item as a CRX. Should only be called on
365 // items which are CRXes. Use is_extension_install() to check. 368 // items which are CRXes. Use is_extension_install() to check.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // only. 474 // only.
472 bool open_enabled_; 475 bool open_enabled_;
473 476
474 // DownloadItem observes CRX installs it initiates. 477 // DownloadItem observes CRX installs it initiates.
475 NotificationRegistrar registrar_; 478 NotificationRegistrar registrar_;
476 479
477 DISALLOW_COPY_AND_ASSIGN(DownloadItem); 480 DISALLOW_COPY_AND_ASSIGN(DownloadItem);
478 }; 481 };
479 482
480 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 483 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/download_history.cc ('k') | chrome/browser/download/download_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698