| 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/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
| 15 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | 15 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
| 16 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
| 17 #include "content/public/browser/android/download_controller_android.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 19 | 20 |
| 21 using content::DownloadControllerAndroid; |
| 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 void DeleteExistingDownloadFile( | 25 void DeleteExistingDownloadFile( |
| 23 const base::FilePath& download_path, | 26 const base::FilePath& download_path, |
| 24 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | 27 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
| 25 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 28 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 26 base::File::Info info; | 29 base::File::Info info; |
| 27 if (GetFileInfo(download_path, &info) && !info.is_directory) | 30 if (GetFileInfo(download_path, &info) && !info.is_directory) |
| 28 base::DeleteFile(download_path, false); | 31 base::DeleteFile(download_path, false); |
| 29 | 32 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return suggested_download_path_.DirName().BaseName().value(); | 92 return suggested_download_path_.DirName().BaseName().value(); |
| 90 } | 93 } |
| 91 | 94 |
| 92 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath() | 95 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath() |
| 93 const { | 96 const { |
| 94 return suggested_download_path_.DirName().value(); | 97 return suggested_download_path_.DirName().value(); |
| 95 } | 98 } |
| 96 | 99 |
| 97 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() { | 100 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() { |
| 98 file_selected_callback_.Run(base::FilePath()); | 101 file_selected_callback_.Run(base::FilePath()); |
| 102 DownloadControllerAndroid::RecordDownloadCancelReason( |
| 103 DownloadControllerAndroid::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED); |
| 99 } | 104 } |
| 100 | 105 |
| 101 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal( | 106 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal( |
| 102 const base::FilePath& suggested_download_path, | 107 const base::FilePath& suggested_download_path, |
| 103 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | 108 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
| 104 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 109 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 105 int uniquifier = base::GetUniquePathNumber(suggested_download_path, | 110 int uniquifier = base::GetUniquePathNumber(suggested_download_path, |
| 106 base::FilePath::StringType()); | 111 base::FilePath::StringType()); |
| 107 base::FilePath new_path = suggested_download_path; | 112 base::FilePath new_path = suggested_download_path; |
| 108 if (uniquifier > 0) { | 113 if (uniquifier > 0) { |
| 109 new_path = suggested_download_path.InsertBeforeExtensionASCII( | 114 new_path = suggested_download_path.InsertBeforeExtensionASCII( |
| 110 base::StringPrintf(" (%d)", uniquifier)); | 115 base::StringPrintf(" (%d)", uniquifier)); |
| 111 } | 116 } |
| 112 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 117 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 113 base::Bind(callback, new_path)); | 118 base::Bind(callback, new_path)); |
| 114 } | 119 } |
| 115 | 120 |
| 116 } // namespace android | 121 } // namespace android |
| 117 } // namespace chrome | 122 } // namespace chrome |
| OLD | NEW |