Index: chrome/browser/android/download_overwrite_infobar_delegate.cc |
diff --git a/chrome/browser/android/download_overwrite_infobar_delegate.cc b/chrome/browser/android/download_overwrite_infobar_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d49e3c5196d556bdef9b212b70e177b24230f5cd |
--- /dev/null |
+++ b/chrome/browser/android/download_overwrite_infobar_delegate.cc |
@@ -0,0 +1,106 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/android/download_overwrite_infobar_delegate.h" |
+ |
+#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/strings/stringprintf.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "components/infobars/core/infobar.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/download_item.h" |
+#include "content/public/browser/web_contents.h" |
+#include "grit/theme_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+namespace chrome { |
+namespace android { |
+ |
+DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() { |
+} |
+ |
+// static |
+infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create( |
+ content::DownloadItem* download, |
Peter Kasting
2015/02/18 00:51:31
This argument is only used to calculate the InfoBa
Changwan Ryu
2015/02/18 07:15:02
Done.
|
+ const base::FilePath& suggested_path, |
+ const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
+ content::WebContents* web_contents = download->GetWebContents(); |
+ if (!web_contents) |
+ return NULL; |
+ |
+ InfoBarService* infobar_service = |
+ InfoBarService::FromWebContents(web_contents); |
+ |
+ scoped_ptr<infobars::InfoBar> infobar = |
Peter Kasting
2015/02/18 00:51:31
Nit: Inline this into the next statement to avoid
Changwan Ryu
2015/02/18 07:15:02
Done.
|
+ DownloadOverwriteInfoBar::CreateInfoBar( |
+ make_scoped_ptr(new DownloadOverwriteInfoBarDelegate( |
+ download, suggested_path, callback))); |
+ return infobar_service->AddInfoBar(infobar.Pass()); |
+} |
+ |
+bool DownloadOverwriteInfoBarDelegate::AcceptOverwrite() { |
Peter Kasting
2015/02/18 00:51:31
If these two button-handler functions will always
Changwan Ryu
2015/02/18 07:15:02
Done.
|
+ file_selected_callback_.Run(suggested_download_path_); |
+ return true; |
+} |
+ |
+void DownloadOverwriteInfoBarDelegate::CreateNewFileInternal( |
+ const base::FilePath& suggested_download_path, |
+ const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
+ int uniquifier = base::GetUniquePathNumber(suggested_download_path, |
+ base::FilePath::StringType()); |
+ base::FilePath new_path; |
+ if (uniquifier > 0) { |
Peter Kasting
2015/02/18 00:51:31
What if uniquifer <= 0? Then it seems like you pa
Changwan Ryu
2015/02/18 07:15:02
Fixed to overwrite the existing file.
|
+ new_path = suggested_download_path.InsertBeforeExtensionASCII( |
+ base::StringPrintf(" (%d)", uniquifier)); |
+ } |
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(callback, new_path)); |
+} |
+ |
+bool DownloadOverwriteInfoBarDelegate::CreateNewFile() { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&DownloadOverwriteInfoBarDelegate::CreateNewFileInternal, |
+ suggested_download_path_, file_selected_callback_)); |
+ return true; |
+} |
+ |
+std::string DownloadOverwriteInfoBarDelegate::GetFileName() const { |
+ return suggested_download_path_.BaseName().value(); |
+} |
+ |
+std::string DownloadOverwriteInfoBarDelegate::GetDirName() const { |
+ return suggested_download_path_.DirName().BaseName().value(); |
+} |
+ |
+std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const { |
+ return suggested_download_path_.DirName().value(); |
+} |
+ |
+void DownloadOverwriteInfoBarDelegate::InfoBarDismissed() { |
+ file_selected_callback_.Run(base::FilePath()); |
+} |
+ |
+bool DownloadOverwriteInfoBarDelegate::ShouldExpire( |
+ const NavigationDetails& details) const { |
+ return false; |
+} |
+ |
+DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate( |
+ content::DownloadItem* download, |
Peter Kasting
2015/02/18 00:51:31
This argument seems to be unused.
Changwan Ryu
2015/02/18 07:15:02
Removed
|
+ const base::FilePath& suggested_download_path, |
+ const DownloadTargetDeterminerDelegate::FileSelectedCallback& |
+ file_selected_callback) |
+ : suggested_download_path_(suggested_download_path), |
+ file_selected_callback_(file_selected_callback) { |
+} |
+ |
+} // namespace android |
+} // namespace chrome |