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

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 try 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(
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 }
asanka 2016/11/07 16:01:55 } else { clang-format should've fixed this for yo
Jialiu Lin 2016/11/14 20:57:39 Done.
104 else {
105 // Deletes the file at |temp_file_path| if it exists.
106 if (base::PathExists(temp_file_path)) {
asanka 2016/11/07 16:01:55 DeleteFile is a no-op if the file doesn't exist an
Jialiu Lin 2016/11/14 20:57:39 Done.
107 DeleteFile(temp_file_path, false);
108 }
109 temp_file_path.clear();
110 return base::FilePath();
111 }
112 }
113
96 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { 114 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) {
97 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 115 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
98 download_file->Cancel(); 116 download_file->Cancel();
99 } 117 }
100 118
101 } // namespace 119 } // namespace
102 120
103 const uint32_t DownloadItem::kInvalidId = 0; 121 const uint32_t DownloadItem::kInvalidId = 0;
104 122
105 // The maximum number of attempts we will make to resume automatically. 123 // 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())); 310 base::Bind(&ItemCheckedNetLogCallback, GetDangerType()));
293 311
294 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download 312 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download
295 // may not be in a consistent state or around at all after 313 // may not be in a consistent state or around at all after
296 // invoking observers. http://crbug.com/586610 314 // invoking observers. http://crbug.com/586610
297 315
298 MaybeCompleteDownload(); 316 MaybeCompleteDownload();
299 } 317 }
300 318
301 void DownloadItemImpl::StealDangerousDownload( 319 void DownloadItemImpl::StealDangerousDownload(
320 bool delete_file_afterward,
302 const AcquireFileCallback& callback) { 321 const AcquireFileCallback& callback) {
303 DVLOG(20) << __func__ << "() download = " << DebugString(true); 322 DVLOG(20) << __func__ << "() download = " << DebugString(true);
304 DCHECK_CURRENTLY_ON(BrowserThread::UI); 323 DCHECK_CURRENTLY_ON(BrowserThread::UI);
305 DCHECK(IsDangerous()); 324 DCHECK(IsDangerous());
325 DCHECK(AllDataSaved());
306 326
307 if (download_file_) { 327 if (delete_file_afterward) {
328 if (download_file_){
329 BrowserThread::PostTaskAndReplyWithResult(
330 BrowserThread::FILE,
331 FROM_HERE,
332 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
333 callback);
334 } else {
335 callback.Run(current_path_);
336 }
337 current_path_.clear();
338 Remove();
339 // Download item has now been deleted.
340 } else if (download_file_) {
308 BrowserThread::PostTaskAndReplyWithResult( 341 BrowserThread::PostTaskAndReplyWithResult(
309 BrowserThread::FILE, 342 BrowserThread::FILE,
310 FROM_HERE, 343 FROM_HERE,
311 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), 344 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()),
312 callback); 345 callback);
313 } else { 346 } else {
314 callback.Run(current_path_); 347 callback.Run(current_path_);
315 } 348 }
316 current_path_.clear();
317 Remove();
318 // We have now been deleted.
319 } 349 }
320 350
321 void DownloadItemImpl::Pause() { 351 void DownloadItemImpl::Pause() {
322 DCHECK_CURRENTLY_ON(BrowserThread::UI); 352 DCHECK_CURRENTLY_ON(BrowserThread::UI);
323 353
324 // Ignore irrelevant states. 354 // Ignore irrelevant states.
325 if (is_paused_) 355 if (is_paused_)
326 return; 356 return;
327 357
328 switch (state_) { 358 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 1398 // downloads. SavePackage always uses its own Finish() to mark downloads
1369 // complete. 1399 // complete.
1370 void DownloadItemImpl::MaybeCompleteDownload() { 1400 void DownloadItemImpl::MaybeCompleteDownload() {
1371 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1401 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1372 DCHECK(!is_save_package_download_); 1402 DCHECK(!is_save_package_download_);
1373 1403
1374 if (!IsDownloadReadyForCompletion( 1404 if (!IsDownloadReadyForCompletion(
1375 base::Bind(&DownloadItemImpl::MaybeCompleteDownload, 1405 base::Bind(&DownloadItemImpl::MaybeCompleteDownload,
1376 weak_ptr_factory_.GetWeakPtr()))) 1406 weak_ptr_factory_.GetWeakPtr())))
1377 return; 1407 return;
1378
1379 // Confirm we're in the proper set of states to be here; have all data, have a 1408 // Confirm we're in the proper set of states to be here; have all data, have a
1380 // history handle, (validated or safe). 1409 // history handle, (validated or safe).
1381 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 1410 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
1382 DCHECK(!IsDangerous()); 1411 DCHECK(!IsDangerous());
1383 DCHECK(all_data_saved_); 1412 DCHECK(all_data_saved_);
1384 1413
1385 OnDownloadCompleting(); 1414 OnDownloadCompleting();
1386 } 1415 }
1387 1416
1388 // Called by MaybeCompleteDownload() when it has determined that the download 1417 // 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: 2122 case RESUME_MODE_USER_CONTINUE:
2094 return "USER_CONTINUE"; 2123 return "USER_CONTINUE";
2095 case RESUME_MODE_USER_RESTART: 2124 case RESUME_MODE_USER_RESTART:
2096 return "USER_RESTART"; 2125 return "USER_RESTART";
2097 } 2126 }
2098 NOTREACHED() << "Unknown resume mode " << mode; 2127 NOTREACHED() << "Unknown resume mode " << mode;
2099 return "unknown"; 2128 return "unknown";
2100 } 2129 }
2101 2130
2102 } // namespace content 2131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698