| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_file.h" | 5 #include "chrome/browser/download/download_file.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (manager) | 422 if (manager) |
| 423 manager->DownloadFinished(id, bytes_so_far); | 423 manager->DownloadFinished(id, bytes_so_far); |
| 424 RemoveDownload(id, manager); | 424 RemoveDownload(id, manager); |
| 425 RemoveDownloadFromUIProgress(id); | 425 RemoveDownloadFromUIProgress(id); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void DownloadFileManager::DownloadUrl( | 428 void DownloadFileManager::DownloadUrl( |
| 429 const GURL& url, | 429 const GURL& url, |
| 430 const GURL& referrer, | 430 const GURL& referrer, |
| 431 const std::string& referrer_charset, | 431 const std::string& referrer_charset, |
| 432 const FilePath& save_file_path, |
| 432 int render_process_host_id, | 433 int render_process_host_id, |
| 433 int render_view_id, | 434 int render_view_id, |
| 434 URLRequestContextGetter* request_context_getter) { | 435 URLRequestContextGetter* request_context_getter) { |
| 435 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 436 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 436 ChromeThread::PostTask( | 437 ChromeThread::PostTask( |
| 437 ChromeThread::IO, FROM_HERE, | 438 ChromeThread::IO, FROM_HERE, |
| 438 NewRunnableMethod(this, | 439 NewRunnableMethod(this, |
| 439 &DownloadFileManager::OnDownloadUrl, | 440 &DownloadFileManager::OnDownloadUrl, |
| 440 url, | 441 url, |
| 441 referrer, | 442 referrer, |
| 442 referrer_charset, | 443 referrer_charset, |
| 444 save_file_path, |
| 443 render_process_host_id, | 445 render_process_host_id, |
| 444 render_view_id, | 446 render_view_id, |
| 445 request_context_getter)); | 447 request_context_getter)); |
| 446 } | 448 } |
| 447 | 449 |
| 448 // Relate a download ID to its owning DownloadManager. | 450 // Relate a download ID to its owning DownloadManager. |
| 449 DownloadManager* DownloadFileManager::LookupManager(int download_id) { | 451 DownloadManager* DownloadFileManager::LookupManager(int download_id) { |
| 450 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 452 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 451 DownloadManagerMap::iterator it = managers_.find(download_id); | 453 DownloadManagerMap::iterator it = managers_.find(download_id); |
| 452 if (it != managers_.end()) | 454 if (it != managers_.end()) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 519 } |
| 518 | 520 |
| 519 | 521 |
| 520 // Notifications from the UI thread and run on the IO thread | 522 // Notifications from the UI thread and run on the IO thread |
| 521 | 523 |
| 522 // Initiate a request for URL to be downloaded. | 524 // Initiate a request for URL to be downloaded. |
| 523 void DownloadFileManager::OnDownloadUrl( | 525 void DownloadFileManager::OnDownloadUrl( |
| 524 const GURL& url, | 526 const GURL& url, |
| 525 const GURL& referrer, | 527 const GURL& referrer, |
| 526 const std::string& referrer_charset, | 528 const std::string& referrer_charset, |
| 529 const FilePath& save_file_path, |
| 527 int render_process_host_id, | 530 int render_process_host_id, |
| 528 int render_view_id, | 531 int render_view_id, |
| 529 URLRequestContextGetter* request_context_getter) { | 532 URLRequestContextGetter* request_context_getter) { |
| 530 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 533 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 531 | 534 |
| 532 URLRequestContext* context = request_context_getter->GetURLRequestContext(); | 535 URLRequestContext* context = request_context_getter->GetURLRequestContext(); |
| 533 context->set_referrer_charset(referrer_charset); | 536 context->set_referrer_charset(referrer_charset); |
| 534 | 537 |
| 535 resource_dispatcher_host_->BeginDownload(url, | 538 resource_dispatcher_host_->BeginDownload(url, |
| 536 referrer, | 539 referrer, |
| 540 save_file_path, |
| 537 render_process_host_id, | 541 render_process_host_id, |
| 538 render_view_id, | 542 render_view_id, |
| 539 context); | 543 context); |
| 540 } | 544 } |
| 541 | 545 |
| 542 // Actions from the UI thread and run on the download thread | 546 // Actions from the UI thread and run on the download thread |
| 543 | 547 |
| 544 // Open a download, or show it in a file explorer window. We run on this | 548 // Open a download, or show it in a file explorer window. We run on this |
| 545 // thread to avoid blocking the UI with (potentially) slow Shell operations. | 549 // thread to avoid blocking the UI with (potentially) slow Shell operations. |
| 546 // TODO(paulg): File 'stat' operations. | 550 // TODO(paulg): File 'stat' operations. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 NewRunnableMethod(this, &DownloadFileManager::StopUpdateTimer)); | 631 NewRunnableMethod(this, &DownloadFileManager::StopUpdateTimer)); |
| 628 } | 632 } |
| 629 } | 633 } |
| 630 | 634 |
| 631 // static | 635 // static |
| 632 void DownloadFileManager::DeleteFile(const FilePath& path) { | 636 void DownloadFileManager::DeleteFile(const FilePath& path) { |
| 633 // Make sure we only delete files. | 637 // Make sure we only delete files. |
| 634 if (!file_util::DirectoryExists(path)) | 638 if (!file_util::DirectoryExists(path)) |
| 635 file_util::Delete(path, false); | 639 file_util::Delete(path, false); |
| 636 } | 640 } |
| OLD | NEW |