OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/component_updater/background_downloader_win.h" | 5 #include "chrome/browser/component_updater/background_downloader_win.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 HRESULT hr = object.CreateInstance(__uuidof(BackgroundCopyManager)); | 303 HRESULT hr = object.CreateInstance(__uuidof(BackgroundCopyManager)); |
304 if (FAILED(hr)) { | 304 if (FAILED(hr)) { |
305 VLOG(1) << "Failed to instantiate BITS." << std::hex << hr; | 305 VLOG(1) << "Failed to instantiate BITS." << std::hex << hr; |
306 // TODO: add UMA pings. | 306 // TODO: add UMA pings. |
307 return hr; | 307 return hr; |
308 } | 308 } |
309 *bits_manager = object.Detach(); | 309 *bits_manager = object.Detach(); |
310 return S_OK; | 310 return S_OK; |
311 } | 311 } |
312 | 312 |
| 313 void CleanupJobFiles(IBackgroundCopyJob* job) { |
| 314 std::vector<ScopedComPtr<IBackgroundCopyFile> > files; |
| 315 if (FAILED(GetFilesInJob(job, &files))) |
| 316 return; |
| 317 for (size_t i = 0; i != files.size(); ++i) { |
| 318 base::string16 local_name; |
| 319 HRESULT hr(GetJobFileProperties(files[i], &local_name, NULL, NULL)); |
| 320 if (SUCCEEDED(hr)) |
| 321 DeleteFileAndEmptyParentDirectory(base::FilePath(local_name)); |
| 322 } |
| 323 } |
| 324 |
313 } // namespace | 325 } // namespace |
314 | 326 |
315 BackgroundDownloader::BackgroundDownloader( | 327 BackgroundDownloader::BackgroundDownloader( |
316 scoped_ptr<CrxDownloader> successor, | 328 scoped_ptr<CrxDownloader> successor, |
317 net::URLRequestContextGetter* context_getter, | 329 net::URLRequestContextGetter* context_getter, |
318 scoped_refptr<base::SequencedTaskRunner> task_runner, | 330 scoped_refptr<base::SequencedTaskRunner> task_runner, |
319 const DownloadCallback& download_callback) | 331 const DownloadCallback& download_callback) |
320 : CrxDownloader(successor.Pass(), download_callback), | 332 : CrxDownloader(successor.Pass(), download_callback), |
321 context_getter_(context_getter), | 333 context_getter_(context_getter), |
322 task_runner_(task_runner), | 334 task_runner_(task_runner), |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 BG_FILE_PROGRESS progress = {0}; | 449 BG_FILE_PROGRESS progress = {0}; |
438 HRESULT hr = GetJobFileProperties(files[0], &local_name, NULL, &progress); | 450 HRESULT hr = GetJobFileProperties(files[0], &local_name, NULL, &progress); |
439 if (SUCCEEDED(hr)) { | 451 if (SUCCEEDED(hr)) { |
440 DCHECK(progress.Completed); | 452 DCHECK(progress.Completed); |
441 response = base::FilePath(local_name); | 453 response = base::FilePath(local_name); |
442 } else { | 454 } else { |
443 error = hr; | 455 error = hr; |
444 } | 456 } |
445 } | 457 } |
446 | 458 |
447 if (FAILED(error) && job_) | 459 if (FAILED(error) && job_) { |
448 job_->Cancel(); | 460 job_->Cancel(); |
| 461 CleanupJobFiles(job_); |
| 462 } |
449 | 463 |
450 job_ = NULL; | 464 job_ = NULL; |
451 | 465 |
452 // Consider the url handled if it has been successfully downloaded or a | 466 // Consider the url handled if it has been successfully downloaded or a |
453 // 5xx has been received. | 467 // 5xx has been received. |
454 const bool is_handled = SUCCEEDED(error) || | 468 const bool is_handled = SUCCEEDED(error) || |
455 IsHttpServerError(GetHttpStatusFromBitsError(error)); | 469 IsHttpServerError(GetHttpStatusFromBitsError(error)); |
456 | 470 |
457 Result result; | 471 Result result; |
458 result.error = error; | 472 result.error = error; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 std::vector<ScopedComPtr<IBackgroundCopyJob> > jobs; | 665 std::vector<ScopedComPtr<IBackgroundCopyJob> > jobs; |
652 HRESULT hr = FindBitsJobIf( | 666 HRESULT hr = FindBitsJobIf( |
653 std::bind2nd(JobCreationOlderThanDays(), kPurgeStaleJobsAfterDays), | 667 std::bind2nd(JobCreationOlderThanDays(), kPurgeStaleJobsAfterDays), |
654 bits_manager, | 668 bits_manager, |
655 &jobs); | 669 &jobs); |
656 if (FAILED(hr)) | 670 if (FAILED(hr)) |
657 return hr; | 671 return hr; |
658 | 672 |
659 for (size_t i = 0; i != jobs.size(); ++i) { | 673 for (size_t i = 0; i != jobs.size(); ++i) { |
660 jobs[i]->Cancel(); | 674 jobs[i]->Cancel(); |
| 675 CleanupJobFiles(jobs[i]); |
661 } | 676 } |
662 | 677 |
663 return S_OK; | 678 return S_OK; |
664 } | 679 } |
665 | 680 |
666 } // namespace component_updater | 681 } // namespace component_updater |
667 | 682 |
OLD | NEW |