Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1430)

Unified Diff: chrome/browser/android/download/download_overwrite_infobar_delegate_native_initiated.cc

Issue 580043002: [Android] Prompt with infobar on filename conflict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: avoided Java-only infobar Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/download/download_overwrite_infobar_delegate_native_initiated.cc
diff --git a/chrome/browser/android/download/download_overwrite_infobar_delegate_native_initiated.cc b/chrome/browser/android/download/download_overwrite_infobar_delegate_native_initiated.cc
new file mode 100644
index 0000000000000000000000000000000000000000..57d9485f2a518281c0a512fde3a91493677a01be
--- /dev/null
+++ b/chrome/browser/android/download/download_overwrite_infobar_delegate_native_initiated.cc
@@ -0,0 +1,93 @@
+// 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/download_overwrite_infobar_delegate_native_initiated.h>
+#include "base/files/file_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
+#include "components/infobars/core/infobar.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+
+namespace chrome {
+namespace android {
+
+DownloadOverwriteInfoBarDelegateNativeInitiated::
+ ~DownloadOverwriteInfoBarDelegateNativeInitiated() {
+}
+
+// static
+void DownloadOverwriteInfoBarDelegateNativeInitiated::Create(
+ InfoBarService* infobar_service,
+ const base::FilePath& suggested_path,
+ const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
+ infobar_service->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar(
+ make_scoped_ptr(new DownloadOverwriteInfoBarDelegateNativeInitiated(
+ suggested_path, callback))));
+}
+
+void DownloadOverwriteInfoBarDelegateNativeInitiated::OverwriteExistingFile() {
+ file_selected_callback_.Run(suggested_download_path_);
+}
+
+void DownloadOverwriteInfoBarDelegateNativeInitiated::CreateNewFile() {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DownloadOverwriteInfoBarDelegateNativeInitiated::
+ CreateNewFileInternal,
+ suggested_download_path_, file_selected_callback_));
+}
+
+std::string DownloadOverwriteInfoBarDelegateNativeInitiated::GetFileName()
+ const {
Peter Kasting 2015/02/25 06:24:57 Nit: Arguable, but I think this wrapping would be
Changwan Ryu 2015/03/02 14:46:37 Hmm... I tried it but git cl format reverses the c
+ return suggested_download_path_.BaseName().value();
+}
+
+std::string DownloadOverwriteInfoBarDelegateNativeInitiated::GetDirName()
+ const {
+ return suggested_download_path_.DirName().BaseName().value();
+}
+
+std::string DownloadOverwriteInfoBarDelegateNativeInitiated::GetDirFullPath()
+ const {
+ return suggested_download_path_.DirName().value();
+}
+
+DownloadOverwriteInfoBarDelegateNativeInitiated::
+ DownloadOverwriteInfoBarDelegateNativeInitiated(
+ const base::FilePath& suggested_download_path,
+ const DownloadTargetDeterminerDelegate::FileSelectedCallback&
+ file_selected_callback)
+ : suggested_download_path_(suggested_download_path),
+ file_selected_callback_(file_selected_callback) {
+}
+
+bool DownloadOverwriteInfoBarDelegateNativeInitiated::ShouldExpire(
+ const infobars::InfoBarDelegate::NavigationDetails& details) const {
+ return false;
Peter Kasting 2015/02/25 06:24:57 Seems like method implementations like this which
Changwan Ryu 2015/03/02 14:46:36 Done.
+}
+
+void DownloadOverwriteInfoBarDelegateNativeInitiated::InfoBarDismissed() {
+ file_selected_callback_.Run(base::FilePath());
+}
+
+void DownloadOverwriteInfoBarDelegateNativeInitiated::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 = suggested_download_path;
+ if (uniquifier > 0) {
+ new_path = suggested_download_path.InsertBeforeExtensionASCII(
+ base::StringPrintf(" (%d)", uniquifier));
+ }
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, new_path));
+}
+
+} // namespace android
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698