Chromium Code Reviews| 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_overwrite_infobar_delegate.h" | |
| 6 | |
| 7 #include "base/files/file_util.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "chrome/browser/infobars/infobar_service.h" | |
| 11 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | |
| 12 #include "components/infobars/core/infobar.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 | |
| 16 namespace chrome { | |
| 17 namespace android { | |
| 18 | |
| 19 DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() { | |
| 20 } | |
|
qinmin
2015/02/20 01:00:40
nit: move this to the previous line
Changwan Ryu
2015/02/23 06:50:37
This is the result of git cl format. It seems that
| |
| 21 | |
| 22 // static | |
| 23 void DownloadOverwriteInfoBarDelegate::Create( | |
| 24 InfoBarService* infobar_service, | |
| 25 const base::FilePath& suggested_path, | |
| 26 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | |
| 27 infobar_service->AddInfoBar( | |
| 28 DownloadOverwriteInfoBar::CreateInfoBar(make_scoped_ptr( | |
| 29 new DownloadOverwriteInfoBarDelegate(suggested_path, callback)))); | |
| 30 } | |
| 31 | |
| 32 void DownloadOverwriteInfoBarDelegate::OverwriteExistingFile() { | |
| 33 file_selected_callback_.Run(suggested_download_path_); | |
| 34 } | |
| 35 | |
| 36 void DownloadOverwriteInfoBarDelegate::CreateNewFile() { | |
| 37 content::BrowserThread::PostTask( | |
| 38 content::BrowserThread::FILE, FROM_HERE, | |
| 39 base::Bind(&DownloadOverwriteInfoBarDelegate::CreateNewFileInternal, | |
| 40 suggested_download_path_, file_selected_callback_)); | |
| 41 } | |
| 42 | |
| 43 DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate( | |
| 44 const base::FilePath& suggested_download_path, | |
| 45 const DownloadTargetDeterminerDelegate::FileSelectedCallback& | |
| 46 file_selected_callback) | |
| 47 : suggested_download_path_(suggested_download_path), | |
| 48 file_selected_callback_(file_selected_callback) { | |
| 49 } | |
| 50 | |
| 51 bool DownloadOverwriteInfoBarDelegate::ShouldExpire( | |
| 52 const NavigationDetails& details) const { | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 void DownloadOverwriteInfoBarDelegate::InfoBarDismissed() { | |
| 57 file_selected_callback_.Run(base::FilePath()); | |
| 58 } | |
| 59 | |
| 60 void DownloadOverwriteInfoBarDelegate::CreateNewFileInternal( | |
| 61 const base::FilePath& suggested_download_path, | |
| 62 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | |
| 63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
| 64 int uniquifier = base::GetUniquePathNumber(suggested_download_path, | |
| 65 base::FilePath::StringType()); | |
| 66 base::FilePath new_path = suggested_download_path; | |
| 67 if (uniquifier > 0) { | |
| 68 new_path = suggested_download_path.InsertBeforeExtensionASCII( | |
| 69 base::StringPrintf(" (%d)", uniquifier)); | |
| 70 } | |
| 71 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 72 base::Bind(callback, new_path)); | |
| 73 } | |
| 74 | |
| 75 } // namespace android | |
| 76 } // namespace chrome | |
| OLD | NEW |