OLD | NEW |
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 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | |
10 #include "base/bind.h" | 9 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
13 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/macros.h" |
14 #include "base/prefs/pref_member.h" | 14 #include "base/prefs/pref_member.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
20 #include "base/task_runner_util.h" | 20 #include "base/task_runner_util.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "build/build_config.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/download/download_completion_blocker.h" | 25 #include "chrome/browser/download/download_completion_blocker.h" |
25 #include "chrome/browser/download/download_crx_util.h" | 26 #include "chrome/browser/download/download_crx_util.h" |
26 #include "chrome/browser/download/download_file_picker.h" | 27 #include "chrome/browser/download/download_file_picker.h" |
27 #include "chrome/browser/download/download_history.h" | 28 #include "chrome/browser/download/download_history.h" |
28 #include "chrome/browser/download/download_item_model.h" | 29 #include "chrome/browser/download/download_item_model.h" |
29 #include "chrome/browser/download/download_path_reservation_tracker.h" | 30 #include "chrome/browser/download/download_path_reservation_tracker.h" |
30 #include "chrome/browser/download/download_prefs.h" | 31 #include "chrome/browser/download/download_prefs.h" |
31 #include "chrome/browser/download/download_service.h" | 32 #include "chrome/browser/download/download_service.h" |
32 #include "chrome/browser/download/download_service_factory.h" | 33 #include "chrome/browser/download/download_service_factory.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 weak_ptr_factory_.InvalidateWeakPtrs(); | 206 weak_ptr_factory_.InvalidateWeakPtrs(); |
206 download_manager_ = NULL; | 207 download_manager_ = NULL; |
207 } | 208 } |
208 | 209 |
209 content::DownloadIdCallback | 210 content::DownloadIdCallback |
210 ChromeDownloadManagerDelegate::GetDownloadIdReceiverCallback() { | 211 ChromeDownloadManagerDelegate::GetDownloadIdReceiverCallback() { |
211 return base::Bind(&ChromeDownloadManagerDelegate::SetNextId, | 212 return base::Bind(&ChromeDownloadManagerDelegate::SetNextId, |
212 weak_ptr_factory_.GetWeakPtr()); | 213 weak_ptr_factory_.GetWeakPtr()); |
213 } | 214 } |
214 | 215 |
215 void ChromeDownloadManagerDelegate::SetNextId(uint32 next_id) { | 216 void ChromeDownloadManagerDelegate::SetNextId(uint32_t next_id) { |
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 217 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
217 DCHECK(!profile_->IsOffTheRecord()); | 218 DCHECK(!profile_->IsOffTheRecord()); |
218 DCHECK_NE(content::DownloadItem::kInvalidId, next_id); | 219 DCHECK_NE(content::DownloadItem::kInvalidId, next_id); |
219 next_download_id_ = next_id; | 220 next_download_id_ = next_id; |
220 | 221 |
221 IdCallbackVector callbacks; | 222 IdCallbackVector callbacks; |
222 id_callbacks_.swap(callbacks); | 223 id_callbacks_.swap(callbacks); |
223 for (IdCallbackVector::const_iterator it = callbacks.begin(); | 224 for (IdCallbackVector::const_iterator it = callbacks.begin(); |
224 it != callbacks.end(); ++it) { | 225 it != callbacks.end(); ++it) { |
225 ReturnNextId(*it); | 226 ReturnNextId(*it); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // Don't complete the download until we have an answer. | 339 // Don't complete the download until we have an answer. |
339 state->set_callback(internal_complete_callback); | 340 state->set_callback(internal_complete_callback); |
340 return false; | 341 return false; |
341 } | 342 } |
342 | 343 |
343 #endif | 344 #endif |
344 return true; | 345 return true; |
345 } | 346 } |
346 | 347 |
347 void ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal( | 348 void ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal( |
348 uint32 download_id, | 349 uint32_t download_id, |
349 const base::Closure& user_complete_callback) { | 350 const base::Closure& user_complete_callback) { |
350 DownloadItem* item = download_manager_->GetDownload(download_id); | 351 DownloadItem* item = download_manager_->GetDownload(download_id); |
351 if (!item) | 352 if (!item) |
352 return; | 353 return; |
353 if (ShouldCompleteDownload(item, user_complete_callback)) | 354 if (ShouldCompleteDownload(item, user_complete_callback)) |
354 user_complete_callback.Run(); | 355 user_complete_callback.Run(); |
355 } | 356 } |
356 | 357 |
357 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( | 358 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( |
358 DownloadItem* item, | 359 DownloadItem* item, |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 const GetFileMimeTypeCallback& callback) { | 636 const GetFileMimeTypeCallback& callback) { |
636 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 637 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
637 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), | 638 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), |
638 FROM_HERE, | 639 FROM_HERE, |
639 base::Bind(&GetMimeType, path), | 640 base::Bind(&GetMimeType, path), |
640 callback); | 641 callback); |
641 } | 642 } |
642 | 643 |
643 #if defined(FULL_SAFE_BROWSING) | 644 #if defined(FULL_SAFE_BROWSING) |
644 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 645 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
645 uint32 download_id, | 646 uint32_t download_id, |
646 DownloadProtectionService::DownloadCheckResult result) { | 647 DownloadProtectionService::DownloadCheckResult result) { |
647 DownloadItem* item = download_manager_->GetDownload(download_id); | 648 DownloadItem* item = download_manager_->GetDownload(download_id); |
648 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) | 649 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) |
649 return; | 650 return; |
650 | 651 |
651 DVLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 652 DVLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
652 << " verdict = " << result; | 653 << " verdict = " << result; |
653 // We only mark the content as being dangerous if the download's safety state | 654 // We only mark the content as being dangerous if the download's safety state |
654 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 655 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
655 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 656 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 scoped_refptr<extensions::CrxInstaller> installer = | 704 scoped_refptr<extensions::CrxInstaller> installer = |
704 content::Source<extensions::CrxInstaller>(source).ptr(); | 705 content::Source<extensions::CrxInstaller>(source).ptr(); |
705 content::DownloadOpenDelayedCallback callback = | 706 content::DownloadOpenDelayedCallback callback = |
706 crx_installers_[installer.get()]; | 707 crx_installers_[installer.get()]; |
707 crx_installers_.erase(installer.get()); | 708 crx_installers_.erase(installer.get()); |
708 callback.Run(installer->did_handle_successfully()); | 709 callback.Run(installer->did_handle_successfully()); |
709 #endif | 710 #endif |
710 } | 711 } |
711 | 712 |
712 void ChromeDownloadManagerDelegate::OnDownloadTargetDetermined( | 713 void ChromeDownloadManagerDelegate::OnDownloadTargetDetermined( |
713 int32 download_id, | 714 int32_t download_id, |
714 const content::DownloadTargetCallback& callback, | 715 const content::DownloadTargetCallback& callback, |
715 scoped_ptr<DownloadTargetInfo> target_info) { | 716 scoped_ptr<DownloadTargetInfo> target_info) { |
716 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 717 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
717 DownloadItem* item = download_manager_->GetDownload(download_id); | 718 DownloadItem* item = download_manager_->GetDownload(download_id); |
718 if (item) { | 719 if (item) { |
719 if (!target_info->target_path.empty() && | 720 if (!target_info->target_path.empty() && |
720 IsOpenInBrowserPreferreredForFile(target_info->target_path) && | 721 IsOpenInBrowserPreferreredForFile(target_info->target_path) && |
721 target_info->is_filetype_handled_safely) | 722 target_info->is_filetype_handled_safely) |
722 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true); | 723 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true); |
723 | 724 |
(...skipping 29 matching lines...) Expand all Loading... |
753 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 754 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
754 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 755 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
755 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 756 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
756 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 757 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
757 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 758 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
758 return true; | 759 return true; |
759 } | 760 } |
760 #endif | 761 #endif |
761 return false; | 762 return false; |
762 } | 763 } |
OLD | NEW |