OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/download/chrome_download_manager_overwrite_info
bar_delegate.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" |
| 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
| 14 #include "components/infobars/core/infobar.h" |
| 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 17 |
| 18 namespace chrome { |
| 19 namespace android { |
| 20 |
| 21 ChromeDownloadManagerOverwriteInfoBarDelegate:: |
| 22 ~ChromeDownloadManagerOverwriteInfoBarDelegate() { |
| 23 } |
| 24 |
| 25 // static |
| 26 void ChromeDownloadManagerOverwriteInfoBarDelegate::Create( |
| 27 InfoBarService* infobar_service, |
| 28 const base::FilePath& suggested_path, |
| 29 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
| 30 infobar_service->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar( |
| 31 make_scoped_ptr(new ChromeDownloadManagerOverwriteInfoBarDelegate( |
| 32 suggested_path, callback)))); |
| 33 } |
| 34 |
| 35 ChromeDownloadManagerOverwriteInfoBarDelegate:: |
| 36 ChromeDownloadManagerOverwriteInfoBarDelegate( |
| 37 const base::FilePath& suggested_download_path, |
| 38 const DownloadTargetDeterminerDelegate::FileSelectedCallback& |
| 39 file_selected_callback) |
| 40 : suggested_download_path_(suggested_download_path), |
| 41 file_selected_callback_(file_selected_callback) { |
| 42 } |
| 43 |
| 44 void ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() { |
| 45 file_selected_callback_.Run(suggested_download_path_); |
| 46 } |
| 47 |
| 48 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() { |
| 49 content::BrowserThread::PostTask( |
| 50 content::BrowserThread::FILE, FROM_HERE, |
| 51 base::Bind( |
| 52 &ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal, |
| 53 suggested_download_path_, file_selected_callback_)); |
| 54 } |
| 55 |
| 56 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetFileName() const { |
| 57 return suggested_download_path_.BaseName().value(); |
| 58 } |
| 59 |
| 60 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirName() const { |
| 61 return suggested_download_path_.DirName().BaseName().value(); |
| 62 } |
| 63 |
| 64 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath() |
| 65 const { |
| 66 return suggested_download_path_.DirName().value(); |
| 67 } |
| 68 |
| 69 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() { |
| 70 file_selected_callback_.Run(base::FilePath()); |
| 71 } |
| 72 |
| 73 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal( |
| 74 const base::FilePath& suggested_download_path, |
| 75 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
| 76 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 77 int uniquifier = base::GetUniquePathNumber(suggested_download_path, |
| 78 base::FilePath::StringType()); |
| 79 base::FilePath new_path = suggested_download_path; |
| 80 if (uniquifier > 0) { |
| 81 new_path = suggested_download_path.InsertBeforeExtensionASCII( |
| 82 base::StringPrintf(" (%d)", uniquifier)); |
| 83 } |
| 84 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 85 base::Bind(callback, new_path)); |
| 86 } |
| 87 |
| 88 } // namespace android |
| 89 } // namespace chrome |
OLD | NEW |