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

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

Issue 2439533002: Download Feedback Service should upload all eligible downloads (Closed)
Patch Set: fix comments and nits 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(
97 DownloadFile* download_file) {
98 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
99 base::FilePath temp_file_path;
100 if(base::CreateTemporaryFile(&temp_file_path) &&
101 base::CopyFile(download_file->FullPath(), temp_file_path))
102 return temp_file_path;
103 else
104 return base::FilePath();
asanka 2016/11/01 21:09:23 Can this branch delete the file at |temp_file_path
Jialiu Lin 2016/11/03 20:16:50 Done.
105 }
106
96 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { 107 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) {
97 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 108 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
98 download_file->Cancel(); 109 download_file->Cancel();
99 } 110 }
100 111
101 } // namespace 112 } // namespace
102 113
103 const uint32_t DownloadItem::kInvalidId = 0; 114 const uint32_t DownloadItem::kInvalidId = 0;
104 115
105 // The maximum number of attempts we will make to resume automatically. 116 // 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())); 303 base::Bind(&ItemCheckedNetLogCallback, GetDangerType()));
293 304
294 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download 305 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download
295 // may not be in a consistent state or around at all after 306 // may not be in a consistent state or around at all after
296 // invoking observers. http://crbug.com/586610 307 // invoking observers. http://crbug.com/586610
297 308
298 MaybeCompleteDownload(); 309 MaybeCompleteDownload();
299 } 310 }
300 311
301 void DownloadItemImpl::StealDangerousDownload( 312 void DownloadItemImpl::StealDangerousDownload(
313 bool delete_file_afterward,
302 const AcquireFileCallback& callback) { 314 const AcquireFileCallback& callback) {
303 DVLOG(20) << __func__ << "() download = " << DebugString(true); 315 DVLOG(20) << __func__ << "() download = " << DebugString(true);
304 DCHECK_CURRENTLY_ON(BrowserThread::UI); 316 DCHECK_CURRENTLY_ON(BrowserThread::UI);
305 DCHECK(IsDangerous()); 317 DCHECK(IsDangerous());
asanka 2016/11/01 20:58:58 Can you also DCHECK AllDataSaved() ? It appears t
Jialiu Lin 2016/11/03 20:16:50 Done.
306 318
307 if (download_file_) { 319 if (delete_file_afterward) {
320 if (download_file_){
321 BrowserThread::PostTaskAndReplyWithResult(
322 BrowserThread::FILE,
323 FROM_HERE,
324 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
325 callback);
326 } else {
327 callback.Run(current_path_);
328 }
329 current_path_.clear();
330 Remove();
331 // We have now been deleted.
332 } else if (download_file_) {
asanka 2016/11/01 20:58:58 If there's no download_file_, then you can callbac
Jialiu Lin 2016/11/03 20:16:50 Done.
308 BrowserThread::PostTaskAndReplyWithResult( 333 BrowserThread::PostTaskAndReplyWithResult(
309 BrowserThread::FILE, 334 BrowserThread::FILE,
310 FROM_HERE, 335 FROM_HERE,
311 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), 336 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()),
312 callback); 337 callback);
313 } else {
314 callback.Run(current_path_);
315 } 338 }
316 current_path_.clear();
317 Remove();
318 // We have now been deleted.
319 } 339 }
320 340
321 void DownloadItemImpl::Pause() { 341 void DownloadItemImpl::Pause() {
322 DCHECK_CURRENTLY_ON(BrowserThread::UI); 342 DCHECK_CURRENTLY_ON(BrowserThread::UI);
323 343
324 // Ignore irrelevant states. 344 // Ignore irrelevant states.
325 if (is_paused_) 345 if (is_paused_)
326 return; 346 return;
327 347
328 switch (state_) { 348 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 1388 // downloads. SavePackage always uses its own Finish() to mark downloads
1369 // complete. 1389 // complete.
1370 void DownloadItemImpl::MaybeCompleteDownload() { 1390 void DownloadItemImpl::MaybeCompleteDownload() {
1371 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1391 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1372 DCHECK(!is_save_package_download_); 1392 DCHECK(!is_save_package_download_);
1373 1393
1374 if (!IsDownloadReadyForCompletion( 1394 if (!IsDownloadReadyForCompletion(
1375 base::Bind(&DownloadItemImpl::MaybeCompleteDownload, 1395 base::Bind(&DownloadItemImpl::MaybeCompleteDownload,
1376 weak_ptr_factory_.GetWeakPtr()))) 1396 weak_ptr_factory_.GetWeakPtr())))
1377 return; 1397 return;
1378
1379 // Confirm we're in the proper set of states to be here; have all data, have a 1398 // Confirm we're in the proper set of states to be here; have all data, have a
1380 // history handle, (validated or safe). 1399 // history handle, (validated or safe).
1381 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 1400 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
1382 DCHECK(!IsDangerous()); 1401 DCHECK(!IsDangerous());
1383 DCHECK(all_data_saved_); 1402 DCHECK(all_data_saved_);
1384 1403
1385 OnDownloadCompleting(); 1404 OnDownloadCompleting();
1386 } 1405 }
1387 1406
1388 // Called by MaybeCompleteDownload() when it has determined that the download 1407 // 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: 2112 case RESUME_MODE_USER_CONTINUE:
2094 return "USER_CONTINUE"; 2113 return "USER_CONTINUE";
2095 case RESUME_MODE_USER_RESTART: 2114 case RESUME_MODE_USER_RESTART:
2096 return "USER_RESTART"; 2115 return "USER_RESTART";
2097 } 2116 }
2098 NOTREACHED() << "Unknown resume mode " << mode; 2117 NOTREACHED() << "Unknown resume mode " << mode;
2099 return "unknown"; 2118 return "unknown";
2100 } 2119 }
2101 2120
2102 } // namespace content 2121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698