| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "base/thread.h" | 17 #include "base/thread.h" |
| 18 #include "base/timer.h" | 18 #include "base/timer.h" |
| 19 #include "chrome/browser/browser_list.h" | 19 #include "chrome/browser/browser_list.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_thread.h" |
| 21 #include "chrome/browser/download/download_file.h" | 22 #include "chrome/browser/download/download_file.h" |
| 22 #include "chrome/browser/download/download_util.h" | 23 #include "chrome/browser/download/download_util.h" |
| 23 #include "chrome/browser/extensions/crx_installer.h" | 24 #include "chrome/browser/extensions/crx_installer.h" |
| 24 #include "chrome/browser/extensions/extension_install_ui.h" | 25 #include "chrome/browser/extensions/extension_install_ui.h" |
| 25 #include "chrome/browser/extensions/extensions_service.h" | 26 #include "chrome/browser/extensions/extensions_service.h" |
| 26 #include "chrome/browser/net/chrome_url_request_context.h" | 27 #include "chrome/browser/net/chrome_url_request_context.h" |
| 27 #include "chrome/browser/profile.h" | 28 #include "chrome/browser/profile.h" |
| 28 #include "chrome/browser/renderer_host/render_process_host.h" | 29 #include "chrome/browser/renderer_host/render_process_host.h" |
| 29 #include "chrome/browser/renderer_host/render_view_host.h" | 30 #include "chrome/browser/renderer_host/render_view_host.h" |
| 30 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 31 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 prefs->SetString(prefs::kDownloadDefaultDirectory, | 341 prefs->SetString(prefs::kDownloadDefaultDirectory, |
| 341 default_download_path.ToWStringHack()); | 342 default_download_path.ToWStringHack()); |
| 342 } | 343 } |
| 343 prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); | 344 prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); |
| 344 } | 345 } |
| 345 } | 346 } |
| 346 | 347 |
| 347 DownloadManager::DownloadManager() | 348 DownloadManager::DownloadManager() |
| 348 : shutdown_needed_(false), | 349 : shutdown_needed_(false), |
| 349 profile_(NULL), | 350 profile_(NULL), |
| 350 file_manager_(NULL), | 351 file_manager_(NULL) { |
| 351 ui_loop_(MessageLoop::current()), | |
| 352 file_loop_(NULL) { | |
| 353 } | 352 } |
| 354 | 353 |
| 355 DownloadManager::~DownloadManager() { | 354 DownloadManager::~DownloadManager() { |
| 356 if (shutdown_needed_) | 355 if (shutdown_needed_) |
| 357 Shutdown(); | 356 Shutdown(); |
| 358 } | 357 } |
| 359 | 358 |
| 360 void DownloadManager::Shutdown() { | 359 void DownloadManager::Shutdown() { |
| 361 DCHECK(shutdown_needed_) << "Shutdown called when not needed."; | 360 DCHECK(shutdown_needed_) << "Shutdown called when not needed."; |
| 362 | 361 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 NOTREACHED(); | 486 NOTREACHED(); |
| 488 return false; | 487 return false; |
| 489 } | 488 } |
| 490 | 489 |
| 491 file_manager_ = rdh->download_file_manager(); | 490 file_manager_ = rdh->download_file_manager(); |
| 492 if (!file_manager_) { | 491 if (!file_manager_) { |
| 493 NOTREACHED(); | 492 NOTREACHED(); |
| 494 return false; | 493 return false; |
| 495 } | 494 } |
| 496 | 495 |
| 497 file_loop_ = g_browser_process->file_thread()->message_loop(); | |
| 498 if (!file_loop_) { | |
| 499 NOTREACHED(); | |
| 500 return false; | |
| 501 } | |
| 502 | |
| 503 // Get our user preference state. | 496 // Get our user preference state. |
| 504 PrefService* prefs = profile_->GetPrefs(); | 497 PrefService* prefs = profile_->GetPrefs(); |
| 505 DCHECK(prefs); | 498 DCHECK(prefs); |
| 506 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); | 499 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); |
| 507 | 500 |
| 508 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); | 501 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); |
| 509 | 502 |
| 510 // This variable is needed to resolve which CreateDirectory we want to point | 503 // This variable is needed to resolve which CreateDirectory we want to point |
| 511 // to. Without it, the NewRunnableFunction cannot resolve the ambiguity. | 504 // to. Without it, the NewRunnableFunction cannot resolve the ambiguity. |
| 512 // TODO(estade): when file_util::CreateDirectory(wstring) is removed, | 505 // TODO(estade): when file_util::CreateDirectory(wstring) is removed, |
| 513 // get rid of |CreateDirectoryPtr|. | 506 // get rid of |CreateDirectoryPtr|. |
| 514 bool (*CreateDirectoryPtr)(const FilePath&) = &file_util::CreateDirectory; | 507 bool (*CreateDirectoryPtr)(const FilePath&) = &file_util::CreateDirectory; |
| 515 // Ensure that the download directory specified in the preferences exists. | 508 // Ensure that the download directory specified in the preferences exists. |
| 516 file_loop_->PostTask(FROM_HERE, NewRunnableFunction( | 509 ChromeThread::PostTask( |
| 517 CreateDirectoryPtr, download_path())); | 510 ChromeThread::FILE, FROM_HERE, |
| 511 NewRunnableFunction(CreateDirectoryPtr, download_path())); |
| 518 | 512 |
| 519 // We use this to determine possibly dangerous downloads. | 513 // We use this to determine possibly dangerous downloads. |
| 520 download_util::InitializeExeTypes(&exe_types_); | 514 download_util::InitializeExeTypes(&exe_types_); |
| 521 | 515 |
| 522 // We store any file extension that should be opened automatically at | 516 // We store any file extension that should be opened automatically at |
| 523 // download completion in this pref. | 517 // download completion in this pref. |
| 524 std::wstring extensions_to_open = | 518 std::wstring extensions_to_open = |
| 525 prefs->GetString(prefs::kDownloadExtensionsToOpen); | 519 prefs->GetString(prefs::kDownloadExtensionsToOpen); |
| 526 std::vector<std::wstring> extensions; | 520 std::vector<std::wstring> extensions; |
| 527 SplitString(extensions_to_open, L':', &extensions); | 521 SplitString(extensions_to_open, L':', &extensions); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 544 } | 538 } |
| 545 | 539 |
| 546 // We have received a message from DownloadFileManager about a new download. We | 540 // We have received a message from DownloadFileManager about a new download. We |
| 547 // create a download item and store it in our download map, and inform the | 541 // create a download item and store it in our download map, and inform the |
| 548 // history system of a new download. Since this method can be called while the | 542 // history system of a new download. Since this method can be called while the |
| 549 // history service thread is still reading the persistent state, we do not | 543 // history service thread is still reading the persistent state, we do not |
| 550 // insert the new DownloadItem into 'downloads_' or inform our observers at this | 544 // insert the new DownloadItem into 'downloads_' or inform our observers at this |
| 551 // point. OnCreateDatabaseEntryComplete() handles that finalization of the the | 545 // point. OnCreateDatabaseEntryComplete() handles that finalization of the the |
| 552 // download creation as a callback from the history thread. | 546 // download creation as a callback from the history thread. |
| 553 void DownloadManager::StartDownload(DownloadCreateInfo* info) { | 547 void DownloadManager::StartDownload(DownloadCreateInfo* info) { |
| 554 DCHECK(MessageLoop::current() == ui_loop_); | 548 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 555 DCHECK(info); | 549 DCHECK(info); |
| 556 | 550 |
| 557 // Freeze the user's preference for showing a Save As dialog. We're going to | 551 // Freeze the user's preference for showing a Save As dialog. We're going to |
| 558 // bounce around a bunch of threads and we don't want to worry about race | 552 // bounce around a bunch of threads and we don't want to worry about race |
| 559 // conditions where the user changes this pref out from under us. | 553 // conditions where the user changes this pref out from under us. |
| 560 if (*prompt_for_download_) { | 554 if (*prompt_for_download_) { |
| 561 // But never obey the preference for extension installation. Note that we | 555 // But never obey the preference for extension installation. Note that we |
| 562 // only care here about the case where an extension is installed, not when | 556 // only care here about the case where an extension is installed, not when |
| 563 // one is downloaded with "save as...". | 557 // one is downloaded with "save as...". |
| 564 if (!IsExtensionInstall(info)) | 558 if (!IsExtensionInstall(info)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 583 info->is_dangerous = true; | 577 info->is_dangerous = true; |
| 584 else if (IsExtensionInstall(info) && | 578 else if (IsExtensionInstall(info) && |
| 585 !ExtensionsService::IsDownloadFromGallery(info->url, | 579 !ExtensionsService::IsDownloadFromGallery(info->url, |
| 586 info->referrer_url)) { | 580 info->referrer_url)) { |
| 587 info->is_dangerous = true; | 581 info->is_dangerous = true; |
| 588 } | 582 } |
| 589 } | 583 } |
| 590 | 584 |
| 591 // We need to move over to the download thread because we don't want to stat | 585 // We need to move over to the download thread because we don't want to stat |
| 592 // the suggested path on the UI thread. | 586 // the suggested path on the UI thread. |
| 593 file_loop_->PostTask(FROM_HERE, | 587 ChromeThread::PostTask( |
| 594 NewRunnableMethod(this, | 588 ChromeThread::FILE, FROM_HERE, |
| 595 &DownloadManager::CheckIfSuggestedPathExists, | 589 NewRunnableMethod( |
| 596 info)); | 590 this, &DownloadManager::CheckIfSuggestedPathExists, info)); |
| 597 } | 591 } |
| 598 | 592 |
| 599 void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) { | 593 void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) { |
| 600 DCHECK(info); | 594 DCHECK(info); |
| 601 | 595 |
| 602 // Check writability of the suggested path. If we can't write to it, default | 596 // Check writability of the suggested path. If we can't write to it, default |
| 603 // to the user's "My Documents" directory. We'll prompt them in this case. | 597 // to the user's "My Documents" directory. We'll prompt them in this case. |
| 604 FilePath dir = info->suggested_path.DirName(); | 598 FilePath dir = info->suggested_path.DirName(); |
| 605 FilePath filename = info->suggested_path.BaseName(); | 599 FilePath filename = info->suggested_path.BaseName(); |
| 606 if (!file_util::PathIsWritable(dir)) { | 600 if (!file_util::PathIsWritable(dir)) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 } | 634 } |
| 641 | 635 |
| 642 if (!info->save_as) { | 636 if (!info->save_as) { |
| 643 // Create an empty file at the suggested path so that we don't allocate the | 637 // Create an empty file at the suggested path so that we don't allocate the |
| 644 // same "non-existant" path to multiple downloads. | 638 // same "non-existant" path to multiple downloads. |
| 645 // See: http://code.google.com/p/chromium/issues/detail?id=3662 | 639 // See: http://code.google.com/p/chromium/issues/detail?id=3662 |
| 646 file_util::WriteFile(info->suggested_path, "", 0); | 640 file_util::WriteFile(info->suggested_path, "", 0); |
| 647 } | 641 } |
| 648 | 642 |
| 649 // Now we return to the UI thread. | 643 // Now we return to the UI thread. |
| 650 ui_loop_->PostTask(FROM_HERE, | 644 ChromeThread::PostTask( |
| 645 ChromeThread::UI, FROM_HERE, |
| 651 NewRunnableMethod(this, | 646 NewRunnableMethod(this, |
| 652 &DownloadManager::OnPathExistenceAvailable, | 647 &DownloadManager::OnPathExistenceAvailable, |
| 653 info)); | 648 info)); |
| 654 } | 649 } |
| 655 | 650 |
| 656 void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { | 651 void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { |
| 657 DCHECK(MessageLoop::current() == ui_loop_); | 652 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 658 DCHECK(info); | 653 DCHECK(info); |
| 659 | 654 |
| 660 if (info->save_as) { | 655 if (info->save_as) { |
| 661 // We must ask the user for the place to put the download. | 656 // We must ask the user for the place to put the download. |
| 662 if (!select_file_dialog_.get()) | 657 if (!select_file_dialog_.get()) |
| 663 select_file_dialog_ = SelectFileDialog::Create(this); | 658 select_file_dialog_ = SelectFileDialog::Create(this); |
| 664 | 659 |
| 665 TabContents* contents = tab_util::GetTabContentsByID(info->child_id, | 660 TabContents* contents = tab_util::GetTabContentsByID(info->child_id, |
| 666 info->render_view_id); | 661 info->render_view_id); |
| 667 SelectFileDialog::FileTypeInfo file_type_info; | 662 SelectFileDialog::FileTypeInfo file_type_info; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 info->save_as); | 701 info->save_as); |
| 707 download->set_manager(this); | 702 download->set_manager(this); |
| 708 in_progress_[info->download_id] = download; | 703 in_progress_[info->download_id] = download; |
| 709 } else { | 704 } else { |
| 710 NOTREACHED(); // Should not exist! | 705 NOTREACHED(); // Should not exist! |
| 711 return; | 706 return; |
| 712 } | 707 } |
| 713 | 708 |
| 714 // Called before DownloadFinished in order to avoid a race condition where we | 709 // Called before DownloadFinished in order to avoid a race condition where we |
| 715 // attempt to open a completed download before it has been renamed. | 710 // attempt to open a completed download before it has been renamed. |
| 716 file_loop_->PostTask(FROM_HERE, | 711 ChromeThread::PostTask( |
| 717 NewRunnableMethod(file_manager_, | 712 ChromeThread::FILE, FROM_HERE, |
| 718 &DownloadFileManager::OnFinalDownloadName, | 713 NewRunnableMethod( |
| 719 download->id(), | 714 file_manager_, &DownloadFileManager::OnFinalDownloadName, |
| 720 target_path, | 715 download->id(), target_path, this)); |
| 721 this)); | |
| 722 | 716 |
| 723 // If the download already completed by the time we reached this point, then | 717 // If the download already completed by the time we reached this point, then |
| 724 // notify observers that it did. | 718 // notify observers that it did. |
| 725 PendingFinishedMap::iterator pending_it = | 719 PendingFinishedMap::iterator pending_it = |
| 726 pending_finished_downloads_.find(info->download_id); | 720 pending_finished_downloads_.find(info->download_id); |
| 727 if (pending_it != pending_finished_downloads_.end()) | 721 if (pending_it != pending_finished_downloads_.end()) |
| 728 DownloadFinished(pending_it->first, pending_it->second); | 722 DownloadFinished(pending_it->first, pending_it->second); |
| 729 | 723 |
| 730 download->Rename(target_path); | 724 download->Rename(target_path); |
| 731 | 725 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 // anything. When the user notifies us, it will trigger a call to | 823 // anything. When the user notifies us, it will trigger a call to |
| 830 // ProceedWithFinishedDangerousDownload. | 824 // ProceedWithFinishedDangerousDownload. |
| 831 if (download->safety_state() == DownloadItem::DANGEROUS) { | 825 if (download->safety_state() == DownloadItem::DANGEROUS) { |
| 832 dangerous_finished_[download_id] = download; | 826 dangerous_finished_[download_id] = download; |
| 833 return; | 827 return; |
| 834 } | 828 } |
| 835 | 829 |
| 836 if (download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) { | 830 if (download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) { |
| 837 // We first need to rename the downloaded file from its temporary name to | 831 // We first need to rename the downloaded file from its temporary name to |
| 838 // its final name before we can continue. | 832 // its final name before we can continue. |
| 839 file_loop_->PostTask(FROM_HERE, | 833 ChromeThread::PostTask( |
| 834 ChromeThread::FILE, FROM_HERE, |
| 840 NewRunnableMethod( | 835 NewRunnableMethod( |
| 841 this, &DownloadManager::ProceedWithFinishedDangerousDownload, | 836 this, &DownloadManager::ProceedWithFinishedDangerousDownload, |
| 842 download->db_handle(), | 837 download->db_handle(), |
| 843 download->full_path(), download->original_name())); | 838 download->full_path(), download->original_name())); |
| 844 return; | 839 return; |
| 845 } | 840 } |
| 846 ContinueDownloadFinished(download); | 841 ContinueDownloadFinished(download); |
| 847 } | 842 } |
| 848 | 843 |
| 849 void DownloadManager::DownloadRenamedToFinalName(int download_id, | 844 void DownloadManager::DownloadRenamedToFinalName(int download_id, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 // start, and at that time the first file does not exists yet, so the second | 884 // start, and at that time the first file does not exists yet, so the second |
| 890 // file gets the same name. | 885 // file gets the same name. |
| 891 uniquifier = GetUniquePathNumber(new_path); | 886 uniquifier = GetUniquePathNumber(new_path); |
| 892 if (uniquifier > 0) | 887 if (uniquifier > 0) |
| 893 AppendNumberToPath(&new_path, uniquifier); | 888 AppendNumberToPath(&new_path, uniquifier); |
| 894 success = file_util::Move(path, new_path); | 889 success = file_util::Move(path, new_path); |
| 895 } else { | 890 } else { |
| 896 NOTREACHED(); | 891 NOTREACHED(); |
| 897 } | 892 } |
| 898 | 893 |
| 899 ui_loop_->PostTask(FROM_HERE, | 894 ChromeThread::PostTask( |
| 895 ChromeThread::UI, FROM_HERE, |
| 900 NewRunnableMethod(this, &DownloadManager::DangerousDownloadRenamed, | 896 NewRunnableMethod(this, &DownloadManager::DangerousDownloadRenamed, |
| 901 download_handle, success, new_path, uniquifier)); | 897 download_handle, success, new_path, uniquifier)); |
| 902 } | 898 } |
| 903 | 899 |
| 904 // Call from the file thread when the finished dangerous download was renamed. | 900 // Call from the file thread when the finished dangerous download was renamed. |
| 905 void DownloadManager::DangerousDownloadRenamed(int64 download_handle, | 901 void DownloadManager::DangerousDownloadRenamed(int64 download_handle, |
| 906 bool success, | 902 bool success, |
| 907 const FilePath& new_path, | 903 const FilePath& new_path, |
| 908 int new_path_uniquifier) { | 904 int new_path_uniquifier) { |
| 909 DownloadMap::iterator it = downloads_.find(download_handle); | 905 DownloadMap::iterator it = downloads_.find(download_handle); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 // Cancel the network request. RDH is guaranteed to outlive the IO thread. | 953 // Cancel the network request. RDH is guaranteed to outlive the IO thread. |
| 958 ChromeThread::PostTask( | 954 ChromeThread::PostTask( |
| 959 ChromeThread::IO, FROM_HERE, | 955 ChromeThread::IO, FROM_HERE, |
| 960 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, | 956 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, |
| 961 g_browser_process->resource_dispatcher_host(), | 957 g_browser_process->resource_dispatcher_host(), |
| 962 render_process_id, | 958 render_process_id, |
| 963 request_id)); | 959 request_id)); |
| 964 | 960 |
| 965 // Tell the file manager to cancel the download. | 961 // Tell the file manager to cancel the download. |
| 966 file_manager_->RemoveDownload(download_id, this); // On the UI thread | 962 file_manager_->RemoveDownload(download_id, this); // On the UI thread |
| 967 file_loop_->PostTask(FROM_HERE, | 963 ChromeThread::PostTask( |
| 968 NewRunnableMethod(file_manager_, | 964 ChromeThread::FILE, FROM_HERE, |
| 969 &DownloadFileManager::CancelDownload, | 965 NewRunnableMethod( |
| 970 download_id)); | 966 file_manager_, &DownloadFileManager::CancelDownload, download_id)); |
| 971 } | 967 } |
| 972 | 968 |
| 973 void DownloadManager::PauseDownload(int32 download_id, bool pause) { | 969 void DownloadManager::PauseDownload(int32 download_id, bool pause) { |
| 974 DownloadMap::iterator it = in_progress_.find(download_id); | 970 DownloadMap::iterator it = in_progress_.find(download_id); |
| 975 if (it == in_progress_.end()) | 971 if (it == in_progress_.end()) |
| 976 return; | 972 return; |
| 977 | 973 |
| 978 DownloadItem* download = it->second; | 974 DownloadItem* download = it->second; |
| 979 if (pause == download->is_paused()) | 975 if (pause == download->is_paused()) |
| 980 return; | 976 return; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 } | 1201 } |
| 1206 | 1202 |
| 1207 void DownloadManager::RemoveObserver(Observer* observer) { | 1203 void DownloadManager::RemoveObserver(Observer* observer) { |
| 1208 observers_.RemoveObserver(observer); | 1204 observers_.RemoveObserver(observer); |
| 1209 } | 1205 } |
| 1210 | 1206 |
| 1211 // Post Windows Shell operations to the Download thread, to avoid blocking the | 1207 // Post Windows Shell operations to the Download thread, to avoid blocking the |
| 1212 // user interface. | 1208 // user interface. |
| 1213 void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { | 1209 void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { |
| 1214 DCHECK(file_manager_); | 1210 DCHECK(file_manager_); |
| 1215 DCHECK(MessageLoop::current() == ui_loop_); | 1211 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 1216 #if defined(OS_MACOSX) | 1212 #if defined(OS_MACOSX) |
| 1217 // Mac needs to run this operation on the UI thread. | 1213 // Mac needs to run this operation on the UI thread. |
| 1218 platform_util::ShowItemInFolder(download->full_path()); | 1214 platform_util::ShowItemInFolder(download->full_path()); |
| 1219 #else | 1215 #else |
| 1220 file_loop_->PostTask(FROM_HERE, | 1216 ChromeThread::PostTask( |
| 1221 NewRunnableMethod(file_manager_, | 1217 ChromeThread::FILE, FROM_HERE, |
| 1222 &DownloadFileManager::OnShowDownloadInShell, | 1218 NewRunnableMethod( |
| 1223 FilePath(download->full_path()))); | 1219 file_manager_, &DownloadFileManager::OnShowDownloadInShell, |
| 1220 FilePath(download->full_path()))); |
| 1224 #endif | 1221 #endif |
| 1225 } | 1222 } |
| 1226 | 1223 |
| 1227 void DownloadManager::OpenDownload(const DownloadItem* download, | 1224 void DownloadManager::OpenDownload(const DownloadItem* download, |
| 1228 gfx::NativeView parent_window) { | 1225 gfx::NativeView parent_window) { |
| 1229 // Open Chrome extensions with ExtensionsService. For everything else do shell | 1226 // Open Chrome extensions with ExtensionsService. For everything else do shell |
| 1230 // execute. | 1227 // execute. |
| 1231 if (IsExtensionInstall(download)) { | 1228 if (IsExtensionInstall(download)) { |
| 1232 OpenChromeExtension(download->full_path(), download->url(), | 1229 OpenChromeExtension(download->full_path(), download->url(), |
| 1233 download->referrer_url()); | 1230 download->referrer_url()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1253 true, // please delete crx on completion | 1250 true, // please delete crx on completion |
| 1254 true, // privilege increase allowed | 1251 true, // privilege increase allowed |
| 1255 service, | 1252 service, |
| 1256 new ExtensionInstallUI(profile_)); | 1253 new ExtensionInstallUI(profile_)); |
| 1257 } | 1254 } |
| 1258 } | 1255 } |
| 1259 | 1256 |
| 1260 void DownloadManager::OpenDownloadInShell(const DownloadItem* download, | 1257 void DownloadManager::OpenDownloadInShell(const DownloadItem* download, |
| 1261 gfx::NativeView parent_window) { | 1258 gfx::NativeView parent_window) { |
| 1262 DCHECK(file_manager_); | 1259 DCHECK(file_manager_); |
| 1263 DCHECK(MessageLoop::current() == ui_loop_); | 1260 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 1264 #if defined(OS_MACOSX) | 1261 #if defined(OS_MACOSX) |
| 1265 // Mac OS X requires opening downloads on the UI thread. | 1262 // Mac OS X requires opening downloads on the UI thread. |
| 1266 platform_util::OpenItem(download->full_path()); | 1263 platform_util::OpenItem(download->full_path()); |
| 1267 #else | 1264 #else |
| 1268 file_loop_->PostTask(FROM_HERE, | 1265 ChromeThread::PostTask( |
| 1269 NewRunnableMethod(file_manager_, | 1266 ChromeThread::FILE, FROM_HERE, |
| 1270 &DownloadFileManager::OnOpenDownloadInShell, | 1267 NewRunnableMethod( |
| 1271 download->full_path(), download->url(), parent_window)); | 1268 file_manager_, &DownloadFileManager::OnOpenDownloadInShell, |
| 1269 download->full_path(), download->url(), parent_window)); |
| 1272 #endif | 1270 #endif |
| 1273 } | 1271 } |
| 1274 | 1272 |
| 1275 void DownloadManager::OpenFilesBasedOnExtension( | 1273 void DownloadManager::OpenFilesBasedOnExtension( |
| 1276 const FilePath& path, bool open) { | 1274 const FilePath& path, bool open) { |
| 1277 FilePath::StringType extension = path.Extension(); | 1275 FilePath::StringType extension = path.Extension(); |
| 1278 if (extension.empty()) | 1276 if (extension.empty()) |
| 1279 return; | 1277 return; |
| 1280 DCHECK(extension[0] == FilePath::kExtensionSeparator); | 1278 DCHECK(extension[0] == FilePath::kExtensionSeparator); |
| 1281 extension.erase(0, 1); | 1279 extension.erase(0, 1); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 void DownloadManager::FileSelectionCanceled(void* params) { | 1398 void DownloadManager::FileSelectionCanceled(void* params) { |
| 1401 // The user didn't pick a place to save the file, so need to cancel the | 1399 // The user didn't pick a place to save the file, so need to cancel the |
| 1402 // download that's already in progress to the temporary location. | 1400 // download that's already in progress to the temporary location. |
| 1403 DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params); | 1401 DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params); |
| 1404 DownloadCancelledInternal(info->download_id, | 1402 DownloadCancelledInternal(info->download_id, |
| 1405 info->child_id, | 1403 info->child_id, |
| 1406 info->request_id); | 1404 info->request_id); |
| 1407 } | 1405 } |
| 1408 | 1406 |
| 1409 void DownloadManager::DeleteDownload(const FilePath& path) { | 1407 void DownloadManager::DeleteDownload(const FilePath& path) { |
| 1410 file_loop_->PostTask(FROM_HERE, NewRunnableFunction( | 1408 ChromeThread::PostTask( |
| 1411 &DownloadFileManager::DeleteFile, FilePath(path))); | 1409 ChromeThread::FILE, FROM_HERE, |
| 1410 NewRunnableFunction(&DownloadFileManager::DeleteFile, FilePath(path))); |
| 1412 } | 1411 } |
| 1413 | 1412 |
| 1414 | 1413 |
| 1415 void DownloadManager::DangerousDownloadValidated(DownloadItem* download) { | 1414 void DownloadManager::DangerousDownloadValidated(DownloadItem* download) { |
| 1416 DCHECK_EQ(DownloadItem::DANGEROUS, download->safety_state()); | 1415 DCHECK_EQ(DownloadItem::DANGEROUS, download->safety_state()); |
| 1417 download->set_safety_state(DownloadItem::DANGEROUS_BUT_VALIDATED); | 1416 download->set_safety_state(DownloadItem::DANGEROUS_BUT_VALIDATED); |
| 1418 download->UpdateObservers(); | 1417 download->UpdateObservers(); |
| 1419 | 1418 |
| 1420 // If the download is not complete, nothing to do. The required | 1419 // If the download is not complete, nothing to do. The required |
| 1421 // post-processing will be performed when it does complete. | 1420 // post-processing will be performed when it does complete. |
| 1422 if (download->state() != DownloadItem::COMPLETE) | 1421 if (download->state() != DownloadItem::COMPLETE) |
| 1423 return; | 1422 return; |
| 1424 | 1423 |
| 1425 file_loop_->PostTask(FROM_HERE, | 1424 ChromeThread::PostTask( |
| 1426 NewRunnableMethod(this, | 1425 ChromeThread::FILE, FROM_HERE, |
| 1427 &DownloadManager::ProceedWithFinishedDangerousDownload, | 1426 NewRunnableMethod( |
| 1428 download->db_handle(), download->full_path(), | 1427 this, &DownloadManager::ProceedWithFinishedDangerousDownload, |
| 1429 download->original_name())); | 1428 download->db_handle(), download->full_path(), |
| 1429 download->original_name())); |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 void DownloadManager::GenerateSafeFilename(const std::string& mime_type, | 1432 void DownloadManager::GenerateSafeFilename(const std::string& mime_type, |
| 1433 FilePath* file_name) { | 1433 FilePath* file_name) { |
| 1434 // Make sure we get the right file extension | 1434 // Make sure we get the right file extension |
| 1435 FilePath::StringType extension; | 1435 FilePath::StringType extension; |
| 1436 GenerateExtension(*file_name, mime_type, &extension); | 1436 GenerateExtension(*file_name, mime_type, &extension); |
| 1437 file_util::ReplaceExtension(file_name, extension); | 1437 file_util::ReplaceExtension(file_name, extension); |
| 1438 | 1438 |
| 1439 #if defined(OS_WIN) | 1439 #if defined(OS_WIN) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 | 1547 |
| 1548 if (contents) | 1548 if (contents) |
| 1549 contents->OnStartDownload(download); | 1549 contents->OnStartDownload(download); |
| 1550 } | 1550 } |
| 1551 | 1551 |
| 1552 // Clears the last download path, used to initialize "save as" dialogs. | 1552 // Clears the last download path, used to initialize "save as" dialogs. |
| 1553 void DownloadManager::ClearLastDownloadPath() { | 1553 void DownloadManager::ClearLastDownloadPath() { |
| 1554 last_download_path_ = FilePath(); | 1554 last_download_path_ = FilePath(); |
| 1555 } | 1555 } |
| 1556 | 1556 |
| OLD | NEW |