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

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 2439533002: Download Feedback Service should upload all eligible downloads (Closed)
Patch Set: make windows bots happy Created 4 years, 1 month 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) 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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // takes ownership of the DownloadFile and hence implicitly destroys it 86 // takes ownership of the DownloadFile and hence implicitly destroys it
87 // at the end of the function. 87 // at the end of the function.
88 static base::FilePath DownloadFileDetach( 88 static base::FilePath DownloadFileDetach(
89 std::unique_ptr<DownloadFile> download_file) { 89 std::unique_ptr<DownloadFile> download_file) {
90 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 90 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
91 base::FilePath full_path = download_file->FullPath(); 91 base::FilePath full_path = download_file->FullPath();
92 download_file->Detach(); 92 download_file->Detach();
93 return full_path; 93 return full_path;
94 } 94 }
95 95
96 static base::FilePath MakeCopyOfDownloadFile(DownloadFile* download_file) {
97 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
98 base::FilePath temp_file_path;
99 if (base::CreateTemporaryFile(&temp_file_path) &&
100 base::CopyFile(download_file->FullPath(), temp_file_path)) {
101 return temp_file_path;
102 } else {
103 // Deletes the file at |temp_file_path|.
104 if (!base::DirectoryExists(temp_file_path))
105 base::DeleteFile(temp_file_path, false);
106 temp_file_path.clear();
107 return base::FilePath();
108 }
109 }
110
96 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { 111 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) {
97 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 112 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
98 download_file->Cancel(); 113 download_file->Cancel();
99 } 114 }
100 115
101 } // namespace 116 } // namespace
102 117
103 const uint32_t DownloadItem::kInvalidId = 0; 118 const uint32_t DownloadItem::kInvalidId = 0;
104 119
105 // The maximum number of attempts we will make to resume automatically. 120 // The maximum number of attempts we will make to resume automatically.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); 307 base::Bind(&ItemCheckedNetLogCallback, GetDangerType()));
293 308
294 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download 309 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download
295 // may not be in a consistent state or around at all after 310 // may not be in a consistent state or around at all after
296 // invoking observers. http://crbug.com/586610 311 // invoking observers. http://crbug.com/586610
297 312
298 MaybeCompleteDownload(); 313 MaybeCompleteDownload();
299 } 314 }
300 315
301 void DownloadItemImpl::StealDangerousDownload( 316 void DownloadItemImpl::StealDangerousDownload(
317 bool delete_file_afterward,
302 const AcquireFileCallback& callback) { 318 const AcquireFileCallback& callback) {
303 DVLOG(20) << __func__ << "() download = " << DebugString(true); 319 DVLOG(20) << __func__ << "() download = " << DebugString(true);
304 DCHECK_CURRENTLY_ON(BrowserThread::UI); 320 DCHECK_CURRENTLY_ON(BrowserThread::UI);
305 DCHECK(IsDangerous()); 321 DCHECK(IsDangerous());
322 DCHECK(AllDataSaved());
306 323
307 if (download_file_) { 324 if (delete_file_afterward) {
325 if (download_file_) {
326 BrowserThread::PostTaskAndReplyWithResult(
327 BrowserThread::FILE, FROM_HERE,
328 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
329 callback);
330 } else {
331 callback.Run(current_path_);
332 }
333 current_path_.clear();
334 Remove();
335 // Download item has now been deleted.
336 } else if (download_file_) {
308 BrowserThread::PostTaskAndReplyWithResult( 337 BrowserThread::PostTaskAndReplyWithResult(
309 BrowserThread::FILE, 338 BrowserThread::FILE, FROM_HERE,
310 FROM_HERE, 339 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback);
311 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
312 callback);
313 } else { 340 } else {
314 callback.Run(current_path_); 341 callback.Run(current_path_);
315 } 342 }
316 current_path_.clear();
317 Remove();
318 // We have now been deleted.
319 } 343 }
320 344
321 void DownloadItemImpl::Pause() { 345 void DownloadItemImpl::Pause() {
322 DCHECK_CURRENTLY_ON(BrowserThread::UI); 346 DCHECK_CURRENTLY_ON(BrowserThread::UI);
323 347
324 // Ignore irrelevant states. 348 // Ignore irrelevant states.
325 if (is_paused_) 349 if (is_paused_)
326 return; 350 return;
327 351
328 switch (state_) { 352 switch (state_) {
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 // downloads. SavePackage always uses its own Finish() to mark downloads 1392 // downloads. SavePackage always uses its own Finish() to mark downloads
1369 // complete. 1393 // complete.
1370 void DownloadItemImpl::MaybeCompleteDownload() { 1394 void DownloadItemImpl::MaybeCompleteDownload() {
1371 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1395 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1372 DCHECK(!is_save_package_download_); 1396 DCHECK(!is_save_package_download_);
1373 1397
1374 if (!IsDownloadReadyForCompletion( 1398 if (!IsDownloadReadyForCompletion(
1375 base::Bind(&DownloadItemImpl::MaybeCompleteDownload, 1399 base::Bind(&DownloadItemImpl::MaybeCompleteDownload,
1376 weak_ptr_factory_.GetWeakPtr()))) 1400 weak_ptr_factory_.GetWeakPtr())))
1377 return; 1401 return;
1378
1379 // Confirm we're in the proper set of states to be here; have all data, have a 1402 // Confirm we're in the proper set of states to be here; have all data, have a
1380 // history handle, (validated or safe). 1403 // history handle, (validated or safe).
1381 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 1404 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
1382 DCHECK(!IsDangerous()); 1405 DCHECK(!IsDangerous());
1383 DCHECK(all_data_saved_); 1406 DCHECK(all_data_saved_);
1384 1407
1385 OnDownloadCompleting(); 1408 OnDownloadCompleting();
1386 } 1409 }
1387 1410
1388 // Called by MaybeCompleteDownload() when it has determined that the download 1411 // Called by MaybeCompleteDownload() when it has determined that the download
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 case RESUME_MODE_USER_CONTINUE: 2116 case RESUME_MODE_USER_CONTINUE:
2094 return "USER_CONTINUE"; 2117 return "USER_CONTINUE";
2095 case RESUME_MODE_USER_RESTART: 2118 case RESUME_MODE_USER_RESTART:
2096 return "USER_RESTART"; 2119 return "USER_RESTART";
2097 } 2120 }
2098 NOTREACHED() << "Unknown resume mode " << mode; 2121 NOTREACHED() << "Unknown resume mode " << mode;
2099 return "unknown"; 2122 return "unknown";
2100 } 2123 }
2101 2124
2102 } // namespace content 2125 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698