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

Unified Diff: chrome/browser/android/download_overwrite_infobar_delegate.cc

Issue 580043002: [Android] Prompt with infobar on filename conflict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed ted's comments Created 6 years, 2 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_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..c47c7f6daca2c42043507505c92c58f2ffec0436
--- /dev/null
+++ b/chrome/browser/android/download_overwrite_infobar_delegate.cc
@@ -0,0 +1,83 @@
+// Copyright 2014 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/memory/scoped_ptr.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/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 {
+
+// static
+infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create(
Ted C 2014/10/15 00:19:44 the ordering of the .cc should match exactly the .
Changwan Ryu 2014/10/15 22:23:24 Done.
+ content::DownloadItem* download,
+ const base::FilePath& suggested_path,
+ const FileSelectedCallback& callback) {
+ DCHECK(download);
+ if (!download)
+ return NULL;
+ content::WebContents* web_contents = download->GetWebContents();
+ if (!web_contents)
+ return NULL;
+
+ InfoBarService* infobar_service =
+ InfoBarService::FromWebContents(web_contents);
+
+ DownloadOverwriteInfoBarDelegate* const delegate =
+ new DownloadOverwriteInfoBarDelegate(download, suggested_path, callback);
+ infobars::InfoBar* infobar = DownloadOverwriteInfoBar::CreateInfoBar(
+ scoped_ptr<DownloadOverwriteInfoBarDelegate>(delegate)).release();
+ return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar));
+}
+
+bool DownloadOverwriteInfoBarDelegate::Accept() {
+ callback_.Run(suggested_path_);
+ return true;
+}
+
+bool DownloadOverwriteInfoBarDelegate::Cancel() {
+ callback_.Run(base::FilePath());
+ return true;
+}
+
+DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate(
+ content::DownloadItem* download,
+ const base::FilePath& suggested_path,
+ const FileSelectedCallback& callback) :
Ted C 2014/10/15 00:19:44 the : goes on the next line (aligning with the con
Changwan Ryu 2014/10/15 22:23:24 Done.
+ pending_id_(download->GetId()),
+ suggested_path_(suggested_path),
+ callback_(callback) {
+}
+
+DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() {
+}
+
+std::string DownloadOverwriteInfoBarDelegate::GetFileName() const {
+ return suggested_path_.BaseName().value();
+}
+
+std::string DownloadOverwriteInfoBarDelegate::GetDirName() const {
+ return suggested_path_.DirName().BaseName().value();
+}
+
+std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const {
+ return suggested_path_.DirName().value();
+}
+
+DownloadOverwriteInfoBarDelegate*
+ DownloadOverwriteInfoBarDelegate::AsDownloadOverwriteInfoBarDelegate() {
+ return this;
+}
+
+} // namespace android
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698