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

Side by Side 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 comments and added 'create new file' behavior Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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_path.h"
8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/infobars/core/infobar.h"
16 #include "content/public/browser/download_item.h"
17 #include "content/public/browser/web_contents.h"
18 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
20
21 namespace chrome {
22 namespace android {
23
24 DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() {
25 }
26
27 // static
28 infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create(
29 content::DownloadItem* download,
30 const base::FilePath& suggested_path,
31 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
32 if (!download)
Ted C 2014/10/29 00:15:12 At a minimum, you should be able to remove this as
Changwan Ryu 2015/02/16 01:01:03 Done.
33 return NULL;
34
35 content::WebContents* web_contents = download->GetWebContents();
36 if (!web_contents)
37 return NULL;
38
39 InfoBarService* infobar_service =
40 InfoBarService::FromWebContents(web_contents);
41
42 scoped_ptr<infobars::InfoBar> infobar =
43 DownloadOverwriteInfoBar::CreateInfoBar(
44 make_scoped_ptr(new DownloadOverwriteInfoBarDelegate(
45 download, suggested_path, callback)));
46 return infobar_service->AddInfoBar(infobar.Pass());
47 }
48
49 bool DownloadOverwriteInfoBarDelegate::AcceptOverwrite() {
50 file_selected_callback_.Run(suggested_download_path_);
51 return true;
52 }
53
54 bool DownloadOverwriteInfoBarDelegate::CreateNewFile() {
55 // TODO(changwan): use GetUniquePath() instead once
56 // https://codereview.chromium.org/493363003/ lands.
57 int uniquifier = base::GetUniquePathNumber(suggested_download_path_,
58 base::FilePath::StringType());
59 if (uniquifier > 0) {
60 file_selected_callback_.Run(
61 suggested_download_path_.InsertBeforeExtensionASCII(
62 base::StringPrintf(" (%d)", uniquifier)));
63 } else {
64 file_selected_callback_.Run(base::FilePath());
65 }
66 return true;
67 }
68
69 std::string DownloadOverwriteInfoBarDelegate::GetFileName() const {
70 return suggested_download_path_.BaseName().value();
71 }
72
73 std::string DownloadOverwriteInfoBarDelegate::GetDirName() const {
74 return suggested_download_path_.DirName().BaseName().value();
75 }
76
77 std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const {
78 return suggested_download_path_.DirName().value();
79 }
80
81 void DownloadOverwriteInfoBarDelegate::InfoBarDismissed() {
82 file_selected_callback_.Run(base::FilePath());
83 }
84
85 DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate(
86 content::DownloadItem* download,
87 const base::FilePath& suggested_download_path,
88 const DownloadTargetDeterminerDelegate::FileSelectedCallback&
89 file_selected_callback)
90 : suggested_download_path_(suggested_download_path),
91 file_selected_callback_(file_selected_callback) {
92 }
93
94 } // namespace android
95 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698