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

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

Issue 3043048: Clean up download code: (Closed)
Patch Set: Created 10 years, 4 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
« no previous file with comments | « chrome/browser/download/download_exe.cc ('k') | chrome/browser/download/download_manager.h » ('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) 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 #include "chrome/browser/download/download_item.h" 5 #include "chrome/browser/download/download_item.h"
6 6
7 #include "base/file_util.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/timer.h" 9 #include "base/timer.h"
10 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/download/download_history.h" 11 #include "chrome/browser/download/download_history.h"
10 #include "chrome/browser/download/download_manager.h" 12 #include "chrome/browser/download/download_manager.h"
11 #include "chrome/browser/download/download_util.h" 13 #include "chrome/browser/download/download_util.h"
12 #include "chrome/browser/history/download_types.h" 14 #include "chrome/browser/history/download_types.h"
13 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
14 16
15 namespace { 17 namespace {
16 18
17 // Update frequency (milliseconds). 19 // Update frequency (milliseconds).
18 const int kUpdateTimeMs = 1000; 20 const int kUpdateTimeMs = 1000;
19 21
22 void DeleteDownloadedFile(const FilePath& path) {
23 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
24
25 // Make sure we only delete files.
26 if (!file_util::DirectoryExists(path))
27 file_util::Delete(path, false);
28 }
29
20 } // namespace 30 } // namespace
21 31
22 // Constructor for reading from the history service. 32 // Constructor for reading from the history service.
23 DownloadItem::DownloadItem(DownloadManager* download_manager, 33 DownloadItem::DownloadItem(DownloadManager* download_manager,
24 const DownloadCreateInfo& info) 34 const DownloadCreateInfo& info)
25 : id_(-1), 35 : id_(-1),
26 full_path_(info.path), 36 full_path_(info.path),
27 url_(info.url), 37 url_(info.url),
28 referrer_url_(info.referrer_url), 38 referrer_url_(info.referrer_url),
29 mime_type_(info.mime_type), 39 mime_type_(info.mime_type),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 232
223 void DownloadItem::Finished(int64 size) { 233 void DownloadItem::Finished(int64 size) {
224 state_ = COMPLETE; 234 state_ = COMPLETE;
225 UpdateSize(size); 235 UpdateSize(size);
226 StopProgressTimer(); 236 StopProgressTimer();
227 } 237 }
228 238
229 void DownloadItem::Remove(bool delete_on_disk) { 239 void DownloadItem::Remove(bool delete_on_disk) {
230 Cancel(true); 240 Cancel(true);
231 state_ = REMOVING; 241 state_ = REMOVING;
232 if (delete_on_disk) 242 if (delete_on_disk) {
233 download_manager_->DeleteDownload(full_path_); 243 ChromeThread::PostTask(
244 ChromeThread::FILE, FROM_HERE,
245 NewRunnableFunction(&DeleteDownloadedFile, full_path_));
246 }
234 download_manager_->RemoveDownload(db_handle_); 247 download_manager_->RemoveDownload(db_handle_);
235 // We have now been deleted. 248 // We have now been deleted.
236 } 249 }
237 250
238 bool DownloadItem::TimeRemaining(base::TimeDelta* remaining) const { 251 bool DownloadItem::TimeRemaining(base::TimeDelta* remaining) const {
239 if (total_bytes_ <= 0) 252 if (total_bytes_ <= 0)
240 return false; // We never received the content_length for this download. 253 return false; // We never received the content_length for this download.
241 254
242 int64 speed = CurrentSpeed(); 255 int64 speed = CurrentSpeed();
243 if (speed == 0) 256 if (speed == 0)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return name; 307 return name;
295 } 308 }
296 return original_name_; 309 return original_name_;
297 } 310 }
298 311
299 void DownloadItem::Init(bool start_timer) { 312 void DownloadItem::Init(bool start_timer) {
300 file_name_ = full_path_.BaseName(); 313 file_name_ = full_path_.BaseName();
301 if (start_timer) 314 if (start_timer)
302 StartProgressTimer(); 315 StartProgressTimer();
303 } 316 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_exe.cc ('k') | chrome/browser/download/download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698