| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/download/chrome_download_manager_overwrite_info
bar_delegate.h" | 5 #include "chrome/browser/android/download/chrome_download_manager_overwrite_info
bar_delegate.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/android/path_utils.h" | 11 #include "base/android/path_utils.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "chrome/browser/android/download/download_controller.h" | 15 #include "chrome/browser/android/download/download_controller.h" |
| 16 #include "chrome/browser/android/download/download_manager_service.h" |
| 16 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 17 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | 18 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
| 18 #include "components/infobars/core/infobar.h" | 19 #include "components/infobars/core/infobar.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 25 void DeleteExistingDownloadFileDone( |
| 26 const base::FilePath& download_path, |
| 27 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
| 28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 29 DownloadManagerService::GetInstance()->RemoveDownloadsForPath( |
| 30 download_path); |
| 31 callback.Run(download_path); |
| 32 } |
| 33 |
| 24 void DeleteExistingDownloadFile( | 34 void DeleteExistingDownloadFile( |
| 25 const base::FilePath& download_path, | 35 const base::FilePath& download_path, |
| 26 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | 36 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
| 27 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 37 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 28 base::File::Info info; | 38 base::File::Info info; |
| 29 if (GetFileInfo(download_path, &info) && !info.is_directory) | 39 if (GetFileInfo(download_path, &info) && !info.is_directory) |
| 30 base::DeleteFile(download_path, false); | 40 base::DeleteFile(download_path, false); |
| 31 | 41 |
| 32 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 42 content::BrowserThread::PostTask( |
| 33 base::Bind(callback, download_path)); | 43 content::BrowserThread::UI, FROM_HERE, |
| 44 base::Bind(&DeleteExistingDownloadFileDone, download_path, callback)); |
| 34 } | 45 } |
| 35 | 46 |
| 36 void CreateNewFileDone( | 47 void CreateNewFileDone( |
| 37 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback, | 48 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback, |
| 38 const base::FilePath& target_path, bool verified) { | 49 const base::FilePath& target_path, bool verified) { |
| 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 40 if (verified) | 51 if (verified) |
| 41 callback.Run(target_path); | 52 callback.Run(target_path); |
| 42 else | 53 else |
| 43 callback.Run(base::FilePath()); | 54 callback.Run(base::FilePath()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 file_selected_callback_(file_selected_callback) { | 93 file_selected_callback_(file_selected_callback) { |
| 83 download_item_->AddObserver(this); | 94 download_item_->AddObserver(this); |
| 84 } | 95 } |
| 85 | 96 |
| 86 infobars::InfoBarDelegate::InfoBarIdentifier | 97 infobars::InfoBarDelegate::InfoBarIdentifier |
| 87 ChromeDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const { | 98 ChromeDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const { |
| 88 return CHROME_DOWNLOAD_MANAGER_OVERWRITE_INFOBAR_DELEGATE; | 99 return CHROME_DOWNLOAD_MANAGER_OVERWRITE_INFOBAR_DELEGATE; |
| 89 } | 100 } |
| 90 | 101 |
| 91 bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() { | 102 bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() { |
| 103 if (!download_item_) |
| 104 return true; |
| 105 |
| 92 content::BrowserThread::PostTask( | 106 content::BrowserThread::PostTask( |
| 93 content::BrowserThread::FILE, FROM_HERE, | 107 content::BrowserThread::FILE, FROM_HERE, |
| 94 base::Bind(&DeleteExistingDownloadFile, suggested_download_path_, | 108 base::Bind(&DeleteExistingDownloadFile, suggested_download_path_, |
| 95 file_selected_callback_)); | 109 file_selected_callback_)); |
| 96 return true; | 110 return true; |
| 97 } | 111 } |
| 98 | 112 |
| 99 bool ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() { | 113 bool ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() { |
| 100 if (!download_item_) | 114 if (!download_item_) |
| 101 return true; | 115 return true; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 128 } | 142 } |
| 129 | 143 |
| 130 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() { | 144 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() { |
| 131 file_selected_callback_.Run(base::FilePath()); | 145 file_selected_callback_.Run(base::FilePath()); |
| 132 DownloadController::RecordDownloadCancelReason( | 146 DownloadController::RecordDownloadCancelReason( |
| 133 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED); | 147 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED); |
| 134 } | 148 } |
| 135 | 149 |
| 136 } // namespace android | 150 } // namespace android |
| 137 } // namespace chrome | 151 } // namespace chrome |
| OLD | NEW |